Model not feasible while solution does exists
AnsweredHi,
I create model as follows
def create_model() -> gurobi.Model:
m = gurobi.Model()
m.Params.LogToConsole = 1
m.Params.PoolSearchMode = 1
m.Params.PoolSolutions = 1
m.Params.PoolGap = 0
m.Params.NonConvex = 2
return m
Next,
I introduce a number of variables and constraints:
proj_matrix = [[-0.47686108766245655, 0.8789748939150358, -0.002576614140793262],
[-0.8789639728247254, -0.4768680170660497, -0.00438506278966113],
[-0.005083064976417589, 0.00017368519028203956, 0.9999870660583067]]
shot_x = m.addVar(vtype=gurobi.GRB.CONTINUOUS, name='shot_x')
shot_y = m.addVar(vtype=gurobi.GRB.CONTINUOUS, name='shot_y')
shot_z = m.addVar(vtype=gurobi.GRB.CONTINUOUS, name='shot_z')
condition_x = shot_x * proj_matrix[0][0] + shot_y * proj_matrix[1][0] + shot_z * proj_matrix[2][0]
condition_y = shot_x * proj_matrix[0][1] + shot_y * proj_matrix[1][1] + shot_z * proj_matrix[2][1]
condition_z = shot_x * proj_matrix[0][2] + shot_y * proj_matrix[1][2] + shot_z * proj_matrix[2][2]
proj_z = -24.008363727141393
proj_x = -0.2297853284073595
proj_y = -35.20627970757762
m.addConstr(gurobi.quicksum([condition_x]) == proj_x)
m.addConstr(gurobi.quicksum([condition_y]) == proj_y)
m.addConstr(gurobi.quicksum([condition_z]) == proj_z)
m.update()
m.optimize()
print(f'number of solutions: {m.SolCount}')
The above results in no solution. However. I know that the correct solution is:
x = -30.77400000000125
y = 17.09599999999955
z = -24.013000000000005
What am I doing wrong? Thanks in advance!
0
-
The default lower bound for variables is \(0\). You have to explicitly state that a variable is allowed to attain negative values.
shot_x = m.addVar(lb=-gurobi.GRB.INFINITY, vtype=gurobi.GRB.CONTINUOUS, name='shot_x')
shot_y = m.addVar(lb=-gurobi.GRB.INFINITY, vtype=gurobi.GRB.CONTINUOUS, name='shot_y')
shot_z = m.addVar(lb=-gurobi.GRB.INFINITY, vtype=gurobi.GRB.CONTINUOUS, name='shot_z')Best regards,
Jaromił0 -
Hi,
The default lower bound of variables is 0.0 Model.addVar().
You can change this when you create the variables:shot_x = m.addVar(lb=-100, vtype=gurobi.GRB.CONTINUOUS, name='shot_x')
Additionally, you don't need to add the \(\texttt{quicksum}\) expression as your \(\texttt{condition_*}\) are already LinExpr.
Cheers,
David0 -
Thank you Jaromil and David!
0
Please sign in to leave a comment.
Comments
3 comments