Hello,
I am trying to use the procoptmodel to solve a minimization of total cost. I have crossdock facilities that, when used, have a fixed cost. However, my solution is using two crossdock facilities, but only adding the cost for one of them and ignoring the other cost even though the facility is being used. The constraint where I tried to bind the use and cost is called xMaxP. My code is posted below, any suggestions?
proc optmodel;
Set Ps={'South Carolina','New York','Alaska','Rhode Island'};
Set Ts={'South Dakota','Nebraska','Indiana'};
Set Ds={'North Dakota','Hawaii','Pennsylvania','Illinois'};
number MaxP{Ps}=[
40 25 37 34];
number MinD{Ds}=[
21 15 12 15];
number InspectionCapacity{Ts}=[
40 45 42];
number FixedInspectionCost{Ts}=[
950 850 950];
number incost{Ps,TS}=[
43 26 44
40 33 39
31 36 45
45 27 40];
number outcost{Ts,Ds}=[
44 27 41 36
21 33 27 30
34 30 47 48];
var inflow{Ps,Ts}>=0;
var outflow{Ts,Ds}>=0;
var InspectDecision{Ts} binary;
minimize TotalCost= sum{i in Ps, j in Ts} incost[i,j]*inflow[i,j]+sum {j in Ts, k in Ds} outcost[j,k]*outflow[j,k]
+sum{j in Ts}InspectDecision[j]*FixedInspectionCost[j];
con cMaxP{i in Ps}: sum{j in Ts} inflow[i,j]<=MaxP[i];
con cMinD{k in Ds}: sum{j in Ts} outflow[j,k]>=MinD[k];
con NoStock{j in Ts}: sum{i in Ps} inflow[i,j] = sum {k in Ds} outflow[j,k];
con xMaxP{j in Ts}:sum{i in Ps} inflow[i,j]<=InspectionCapacity[j]*sum{j in Ts}InspectDecision[j];
solve;
print TotalCost;
print inflow;
print outflow;
quit;
You have used j as both a constraint index and a summation index in the xMaxP constraint:
con xMaxP{j in Ts}:sum{i in Ps} inflow[i,j]<=InspectionCapacity[j]*sum{j in Ts}InspectDecision[j];
Corrected version:
con xMaxP{j in Ts}:sum{i in Ps} inflow[i,j]<=InspectionCapacity[j]*InspectDecision[j];
To see that it does what you want, check the two cases InspectDecision[j] = 0 and InspectDecision[j] = 1.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.