Closed felipemarkson closed 1 year ago
Since it is a nonlinear term and that Alpine recognizes it as an NLexpression
, write the above model as follows, and it should work:
model = Model(alpine)
@variable(model, 0 <= x <= 10)
@NLexpression(model, expr, x^2)
@NLconstraint(model, expr ≥ 3)
@NLobjective(model, Min, x^3)
I agree that should work! But there's situations where this is not desired, I place an example below:
model = Model(alpine)
@variable(model, 0 <= x <= 10)
@expression(model, expr, x^2)
@constraint(model, expr ≤ 4) # This is already convex, the MICP can solved it.
@NLconstraint(model, expr ≥ 3) # This is not convex, it needs convexification.
@NLobjective(model, Min, x^3)
This is important for large models, where the MICP
can improve the time for solution.
Good point! In the above example, since the same variable x
and expression expr
are shared across both convex and non-convex constraint, it wouldn't make any difference. But for cases with different variables with subset of them in convex constraints, Alpine internally detects them as convex and excludes them from partitioning to reduce the overhead. In this case, it is upon the user to use expression
and NLexpression
as follows:
@variable(model, 0 <= x <= 10)
@variable(model, 0 <= y <= 10)
@expression(model, expr_x, x^2)
@NLexpression(model, expr_y, y^2)
@constraint(model, expr_x <= 4)
@NLconstraint(model, expr_y >= 3)
@NLobjective(model, Min, x^2 + y^2)
In Alpine's output, you can observe that it detects the expr_x
as convex and partitions only y
variable:
PROBLEM STATISTICS
Objective sense = Min
# Variables = 2
# Bin-Int Variables = 0
# Constraints = 2
# NL Constraints = 2
# Linear Constraints = 0
# Detected convex constraints = 1
# Detected nonlinear terms = 1
# Variables involved in nonlinear terms = 1
# Potential variables for partitioning = 1
As it is a limitation of the solver (the need to use two different expressions), this could also be in the documentation!
Thanks!
@harshangrjn could you leave this issue open?
Maybe, I will try to fix it.
This should be addressed in v0.5.2
NOTE: This issue was created after the changes indicated on #220.
When you try to create a
@NLconstraint
quadratic constraint from a@expression
,Alpine
throws an error.The issue is not found if using only
Pavito
to solve the problem, so I think the problem is not the MIP solver.The issue is not found if the
@expression
is linear.Here you can see the Error message:![image](https://user-images.githubusercontent.com/47871564/192594590-8a646e7a-4d47-4abe-9cec-d8860d8ac964.png)