Min GenExpr and multiplying by -1
AnsweredWe're trying to model and implement a constraint that relies on the "end of an event" in its schedule.
To do so, we're trying to do (in python):
g = min_(0, -w) or alternatively, g = - min_(0,w); w is an auxiliary variable in {-1,0,1} and we want to detect the case of w = -1.
However we get an error that the gen expr can't be multiplied or invalid array multiplication.
Is there any functionality to implement like this? Our alternative is to use additional auxiliary variables that are in essence the reverse of w, but it would be nice if this function could be possible.
-
Hi Phillip,
Could you please post the (relevant section of) your source code so we can better help you understand the issue?
Cheers,
Matthias1 -
Hi Matthias, we had:
self.scheme.g_w_relationship = {}
for b in self.list_of_b:
self.scheme.g_w_relationship[b] = {}
for event in self.events:
self.scheme.g_w_relationship[b][event] = {}
for season in self.seasons:
ret_name = 'f_w_rel' + '_' + str(b.id) + '_' + str(event.id) + '_' + str(season.id)
lhs = self.scheme.g[b][event][season]
if not season.last:
rhs = self.model.max_([0, -self.scheme.w[b][event][season.successor]])
else:
rhs = 1 - self.scheme.a[b][event][season]
self.scheme.g_w_relationship[b][event][season] = self.model.add_constraint(full_expression=lhs == rhs, name=ret_name)It returns specifically:
return self._model.addConstr(full_expression, name=name)
File "model.pxi", line 3218, in gurobipy.Model.addConstr
File "model.pxi", line 3939, in gurobipy.Model.addGenConstrMax
gurobipy.GurobiError: Invalid data in vars array
I hope that is useful.
Regards, Phillip0 -
Hi Phillip,
I'm sorry but this is still not very helpful. There is no add_constraint method in Gurobi; it appears the model object wraps the Gurobi Model. I also cannot tell what kind of data you are using to construct the max constraint and where the error really comes from.
Please try to post a minimal reproducible example.
Cheers,
Matthias0 -
Thought I would follow this one up whilst logged in - turns out our modelling was prohibitive for the constraint behaviour we were trying to design. Remodelling seemed to find a way around the issue.
0
Please sign in to leave a comment.
Comments
4 comments