Optimization Theory (DS2) Lecture #2
Examples of Linear, Integer and Graph Problems
Abstract
Today we are primarily going to look at how to formulate problems, starting from word descriptions of the problem, into a rigorous mathematical form. How we solve those problems will come during the course of the semester.
Text and examples adapted from A Gentle Introduction to Optimization.
1 Introduction
Today we are going to run through a set of examples. Ideally, you should follow up on this by reading the corresponding sections in the book and trying some of the exercises.
Examples:
-
1.
Linear Program: WaterTech (Sec. 1.1 from the textbook)
-
2.
Integer Program: KitchTech, the knapsack problem (Sec. 1.3.2)
-
3.
Graphs: shortest path problem (Sec. 1.4.1, 1.5.2)
-
4.
Graphs: minimum cost perfect matching (Sec. 1.4.2, 1.5.1)
2 Linear Program: WaterTech
WaterTech makes four types of products, each of which requires some amount of time on Machine 1 (say, a milling machine) and a certain amount of time on Machine 2 (say, a polishing machine). It takes both skilled and unskilled labor to make the products, and of course each sells for a certain price. How can we maximize profit?
Table of times and selling price:
Product | Machine 1 | Machine 2 | Skilled labor | Unskilled labor | Unit sale price |
1 | 11 | 4 | 8 | 7 | $300 |
2 | 7 | 6 | 5 | 8 | $260 |
3 | 6 | 5 | 5 | 7 | $220 |
4 | 5 | 4 | 6 | 4 | $180 |
We have the following constraints:
-
1.
700 hours of time are available on Machine 1.
-
2.
500 hours of time are available on Machine 2.
-
3.
Up to 600 hours of skilled labor at $8/hour can be purchased.
-
4.
Up to 650 hours of unskilled labor at $6/hour can be purchased.
Variables. Our product “names” are the numbers 1 to 4, so let’s call the number of each product we decide to make, for . (Later we will see that sometimes you have to add artificial variables, but in this case we’ll stick with the basics.)
Constraints. The total amount of time used on Machine 1 has to be less than 700 hours, and can be written
(1) |
Likewise, the constraint on Machine 2 is
(2) |
You can see these equations by going down the columns labeled Machine 1 and Machine 2 in the table above.
We don’t yet know how much labor we’re buying, so let’s call unskilled labor and skilled labor . Going down the corresponding columns, we get the constraints
(3) | ||||
(4) |
Objective function. This is the thing we’re optimizing for: profit! Let’s call our income from sales , costs , and profit . Obviously,
(5) |
and we want that to be positive and as big as possible! We can read the income off the right hand column of the table,
(6) |
and the labor costs are
(7) |
2.1 Formulation
Finally, this gives us the formal formulation of the formulas for this problem:
Maximize
(8) |
subject to the constraints
(9) | ||||
(10) | ||||
(11) | ||||
(12) | ||||
(13) | ||||
(14) | ||||
(15) |
The first four of those constraints are the equations we derived above, but don’t forget the bottom three – without them our techniques can easily yield an unphysical solution such as buying a negative amount of labor or building an infinite number of some product!
3 Knapsack Problem
(Our first real integer programming problem! Might not get there today, but the problem is from 1.3.2.)
4 Shortest Path Problem
A graph is a set of vertices and a set of edges , where each edge connects to two of the vertices, or nodes. For some problems, we may begin bg guaranteeing that the whole thing is connected, for others, we may not.
You will see this problem in several forms in different fields; the way networking people approach it is somewhat different from the way we will see it here. Today, we will formulate it as an integer problem. (Later in the semester, if we have time, we will see another means of solving this problem, called shortest path first, by a dude named Edsger Dijkstra.)
See Fig. 1.9 in the text. We have four vertices, (our source), (our target), and . Let’s first see the adjacency matrix, which contains 1 if two vertices are connected by an edge, and 0 if not (and along the diagonal):
(16) |
Obviously, this is an matrix for a graph with nodes. If the edges are weighted, e.g. representing distances between two points, we have the weighted adjacency matrix (or sometimes the distance matrix):
(17) |
The numbers are known as the cost or weight. (Often edges in a graph have a direction, known as a directed graph or digraph, but here we are dealing only with undirected edges.)
4.1 Paths
A path is a list of edges that connects to . Their order matters, and the tail of each edge has to be the head of the next edge. No node can be repeated. So for this simple graph, we have four possible paths:
(18) | |||
(19) | |||
(20) | |||
(21) |
Each edge has a cost, as above. If we establish the order of our edges to be , then we can write the vector to represent the path . (Question: What is the length of this vector?)
If we write the edge costs as a vector, also, then we can calculate the path cost as
(22) |
which is the same as
(23) |
where is the cost for the edge , is the path, and is the (complete) set of edges.
4.2 Cuts (or Partitions)
How many different ways can we split our graph into two parts, with in one part and in the other? If there are total nodes in our graph, there are ways (because we start with the assumption that is in one half and in the other). In our example, we only have two other nodes, and , so we have possible sets. We’ll refer to as the cut or st-cut of the set , and the four possibilities are plus: . Then our possible cuts are:
(24) | ||||
(25) | ||||
(26) | ||||
(27) |
It turns out that a path that reaches from to has at least one edge in every one of those cuts above.
4.3 Formulation
Variables. As above, is 0/1 for each edge .
Constraints. Our strategy for the integer problem formulation of this is to have a constraint for each one of those sets above, saying that we have at least one edge from each of them. (Question: how many constraints is this? Recall that we said last time that the number of constraints must be finite, but we didn’t say it has to be small!)
Objective function. Our cost , above.
We can write this down more mathematically as:
Minimize subject to
(28) |
and
(29) |
where I’ve used to mean the vector of all ones of the appropriate length, and is the set of all integers, that is, every has to be an integer. This big matrix constraint means that every element of the vector resulting from multiplying this matrix times our solution vector has be at least one.
Note that many non-paths are technically solutions to this problem, but it can be proven that all optimal solutions will be st-paths.
5 Minimum Cost Perfect Matching
(Might not get there today, but the problem is from 1.4.2 and 1.5.1.)