Rob. - This is still a MILP.
This should be straight forward but I am not getting it correct. I am trying to have a constraint called "LSP_DC" and an associated "LSP_DCLink" . What I am trying to enforce is that a given LSP should go to "x" number of DCs . I define what x is. This does not seem to do what I want.
proc optmodel;
set<str> Ports=/'SHA' 'YAN'/;
set<str> DC=/'AL1' 'FU1'/;
set<str> LSP=/'MAEU' 'ONEY' 'COSC'/;
set <str> Transit=/'West','East', 'Gulf'/;
num Containers {Ports,DC}= [2000,3000,1000,4000];
print containers;
var Is_LSP {LSP} binary;
var IsLSPDC {LSP,DC} binary;
var IsPortsLSPDC {Ports,LSP,DC} binary;
var IsPortsTransitLSPDC {Ports,Transit,LSP,DC} binary;
/* declare Constants*/
num Min_Qty_LSP=200;
/*RATES*/
num InboundLinehaul {Ports,Transit,LSP,DC}= [40,10,30,5,20,10,
20,6,30,7,3,5,
2,6,2,60,18,4,
32,70,2,30,18,40,
19,10,2,29,3,9,
42,36,79,10,5,14
];
/* 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] <= 10000*Is_LSP[c];
/*Constraint for retricting LSP-DC: given LSP can go to only "x" number of DC* - in this case x=2/
num MAEU_DCs=2;
fix Is_LSP ['MAEU']=1;
con LSP_DC: sum{d in DC} IsLSPDC['MAEU',d] = MAEU_DCs;
con LSP_DC_Link{p in Ports, t in Transit,c in LSP, d in DC}:
ContainersfromPortstoLSPtoDC[p,t,'MAEU',d] <= 10000 * IsLSPDC['MAEU',d];
expand;
solve with milp;
OK, thanks for the clarification. Your constraints enforce only that ContainersfromPortstoLSPtoDC[p,t,c,d] > 0 for some p and t implies IsLSPDC[c,d] = 1, but you need additional constraints to enforce the converse:
con LSP_DC_Link2{c in LSP, d in DC}:
sum {p in Ports, t in Transit} ContainersfromPortstoLSPtoDC[p,t,c,d] >= IsLSPDC[c,d];
I changed the constraint to but with no luck yet.
con LSP_DC_Link{p in Ports, t in Transit,c in {"MAEU"}, d in DC}:
ContainersfromPortstoLSPtoDC[p,t,'MAEU',d] <= 10000 * IsLSPDC['MAEU',d];
Sorry, I don't quite follow. Can you please describe what is wrong with the resulting solution?
Sure. Sorry for not articulating it .
I have this LSP called "MAEU" . I want this LSP to serve 2 DCs (that is AL1 and FU1). However the model does not allocate MAEU to 2 DCs. It does allocate to only 1 DC. I want any given LSP to serve any number of DCs. That is my objective.
Here is the output:
Ports | Transit | LSP | Destination | ScenarioName | ContainersfromPortstoLSPtoDC | InboundLinehaul | Inbound_Linehaul_Costs |
SHA | Gulf | MAEU | AL1 | PN3158-Alt4 | 200 | 2 | 400 |
SHA | Gulf | ONEY | AL1 | PN3158-Alt4 | 1800 | 2 | 3600 |
SHA | Gulf | COSC | FU1 | PN3158-Alt4 | 3000 | 4 | 12000 |
YAN | East | ONEY | AL1 | PN3158-Alt4 | 1000 | 2 | 2000 |
YAN | East | COSC | FU1 | PN3158-Alt4 | 4000 | 9 | 36000 |
Please let me know.
OK, thanks for the clarification. Your constraints enforce only that ContainersfromPortstoLSPtoDC[p,t,c,d] > 0 for some p and t implies IsLSPDC[c,d] = 1, but you need additional constraints to enforce the converse:
con LSP_DC_Link2{c in LSP, d in DC}:
sum {p in Ports, t in Transit} ContainersfromPortstoLSPtoDC[p,t,c,d] >= IsLSPDC[c,d];
THanks Rob. It worked.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.