I need the solution of last iteration to construct the model of next iteration. it means each iteration has different model.But it is illegal to define model in a loop.How to fix this.Thanks.
If you are doing an iterative model, where you want time period n+1 to start with variable values from the previous solution what you could do something along these lines.
Pseudo Code:
* Declare your model
$INCLUDE ModelDeclare.inc
* Call initialization file, where you inititalize variable levels
$INCLUDE varinit.inc
loop(yrs,
Solve ModelName using XXX solver
* Call another include file where you unload the values of the model solution into a data parameter with a yrs dimension
$INCLUDE SolutionSave.inc
* Now you can update the model variables with current values, as well as any exogenous trends you might want "shocking" your model from its previous state
$INCLUDE VarUpdate.inc
* End of Loop
);
If you actually want a different model to be called for each iteration, you could try something using if statements, where you can define all of the potential models you would call before the loop, and then based on conditional statements chose which model is actually used in a particular year. If you did this, then you would need to have the Solve statement within an If Statement, and in your varupdate.inc file you would need to assign some kind of counter or state parameter for which model to use in the next solution. I've never done this before so I am not sure if it would work, but I would do something like this