Reputation: 51
I am working on a POC to see if pyomo will work for my application and I could use some help determining if there is a fix for the error below of if my intent is not possible.
After adding the constraint "split_comp_color" I am getting the error: "CPLEXDirect does not support expressions of degree None." I have not been able to find any relevant posts to this topic. Originally the expression for this constraint was dependent on the variable values which I did learn is not possible. Instead I changed the expression to find every combination and multiply by the variables which will cancel if any/all are zeros. Basically what I'm trying to do, for each Look I want to verify that the hues of the top, bottom and shoe meet the formula inequality. Is this possible? Is there a better way to do this? I don't understand why the expression is degree None where I would expect three (the three variables are multiple by each other). Can anyone explain why this is the case?
I am running the code with the command $ python toy_abstract.py toy_data.dat
Thank you for any help in advance! Christine
Below is just the snippets relevant to the question but additional code can be provided.
model = AbstractModel()
model.tops = Set()
model.bottoms = Set()
model.shoes = Set()
model.looks = Set()
model.theta = Param(within=NonNegativeIntegers)
model.tol = Param(within=NonNegativeIntegers)
model.hue_tops = Param(model.tops, within=UnitInterval)
model.hue_bottoms = Param(model.bottoms, within=UnitInterval)
model.hue_shoes = Param(model.shoes, within=UnitInterval)
model.top_cnt = Var(model.looks * model.tops, domain=Binary)
model.bottom_cnt = Var(model.looks * model.bottoms, domain=Binary)
model.shoe_cnt = Var(model.looks * model.shoes, domain=Binary)
def split_comp_color(model, look):
theta = model.theta # 30
tol = model.tol # 10
return sum([model.top_cnt[look, top] * model.bottom_cnt[look, bottom] * model.shoe_cnt[look, shoe] * int(((p[0]-p[1])-math.floor(p[0]-p[1]) > ((180-theta/2)-tol/2)/360) & ((p[0]-p[1])-math.floor(p[0]-p[1]) < ((180-theta/2)+tol/2)/360) & ((p[0]-p[2])-math.floor(p[0]-p[2]) > ((180+theta/2)-tol/2)/360) & ((p[0]-p[2])-math.floor(p[0]-p[2]) < ((180+theta/2)+tol/2)/360)) for top in model.tops for bottom in model.bottoms for shoe in model.shoes for p in permutations(np.array([model.hue_tops[top], model.hue_bottoms[bottom], model.hue_shoes[shoe]]), 3)]) >= 0.1
model.split_comp_color = Constraint(model.looks, rule=split_comp_color)
Actual results:
pyomo.solvers.plugins.solvers.cplex_direct.DegreeError: CPLEXDirect does not support expressions of degree None. expr: top_cnt[Look1,5115232-100]*bottom_cnt[Look1,5108339-001]*shoe_cnt[Look1,5181676-001] + top_cnt[Look1,5115232-100]*bottom_cnt[Look1,5108339-001]*shoe_cnt[Look1,5120179-001] + ...
Upvotes: 2
Views: 1275
Reputation: 16772
No. Cplex can only do linear and (some) quadratic models.
However, you have expressions of the form x[i,p]*y[i,q]*z[i,r]
with x,y, and z all binary variables. We can linearize xyz[i,p,q,r] = x[i,p]*y[i,q]*z[i,r]
by using a well-known reformulation:
xyz[i,p,q,r] <= x[i,p]
xyz[i,p,q,r] <= y[i,q]
xyz[i,p,q,r] <= z[i,r]
xyz[i,p,q,r] >= x[i,p]+y[i,q]+z[i,r]-2
xyz[i,p,q,r] in {0,1}
Upvotes: 2