Solve and optimize in loop

596 views
Skip to first unread message

hh....@lycos.com

unread,
Nov 16, 2011, 9:53:28 AM11/16/11
to gams...@googlegroups.com
Hello all,

I am a beginner, trying to write this in GAMS.
I have a set t(time) and other sets and I want to calculate something that is growing over time.
p(0) (p at t = 0) is the initial value.
X is the growing factor, a constant.
O(a,b) is a variables that needs to be optimized over time period, a and b is set names
So I wrote something like:

//the empty lines contains  model
//.................................................
//.................................................
model mymodel/ALL;
loop(t,
        solve problem maximizing my objective function;     // to get O(a,b) and other variables
        p(t) = (1+X) * p(t-1) - O(a,b,t-1);
);

I know how to do this in C/C++ with while do loop or for loop, but I am not familiar yet with GAMS syntax.
Thanks.

regards,
sungai.

Nikit Abhyankar

unread,
Nov 16, 2011, 3:17:48 PM11/16/11
to gams...@googlegroups.com
You cannot put solve statement or equations in the loop statements.
So, take the solve statement out of the loop and it should work. 

--
You received this message because you are subscribed to the Google Groups "gamsworld" group.
To post to this group, send email to gams...@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.

Steven Dirkse

unread,
Nov 16, 2011, 8:45:00 PM11/16/11
to gams...@googlegroups.com
Sungai,

You should have a look at the models in the GAMS model library. For
example, the model icut has a solve within a loop, etc.

-Steve

> --
> You received this message because you are subscribed to the Google Groups
> "gamsworld" group.
> To post to this group, send email to gams...@googlegroups.com.
> To unsubscribe from this group, send email to
> gamsworld+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/gamsworld?hl=en.
>

--
Steven Dirkse, Ph.D.
GAMS Development Corp.,  Washington DC
Voice: (202)342-0180     Fax: (202)342-0181
sdi...@gams.com
http://www.gams.com

hh....@lycos.com

unread,
Nov 17, 2011, 5:53:32 AM11/17/11
to gams...@googlegroups.com
Thanks for your insight.
My solution shouldn't be integers. And to change it to MIP model could be painful for me.
Does icut also cover non MIP?

regards,
sungai.

hh....@lycos.com

unread,
Nov 17, 2011, 6:00:34 AM11/17/11
to gams...@googlegroups.com
Thanks for your insight.
My solution shouldn't be integers. And to change it to MIP model could be painful for me.
However, it is intended to be an equilibrium model.

hh....@lycos.com

unread,
Nov 17, 2011, 6:02:17 AM11/17/11
to gams...@googlegroups.com
Another thing, it is supposed to be an equilibrium model
Thanks. Sorry for double message.

regards,
sungai.
Reply all
Reply to author
Forward
0 new messages