results from comparative analysis Topic is solved

Problems with syntax of GAMS
Post Reply
M07a2M3D
User
User
Posts: 5
Joined: 2 years ago

results from comparative analysis

Post by M07a2M3D »

Hello,
I need some help with my code.
i made a comparative analysis with the loop procedure.
i was able to determine the best scenario and it set.
but when i want to write the results from optimal scenario to an output file, the assigned results were always from the last scenario.
Do you have any ideas how to write the results from the best scenario.
Cordialy.

Code: Select all

Sets S             'Scenarios for comparative analysis' /S1*S8/
     OptCostSet(S) ' Optimal cost scenario'
;

Table PM(S,t) 'Scenarios of plannend PM'

            1   2   3  
        S1  0   0   0   
        S2  1   0   0   
        S3  0   1   0   
        S4  0   0   1   
        S5  1   1   0   
        S6  1   0   1   
        S7  0   1   1  
        S8  1   1   1  
;

Parameters Output(*,*,*) 'Results'
           saveM(t)      'saving M(t) of base scenario'
           saveTC(S)     'saving results of each scenario'
           OptimalCost 'least cost'
;

saveM(t) = M(t) ;

Loop (S,
      M(t) = saveM(t) ;
      M(t) = PM(S,t)  ;
      
*Option MINLP = KNITRO ;
Option MIP = CPLEX ;

Solve CSPLSP_BRO using MIP minimizing TC ;

*display TC.l, Xm.l, Xr.l, Xo.l, Xc.l, Xb.l, Is.l, Ir.l, Io.l, Ic.l, W.l, Ym.l, Yr.l, M.l, Z.l, a.l, EN.l ;

saveTC(S) = TC.l ;

) ;

OptimalCost = smin(S,saveTC(S));
OptCostSet(S) = saveTC(S) = OptimalCost ;

Loop (S,
If (saveTC(S) = OptimalCost,

Output("a",S,t)   = a.l(t)  ;
);
);

Option Output :3:2:1 ;
display Output
GFA
User
User
Posts: 50
Joined: 5 years ago

Re: results from comparative analysis

Post by GFA »

Hi M07a2M3D,
Your code is not running, seems like you only posted some parts of it. This is not very helpful as it is not possible to reproduce your problem.
Cheers,
GFA
M07a2M3D
User
User
Posts: 5
Joined: 2 years ago

Re: results from comparative analysis

Post by M07a2M3D »

Hello GFA
CSPLSP.gms
(4.44 KiB) Downloaded 208 times

I thought that you don't need all of the code
I attached the file
thank you
GFA
User
User
Posts: 50
Joined: 5 years ago

Re: results from comparative analysis

Post by GFA »

M07a2M3D wrote: 1 year ago Hello GFACSPLSP.gms
I thought that you don't need all of the code
I attached the file
thank you
Dear M07a2M3D ,

The problem is that the values you assign to the output parameter (M, TC, etc.) are not stored per loop, therefore after the last solve they are assigned the value from this last solve.
There are multiple ways to solve this but one solution would be to move the output reporting inside the solve loop, then you have the output per solve (S1*S8).
If you want you can check for lowest/optimal cost per solve loop and only report this solve in the output (see code below).

Hope this helps.

Cheers,
GFA

Code: Select all

OptimalCost = 10**10;

Loop (S,
      M(t) = saveM(t) ;
      M(t) = PM(S,t)  ;
      
Option MIP = CPLEX ;

Solve CSPLSP_BRO using MIP minimizing TC ;

if(TC.l < OptimalCost,
Output(S,"M",t)   = M(t)    ;
Output(S,"TC","") = TC.l    ;
Output(S,"Xm",t)  = Xm.l(t) ;
Output(S,"Xr",t)  = Xr.l(t) ;
Output(S,"Xo",t)  = Xo.l(t) ;
Output(S,"Xb",t)  = Xb.l(t) ;
Output(S,"Is",t)  = Is.l(t) ;
Output(S,"Ir",t)  = Ir.l(t) ;
Output(S,"Io",t)  = Io.l(t) ;
Output(S,"Ic",t)  = Ic.l(t) ;
Output(S,"W",t)   = W.l(t)  ;
Output(S,"Ym",t)  = Ym.l(t) ;
Output(S,"Yr",t)  = Yr.l(t) ;
Output(S,"Z",t)   = Z.l(t)  ;
Output(S,"a",t)   = a.l(t)  ;
Output(S,"EN",t)  = EN.l(t) ;
OptimalCost = TC.l
);
);
M07a2M3D
User
User
Posts: 5
Joined: 2 years ago

Re: results from comparative analysis

Post by M07a2M3D »

Thank you GFA
I am really grateful for your help
Cordially
M07a2M3D
User
User
Posts: 5
Joined: 2 years ago

Re: results from comparative analysis

Post by M07a2M3D »

Dear GFA
Is there a way to display only the results from the best scenario.
It true that the code worked before because the best scenario was the first one.
But when I changed the parameters, the best scenario became 'S3'
So the displayed results are from all scenarios where the cost was better from the scenarios before.
For more informations, please check the file attached.
Cordially
CSPLSP.gms
(4.35 KiB) Downloaded 170 times
GFA
User
User
Posts: 50
Joined: 5 years ago

Re: results from comparative analysis

Post by GFA »

Dear M07a2M3D,

There are multiple ways to do this, but one would be to remove the S-index of Output parameter and save the scenario number as a parameter value:

Code: Select all

if( TC.l < OptimalCost,
Output("S","")${saveTC(S)} = ORD(S);
Output("M",t)   = M(t)    ;
Output("TC","") = TC.l    ;
Output("Xm",t)  = Xm.l(t) ;
Output("Xr",t)  = Xr.l(t) ;
Output("Xo",t)  = Xo.l(t) ;
Output("Xb",t)  = Xb.l(t) ;
Output("Is",t)  = Is.l(t) ;
Output("Ir",t)  = Ir.l(t) ;
Output("Io",t)  = Io.l(t) ;
Output("Ic",t)  = Ic.l(t) ;
Output("W",t)   = W.l(t)  ;
Output("Ym",t)  = Ym.l(t) ;
Output("Yr",t)  = Yr.l(t) ;
Output("Z",t)   = Z.l(t)  ;
Output("a",t)   = a.l(t)  ;
Output("EN",t)  = EN.l(t) ;
OptimalCost = TC.l
);
Hope this helps.

Cheers,
GFA
M07a2M3D
User
User
Posts: 5
Joined: 2 years ago

Re: results from comparative analysis

Post by M07a2M3D »

Dear GFA
Thank you for your help.
Post Reply