BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
user24feb
Barite | Level 11

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

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

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];

 

View solution in original post

2 REPLIES 2
RobPratt
SAS Super FREQ

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];

 

user24feb
Barite | Level 11

Thanks Rob Pratt for helping on countless occasions. 🙂

sas-innovate-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

Multiple Linear Regression in SAS

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.

Discussion stats
  • 2 replies
  • 861 views
  • 0 likes
  • 2 in conversation