GPrathap
GPrathap

Reputation: 7810

How can we set a objective function in setObjective in Gurobi

import numpy as np
import scipy.optimize
import gurobipy as gp

halfspaces = np.array([[-0.513574, 0.858045 , 0,1.99106]
,[0.513574 ,-0.858045 , -0,2.00894]
,[-0.856348 , -0.512558, -0.0628725, 3.28365]
,[ 0.856348 , 0.512558 , 0.0628725,-0.402219]
,[0.0539475 , 0.0322897 ,-0.998022,-0.928943]
,[-0.0539475 ,-0.0322897 , 0.998022,2.92894]
,[-0.853709 , -0.509332 , -0.108451,0.0116693]])


A = halfspaces[:,0:3]
b = halfspaces[:,-1]

def objective(c):
    d = np.dot(A,c)-b
    d=np.where(d<=-1e-15, d, d+1.0)
    return np.max([0, np.max(d)])

c = np.dot(np.linalg.pinv(A), b)
c = scipy.optimize.fmin(func=objective, x0=c)

I need to convert into Gurobi, yet I have not found a way to define the objective as a function. Here it says it is not supported yet. Could someone advise me is there any workaround for this? Or this yet to be implemented.

Upvotes: 1

Views: 192

Answers (1)

mattmilten
mattmilten

Reputation: 6706

This is not possible in Gurobi. Usually, MIP solvers need to rely on fixed and known coefficients to perform the optimization. Defining a function as an objective would heavily impact the performance of the solver.

Upvotes: 1

Related Questions