Originally posted by: RWunderling
You introduce indicator variables y_p which tell you if you are using provider p or not:
sum_{r \in R} x_{r,p} <= |R| * y_p for all p \in P
The y_p are also binary. Now you can specify to use at most 2 providers:
To understand the y_p's consider y_p = 0. Then if follows that all x_{r,p} must be 0 as well, i.e. if y_p = 0, then provider p cannot be used for any product. If y_p = 1, then up to |R| variables x_{r,p} can be 1, i.e. you can choose provider p for up to |R| products.
This is known as the big-M formulation of indicator variables. CPLEX also offeres indicator constraints that allow you to specify indicator variables more directly. Please read up on this in the documentation.
#CPLEXOptimizers#DecisionOptimization