Skip to content

Instantly share code, notes, and snippets.

@phabee
Created May 13, 2020 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phabee/dea5bc5a1b60fd7a3adcf705dfa1e02e to your computer and use it in GitHub Desktop.
Save phabee/dea5bc5a1b60fd7a3adcf705dfa1e02e to your computer and use it in GitHub Desktop.
Call Gurobi from Matlab and transform inequalities to equalities introducing Slack-Variables
model.obj = [1,1,0,0,0,0]';
model.sense = ['=', '=', '=', '=', '>', '>', '>', '>']';
model.rhs = [200000, 100, 200, 0, 0, 0, 0, 0]';
model.lb = [0, 0, 0, 0, 0, 0]';
model.ub = [1e22, 1e22, 1e22, 1e22, 1e22, 1e22]';
model.vtype = ['C', 'C', 'C', 'C', 'C', 'C']'
model.A = sparse([800, 400, 1, 0, 0, 0; 1, 0, 0, -1, 0, 0; 0, 1, 0, 0, -1, 0; 2, -1, 0, 0, 0, 1; zeros(4,2), eye(4)]);
model.modelsense = 'max';
model.slack = [0, 0, 1, 1, 1, 1];
params.outputflag = 1;
params.logfile = 'gurobi_solver.log';
result = gurobi(model, params);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment