extract Gurobi variable value to type float in python

473 views
Skip to first unread message

Zheng GONG

unread,
Jan 26, 2017, 1:10:36 AM1/26/17
to Gurobi Optimization
in the simple example below, self_defined_function is complicated and can't be expressed with common operator such as +, -.
both arguments, x, y of self_defined_function are float.

my question is how to extract Gurobi variable value of x, y to float so that I can feed both to self_defined_function? 

def func(x, y):
    r = self_defined_function(x,y)
    return r

m = Model("model")
x = m.addVar(vtype=GRB.CONTINUOUS, name="x", lb = 0.1, ub = 1.0)
y = m.addVar(vtype=GRB.CONTINUOUS, name="x", lb = 0.1, ub = 1.0)

r = func(x, y)
    
m.setObjective(r, GRB.MINIMIZE)
        
m.optimize()

Thanks.


Sonja Mars

unread,
Jan 26, 2017, 1:31:32 AM1/26/17
to gur...@googlegroups.com
Hi,

What you are trying to do is not possible. x and y are Gurobi variable objects (http://www.gurobi.com/documentation/7.0/refman/py_var.html). Additionally, before calling optimize they don't have a value.

What is self_defined_function supposed to do with the variables?

Best regards,
Sonja


----
Dr. Sonja Mars
Gurobi Optimization - Technical Support
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "Gurobi Optimization" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to gurobi+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Zheng GONG

unread,
Jan 26, 2017, 2:31:17 PM1/26/17
to Gurobi Optimization
Hi Sonja,

Actually the self_defined_function is our product. We are interested in integrating Gurobi into our product.
For our product, we want to use Gurobi as an optimizer.
For Gurobi, our product is the objective function, or external cost function, but is a black box to Gurobi.

Please advise how we can do it, how an external cost function can be called by Gurobi.

Thanks,
Zheng
Reply all
Reply to author
Forward
0 new messages