ILP Part 79 — Complex constraints and comparisons

This is the seventieth ninth part of the ILP series. For your convenience you can find other parts in the table of contents in Part 1 – Boolean algebra

Today we are going to explore constraints and comparisons a little more. We already know how to compare integers, we sort of know how to do the same for real numbers (and we remember it’s dangerous). We’ll now try asking questions “what if”.

Is

This part describes constraints we already covered. They should be easy to grasp.

Set Is

We start with “set is” constraints which are directly built into the model. They include the following:

  • Set Is Equal – a = b
  • Set Is Less Or Equal – a \le b
  • Set Is Greater Or Equal – a \ge b

Notice that these are “positive” constraints as they want to make “something to happen”. Each solver supports them.

Positive Is?

Now we may want to ask about the same. These include:

  • Is Equal – a \stackrel{?}{=} b
  • Is Greater Or Equal – a \stackrel{?}{\ge} b
  • Is Less Or Equal – a \stackrel{?}{\le} b
  • Is Greater Than – a \stackrel{?}{>} b
  • Is Less Than – a\stackrel{?}{<} b

We can calculate all of them by using regular comparisons we already defined.

Positive Set Is

Rest of “positive is” constraints we can implement by using comparisons:

  • Set Is Greater Than – a\stackrel{?}{>} b = 1
  • Set Is Less Than – a \stackrel{?}{<} b = 1

Negative Is?

Now we enter the world of negative constraints. We may ask the following:

  • Is Not Equal – equivalent to Is Greater Than or Is Less Than
  • Is Not Greater or Equal – equivalent to Is Less Than
  • Is Not Less Or Equal – equivalent to Is Greater Than
  • Is Not Greater Than – equivalent to Is Less Or Equal
  • Is Not Less Than – equivalent to Is Greater or Or Equal

Still, no magic in here. We just use Positive Is formulas.

Negative Set Is

Finally, we may want to add constraints that something doesn’t happen. They are obvious as well, we just take Negative Is and set them to true.

Can be

Okay, now things get a little trickier. Previously we were asking whether something “is” happening. Now we ask if something “can be” happening. How is this useful? Let’s take this problem with integer variables:

    \begin{gather*} 0 \le a, b \le 10 \\ a + b \le 8 \end{gather*}

with goal to minimize a + b. The optimal solution is a = 0, b = 0 as the sum is zero then.

Positive Can Be?

We may ask the following about variable a where x is either variable or constant:

  • Can Be Equal – a \stackrel{??}{=} x
  • Can Be Greater Or Equal – a \stackrel{??}{\ge} x
  • Can Be Less Or Equal – a \stackrel{??}{\le} x
  • Can Be Greater Than – a \stackrel{??}{>} x
  • Can Be Less Than – a\stackrel{??}{<} x

What do they do? They answer whether a can be changed (but does not need to) in the final solution to particular option in a way that the model is still feasible, no other variable gets changed, and the goal function is allowed to change. So we may have the following examples:

  • a \stackrel{??}{=} 8 – true as if we set a=8 then model is still feasible
  • a \stackrel{??}{\ge} 8 – true based on the same reasoning
  • a \stackrel{??}{\le} 8 – true as it’s already met
  • a \stackrel{??}{>} 8 – false as then a + b would be too big
  • a\stackrel{??}{<} 8 – true

Notice however that if we set b = 4 then we get the following answers:

  • a \stackrel{??}{=} 8 – false as 8 + 4 = 12 > 8
  • a \stackrel{??}{\ge} 8 – false based on the same reasoning
  • a \stackrel{??}{\le} 8 – true as we can set a = 4
  • a \stackrel{??}{>} 8 – false as then a + b would be too big
  • a\stackrel{??}{<} 8 – true

So notice that we didn’t modify a in any way, we only modified some other variable and still we affected a. Now, how do we implement these constraints?

Can Be Equal?

This is the simplest one and actually something we can implement. We just need to imagine that a is indeed equal to something and then replicate all constraints including it. This is called “Level 0 Model Transformation” (L0MT). So in our case it would be:

    \begin{gather*} 0 \stackrel{?}{\le} a \stackrel{?}{\le} 10\\ a + b \stackrel{?}{\le} 8 \end{gather*}

And now we take conjunction of all these “positive is” constraints.

Other Positive Can Be?

Other Positive Can Be constraints can’t be represented that easily. That’s because when we ask a \stackrel{??}{\ge} 8 it may be that it’s true for a = 9 but false for a = 10 so we don’t know which value to use. This can be represented using Level 2 Model Transformation (L2MT) explained later.

Positive Set Can Be

Now we discuss constraints setting whether something can happen. We can implement them in some ways.

Set Can Be Equal

This is the simplest one. Since we know what value we’re talking about, we can just substitute it as in a \stackrel{??}{=} x and then make this true.

Other Positive Set Can Be

For other constraints we need to use “Level 1 Model Transformation” (L1MT). We introduce a new variable a' and then check for constraints. Let’s see an example for a \stackrel{??}{\ge} 5. We start with this model:

    \begin{gather*} 0 \le a, b \le 10 \\ a + b \le 8 \end{gather*}

and now we add this:

    \begin{gather*} a' \ge 5\\ 0 \le a' \le 10 \\ a' + b \le 8 \end{gather*}

We can see that solver needs to find an assignment meeting constraints. The model must be feasible so we don’t break anything.

Negative Can Be?

Now we ask the following:

  • Can Be Not Equal – equivalent to Can Be Greater Than or Can Be Less Than
  • Can Be Not Greater Or Equal – equivalent to Can Be Less Than
  • Can Be Less Or Equal – equivalent to Can Be Greater Than
  • Can Be Greater Than – equivalent to Can Be Less Or Equal
  • Can Be Less Than – equivalent to Can Be Greater Or Equal

Notice that Can Be Not Greater Or Equal and Not Can Be Greater Or Equal are not equivalent anymore. The former effectively asks if there is a value Not Greater Or Equal to something which makes the model feasible, the latter negates the constraint which is different for infeasible models.

To implement these constraints we can’t introduce new variables as in case of negative answers the model would become infeasible. However, we can represent them using L2MT.

Negative Set Can Be

And now we consider constraints. Again, they can be represented using L2MT as if we added some more variables and constrain them then we would end up with infeasible model.

Could Be

Now we go similar route but allow to change some other variables as well (not all of them).

Positive Could Be?

Let’s take this model:

    \begin{gather*} 0 \le a, b, x \le 10 \\ a + b \le 8 \\ b = 5\\ x = 0\\ b \ge x \end{gather*}

x is not very useful here but actually adds some constraint to depict the principle. Let’s say that we ask a \stackrel{???}{=} 5 so if a could be equal to five if we are allowed to change some other variables. The answer is yes as we may set a equal to five if we change b. However, x remains unchanged.

These constraints can be represented using L2MT. We cannot go with copying variables as for negative answer we would make model infeasible.

Positive Set Could Be

While we cannot answer the question easily, we can make the constraint. We go with L1MT, copy variables and then add constraints. We would need to make sure that only some variables change which adds a little bit of complexity.

Negative Could Be? and Negative Set Could Be

Again, we need to remember that Could Not Be Equal and Not Could Be Equal are not equivalent in terms of infeasibility. We can represent these by using L2MT.

Might Be

Now we enter the world when all variables can change values.

Positive Might Be? and Negative Might Be?

For these we basically ask if there is any solution with constraint met. Again, copying variables is not helpful. We need to go with L2MT.

Positive Set Might Be and Negative Set Might Be

Now, these are very interesting. In the former we need to guarantee that there exists any solution which can be done with L1MT. For the latter we need to make sure that no solution exists which requires L2MT. However, notice that in the latter case we’re very close to the halting problem so in some cases it may not be possible at all.

Model Transformations

Okay, but what are these all model transformations?

Level 0 Model Transformation

In this transformation we already know all the values as we modify only one variable to some constant so we don’t need to introduce any other free-ish variables. What we need is to verify if all other constraints hold which we can do by replacing them with Positive Is? and Set Positive Is.

Level 1 Model Transformation

In this case we need to introduce free-ish variables and include them in the model we solve. This is somewhat similar to Type 1 Hypervisor in VMs. We sort of build a model on the side and solve it when solving the original model.

Level 2 Model Transformation

Now something interesting happens. When we need to make sure something is not possible then we need to create a model where something is impossible. But if we included that model in the original one then we would make the latter infeasible as well. So how do we do it?

The answer is Turing Machine. We know we can emulate Turing Machine in ILP and so we can emulate the ILP solving algorithm inside the model. Since we know how big the input is, we know the complexity, we can calculate the number of steps required to land at solution. So we effectively emulate a computer inside our model to solve some other model.

This is like Level 2 Hypervisors which need to do some emulation. We effectively do the same here. Obviously, it’s only theoretically possible now (as it would lead to gigantic number of variables) but can be represented in ILP.

Summary

Now all operations at a glance:

    \[ \begin{tabular}{c|c|c|c} \text{Operation} & Category & \text{Description} & \text{Solution}\\ \hline a = b & Positive Set Is & Sets a equal to b & Built-in \\ a \le b & Positive Set Is & Sets a less or equal to b & Built-in \\ a \ge b & Positive Set Is & Sets a greater or equal to b & Built-in \\ a < b & Positive Set Is & Sets a less than b & Comparison \\ a > b & Positive Set Is & Sets a greater than b & Comparison\\ a \stackrel{?}{=} b & Positive Is? & Asks if a is equal to b & Comparison \\ a \stackrel{?}{\ge} b & Positive Is? &  Asks if a is greater or equal to b & Comparison \\ a \stackrel{?}{\le} b & Positive Is? & Asks if a is less or equal to b & Comparison \\ a \stackrel{?}{<} b & Positive Is? & Asks if a is less than b & Comparison\\ a \stackrel{?}{>} b & Positive Is? & Asks if a is greater than b & Comparison\\ a \ne b & Negative Set Is & Sets a not equal to b & Comparison\\ a \stackrel{!}{\le} b & Negative Set Is & Sets a not less or equal to b & Comparison\\ a \stackrel{!}{\ge} b & Negative Set Is & Sets a not greater or equal to b & Comparison\\ a \stackrel{!}{<} b & Negative Set Is & Sets a not less than b & Comparison\\ a \stackrel{!}{>} b & Negative Set Is & Sets a not greater than b & Comparison\\ a \stackrel{?}{\ne} b & Negative Is? & Asks if a is not equal to b & Comparison\\ a \stackrel{?!}{\le} b & Negative Is? & Asks if a is not less or equal to b & Comparison\\ a \stackrel{?!}{\ge} b & Negative Is? & Asks if a is not greater or equal to b & Comparison\\ a \stackrel{?!}{<} b & Negative Is? & Asks if a is not less than b & Comparison\\ a \stackrel{?!}{>} b & Negative Is? & Asks if a is not greater than b & Comparison\\ \hline \]

    \[ \begin{tabular}{c|c|c|c} \text{Operation} & Category & \text{Description} & \text{Solution}\\ \hline a \stackrel{==}{=} b & Positive Set Can Be & Sets a can be equal to b & Can Be Equal \\ a \stackrel{==}{\le} b & Positive Set Can Be& Sets a can be less or equal to b & L1MT \\ a \stackrel{==}{\ge} b & Positive Set Can Be & Sets a can be greater or equal to b & L1MT \\ a \stackrel{==}{<} b & Positive Set Can Be & Sets a can be less than b & L1MT \\ a \stackrel{==}{>} b & Positive Set Can Be & Sets a can be greater than b & L1MT\\ a \stackrel{??}{=} b & Positive Can Be? & Asks if a can be equal to b & L0MT \\ a \stackrel{??}{\ge} b & Positive Can Be? &  Asks if a can be greater or equal to b & L2MT \\ a \stackrel{??}{\le} b & Positive Can Be? & Asks if a can be less or equal to b & L2MT\\ a \stackrel{??}{<} b & Positive Can Be? & Asks if a can be less than b & L2MT\\ a \stackrel{??}{>} b & Positive Can Be? & Asks if a can be greater than b & L2MT\\ a \ne b & Negative Set Can Be & Sets a can be not equal to b & L2MT \\ a \stackrel{!!}{\le} b & Negative Set Can Be& Sets a can be not less or equal to b & L2MT \\ a \stackrel{!!}{\ge} b & Negative Set Can Be& Sets a can be not greater or equal to b & L2MT \\ a \stackrel{!!}{<} b & Negative Set Can Be& Sets a can be not less than b & L2MT \\ a \stackrel{!!}{>} b & Negative Set Can Be& Sets a can be not greater than b & L2MT \\ a \stackrel{??}{\ne} b & Negative Can Be? & Asks if a can be not equal to b & L2MT \\ a \stackrel{??!}{\le} b & Negative Can Be? & Asks if a can be not less or equal to b & L2MT \\ a \stackrel{??!}{\ge} b & Negative Can Be? & Asks if a can be not greater or equal to b & L2MT \\ a \stackrel{??!}{<} b & Negative Can Be? & Asks if a can be not less than b & L2MT \\ a \stackrel{??!}{>} b & Negative Can Be? & Asks if a can be not greater than b & L2MT \\ \hline \]

    \[ \begin{tabular}{c|c|c|c} \text{Operation} & Category & \text{Description} & \text{Solution}\\ \hline a \stackrel{===}{=} b & Positive Set Could  Be & Sets a could be equal to b & L1MT \\ a \stackrel{===}{\le} b & Positive Set Could Be& Sets a could be less or equal to b & L1MT \\ a \stackrel{===}{\ge} b & Positive Set Could Be & Sets a could be greater or equal to b & L1MT \\ a \stackrel{===}{<} b & Positive Set Could Be & Sets a could be less than b & L1MT \\ a \stackrel{===}{>} b & Positive Set Could Be & Sets a could be greater than b & L1MT\\ a \stackrel{???}{=} b & Positive Could Be? & Asks if a could be equal to b & L2MT \\ a \stackrel{???}{\ge} b & Positive Could Be? &  Asks if a could be greater or equal to b & L2MT \\ a \stackrel{???}{\le} b & Positive Could Be? & Asks if a could be less or equal to b & L2MT\\ a \stackrel{???}{<} b & Positive Could Be? & Asks if a could be less than b & L2MT\\ a \stackrel{???}{>} b & Positive Could Be? & Asks if a could be greater than b & L2MT\\ a \ne b & Negative Set Could Be & Sets a could be not equal to b & L2MT \\ a \stackrel{!!!}{\le} b & Negative Set Could Be& Sets a could be not less or equal to b & L2MT \\ a \stackrel{!!!}{\ge} b & Negative Set Could Be& Sets a could be not greater or equal to b & L2MT \\ a \stackrel{!!!}{<} b & Negative Set Could Be& Sets a could be not less than b & L2MT \\ a \stackrel{!!!}{>} b & Negative Set Could Be& Sets a could be not greater than b & L2MT \\ a \stackrel{???}{\ne} b & Negative Could Be? & Asks if a could be not equal to b & L2MT \\ a \stackrel{???!}{\le} b & Negative Could Be? & Asks if a could be not less or equal to b & L2MT \\ a \stackrel{???!}{\ge} b & Negative Could Be? & Asks if a could be not greater or equal to b & L2MT \\ a \stackrel{???!}{<} b & Negative Could Be? & Asks if a could be not less than b & L2MT \\ a \stackrel{???!}{>} b & Negative Could Be? & Asks if a could be not greater than b & L2MT \\ \hline \]

    \[ \begin{tabular}{c|c|c|c} \text{Operation} & Category & \text{Description} & \text{Solution}\\ \hline a \stackrel{====}{=} b & Positive Set Might Be & Sets a might be equal to b & L1MT \\ a \stackrel{====}{\le} b & Positive Set Might Be& Sets a might be less or equal to b & L1MT \\ a \stackrel{====}{\ge} b & Positive Set Might Be & Sets a might be greater or equal to b & L1MT \\ a \stackrel{====}{<} b & Positive Set Might Be & Sets a might be less than b & L1MT \\ a \stackrel{====}{>} b & Positive Set Might Be & Sets a might be greater than b & L1MT\\ a \stackrel{????}{=} b & Positive Might Be? & Asks if a might be equal to b & L2MT \\ a \stackrel{????}{\ge} b & Positive Might Be? &  Asks if a might be greater or equal to b & L2MT \\ a \stackrel{????}{\le} b & Positive Might Be? & Asks if a might be less or equal to b & L2MT\\ a \stackrel{????}{<} b & Positive Might Be? & Asks if a might be less than b & L2MT\\ a \stackrel{????}{>} b & Positive Might Be? & Asks if a might be greater than b & L2MT\\ a \ne b & Negative Set Might Be & Sets a might be not equal to b & L2MT \\ a \stackrel{!!!!}{\le} b & Negative Set Might Be& Sets a might be not less or equal to b & L2MT \\ a \stackrel{!!!!}{\ge} b & Negative Set Might Be& Sets a might be not greater or equal to b & L2MT \\ a \stackrel{!!!!}{<} b & Negative Set Might Be& Sets a might be not less than b & L2MT \\ a \stackrel{!!!!}{>} b & Negative Set Might Be& Sets a might be not greater than b & L2MT \\ a \stackrel{????}{\ne} b & Negative Might Be? & Asks if a might be not equal to b & L2MT \\ a \stackrel{????!}{\le} b & Negative Might Be? & Asks if a might be not less or equal to b & L2MT \\ a \stackrel{????!}{\ge} b & Negative Might Be? & Asks if a might be not greater or equal to b & L2MT \\ a \stackrel{????!}{<} b & Negative Might Be? & Asks if a might be not less than b & L2MT \\ a \stackrel{????!}{>} b & Negative Might Be? & Asks if a might be not greater than b & L2MT \\ \hline \]