Introduction to Linear Optimization

Math 245 - Mathematical Models
Goal: Understand how to use Mathematica to solve an optimization problem

See also Mathematica’s tutorial: tutorial/MinimizationAndMaximization

6.1 Plotting a region defined by a set of inequalities.

To plot a region defined by a set of inequalities, use the RegionPlot command.  The first input tells Mathematica which points are valid points.  For example, in the following example, there are three inequalities, x≥0, y≥0, and x+y<1.5, separated by && because points must satisfy inequality 1 AND inequality 2 AND inequality 3.  The second and third inputs are the ranges for x and y.

RegionPlot[x≥0&&y≥0&&x+y<1.5,{x,-2,2},{y,-2,2}]

6.2 Solving an optimization problem

Solving a linear program

A linear program has an objective function f, and constraints (Subscript[c, 1]),... , (Subscript[c, n]) in variable x,y,...
To solve a linear program, use either Maximize or Minimize (depending on whether you are maximizing or minimizing the objective function f).   The first input in the command is a list which contains the objective function as the first entry, and the constraints afterward.  The constraints can either be placed together as (Subscript[c, 1])&&...&&(Subscript[c, n]) or they can be entered as successive elements of the list.  (You can see that the following two commands give the same output.)  The second input to Maximize or Minimize is the set of variables under consideration.

Maximize[{x,x≥0&&y≥0&&x+y≤1.5},{x,y}]

Maximize[{x,x≥0,y≥0,x+y≤1.5},{x,y}]

The second entry of the output is the set of coordinates at which the optimum value is obtained.  The first entry of output gives the value of the objective function at this optimum point.  We see that in the feasible region above, the highest value that the objective function f(x,y)=x can obtain is 1.5, when x=1.5 and y=0.

Solving an integer program

In order to restrict the solutions to be integral solutions, all you need to do is insert a third input “Integers” into Maximize or Minimize to tell Mathematica to restrict the domain of solution.

Maximize[{x,x≥0&&y≥0&&x+y≤1.5},{x,y},Integers]