ILP can be used to solve almost any problem associated with creating multiple solutions, each of which has only a few possible results, all known in advance, and in which you can describe the overall “quality” of any combination of options using a function that is independent of “interaction” between elections. To see how this works, the easiest way is to restrict variables, which can only be 0 or 1 (the smallest useful range of integers). Now:
- Each solution requiring a yes / no response becomes a variable
- The objective function should describe the thing that we want to maximize (or minimize) as a weighted combination of these variables
- You need to find a way to express each constraint (a combination of options that cannot be done at the same time) using one or more constraints of linear equality or inequality
Example
For example, suppose you have 3 employees, Anne, Bill, and Karl, and 3 jobs, Dust, Printing, and Packaging. All people can perform all tasks, but each of them has different levels of efficiency / ability for each task, so we want to find the best task for each of them in order to maximize overall effectiveness. We want each person to do exactly 1 job.
Variables
One way to solve this problem is 9 variables, one for each combination of worker and job. The variable x_ad will be set to 1 if Anne should Dust in the optimal solution, and 0 otherwise; x_bp will get a value of 1 if Bill should pack in the optimal solution, and 0 otherwise; etc.
Objective function
The next thing to do is to formulate the objective function that we want to maximize or minimize. Suppose that based on the latest performance estimates of Anna, Bill, and Karl, we have a table of 9 numbers that says how many minutes each of them needs to complete each of the three tasks. In this case, it makes sense to take the sum of all 9 variables, each of which is multiplied by the time necessary for this particular employee to perform this specific work, and try to minimize this amount, that is, minimize the total time spent on doing all the work.
Limitations
The last step is to give constraints that ensure that (a) everyone does exactly 1 job, and (b) every job does exactly 1 man. (Note that in fact, these steps can be performed in any order.)
To make sure that Anne performs exactly 1 task, we can add the restriction x_ad + x_at + x_ap = 1. Similar restrictions can be added for Bill and Karl.
To make sure that there is exactly 1 person, we can add a constraint that is x_ad + x_bd + x_cd = 1. Similar restrictions can be added for input and packaging.
In total, there are 6 limitations. Now you can put this problem with 9-variable 6-constraints into the ILP solver, and it will return the values of the variables for one of the optimal solutions - exactly 3 of them will be 1, and the rest will be 0. 3, which 1 tells you which people must do the job!
ILP is a common
As it happens, this particular problem has a special structure that allows it to be more efficiently solved using a different algorithm. The advantage of using ILP is that variations of the problem can be easily included: for example, if there really were 4 people and only 3 tasks, then we will need to hide the restrictions so that each person performs no more than one job, and not exactly 1 position . This can be expressed simply by changing the equal sign in each of the 1st 3 restrictions on the sign less or equal.