Issues with using MIN for a constraint
回答済みA is 30*1 dimensional variable (given), set is I
B is 10*1 dimensional variable (unknown, needed to be figured out from the optimization), set is J
objective=grb.quicksum((y[i,j])for i in I for j in J+ min_y[i] for i in I)
c1={j:m.addConstr(lhs=(t[j]),sense=grb.GRB.EQUAL, rhs=B[j+1]-B[j],name="c1".format(j)) for j in range(9)}
c2={(i,j):m.addConstr(lhs=(A[i]-B[j])*(A[i]-B[j]),sense=grb.GRB.EQUAL,rhs=y[i,j],name="c2".format(i,j)) for i in I for j in J}
c3={i:m.addConstr(lhs=min_y[i],sense=grb.GRB.EQUAL,rhs=grb.min_(y[i,j] for j in J), name="c3".format(i)) for i in I}
m.params.NonConvex=2
m.ModelSense = grb.GRB.MINIMIZE
m.setObjective(objective)
m.optimize()
I have been getting error for the third constraint . Unsupported type for LinExpr Addition argument. Without the min constraint, it runs alright. Please let me know how to solve this issue.
To summarize the problem, I need to find the minimum value for each min_y(i) from all y(i,j) to use it in the objective. [e.g. min_y(1)= minimum (y(0,0), y(0,1),...y(0,8), y(0,9))]
Hope it makes sense. Thanks
-
正式なコメント
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?. -
There is a good example of using the general max constraint in the Model.addGenConstrMax() documentation. To translate this to your problem, you would use the following to define c3:
c3={i:m.addConstr(min_y[i] == grb.min_(y[i,j] for j in J), name="c3".format(i)) for i in I}One other item of note, there was an error when I ran the objective definition. According to the quicksum() documentation, the input argument should be a
List of terms to add. The terms can be constants, Var objects, LinExpr objects, or QuadExpr objects.
To remedy this, you can use the following to define your objective
objective = grb.quicksum((y[i,j])for i in I for j in J) + grb.quicksum(min_y[i] for i in I)
1 -
Thanks a lot for your prompt response, Alison.
0 -
Hi,
While I was trying to optimize this, it is taking too long to converge/give an answer. The min_y variable is making it time consuming. Apparently I did not get any answer after keeping it running for a day. I have used/assigned values of MIPFocus=1. Is there anything I can do to make it faster ? I am using a regular laptop with core i-7 and 16 gb RAM.
0 -
There are a few things I can suggest:
- Provide a warm start: Typically, providing a warm start or initial solution can improve performance significantly. Even a relatively poor feasible point could be useful for the solver. A warm start can affect many algorithmic choices during Gurobi's solve.
- Tighten variable bounds: One large challenge in nonconvex optimization is generating tight outer approximations of nonconvex terms. A simple way to improve these approximations is to provide tight bounds on all variables — especially, variables that are part of nonlinear terms. I recommend starting here to see how this affects the solve.
- Scale variables and constraints: Consider scaling your variable ranges, constraint coefficients, and RHS values. Our reference manual's Tolerances and user-scaling section can walk you through why scaling is important, rules of thumb for scaling, and some examples.
- Consider tuning parameters: Gurobi has several parameters that affect the solution time. It may be beneficial to try non-default values to see if you can close the gap. I recommend reading through Most Important MIP Parameters along with your log file for ideas. There are a few specific parameters to test that focus on quadratic problems only (e.g., PreMIQCPForm). While it may be daunting to sift through all of these parameters by hand, Gurobi offers an automated tuning tool to help select quality parameter sets.
0
投稿コメントは受け付けていません。
コメント
5件のコメント