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

Avoid zeros in input-data

Accepted Solution Solved
Reply
Super Contributor
Posts: 334
Accepted Solution

Avoid zeros in input-data

Hello,

Is it possible to avoid zeros in input-datasets for proc optmodel?

A simple example would look like this. In this case I would like to get rid of P1/R3, P2/R1, P3/R3 in "M_Qty".

Data A;
  Input Prod $ Comp $ Qty;
  Datalines;
P1 R1 0.8
P1 R2 0.2
P1 R3 0
P2 R1 0
P2 R2 0.5
P2 R3 0.5
P3 R1 0.2
P3 R2 0.8
P3 R3 0
;
Run;

Data B;
  Input Comp $ Price;
  Datalines;
R1 20
R2 30
R3 50
;
Run;

Proc Optmodel;
  Set <Str,Str> p_c;
  Num M_Qty{p_c};
  Read Data A Into p_c=[Prod Comp] M_Qty=Qty;
  Set Products = SetOf{<p,c> in p_c} p;
  Set Components = SetOf{<p,c> in p_c} c;
  Num M_Price{Components};
  Read Data B Into [Comp] M_Price=Price; 
  Var X{Products} >=0;
  Con Cns1Smiley Frustratedum{p in Products,c in Components} X

*M_Qty[p,c]>=5;
  Con Cns2{c in Components:c="R1"}Smiley Frustratedum{p in Products} X

*M_Qty[p,c]>=5;
  Min Obj=Sum {p in Products, c in Components} M_Qty[p,c]*M_Price*X

;
  Solve;
  Print M_Qty;
Quit;

Thanks&kind regards


Accepted Solutions
Solution
‎07-15-2015 09:15 AM
SAS Employee
Posts: 414

Re: Avoid zeros in input-data

You can use data set options in the READ DATA statement:

  Read Data A(where=(Qty ne 0)) Into p_c=[Prod Comp] M_Qty=Qty;

And then change your constraint and objective declarations to use the sparse set p_c:

  Con Cns1Smiley Frustratedum{<p,c> in p_c} X

*M_Qty[p,c]>=5;

  Con Cns2{c in Components:c="R1"}Smiley Frustratedum{<p,(c)> in p_c} X

*M_Qty[p,c]>=5;

  Min Obj=Sum {<p,c> in p_c} M_Qty[p,c]*M_Price*X

;

View solution in original post


All Replies
Solution
‎07-15-2015 09:15 AM
SAS Employee
Posts: 414

Re: Avoid zeros in input-data

You can use data set options in the READ DATA statement:

  Read Data A(where=(Qty ne 0)) Into p_c=[Prod Comp] M_Qty=Qty;

And then change your constraint and objective declarations to use the sparse set p_c:

  Con Cns1Smiley Frustratedum{<p,c> in p_c} X

*M_Qty[p,c]>=5;

  Con Cns2{c in Components:c="R1"}Smiley Frustratedum{<p,(c)> in p_c} X

*M_Qty[p,c]>=5;

  Min Obj=Sum {<p,c> in p_c} M_Qty[p,c]*M_Price*X

;

☑ This topic is SOLVED.

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

Discussion stats
  • 1 reply
  • 172 views
  • 0 likes
  • 2 in conversation