How can we set a objective function in setObjective
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 want to convert this into gurobi, but still, I could not figure out how to set the objective function as a function. Here it says the setting function is not supported: https://support.gurobi.com/hc/en-us/community/posts/360067891692-Is-it-able-to-define-setObjective-function-by-def-or-lambda- Could you help me to how to solve this issue,
0
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
Post is closed for comments.
Comments
1 comment