Primal Dual
Primal Dual
Assume that all primal constraints are equations with non-negative right-hand side,
and all the variables are non-negative. Then, we have the following rules for constructing
the dual problem
Dual problem
Primal Problem objective
Objective Constraints type Variable sign
maximization minimization unrestricted
minimization maximization unrestricted
Key ideas
- The (column) constraint coefficients and the objective coefficient of the jth primal
variable respectively define the left-hand an the right-hand sides of the jth dual con-
straint.
- The dual objective coefficients equal the right-hand sides of the primal constraint
equations.
Example 1
RSA 1
Operations Research
Example 2
Example 3
RSA 2
Operations Research
Following the rules listed above, we can use matrix-vector notation to easily find the dual
of any linear programming problem (written in standard form).
maximize cT x minimize bT y
subject to Ax = b subject to AT y c
x 0
minimize cT x maximize bT y
subject to Ax = b subject to AT y c
x 0
2. Understanding the dual problem leads to specialized algorithms for some important
classes of linear programming problems. Examples include the transportation simplex
method, the Hungarian algorithm for the assignment problem, and the network simplex
method.
3. The dual can be helpful for sensitivity analysis. Changing the primal’s right-hand side
constraint vector or adding a new constraint to it can make the original primal optimal
solution infeasible. However, this only changes the objective function or adds a new
variable to the dual, respectively, so the original dual optimal solution is still feasible
(and is usually not far from the new dual optimal solution).
4. The dual variables give the shadow prices for the primal constraints. Suppose you have
a profit maximization problem with a resource constraint i. Then the value yi of the
corresponding dual variable in the optimal solution tells you that you get an increase
of yi in the maximum profit for each unit increase in the amount of resource i.
5. Sometimes the dual is easier to solve. A primal problem with many constraints and
few variables can be converted into a dual problem with few constraints and many
variables (the fewer the constraints, the fewer computations required in each iteration
of the simplex method).
RSA 3
Operations Research
6. The dual can be used to detect primal infeasibility. If the dual is a minimization
problem whose objective function value can be made as small as possible, and any
feasible solution to the dual gives an upper bound on the optimal objective function
value in the primal, then the primal problem cannot have any feasible solutions.
1. If you are not familiar with MATLAB please click the following links and watch the
tutorial videos:
2. Recall the Klee and Minty linear programming problem. In its general form, this
LP problem is given by
The Tableau Simplex Method, starting at x = (0, 0, ...0)T , is known to visit all ex-
treme points in this LP.
We can use the MATLAB built-in solver for linear programming (LP) problems (this
is part of the Optimization Toolbox by MathWorks).
http://www.mathworks.com/help/optim/ug/linear-programming-algorithms.html
We use the function linprog in this example.
(a) Run the MATLAB file (.m file) and verify the solution to the Klee and Minty
problem for n = 4.
(b) Compare the running time and number of iterations for both methods, simplex
and interior-point: in the .m file, modify the line that declares the method to
be used
RSA 4
% Rei Sanchez-Arias. WIT
% Spring 2016. MATH 3700 OR
% Linear Programming Example(LP)
% Goal: use MATLAB command linprog to solve the Klee and Minty problem
% Type help linprog for instructions or visit
% http://www.mathworks.com/help/optim/ug/linprog.html
%
% Test Problem: (n = 4)
% maximize 8*x_1 + 4*x_2 + 2*x_3 + x_4
% subject to x_1 <= 5
% 4*x_1 + x_2 <= 25
% 8*x_1 + 4*x_2 + x_3 <= 125
% 16*x_1 + 8*x_2 + 4*x_3 + x_4 <= 625
% x_1 , x_2 , x_3 , x_4 >= 0
% Start timer
tic
[x,fopt,exitflag, output,lambda] = linprog(f,A,b,Aeq,beq,lb,ub,x0,options);
% Stop timer
total_time = toc;
x
fprintf('***************************************\n\n');
message = strcat(['Optimal point x found. Method used: ', ' ',method]);
fprintf(strcat(message, ' algorithm\n'));
fprintf('f(x) = %f, after %d iterations \n', -fopt,output.iterations)
% Notice that the solution that MATLAB returns must be multiplied by -1
% for our maximization problem
fprintf('Time : %f seconds\n', total_time);
fprintf('***************************************\n\n');
Introduction to MATLAB • Logical Operators
Also Matlab is case sensitive; if you try to use for example the constant f but you
type F it will tell you that the variable does not exist.
2
for i=limit1:inc:limit2 (where increment (inc) can be
positive ornegative. If inc is not defined, the -------------------------------------------------------------------------------------------------------------
default increment is one) % Example Simple Newton Method to find x such that
Statements (It will repeat executing f(x)=0
end the statements until limit1 reaches limit2)
x = 3; % initial point
f = (x^2)-1; % Original function
If limit1 is equal to limit2 the statement will still be executed once.
df= 2*x; % First derivative
Example iter = 0;
for i=1:5 for i=5:-.5:n while iter<100 % maximum number of iterations
x=2^i; OR x=2^i;
end end if abs(f)<1e-6,
break
end % you got the solution
• While Loop
The while loop executes the statements while the condition is true. If the deltax = -f/df; % solving the Newton step
condition is false the statements will not be executed. When doing a while loop x = x + deltax; % update
always make sure that inside the loop there is a statement that will eventually
make the condition false, else you will have a runaway computation. The format iter = iter+1; % updating iterations
for the while loop is: f = x^2-1; % Evaluate the function at the
% current step
while condition df = 2*x; % Evaluate the first derivative
Statements
End end
(anything you write right after a % sign will be considered a comment) • Storing Data
• M-Files When doing a program it may be necessary to store the value of different
variables at iterations.
An M-file is a file where you can put a sequence of statements and save them on a To do this you can use fid = fopen( ‘filename’ ,’ Permission’ )
disk. They are called M-files because they must have the file type ".m" as the last opens the file filename in the mode specified by permission. Permission can be:
part of their filename. M-files are useful when you need to execute a series of
statements at the same time and when you need to edit multiple commands. 'r' read 'r+' read and write (do not create)
Inside an m-file you can have if statements, loops and graphs among other things. 'w' write (create if necessary) 'w+' create for read and write
'a' append (create if necessary) 'a+' read and append
3
This will create and open the file where you will be storing the data. To store the 2 1.133333 0.284444
data you will use fprintf(fid, ‘ format’ ,variables) where fid 3 1.007843 0.0157478
has been initialized before to be the file you will be using, variables will be the 4 1.000031 6.1037e-005
name of the variables you want to save and format can be: 5 1.000000 9.31323e-010
• Plotting Example:
To draw a two dimensional graph just type plot(X,Y,S) where X is the plot(x,y)
independent variable, Y is the dependent variable and S is the format of the hold on, grid on
graph. S can be any of the following characters or a combination of the different plot(x,y,'gd')
columns.
y yellow * star - solid
k black o circle : dotted
b blue x x-mark -. dash dot
r red + plus - - dashed
g green d diamond
Example:
Example:
subplot(2,2,1); plot(x,y)
subplot(2,2,2); plot(x,x.^2,'rd-')
subplot(2,2,3); plot(x,x,'b*')
subplot(2,2,4); plot(x,x.^3, 'g')
5
Example:
x =[1:.5:5];
plot(x,x.^2)
hold on
plot(x,x.^2,'gd')
xlabel('independent variable')
ylabel('dependent variable')
title('Example of a plot')
Example of a plot
The last option is to have different graphs in different figures, in other words you 25
will have each graph in a different paper. To do this just type figure(n) where graph
data points
n will be the number of the figure you are using currently.
20
Example:
figure(1)
dependent variable
15
plot(x,y)
figure(2) 10
plot(x,y,'g+')
5
• Axis Labels, Titles and Legend
To add axis labels just type xlabel(‘label’) for the x-axis and
ylabel(‘label’) for the y-axis. To add a title to your graph just type 0
1 1.5 2 2.5 3 3.5 4 4.5 5
title(‘title’). A legend can be added when you are plotting several independent variable
graphs on the same plot. Just type
legend(‘legend1’, ‘legend2’, …, ‘legendn’).