Operations Research topics: SAS/OR,
SAS Optimization, and SAS Simulation Studio

Changing "Con" to "Fix" with Proc Optmodel

Accepted Solution Solved
Reply
Super Contributor
Posts: 339
Accepted Solution

Changing "Con" to "Fix" with Proc Optmodel

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}Smiley Frustratedum{w in Plants}X[q,w]<=Supply;
  Con Cns2{w in Plants}Smiley Frustratedum{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


Accepted Solutions
Solution
‎09-25-2015 06:23 AM
SAS Employee
Posts: 449

Re: Changing "Con" to "Fix" with Proc Optmodel

[ Edited ]

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


All Replies
Solution
‎09-25-2015 06:23 AM
SAS Employee
Posts: 449

Re: Changing "Con" to "Fix" with Proc Optmodel

[ Edited ]

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

 

Super Contributor
Posts: 339

Re: Changing "Con" to "Fix" with Proc Optmodel

Thanks Rob Pratt for helping on countless occasions. :-)

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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