Mixed Integer Quadratic Programming with linear constraints in Matlab calling Gurobi
I have some troubles to understand how to implement the following MIQP (Mixed Integer Quadratic Programming) with linear constraints in Matlab calling Gurobi.
Let me explain in a schematic way my setting.
(1) x
is the unknown and it is a column vector with size 225x1
.
(2) The objective function (which should be minimised wrto x
) looks like
which can be rewritten as
I have a Matlab script computing alpha, Q,c
(Q,c
sparse) when some_known_parameters1
are given:
function [alpha, Q,c]=matrix_objective_function(some_known_parameters1)
%...
end
(3) The constraints are linear in x
, include equalities and inequalities, and are written in the form
I have a Matlab script computing Aeq,beq,Aineq,bineq
(Aeq,Aineq
sparse) when some_known_parameters2
is given:
function [Aeq,beq,Aineq,bineq]=constraints(some_known_parameters2)
%...
end
(4) Some components of x
are restricted to be in 0,1. I have a Matlab script producing a string of letters B
(binary), C
(continous) when some_known_parameters3
is given:
function type=binary_continuous(some_known_parameters3)
%...
end
Now, I need to put together (1)-(4) using Gurobi. I am struggling to understand how. I found this example but it looks very cryptic to me. Below I report some lines I have attempted to write, but they are incomplete and I would like your help to complete them.
clear
rng default
%Define some_known_parameters1,
some_known_parameters2,some_known_parameters3 [...]
%1) generate alpha,Q,c,Aeq,beq,Aineq,bineq,type with Q,c,Aeq, Aineq sparse
[alpha, Q,c]=matrix_objective_function(some_known_parameters1)
[Aeq,beq,Aineq,bineq]=constraints(some_known_parameters2)
type=binary_continuous(some_known_parameters3)
%2) Set up Gurobi
clear model;
model.A=[Aineq; Aeq];
model.rhs=full([bineq(:); beq(:)]);
model.sense=[repmat('<', size(Aineq,1),1); repmat('=', size(Aeq,1),1)];
model.Q=Q; %not sure?
model.alpha=alpha; %not sure?
model.c=c; %not sure?
model.vtype=type;
result=gurobi(model); %how do I get just the objective function here without the minimiser?
Questions:
(1) I'm not sure about
model.Q=Q;
model.alpha=alpha;
model.c=c;
I'm just trying to set the matrices of the objective function using the letters provided here but it gives me error. The example here seems to me doing
model.Q=Q;
model.obj=c;
But then how do I set alpha
? Is it ignoring it because it does not change the set of solutions?
(2) How do I get as output stored in a matrix just the minimum value of the objective function without the corresponding x
?
matlab optimization gurobi quadratic-programming mixed-integer-programming
|
show 3 more comments
I have some troubles to understand how to implement the following MIQP (Mixed Integer Quadratic Programming) with linear constraints in Matlab calling Gurobi.
Let me explain in a schematic way my setting.
(1) x
is the unknown and it is a column vector with size 225x1
.
(2) The objective function (which should be minimised wrto x
) looks like
which can be rewritten as
I have a Matlab script computing alpha, Q,c
(Q,c
sparse) when some_known_parameters1
are given:
function [alpha, Q,c]=matrix_objective_function(some_known_parameters1)
%...
end
(3) The constraints are linear in x
, include equalities and inequalities, and are written in the form
I have a Matlab script computing Aeq,beq,Aineq,bineq
(Aeq,Aineq
sparse) when some_known_parameters2
is given:
function [Aeq,beq,Aineq,bineq]=constraints(some_known_parameters2)
%...
end
(4) Some components of x
are restricted to be in 0,1. I have a Matlab script producing a string of letters B
(binary), C
(continous) when some_known_parameters3
is given:
function type=binary_continuous(some_known_parameters3)
%...
end
Now, I need to put together (1)-(4) using Gurobi. I am struggling to understand how. I found this example but it looks very cryptic to me. Below I report some lines I have attempted to write, but they are incomplete and I would like your help to complete them.
clear
rng default
%Define some_known_parameters1,
some_known_parameters2,some_known_parameters3 [...]
%1) generate alpha,Q,c,Aeq,beq,Aineq,bineq,type with Q,c,Aeq, Aineq sparse
[alpha, Q,c]=matrix_objective_function(some_known_parameters1)
[Aeq,beq,Aineq,bineq]=constraints(some_known_parameters2)
type=binary_continuous(some_known_parameters3)
%2) Set up Gurobi
clear model;
model.A=[Aineq; Aeq];
model.rhs=full([bineq(:); beq(:)]);
model.sense=[repmat('<', size(Aineq,1),1); repmat('=', size(Aeq,1),1)];
model.Q=Q; %not sure?
model.alpha=alpha; %not sure?
model.c=c; %not sure?
model.vtype=type;
result=gurobi(model); %how do I get just the objective function here without the minimiser?
Questions:
(1) I'm not sure about
model.Q=Q;
model.alpha=alpha;
model.c=c;
I'm just trying to set the matrices of the objective function using the letters provided here but it gives me error. The example here seems to me doing
model.Q=Q;
model.obj=c;
But then how do I set alpha
? Is it ignoring it because it does not change the set of solutions?
(2) How do I get as output stored in a matrix just the minimum value of the objective function without the corresponding x
?
matlab optimization gurobi quadratic-programming mixed-integer-programming
1
You should not expect to be able to give gurobi some black-box objective. This is something for NLP territory (where some form of differentiation is happening inside; e.g. Ipopt/Bonmin). Gurobi needs this objective in it's own native form. What form that is depends on your lib/wrapper. In low-level form usually something like0.5 * x'Qx + q'x
with Q psd (convex QP; which is probably the only one gurobi supports; ignoring SOCP generalizations). If that's giving you headaches, look for some more high-level wrapper. Gurobi's Python-API for example supportsexpr = QuadExpr(x*x + y+y)
.
– sascha
Nov 13 '18 at 19:49
@sascha thanks: my problem is very basic I guess: (a) I think my objective function can be rewritten asQ+x'Hx
(I have added this to my question); (b) I still don't understand how to complete steps 3) and 4) above.
– user3285148
Nov 13 '18 at 19:55
1
This is all explained in the docs for this low-level view. Bring your objective in this form and setobj = some_vec
,objcon = some_vec
andQ = some_matrix
. Then (4) is just a string it seems likeBBC
(binary, binary, continuous). The bounds are vectorslb
andub
.
– sascha
Nov 13 '18 at 20:02
1
vtypes is string. lb ub are vectors. 3 vars between (-1,1), then (1,3) and (2,3) will be lb=[-1,1,2] and ub=[1,3,3].
– sascha
Nov 14 '18 at 5:35
1
That's a modelling thing. I recommend grabbing some integer-programming book. You can use one binary variable and replace all occurences with the termx = 1-2*binVar
. x will be in -1,1 then. Yes, this is annoying in low-level form (but there is no way out without wrappers / lib-support). But nobody should do prototyping on this level imho.
– sascha
Nov 14 '18 at 8:15
|
show 3 more comments
I have some troubles to understand how to implement the following MIQP (Mixed Integer Quadratic Programming) with linear constraints in Matlab calling Gurobi.
Let me explain in a schematic way my setting.
(1) x
is the unknown and it is a column vector with size 225x1
.
(2) The objective function (which should be minimised wrto x
) looks like
which can be rewritten as
I have a Matlab script computing alpha, Q,c
(Q,c
sparse) when some_known_parameters1
are given:
function [alpha, Q,c]=matrix_objective_function(some_known_parameters1)
%...
end
(3) The constraints are linear in x
, include equalities and inequalities, and are written in the form
I have a Matlab script computing Aeq,beq,Aineq,bineq
(Aeq,Aineq
sparse) when some_known_parameters2
is given:
function [Aeq,beq,Aineq,bineq]=constraints(some_known_parameters2)
%...
end
(4) Some components of x
are restricted to be in 0,1. I have a Matlab script producing a string of letters B
(binary), C
(continous) when some_known_parameters3
is given:
function type=binary_continuous(some_known_parameters3)
%...
end
Now, I need to put together (1)-(4) using Gurobi. I am struggling to understand how. I found this example but it looks very cryptic to me. Below I report some lines I have attempted to write, but they are incomplete and I would like your help to complete them.
clear
rng default
%Define some_known_parameters1,
some_known_parameters2,some_known_parameters3 [...]
%1) generate alpha,Q,c,Aeq,beq,Aineq,bineq,type with Q,c,Aeq, Aineq sparse
[alpha, Q,c]=matrix_objective_function(some_known_parameters1)
[Aeq,beq,Aineq,bineq]=constraints(some_known_parameters2)
type=binary_continuous(some_known_parameters3)
%2) Set up Gurobi
clear model;
model.A=[Aineq; Aeq];
model.rhs=full([bineq(:); beq(:)]);
model.sense=[repmat('<', size(Aineq,1),1); repmat('=', size(Aeq,1),1)];
model.Q=Q; %not sure?
model.alpha=alpha; %not sure?
model.c=c; %not sure?
model.vtype=type;
result=gurobi(model); %how do I get just the objective function here without the minimiser?
Questions:
(1) I'm not sure about
model.Q=Q;
model.alpha=alpha;
model.c=c;
I'm just trying to set the matrices of the objective function using the letters provided here but it gives me error. The example here seems to me doing
model.Q=Q;
model.obj=c;
But then how do I set alpha
? Is it ignoring it because it does not change the set of solutions?
(2) How do I get as output stored in a matrix just the minimum value of the objective function without the corresponding x
?
matlab optimization gurobi quadratic-programming mixed-integer-programming
I have some troubles to understand how to implement the following MIQP (Mixed Integer Quadratic Programming) with linear constraints in Matlab calling Gurobi.
Let me explain in a schematic way my setting.
(1) x
is the unknown and it is a column vector with size 225x1
.
(2) The objective function (which should be minimised wrto x
) looks like
which can be rewritten as
I have a Matlab script computing alpha, Q,c
(Q,c
sparse) when some_known_parameters1
are given:
function [alpha, Q,c]=matrix_objective_function(some_known_parameters1)
%...
end
(3) The constraints are linear in x
, include equalities and inequalities, and are written in the form
I have a Matlab script computing Aeq,beq,Aineq,bineq
(Aeq,Aineq
sparse) when some_known_parameters2
is given:
function [Aeq,beq,Aineq,bineq]=constraints(some_known_parameters2)
%...
end
(4) Some components of x
are restricted to be in 0,1. I have a Matlab script producing a string of letters B
(binary), C
(continous) when some_known_parameters3
is given:
function type=binary_continuous(some_known_parameters3)
%...
end
Now, I need to put together (1)-(4) using Gurobi. I am struggling to understand how. I found this example but it looks very cryptic to me. Below I report some lines I have attempted to write, but they are incomplete and I would like your help to complete them.
clear
rng default
%Define some_known_parameters1,
some_known_parameters2,some_known_parameters3 [...]
%1) generate alpha,Q,c,Aeq,beq,Aineq,bineq,type with Q,c,Aeq, Aineq sparse
[alpha, Q,c]=matrix_objective_function(some_known_parameters1)
[Aeq,beq,Aineq,bineq]=constraints(some_known_parameters2)
type=binary_continuous(some_known_parameters3)
%2) Set up Gurobi
clear model;
model.A=[Aineq; Aeq];
model.rhs=full([bineq(:); beq(:)]);
model.sense=[repmat('<', size(Aineq,1),1); repmat('=', size(Aeq,1),1)];
model.Q=Q; %not sure?
model.alpha=alpha; %not sure?
model.c=c; %not sure?
model.vtype=type;
result=gurobi(model); %how do I get just the objective function here without the minimiser?
Questions:
(1) I'm not sure about
model.Q=Q;
model.alpha=alpha;
model.c=c;
I'm just trying to set the matrices of the objective function using the letters provided here but it gives me error. The example here seems to me doing
model.Q=Q;
model.obj=c;
But then how do I set alpha
? Is it ignoring it because it does not change the set of solutions?
(2) How do I get as output stored in a matrix just the minimum value of the objective function without the corresponding x
?
matlab optimization gurobi quadratic-programming mixed-integer-programming
matlab optimization gurobi quadratic-programming mixed-integer-programming
edited Nov 14 '18 at 13:34
user3285148
asked Nov 12 '18 at 19:01
user3285148user3285148
623526
623526
1
You should not expect to be able to give gurobi some black-box objective. This is something for NLP territory (where some form of differentiation is happening inside; e.g. Ipopt/Bonmin). Gurobi needs this objective in it's own native form. What form that is depends on your lib/wrapper. In low-level form usually something like0.5 * x'Qx + q'x
with Q psd (convex QP; which is probably the only one gurobi supports; ignoring SOCP generalizations). If that's giving you headaches, look for some more high-level wrapper. Gurobi's Python-API for example supportsexpr = QuadExpr(x*x + y+y)
.
– sascha
Nov 13 '18 at 19:49
@sascha thanks: my problem is very basic I guess: (a) I think my objective function can be rewritten asQ+x'Hx
(I have added this to my question); (b) I still don't understand how to complete steps 3) and 4) above.
– user3285148
Nov 13 '18 at 19:55
1
This is all explained in the docs for this low-level view. Bring your objective in this form and setobj = some_vec
,objcon = some_vec
andQ = some_matrix
. Then (4) is just a string it seems likeBBC
(binary, binary, continuous). The bounds are vectorslb
andub
.
– sascha
Nov 13 '18 at 20:02
1
vtypes is string. lb ub are vectors. 3 vars between (-1,1), then (1,3) and (2,3) will be lb=[-1,1,2] and ub=[1,3,3].
– sascha
Nov 14 '18 at 5:35
1
That's a modelling thing. I recommend grabbing some integer-programming book. You can use one binary variable and replace all occurences with the termx = 1-2*binVar
. x will be in -1,1 then. Yes, this is annoying in low-level form (but there is no way out without wrappers / lib-support). But nobody should do prototyping on this level imho.
– sascha
Nov 14 '18 at 8:15
|
show 3 more comments
1
You should not expect to be able to give gurobi some black-box objective. This is something for NLP territory (where some form of differentiation is happening inside; e.g. Ipopt/Bonmin). Gurobi needs this objective in it's own native form. What form that is depends on your lib/wrapper. In low-level form usually something like0.5 * x'Qx + q'x
with Q psd (convex QP; which is probably the only one gurobi supports; ignoring SOCP generalizations). If that's giving you headaches, look for some more high-level wrapper. Gurobi's Python-API for example supportsexpr = QuadExpr(x*x + y+y)
.
– sascha
Nov 13 '18 at 19:49
@sascha thanks: my problem is very basic I guess: (a) I think my objective function can be rewritten asQ+x'Hx
(I have added this to my question); (b) I still don't understand how to complete steps 3) and 4) above.
– user3285148
Nov 13 '18 at 19:55
1
This is all explained in the docs for this low-level view. Bring your objective in this form and setobj = some_vec
,objcon = some_vec
andQ = some_matrix
. Then (4) is just a string it seems likeBBC
(binary, binary, continuous). The bounds are vectorslb
andub
.
– sascha
Nov 13 '18 at 20:02
1
vtypes is string. lb ub are vectors. 3 vars between (-1,1), then (1,3) and (2,3) will be lb=[-1,1,2] and ub=[1,3,3].
– sascha
Nov 14 '18 at 5:35
1
That's a modelling thing. I recommend grabbing some integer-programming book. You can use one binary variable and replace all occurences with the termx = 1-2*binVar
. x will be in -1,1 then. Yes, this is annoying in low-level form (but there is no way out without wrappers / lib-support). But nobody should do prototyping on this level imho.
– sascha
Nov 14 '18 at 8:15
1
1
You should not expect to be able to give gurobi some black-box objective. This is something for NLP territory (where some form of differentiation is happening inside; e.g. Ipopt/Bonmin). Gurobi needs this objective in it's own native form. What form that is depends on your lib/wrapper. In low-level form usually something like
0.5 * x'Qx + q'x
with Q psd (convex QP; which is probably the only one gurobi supports; ignoring SOCP generalizations). If that's giving you headaches, look for some more high-level wrapper. Gurobi's Python-API for example supports expr = QuadExpr(x*x + y+y)
.– sascha
Nov 13 '18 at 19:49
You should not expect to be able to give gurobi some black-box objective. This is something for NLP territory (where some form of differentiation is happening inside; e.g. Ipopt/Bonmin). Gurobi needs this objective in it's own native form. What form that is depends on your lib/wrapper. In low-level form usually something like
0.5 * x'Qx + q'x
with Q psd (convex QP; which is probably the only one gurobi supports; ignoring SOCP generalizations). If that's giving you headaches, look for some more high-level wrapper. Gurobi's Python-API for example supports expr = QuadExpr(x*x + y+y)
.– sascha
Nov 13 '18 at 19:49
@sascha thanks: my problem is very basic I guess: (a) I think my objective function can be rewritten as
Q+x'Hx
(I have added this to my question); (b) I still don't understand how to complete steps 3) and 4) above.– user3285148
Nov 13 '18 at 19:55
@sascha thanks: my problem is very basic I guess: (a) I think my objective function can be rewritten as
Q+x'Hx
(I have added this to my question); (b) I still don't understand how to complete steps 3) and 4) above.– user3285148
Nov 13 '18 at 19:55
1
1
This is all explained in the docs for this low-level view. Bring your objective in this form and set
obj = some_vec
, objcon = some_vec
and Q = some_matrix
. Then (4) is just a string it seems like BBC
(binary, binary, continuous). The bounds are vectors lb
and ub
.– sascha
Nov 13 '18 at 20:02
This is all explained in the docs for this low-level view. Bring your objective in this form and set
obj = some_vec
, objcon = some_vec
and Q = some_matrix
. Then (4) is just a string it seems like BBC
(binary, binary, continuous). The bounds are vectors lb
and ub
.– sascha
Nov 13 '18 at 20:02
1
1
vtypes is string. lb ub are vectors. 3 vars between (-1,1), then (1,3) and (2,3) will be lb=[-1,1,2] and ub=[1,3,3].
– sascha
Nov 14 '18 at 5:35
vtypes is string. lb ub are vectors. 3 vars between (-1,1), then (1,3) and (2,3) will be lb=[-1,1,2] and ub=[1,3,3].
– sascha
Nov 14 '18 at 5:35
1
1
That's a modelling thing. I recommend grabbing some integer-programming book. You can use one binary variable and replace all occurences with the term
x = 1-2*binVar
. x will be in -1,1 then. Yes, this is annoying in low-level form (but there is no way out without wrappers / lib-support). But nobody should do prototyping on this level imho.– sascha
Nov 14 '18 at 8:15
That's a modelling thing. I recommend grabbing some integer-programming book. You can use one binary variable and replace all occurences with the term
x = 1-2*binVar
. x will be in -1,1 then. Yes, this is annoying in low-level form (but there is no way out without wrappers / lib-support). But nobody should do prototyping on this level imho.– sascha
Nov 14 '18 at 8:15
|
show 3 more comments
1 Answer
1
active
oldest
votes
(1) You're right, there's no need to pass the constant alpha since it doesn't affect the optimal solution. Gurobi's MATLAB API only accepts sparse matrices. Furthermore model.obj
is always the c vector in the problem statement:
model.Q = sparse(Q);
model.obj = c;
(2) To get the optimal objective value, you first need to pass your model to gurobi and solve it. Then you can access it via the objval attribute:
results = gurobi(model);
val = results.objval + alpha
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268494%2fmixed-integer-quadratic-programming-with-linear-constraints-in-matlab-calling-gu%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
(1) You're right, there's no need to pass the constant alpha since it doesn't affect the optimal solution. Gurobi's MATLAB API only accepts sparse matrices. Furthermore model.obj
is always the c vector in the problem statement:
model.Q = sparse(Q);
model.obj = c;
(2) To get the optimal objective value, you first need to pass your model to gurobi and solve it. Then you can access it via the objval attribute:
results = gurobi(model);
val = results.objval + alpha
add a comment |
(1) You're right, there's no need to pass the constant alpha since it doesn't affect the optimal solution. Gurobi's MATLAB API only accepts sparse matrices. Furthermore model.obj
is always the c vector in the problem statement:
model.Q = sparse(Q);
model.obj = c;
(2) To get the optimal objective value, you first need to pass your model to gurobi and solve it. Then you can access it via the objval attribute:
results = gurobi(model);
val = results.objval + alpha
add a comment |
(1) You're right, there's no need to pass the constant alpha since it doesn't affect the optimal solution. Gurobi's MATLAB API only accepts sparse matrices. Furthermore model.obj
is always the c vector in the problem statement:
model.Q = sparse(Q);
model.obj = c;
(2) To get the optimal objective value, you first need to pass your model to gurobi and solve it. Then you can access it via the objval attribute:
results = gurobi(model);
val = results.objval + alpha
(1) You're right, there's no need to pass the constant alpha since it doesn't affect the optimal solution. Gurobi's MATLAB API only accepts sparse matrices. Furthermore model.obj
is always the c vector in the problem statement:
model.Q = sparse(Q);
model.obj = c;
(2) To get the optimal objective value, you first need to pass your model to gurobi and solve it. Then you can access it via the objval attribute:
results = gurobi(model);
val = results.objval + alpha
answered Nov 15 '18 at 9:36
jonijoni
748157
748157
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268494%2fmixed-integer-quadratic-programming-with-linear-constraints-in-matlab-calling-gu%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You should not expect to be able to give gurobi some black-box objective. This is something for NLP territory (where some form of differentiation is happening inside; e.g. Ipopt/Bonmin). Gurobi needs this objective in it's own native form. What form that is depends on your lib/wrapper. In low-level form usually something like
0.5 * x'Qx + q'x
with Q psd (convex QP; which is probably the only one gurobi supports; ignoring SOCP generalizations). If that's giving you headaches, look for some more high-level wrapper. Gurobi's Python-API for example supportsexpr = QuadExpr(x*x + y+y)
.– sascha
Nov 13 '18 at 19:49
@sascha thanks: my problem is very basic I guess: (a) I think my objective function can be rewritten as
Q+x'Hx
(I have added this to my question); (b) I still don't understand how to complete steps 3) and 4) above.– user3285148
Nov 13 '18 at 19:55
1
This is all explained in the docs for this low-level view. Bring your objective in this form and set
obj = some_vec
,objcon = some_vec
andQ = some_matrix
. Then (4) is just a string it seems likeBBC
(binary, binary, continuous). The bounds are vectorslb
andub
.– sascha
Nov 13 '18 at 20:02
1
vtypes is string. lb ub are vectors. 3 vars between (-1,1), then (1,3) and (2,3) will be lb=[-1,1,2] and ub=[1,3,3].
– sascha
Nov 14 '18 at 5:35
1
That's a modelling thing. I recommend grabbing some integer-programming book. You can use one binary variable and replace all occurences with the term
x = 1-2*binVar
. x will be in -1,1 then. Yes, this is annoying in low-level form (but there is no way out without wrappers / lib-support). But nobody should do prototyping on this level imho.– sascha
Nov 14 '18 at 8:15