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. 🙂
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.