Error 149, Uncontrolled set entered as constant

Problems with modeling
Post Reply
sachinpatel_03
User
User
Posts: 5
Joined: 4 months ago

Error 149, Uncontrolled set entered as constant

Post by sachinpatel_03 » 3 months ago

hi,

I want to use values of a 2D parameter by applying a loop in such a way that for every run of the loop, the values of only one set is changing while the value of other set is constant during a single run and changes with an increment of 1 when the loop starts again. eg. in a [168X99] matrix the model is reading values from every column until 99 runs of the loop which mean my DATA is a [168X99] matrix but for every run the data i want to use is [168Xi] where i=1,2,3,4,.........,99

my code is like>

sets
s /1*80/
t(*) set of time periods (168 elements)
scn /1*99/;

load s,t,scn;

variables
Profit, OF,.......;

Parameters
Time, Econcost(t,scn), Price(s),......;

Equations

Profit_eq, OF_eq;

Profit_eq.. PROFIT =E= TIME*PRICE(s) - TIME*sum(t,PCON(t)*ECONCOST(t,scn)); :roll:
OF_eq.. OF=E=PROFIT*(1-MODE);


please help. how to encode the logic into the program? profit equation is the line where I'm getting the error 149 at the parameter econcost.

cbhomia
User
User
Posts: 8
Joined: 5 months ago

Re: Error 149, Uncontrolled set entered as constant

Post by cbhomia » 3 months ago

Sachin,

I don't think the error has anything to do with your logic, which was difficult to understand to begin with.
But, the fix of your error is simple. In the profit equation, you have the set scn, which is not controlled.

Profit_eq.. PROFIT =E= TIME*PRICE(s) - TIME*sum(t,PCON(t)*ECONCOST(t,scn));

you need to sum it over both t and scn. The equation should look like this

Profit_eq.. PROFIT =E= TIME*PRICE(s) - TIME*sum((t,scn),PCON(t)*ECONCOST(t,scn));

This will remove the error 149. Hope this helps.

-Chintan

sachinpatel_03
User
User
Posts: 5
Joined: 4 months ago

Re: Error 149, Uncontrolled set entered as constant

Post by sachinpatel_03 » 3 months ago

Hello Chintan,

yes, it removed the error but I'm still stuck with the loop. As I want to do it for the scn (one increment at a time).


for looping I'm doing like....

Model test /all/;

OPTION MIP = CPLEX;
OPTION optcr=1;
OPTION limrow=0;
OPTION reslim=72000;

Solve test using MIP maximizing OF;

FILE Results /test_results.xls/;
PUT Results;
Results.pc = 6;
Results.pw = 32767;

PUT 'test'//;
PUT 'CPU(s)','nequations','single var','bin var','model status','solver status'/;

if(MODE = 1,
PUT 'OF =','ECONS'//;
else
PUT 'OF =','PROFIT'//;
);
Loop(scn$(ord(scn)=3), :!:
PUT 'Profit',PROFIT.l,'[€]'/;
PUT 'Sales',(sum((s,t)$(FP(s)),TIME*F.l(s,t)*PRICE(s))),'[€]'/;
PUT 'E cost',(TIME*sum(t,PCON(t)*ECONCOST(t,scn)+(sum(i,UTCONS.l(i,'EE',t))-PCON(t))*ECOST(t))),'[€]'/;
.................
..................
................
)
;


in the line where loop statement starts, I'm trying to reproduce the result of a previously optimized case but I'm not getting the same result. my profit is even coming in negative and by the logic of if statement(just over loop statement) if the profit is in a negative(loss) it should give ECONS.

so, I'm a little confused here that what's happening.

cbhomia
User
User
Posts: 8
Joined: 5 months ago

Re: Error 149, Uncontrolled set entered as constant

Post by cbhomia » 3 months ago

Hello Sachin,

Quick question : were you able to run the model for just 1 instance ?

sachinpatel_03
User
User
Posts: 5
Joined: 4 months ago

Re: Error 149, Uncontrolled set entered as constant

Post by sachinpatel_03 » 2 months ago

Hi,

Thanks for checking it up.
The code is running but I'm not able to reproduce the result.

Basically I'd say my code is still not working as whatever changes I'm making into loop with $ conditions and if statements the code is giving me the same output every time which is different from the actual output previously obtained from a deterministic scenario.

So code is running but I dont know for which instance... :roll:

User avatar
dirkse
Moderator
Moderator
Posts: 36
Joined: 2 years ago
Location: Fairfax, VA

Re: Error 149, Uncontrolled set entered as constant

Post by dirkse » 2 months ago

Sachin,

I'm not sure I understand what you are trying to do, but it seems like you want to run a model for a number of different scenarios in the set scn. For each element of scn you will have some different inputs and you'll get (potentially) a different solution. But each solve considers only a single scenario. Is this correct?

If so, have a look at the trnsgrid model from the GAMS Model Library. This illustrates the idea behind formulating such a model: don't use the scenario index in the model itself, but loop over the scenarios, setting the input data , solving, and saving the solution each trip through the loop.

The trnsgrid also illustrates how to use a grid solver, which might be extra complication since it doesn't directly address your question. The paperco model in GAMSLIB is simpler so you might want to look at that instead.

-Steve

sachinpatel_03
User
User
Posts: 5
Joined: 4 months ago

Re: Error 149, Uncontrolled set entered as constant

Post by sachinpatel_03 » 2 months ago

Hi Steve,

Thank you so much...

Yes, you understood my problem completely and perfectly. I'll take a look at the example in gamslib and will post the progress here for your acknowledgement.

once again thank you.

Post Reply