## Conditional Constraint Syntax - Involves Decision Variables

Solved
Occasional Contributor
Posts: 11

# Conditional Constraint Syntax - Involves Decision Variables

Hello,

I have a silly question. However not sure if there is an answer to my silly question.

I am formulating a model where in one of the constraints, for a decision variable to be true, it depends on other decision variables.

example:

for all (<i,j,n> in MasterRoute>

if X=1 and W[i,j]=1 and sum{<nod,(n)> in PickUpNode, p in PickSanity=nod and nod=1} U

<= Ui <= Uj <= Udn then Y[i,j,n]=1

X, Y, U and Y are decision variables.

Accepted Solutions
Solution
‎02-12-2015 10:24 PM
SAS Employee
Posts: 538

## Re: Conditional Constraint Syntax - Involves Decision Variables

The proposition

if AND {j in 1..n} (P = 1) then Q = 1,

where P and Q are binary variables, can be enforced by the linear constraint

sum {j in 1..n} P - n + 1 <= Q.

Assuming X, W, and Y are binary variables in your problem, you can express the desired proposition in this form by introducing additional binary variables (and big-M constraints) to represent each of the following three propositions:

• sum{<nod,(n)> in PickUpNode, p in PickSanity=nod and nod=1} U

<= Ui

• Ui <= Uj
• Uj <= Udn

Do you have bounds for U?

All Replies
Solution
‎02-12-2015 10:24 PM
SAS Employee
Posts: 538

## Re: Conditional Constraint Syntax - Involves Decision Variables

The proposition

if AND {j in 1..n} (P = 1) then Q = 1,

where P and Q are binary variables, can be enforced by the linear constraint

sum {j in 1..n} P - n + 1 <= Q.

Assuming X, W, and Y are binary variables in your problem, you can express the desired proposition in this form by introducing additional binary variables (and big-M constraints) to represent each of the following three propositions:

• sum{<nod,(n)> in PickUpNode, p in PickSanity=nod and nod=1} U

<= Ui

• Ui <= Uj
• Uj <= Udn

Do you have bounds for U?

Occasional Contributor
Posts: 11

## Re: Conditional Constraint Syntax - Involves Decision Variables

Hi Rob,

Thanks for the quick reply. Infact, I have converted the above mentioned proposition into the following constraint. Please excuse my indexing technique. I used different notation for indexes as SAS kept giving me "hides outer declaration"error. My priority was to have a feasible model and then go back and have efficient coding for compression. 1000 is the Big-M and I have bounds for U. U is part of the MTZ subtour elimination. However, the solution is infeasible and I am grinding my teeth debugging the infeasibility. In the routing model that I am developing, I am have a DV "RV" that is indexed over i,j,product,size. In the model the product the truck carries are all unique from each other because the product is an automobile. I have another DV "R" indexed over i,j. While I am getting an optimal route with "R", I am not able to connect RV with R correctly.

example: Civic Medium pickup = Location A dropoff = Location C

Accord Medium pickup = Location B dropoff = Location C

When I solve the model the "R" DV will correctly traverse the arc to get an optimal route, however the "RV" DV does not. I will see RV[A,B,Civic,medium] = 1 and not RV[A,B,Civic,medium]=1 and RV[B,C,Civic,medium]=1. Have the flow balance constraint but still does not work.

Con New{<f,t,ve,si> in MasterRoute}:

RV[f,t,ve,si] >= 5 - sum{<e,z> in Vehicle:e=ve and z=si} 1 * V[e,z] - sum{<fr,to> in RouteDistance:fr=f and to=t} 1 * R[fr,to] -

sum{<node,vehi,size> in JC:node=f and vehi=ve and size=si} 1* A[node,vehi,size]

- sum{<nod,veh,siz> in JC:nod=t and veh=ve and siz=si} 1 * B[nod, veh,siz] - sum{<bh,ga> in RouteDistance:bh=f and ga=t} 1 * C[bh,ga];

con New1{<no,ve,si> in JC}:

1000 * (A[no,ve,si] - 1) <= UAll[no] - sum{<nod,veh,siz> in PickUpNode, s in PickSanity:s=nod and nod=no and veh=ve and siz=si} 1 * UAll;

con New2{<no,ve,si> in JC}:

1000 * (A[no,ve,si] - 1) >= - UAll[no] + sum{<nod,veh,siz> in PickUpNode, s in PickSanity:s=nod and nod=no and veh=ve and siz=si} 1 * UAll;

con New3{<no,ve,si> in JC}:

1000 * (B[no,ve,si] - 1) <= - UAll[no] + sum{<nod,veh,siz> in DropOffNode, s in DropSanity:s=nod and nod=no and veh=ve and siz=si} 1 * UAll;

con New4{<no,ve,si> in JC}:

1000 * (B[no,ve,si] - 1) >= UAll[no] - sum{<nod,veh,siz> in DropOffNode, s in DropSanity:s=nod and nod=no and veh=ve and siz=si} 1 * UAll;

con New5{<fr,to> in RouteDistance}:

1000 * (C[fr,to] - 1) <= UAll[to] - UAll[fr];

con New6{<fr,to> in RouteDistance}:

1000 * (C[fr,to] - 1) >= - UAll[to] + UAll[fr];

SAS Employee
Posts: 538

## Re: Conditional Constraint Syntax - Involves Decision Variables

It will help me understand better if you write the desired logical relationship among V, R, A, B, C, and RV as a proposition using IF, THEN, AND, OR, and NOT, without the indexing.

SAS Employee
Posts: 538

## Re: Conditional Constraint Syntax - Involves Decision Variables

I suspect that you want to enforce the following proposition:

if V = 1 and R = 1 and A = 1 and B = 1 and C = 1 then RV = 1

The corresponding linear constraint would be:

V + R + A + B + C - 4 <= RV

But you currently have (Con New):

V + R + A + B + C + RV >= 5

Occasional Contributor
Posts: 11

## Re: Conditional Constraint Syntax - Involves Decision Variables

Apologies for the delay.

V = Vehicle DV. Indexed over AutoID and Size. Type = Binary.

R = Arc DV. Indexed over I & J. Type = Binary

A = Visit Node. Indexed over I, AutoID and Size, Type = Binary

B = Visit Node. Indexed over J, AutoID and Size. Type = Binary

RV = Arc with AutoID. Indexed over I, J, AutoID and Size. Type = Binary

My main goal is to make sure that I carry my Automobile that is on a truck from it's pickup all the way to dropoff (while visiting transition nodes for other automobile pickup)

So If I select to carry(V) an Automobile and pass through an arc (R) and the arc's I th node and J th node than RV = 1.

Thanks for checking my constraint. I dont think I need the C though. However, The new2...new6 constraints that I have after the V + R + A + B + C + RV >= 5, seems to be the problem. Or probably I have something formulated in the model elsewhere that is causing the model's infeasibility.

SAS Employee
Posts: 538

## Re: Conditional Constraint Syntax - Involves Decision Variables

Then I think you want

V + R + A + B - 3 <= RV