Hello,
How can I translate a set of constraints into a "loop of variable fixations"? This is, in the example below I am trying to shift the Loop-constraint to a set of Fix-statements:
* simple transportation model .. ;
%Let Sources=10;
%Let Plants=%Eval(&Sources.*2);
Data Costs;
Do Source=1 To &Sources.;
Do Plant=1 To &Plants.;
Costs=Ranuni(1)*4+19; Output;
End;
End;
Run;
Data Demand;
Do Plant=1 To &Plants.;
Qty=Ranuni(1)*20+200; Output;
End;
Run;
Data Supply;
Do Source=1 To &Sources.;
Qty=Ranuni(1)*15+600; Output;
End;
Run;
Data Fixed;
Source=1; Plant=7; Fixed=50; Output;
Source=1; Plant=8; Fixed=50; Output;
Source=1; Plant=9; Fixed=50; Output;
Source=1; Plant=10; Fixed=50; Output;
Source=2; Plant=9; Fixed=50; Output;
Source=2; Plant=10; Fixed=50; Output;
Run;
Data Costs;
Merge Costs (in=inC) Fixed;
By Source Plant;
If inC;
Run;
Proc Optmodel;
Set <Num,Num> q_w;
Num Costs{q_w};
Num Fixed_F{q_w};
Read Data Costs Into q_w=[Source Plant] Costs=Costs Fixed_F=Fixed;
Set Sources=Setof{<q,w> in q_w} q;
Set Plants=Setof{<q,w> in q_w} w;
Num Demand{Plants};
Num Supply{Sources};
Read Data Demand Into [Plants=Plant] Demand=Qty;
Read Data Supply Into [Sources=Source] Supply=Qty;
Var X{Sources,Plants}>=0;
Con Cns1{q in Sources}:Sum{w in Plants}X[q,w]<=Supply;
Con Cns2{w in Plants}:Sum{q in Sources}X[q,w]>=Demand
Con Loop{q in Sources, w in Plants:Fixed_F[q,w] ne .}:X[q,w]=Fixed_F[q,w]; * <-- equivalent "Fix"-Loop?;
*Fix X[1,6]=40;
Min Obj=Sum{q in Sources,w in Plants}X[q,w]*Costs[q,w];
Expand;
Solve;
Create Data Result From [Tail Head]={q in Sources, w in Plants} X;
Run;
Thanks & kind regards
Sorry for the delay while SAS Communities was down in preparation for the relaunch. I hope this reply is still useful for you.
for{q in Sources, w in Plants:Fixed_F[q,w] ne .} fix X[q,w]=Fixed_F[q,w];
Sorry for the delay while SAS Communities was down in preparation for the relaunch. I hope this reply is still useful for you.
for{q in Sources, w in Plants:Fixed_F[q,w] ne .} fix X[q,w]=Fixed_F[q,w];
Thanks Rob Pratt for helping on countless occasions. 🙂
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.