Introduction to Linear Programming
Introduction to Linear Programming
3. Example Problem
Problem: Maximize z=3x1+2x2z = 3x_1 + 2x_2z=3x1+2x2 subject to:
x1+x2≤4x_1 + x_2 \leq 4x1+x2≤4 x1≤2x_1 \leq 2x1≤2 x2≤3x_2 \leq 3x2≤3
x1≥0x_1 \geq 0x1≥0 x2≥0x_2 \geq 0x2≥0
Step-by-Step Solution:
1. Define Objective Function:
octave
Copy code
c = [-3; -2]; % Coefficients for the objective function (negative for maximization)
2. Define Constraints:
octave
Copy code
A = [1, 1; 1, 0; 0, 1]; % Coefficients for inequality constraints
b = [4; 2; 3]; % Right-hand side for inequality constraints
3. Define Bounds:
octave
Copy code
lb = [0; 0]; % Lower bounds for x1 and x2
ub = []; % No upper bounds explicitly defined (will use constraints instead)
4. Solve the Problem:
octave
Copy code
[x, fval] = linprog(c, A, b, [], [], lb, ub)
Output Interpretation:
x will contain the values of x1x_1x1 and x2x_2x2 that maximize the
objective function.
fval will contain the maximum value of the objective function zzz.
4. Additional Considerations
4.1 Integer Programming: For problems where decision variables must be
integers, you would typically use integer programming techniques. Octave’s
linprog does not support integer constraints directly, so you may need to use
specialized solvers or packages.
4.2 Sensitivity Analysis: Octave doesn’t provide built-in functions for
sensitivity analysis, but you can manually vary parameters and observe changes
in the solution.
4.3 Advanced Constraints: For more complex constraints, such as nonlinear
constraints or quadratic objectives, you may need to use different optimization
functions or tools.
4.4 Debugging:
Infeasibility: If Octave returns infeasible solutions, check constraints and
bounds.
Unbounded Solutions: If the solution is unbounded, verify that the
problem formulation and constraints are correctly specified.