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

Hi

I have a proc optmodel question.  I used the expand statement to see my constraints. But nothing happens to the expand statement and also codes after the expand statement. 

My variable count here is

Number of variables = 192789

Number of binary = 6813

Number of constraints = 756

Bounded below = 185976

Bounded below and above=6804;

Constraint Coefficients=557937

 

Does something have to do with the size of the problem?

 

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

If I understand correctly, the following CREATE DATA statement does what you want:

create data mydata from [p t c d] ContainersfromPortstoLSPtoDC InboundLinehaul;

Do you also want the product of these values as a new column?

 

What does your quantity Trial depend on?  Does it have the same indices p, t, c, d?

View solution in original post

21 REPLIES 21
RobPratt
SAS Super FREQ

Can you please show the EXPAND statement you used?  Even better would be to provide the full code.

Santha
Pyrite | Level 9

Thanks Rob

 

Here is the code.

proc optmodel;

set <str> Ports;
set <str> DC;
set <str> LSP;
set <str> Transit;

read data STDOPT.PN3158_Ports into Ports=[PortSource];
read data STDOPT.PN3158_DC into DC=[RateMatchDest];
read data STDOPT.PN3158_LSP into LSP=[LSP];
read data STDOPT.PN3158_TRANSIT into Transit=[Transit];

num Containers {Ports,DC};
read data STDOPT.PN3158_data into [PortSource RateMatchDest] Containers=FEU;
print containers;

 

/*END OF GETTING FEU DATA*/

 

var Is_LSP {LSP} binary;
var IsLSPDC {LSP,DC} binary;
var IsPortsLSPDC {Ports,LSP,DC} binary;

 

/*Close/Open Entities */
fix Is_LSP ['EGLV']=0; fix Is_LSP ['CMDU']=0; fix Is_LSP ['APLU']=1;
fix Is_LSP ['COSU']=1; fix Is_LSP ['ONEY']=1; fix Is_LSP ['MAEU']=1;
fix Is_LSP ['ZIMU']=1; fix Is_LSP ['WHLC']=1; fix Is_LSP ['HLCU']=1;

 

/* declare Constants*/
num Min_Qty_LSP=0;
/*NUM BigM=STDOPT.PN3158_BigM.FEU;*/

 

/*RATES*/
num InboundLinehaul {Ports,Transit,LSP,DC};
read data STDOPT.PN3158_RATES into [PortSource Transit LSP RateMatchDest] InboundLinehaul=Rate;


/* DECISON VARIABLE */
var ContainersfromPortstoLSPtoDC {Ports,Transit,LSP,DC}>=0;

 

/* IMPLIED VARIABLE */
impvar Inbound_Linehaul_Costs= sum {p in Ports, t in Transit,c in LSP, d in DC} InboundLinehaul [p,t,c,d] *ContainersfromPortstoLSPtoDC [p,t,c,d];
impvar ContainersatLSP{c in LSP}=sum{p in Ports,t in Transit,d in DC} ContainersfromPortstoLSPtoDC [p,t,c,d];
impvar ContainersatTransitLSP{t in Transit, c in LSP}=sum{p in Ports,d in DC} ContainersfromPortstoLSPtoDC [p,t,c,d];

/* declare Objective Function*/
Min TotalCost = Inbound_Linehaul_Costs;

 

/* GENERAL CONSTRAINTS */
con Min_Qty_at_LSP_is_Respected {c in LSP} :
sum{p in Ports,t in Transit,d in DC} ContainersfromPortstoLSPtoDC [p,t,c,d]>=Min_Qty_LSP*Is_LSP[c];

con ModelOutput_Same_As_ModelInput {p in Ports, d in DC}:
sum {t in Transit,c in LSP} ContainersfromPortstoLSPtoDC[p,t,c, d] = Containers [p,d];

con CheckLSP {c in LSP}: ContainersatLSP[c] <= 40000*Is_LSP[c];


expand;

solve with milp;

 

/*Outputs*/
print ContainersatLSP;
print Is_LSP;
print TotalCost;

RobPratt
SAS Super FREQ

I don't immediately see anything wrong.  Do you get the Problem Summary and Solution Summary and the results from the PRINT statements?

Santha
Pyrite | Level 9

Rob

Yes. The model solved . I do see Problem Summary and Solution summary as well. 

the reason i wanted to see the expand statement is because I want to make tweaks to the code  and so I want to follow the constraints closely to understand correctly.

 

Is there any setting thing that I need to do for me to see the expand constraints thing?

Santha
Pyrite | Level 9

Also I can see the results from the print statements as well

RobPratt
SAS Super FREQ

Are you able to share the data and the log?

Santha
Pyrite | Level 9

here is log. let me see how to share data.

 
174 /* OPTMIZATION CODE*/
175 proc optmodel;
176
177 set <str> Ports;
178 set <str> DC;
179 set <str> LSP;
180 set <str> Transit;
181
182 read data STDOPT.PN3158_Ports into Ports=[PortSource];
NOTE: There were 41 observations read from the data set STDOPT.PN3158_PORTS.
183 read data STDOPT.PN3158_DC into DC=[RateMatchDest];
NOTE: There were 18 observations read from the data set STDOPT.PN3158_DC.
184 read data STDOPT.PN3158_LSP into LSP=[LSP];
NOTE: There were 9 observations read from the data set STDOPT.PN3158_LSP.
185 read data STDOPT.PN3158_TRANSIT into Transit=[Transit];
NOTE: There were 28 observations read from the data set STDOPT.PN3158_TRANSIT.
186
187 num Containers {Ports,DC};
188 read data STDOPT.PN3158_data into [PortSource RateMatchDest] Containers=FEU;
NOTE: There were 738 observations read from the data set STDOPT.PN3158_DATA.
189 print containers;
190
191 /*END OF GETTING FEU DATA*/
192
193 var Is_LSP {LSP} binary;
194 var IsLSPDC {LSP,DC} binary;
195 var IsPortsLSPDC {Ports,LSP,DC} binary;
196
197 /*Close/Open Entities */
198 fix Is_LSP ['EGLV']=0;
198 ! fix Is_LSP ['CMDU']=0;
198 ! fix Is_LSP ['APLU']=1;
199 fix Is_LSP ['COSU']=1;
199 ! fix Is_LSP ['ONEY']=1;
199 ! fix Is_LSP ['MAEU']=1;
200 fix Is_LSP ['ZIMU']=1;
200 ! fix Is_LSP ['WHLC']=1;
200 ! fix Is_LSP ['HLCU']=1;
201
202 /* declare Constants*/
203 num Min_Qty_LSP=0;
204 /*NUM BigM=STDOPT.PN3158_BigM.FEU;*/
205
206 /*RATES*/
207 num InboundLinehaul {Ports,Transit,LSP,DC};
208 read data STDOPT.PN3158_RATES into [PortSource Transit LSP RateMatchDest] InboundLinehaul=Rate;
NOTE: There were 185976 observations read from the data set STDOPT.PN3158_RATES.
209
210
211 /* DECISON VARIABLE */
212 var ContainersfromPortstoLSPtoDC {Ports,Transit,LSP,DC}>=0;
213
214 /* IMPLIED VARIABLE */
215 impvar Inbound_Linehaul_Costs= sum {p in Ports, t in Transit,c in LSP, d in DC} InboundLinehaul [p,t,c,d]
215 ! *ContainersfromPortstoLSPtoDC [p,t,c,d];
216 impvar ContainersatLSP{c in LSP}=sum{p in Ports,t in Transit,d in DC} ContainersfromPortstoLSPtoDC [p,t,c,d];
217 impvar ContainersatTransitLSP{t in Transit, c in LSP}=sum{p in Ports,d in DC} ContainersfromPortstoLSPtoDC [p,t,c,d];
218
219 /* declare Objective Function*/
220 Min TotalCost = Inbound_Linehaul_Costs;
221
222 /* GENERAL CONSTRAINTS */
223 con Min_Qty_at_LSP_is_Respected {c in LSP} :
224 sum{p in Ports,t in Transit,d in DC} ContainersfromPortstoLSPtoDC [p,t,c,d]>=Min_Qty_LSP*Is_LSP[c];
225
226 con ModelOutput_Same_As_ModelInput {p in Ports, d in DC}:
227 sum {t in Transit,c in LSP} ContainersfromPortstoLSPtoDC[p,t,c, d] = Containers [p,d];
228
229 con CheckLSP {c in LSP}: ContainersatLSP[c] <= 40000*Is_LSP[c];
230
231
232 expand;
NOTE: Problem generation will use 4 threads.
NOTE: The problem has 192789 variables (0 free, 9 fixed).
NOTE: The problem uses 10 implicit variables.
NOTE: The problem has 6813 binary and 0 integer variables.
NOTE: The problem has 756 linear constraints (9 LE, 738 EQ, 9 GE, 0 range).
NOTE: The problem has 557937 linear constraint coefficients.
NOTE: The problem has 0 nonlinear constraints (0 LE, 0 EQ, 0 GE, 0 range).
 

 

Santha
Pyrite | Level 9

Hi Rob

I am not sure what is the best way to share data. 

What do u recommend?

RobPratt
SAS Super FREQ

If the data sets are small enough, you can attach to the post in the Attachments section.

Santha
Pyrite | Level 9

Rob. Let me check any memory issues from my side before I share the data. The reason I say that is because EXPAND option works for a toy model with 2 or 3 entities only. So let me make sure there is no problem in my side and will get back to you. Thanks. 

RobPratt
SAS Super FREQ

You might also try expanding just part of the model, as described here.

Santha
Pyrite | Level 9

Another question related to this model . I want to use create data to get my outputs streamlined. 

There are four indices, p, t, c and d each representing a node. I want to count the ContainersfromPortstoLSPtoDC [p,t,c,d], and Inbound_Linehaul for it (which will be ContainersfromPortstoLSPtoDC [p,t,c,d] * InboundLinehaul[p,t,c,d].  What is the correct syntax for it? Also, I want to have a column called "Trial" and i want to enter my own value there. Is it possible?

 

RobPratt
SAS Super FREQ

If I understand correctly, the following CREATE DATA statement does what you want:

create data mydata from [p t c d] ContainersfromPortstoLSPtoDC InboundLinehaul;

Do you also want the product of these values as a new column?

 

What does your quantity Trial depend on?  Does it have the same indices p, t, c, d?

Santha
Pyrite | Level 9

Thanks Rob.

I was looking for this. I built on to what you gave and it worked really well for me. 

Thanks a lot.

About the trial, what I need is a column with just a description of what the model is about in a few characters, like "Best5CustomerScenario". Reason is that I want to be able to view my Visual analytics using this as a selector . Costs by Different scenario. I will have more scenarios with added constraints.  I was thinking to add a column after create data step and updating the column with whatever I want to. Is there  a way, I can specify this text "xxxxx" right when i do create data step?

 

 

I may have a few more questions later. They are pretty straightforward ones. 

Thanks again

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 21 replies
  • 1558 views
  • 2 likes
  • 2 in conversation