Same Model for Different Data Topic is solved

Problems with modeling
Post Reply
diabolik
User
User
Posts: 14
Joined: 1 year ago

Same Model for Different Data

Post by diabolik »

Hey, I have a problem where I need to solve a model for each row of an Excel file. The model for row 1 is as follows:

Code: Select all

Sets
i   sample number /1*1817/
j   criterion /1*17/;

alias(i, k);

Table a(k,j)
$call=xls2gms r=a1:r1818 i=calculations.xls o=parc.inc
$include parc.inc
;

Variables
w(i,j)
z    objective;

Positive Variable
w(i,j);

Equations
constraint1
objective;

objective..z=e=sum(j,w("1",j)*a("1",j));
constraint1(k)..sum(j,w("1",j)*a(k,j))=l=1;
Do you know if there is a shorter way to solve this model for each of the alternatives? Because it could save me huuuge amount of time. I checked the guide but couldn't find anything related. Would be so glad if you could help.

All the best.
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: Same Model for Different Data

Post by abhosekar »

You can modify your code as follows (add singleton set, modify equations, and add a loop to solve).

Code: Select all

singleton set ii(i);
objective.. z =e= sum(ii, sum(j, w(ii, j)) );
constraint1(ii, k)..sum(j,w(ii,j)*a(k,j))=l=1;

loop(i, 
ii(i) = yes;
solve ...
);
The above code defines objective function as a sum over a singleton set ii. and constraint1 defined over ii, k.
ii can only have one element.
You then loop over rows (set i). In each iteration, you set one ii to yes the rest becomes by default no.
Now if you look at your model for first row, it is exactly what you have shown in your code block.

Hope this helps.

( I have not checked the syntax of the above code block so please understand the idea before implementing)

- Atharv
Post Reply