Question: In an MIP, how can I formulate a constraint such that a decision variable is only greater (or equal to) zero if (and only if) the sum of different decision variables is equal to something.

I'm working with a path flow formulation model and I want to have a constraint that forces flow q on path p to be zero if not all routes in path p are flown.

Example: flow *q* on path *p*, which contains flight A to B ($f\_{AB}$) and flight B to C ($f\_{BC}$), can be greater than zero if and only if one aircraft flies from A to B and (the same or another aircraft) flies from B to C.

I) q = 0 if $\sum$($f\_{AB}$ + $f\_{BC}$) $\le$ 1

II) q $\ge$ 0 if $\sum$($f\_{AB}$ + $f\_{BC}$) = 2

In case there are three flights in one path, constraint I becomes $\le$ 2, and constraint II becomes = 3, etc.

(I know exactly which flow can go over which paths, and I know how many flights are contained in all of the available paths. Moreover, all $f\_{ij}$ are binary)

Help with this would be highly appreciated! (I'm writing my problem in python, in case that matters for anything)

Answer: 
Introduce a binary variable $\delta \in \{0,1\}$ to indicate whether $q$ is positive or not. You want:
$$
\sum\_{(i,j) \in A}f\_{ij} \le |A| - 1 \quad \Longrightarrow \quad \delta=0
$$
or the contrapositive:
$$
\delta=1 \quad \Longrightarrow \quad \sum\_{(i,j) \in A}f\_{ij} \ge |A| 
$$
which you can achieve with:
$$
\sum\_{(i,j) \in A}f\_{ij} \ge |A| \delta
$$

Then, assuming you want $q\ge L$ when $\sum\_{(i,j) \in A}f\_{ij} = |A|$, add the constraints:
$$
L\delta \le q \le M \delta
$$
$M$ is an upper bound on $q$. The right hand side of this last constraint enforces $q$ to take value $0$ when $\delta=0$.
With CPLEX you can use logical constraints.

For instance with the OPL API you can write:

```
dvar boolean q;
dvar int a;
dvar int b;

subject to
{
  q==(a+b>=2);
}

```

q is 0 iff a+b<=1