## Constraints with "not in" clause

This constraint forces that a DC is served by exactly "x" number of LSPs.

``````/*Constraint for retricting DC-LSP: given DC can by served by "x" number of LSPs*/
num DC_LSPs=5;
con DC_LSP: sum{c in LSP} IsLSPDC[c,'LAX'] = DC_LSPs;
con DC_LSP_Link1{p in Ports, t in Transit,c in lsp, d in {'LAX'}}:
ContainersfromPortstoLSPtoDC[p,t,c,'AL1'] <= BigM * IsLSPDC[C,'LAX'];
con DC_LSPLink2{c in LSP, d in DC}:
sum {p in Ports, t in Transit} ContainersfromPortstoLSPtoDC[p,t,c,d] >= IsLSPDC[c,d];``````

This works fine. Now I want to have another constraint where I want to follow the same logic but want to limit my choice of DC to anything that is not in ('LAX','SAV'). So am looking to write sthg like

``con DC_LSP_NoSAVLAX: sum{c in LSP} IsLSPDC[c,not in ('SAV,'LAX')] = DC_LSPs;``

Can i do that? If yes what would be the correct syntax.

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: Constraints with "not in" clause

If you really want just one constraint, here are two ways:

``````con DC_LSP_NoSAVLAX:
sum{c in LSP, d in DC: d not in {'SAV,'LAX'}} IsLSPDC[c,d] = DC_LSPs;``````
``````con DC_LSP_NoSAVLAX:
sum{c in LSP, d in DC diff {'SAV,'LAX'}} IsLSPDC[c,d] = DC_LSPs;
``````

If instead you want a family of constraints indexed by d, here are two ways:

``````con DC_LSP_NoSAVLAX {d in DC: d not in {'SAV,'LAX'}}:
sum{c in LSP} IsLSPDC[c,d] = DC_LSPs;``````
``````con DC_LSP_NoSAVLAX {d in DC diff {'SAV,'LAX'}}:
sum{c in LSP} IsLSPDC[c,d] = DC_LSPs;``````
4 REPLIES 4

## Re: Constraints with "not in" clause

If you really want just one constraint, here are two ways:

``````con DC_LSP_NoSAVLAX:
sum{c in LSP, d in DC: d not in {'SAV,'LAX'}} IsLSPDC[c,d] = DC_LSPs;``````
``````con DC_LSP_NoSAVLAX:
sum{c in LSP, d in DC diff {'SAV,'LAX'}} IsLSPDC[c,d] = DC_LSPs;
``````

If instead you want a family of constraints indexed by d, here are two ways:

``````con DC_LSP_NoSAVLAX {d in DC: d not in {'SAV,'LAX'}}:
sum{c in LSP} IsLSPDC[c,d] = DC_LSPs;``````
``````con DC_LSP_NoSAVLAX {d in DC diff {'SAV,'LAX'}}:
sum{c in LSP} IsLSPDC[c,d] = DC_LSPs;``````

## Re: Constraints with "not in" clause

the constraint worked.

I have the second constraint that I changed to this. But i get syntax errors.

con DC_LSP_Direct_Link1{p in Ports, t in Transit,c in lsp, d not in {'SAV','LAX'}}:
ContainersfromPortstoLSPtoDC[p,t,c,d not in {'SAV','LAX'}] <= BigM * IsLSPDC[c,d not in {'SAV','LAX'}];

## Re: Constraints with "not in" clause

I think i know why  . let me try the fix

## Re: Constraints with "not in" clause

I tried this. still got error:

con DC_LSP_Direct_Link1{p in Ports, t in Transit,c in lsp, d in DC: d not in {'SAV','LAX'}}:
ContainersfromPortstoLSPtoDC[p,t,c,d in DC: d not in {'SAV','LAX'}] <= BigM * IsLSPDC[c,d in DC: d not in {'SAV','LAX'}];

Discussion stats
• 4 replies
• 358 views
• 1 like
• 2 in conversation