loop Dynamic set

Description of the issue

My current gams script is:

Set
t time
tc contract type
et Time scenery

set PI(t) Initial period;
PI(t) = t.first

set PFI(t) final period;
PFI(t) = t.last;
set TIM(et,t) time loop

set CD_T(t) Set Dynamic time;
CD_T(t) = Sum(et,TIM(et,t))

loop(et,
loop(CD_T(t),
PFI(t)= yes;
PFI(t-1) = no;
PSF(t) = yes;
)

My issue is with the loop over CD_T(t), I am translating in gamspy as

for idx, et_ in enumerate(et.tolist())
for idx2,CD_Tt_ in enumerate(CD_T.toList())
PFI[t] = True
PFI[t.lag(1,“linear”)] = False
PSF[t] = True
But I am not getting the same results

Error message and stack trace

Error message and stack trace goes here.

GAMSPy version

This information can be retrieved with:

gamspy -v

You can do the translation as follows:

t_vals = CD_T.toList()
for idx, et_ in enumerate(et.tolist()):
  for idx2, CD_Tt_ in enumerate(t_vals):
        if idx2 > 0:
            PFI[CD_Tt_] = True
            PFI[t_vals[idx2 - 1]] = False
            PSF[CD_Tt_] = True

I don’t understand why you need to loop over “et” but I assume you didn’t share the whole code and there is other stuff going on.