Skip to content

Instantly share code, notes, and snippets.

@jdherman
Created March 12, 2014 18:04
Show Gist options
  • Save jdherman/9512628 to your computer and use it in GitHub Desktop.
Save jdherman/9512628 to your computer and use it in GitHub Desktop.
clc; clear all;
% Solve the Masonry LP
% max Z = 140*x1 + 160*x2
% subject to:
% 2*x1 + 4*x2 <= 28
% 5*x1 + 5*x2 <= 50
% x1 <= 8
% x2 <= 6
% x1, x2 >= 0
% MUST CONVERT TO MINIMIZATION PROBLEM
% Cost vector - add negatives to minimize
f = [-140, -160];
% Constraints (the last two need to be negated)
A = [2 4;
5 5;
1 0;
0 1;
-1 0;
0 -1];
% Right-hand side of constraints
b = [28 50 8 6 0 0]';
[X, FVAL, EXITFLAG] = linprog(f, A, b);
% X contains the optimal point (x1,x2)
% FVAL contains the optimal function value
% EXITFLAG should equal 1 for a successful optimization
% (if not, read "help linprog" for more information)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment