How to solve Mixed Integer Non-Linear Programming(MINLP) with GUROBI

1,956 views
Skip to first unread message

Himank Gupta

unread,
Feb 10, 2017, 1:46:06 AM2/10/17
to Gurobi Optimization
I want to know how to write an objective function as a summation of a variable from 1 to n. My objective function looks like as following: Objective =Maximize∑i=1 to U(α_{i}∗X_{i}+α_{i}∗Y_{i}).

Where α is Binary Variable and X and Y are continuous variables. My constraints are linear.

Can anybody tell me how to write these type of objectives function in GUROBI?

If GUROBI can not solve these type of problems then please tell any C++ open-source solver which I can integrate any C++ software.?

Daniel Espinoza

unread,
Feb 10, 2017, 6:48:13 AM2/10/17
to Gurobi Optimization
Himank,

there you can look at the classical diet problem in C, C++, C#, Java and Python, here is the link for python

Best luck,
Daniel

Himank Gupta

unread,
Feb 10, 2017, 12:52:52 PM2/10/17
to Gurobi Optimization
Hi daniel,

Thanks for your response.

My major question is that my Objective contain sum of multiplication of two variable in which one is binary and other is continuous variable. So can we solve these types of problems with GUROBI.

In this diet example we are using GRB_IntAttr_ModelSense to set objective. How it sets objective function for us? Please explain.


Tobias Achterberg

unread,
Feb 10, 2017, 1:39:50 PM2/10/17
to gur...@googlegroups.com
Hi Himank,

yes, such quadratic objective functions can be directly used with Gurobi. If the
continuous variables are bounded, then it should work even for non-convex
objective functions (because a product of a binary and a bounded continuous
variable can be linearized, and Gurobi does so automatically).

Best regards,

Tobias

Himank Gupta

unread,
Feb 11, 2017, 8:35:35 AM2/11/17
to Gurobi Optimization
Hi Tobias,

Thanks for your prompt response.

In diet.cpp example we are minimizing the cost of food provided we will have minimum calories, fat and etc.
My question is that how GRB_IntAttr_ModelSense sense the objective function equation?

As my objective function is Objective =Maximize∑i=1 to U(α_{i}∗X_{i}+α_{i}∗Y_{i}). So how it sense the model ?

Tobias Achterberg

unread,
Feb 12, 2017, 6:37:03 PM2/12/17
to gur...@googlegroups.com
Is your question how one can change the objective sense from minimization to
maximization? Just set the "ModelSense" attribute to -1. For example, in C++ you
would write

m.set(GRB_IntAttr_ModelSense, -1);

with m being your Gurobi model object.


Tobias

Himank Gupta

unread,
Feb 13, 2017, 12:41:40 AM2/13/17
to Gurobi Optimization
Hi All,

My question is not about maximization or minimization.

In general we set the objective function as following:
             model.setObjective(x*a + y*y + z, GRB_MAXIMIZE);

But if we want to maximize a sum of sum variable as I mentioned in my objective function: Maximize∑i=1 to U(α_{i}∗X_{i}+α_{i}∗Y_{i}).

In this case, we write     model.set(GRB_IntAttr_ModelSense, GRB_MINIMIZE);. My question is how GRB_IntAttr_ModelSense set my eauation in objective function.
Please help me to understand this.

Tobias Achterberg

unread,
Feb 13, 2017, 12:33:33 PM2/13/17
to gur...@googlegroups.com
So, your question is how to specify the objective function for a quadratic
program. Please take a look here for a C++ example:

http://www.gurobi.com/documentation/7.0/examples/qp_cpp_cpp.html

You simply define a GRBQuadExpr and then call model.setObjective() with this
expression. You can build GRBQuadExpr objects step by step, like this:

GRBQuadExpr obj;
for (i = 0; i < n; i++) {
obj += alpha[i] * X[i] + alpha[i] * Y[i];
}
model.setObjective(obj, GRB_MAXIMIZE);

with alpha[], X, and Y being arrays of GRBVar objects.


Hope this helps,

Tobias
Reply all
Reply to author
Forward
0 new messages