Comments (7)
I think the issue is
Note the difference between JuMP.QuadExpr
and MOI.ScalarQuadraticFunction
, https://github.com/JuliaOpt/JuMP.jl/blob/c01802926c34aa30e5d272ac1063f1595084aa4a/src/quad_expr.jl#L336-L349. MOI.ScalarQuadraticFunction
already has the 1/2
factor for terms involving distinct variables, as shown in the (confusing) documentation.
from scip.jl.
Thanks for reporting. It's quite possible that there is a problem with the transformation.
However, I read the documentation differently. Actually, I first took the coefficients as they are, and got failing MOI tests, to then look up the documentation and add the scaling factor.
Indeed, MOI's qcp tests are passing, in particular qcp2, where we have
# x^2 <= 2 (c)
cf = MOI.ScalarQuadraticFunction([MOI.ScalarAffineTerm(0.0, x)], [MOI.ScalarQuadraticTerm(2.0, x, x)], 0.0)
c = MOI.add_constraint(model, cf, MOI.LessThan(2.0))
with the the factor 2.0
for x*x
which I'm correcting for SCIP.
Unfortunately, your example model is not completely obvious to me (and I get an ERROR: UndefVarError: × not defined
in the Julia REPL), but I will try again with a simpler model (from JuMP), such as x^2 - 4 == 0
.
from scip.jl.
OK, so I find that the JuMP to MOI conversion makes a distinction between quadratic (x^2
) and bilinear (x*y
) terms. For
using JuMP
using SCIP
model = Model(with_optimizer(SCIP.Optimizer))
@variable(model, x >= 0)
@variable(model, y >= 0)
@constraint(model, x * x == 4)
@constraint(model, x * y == 2)
optimize!(model)
@show value(x) value(y)
I get
value(x) = 2.0
value(y) = 1.999999999
So, the term x^2
is handled properly, while x*y
is scaled incorrectly.
I guess the section of the MOI doc that says:
Duplicate indices in a or Q are accepted, and the corresponding coefficients are summed together. "Mirrored" indices (q,r) and (r,q) (where r and q are VariableIndexes) are considered duplicates; only one need be specified.
means that mirrored indices are expected, and otherwise should have a factor of 2 in the coefficient.
from scip.jl.
Exactly, I was typing up just that.
Just because I was almost done with it, here's my version:
(and I get an
ERROR: UndefVarError: × not defined in the Julia REPL
)
×
(cross
, the cross product) is in LinearAlgebra. Maybe something's going wrong with copy-pasting unicode. Anyway, this simpler version already demonstrates the problem:
using JuMP
using SCIP
m = Model(with_optimizer(SCIP.Optimizer))
@variable m x
@variable m y
w = x * y
@constraint m w == 1
optimize!(m)
@show value(w)
The issue is that the case of distinct variables (off-diagonal terms in the Q
matrix of the MOI.ScalarAffineFunction
) needs to be treated differently than the case of non-distinct variables (diagonal terms), as witnessed by https://github.com/JuliaOpt/JuMP.jl/blob/c01802926c34aa30e5d272ac1063f1595084aa4a/src/quad_expr.jl#L343-L345. This is because MOI.ScalarAffineTerm
. This is because MOI.ScalarQuadraticFunction
uses its list ofScalarQuadraticTerm
s to define a symmetric matrix in sparse form:
- a term with distinct variables, like
x * y
, would have two entries inQ
, corresponding to1/2 * x * y
and1/2 * y * x
, and since 1) ""Mirrored" indices (q,r) and (r,q) [...] are considered duplicates; only one needs to be specified." and 2) "Duplicate indices in a or Q are accepted, and the corresponding coefficients are summed together, you only need the singleScalarQuadraticTerm(1/2, x, y)
in theScalarQuadraticFunction
- a term like
x * x
will have only a single entry inQ
on the diagonal, and so the "mirrored indices" rule doesn't apply.
from scip.jl.
× (cross, the cross product) is in LinearAlgebra.
Yes, I saw that using
later.
I'll produce a patch for this issue shortly...
from scip.jl.
I tagged a new release with the fix: JuliaLang/METADATA.jl#22146
from scip.jl.
Great, and thanks very much for your hard work on the wrapper!
from scip.jl.
Related Issues (20)
- SCIP EXCEPTION_ACCESS_VIOLATION In JuMP 1.1.0 and SCIP V0.11.3 on Windows 11 HOT 26
- How to trigger SCIPsolveConcurrent? HOT 3
- Multiple threads HOT 10
- SCIP not working on Windows HOT 4
- Crash When Optimizing HOT 15
- Get original variables from constraint
- Collect all feasible solutions HOT 4
- Cannot install globally in Windows HOT 1
- [EXCEPTION_ACCESS_VIOLATION] Julia 1.8.5 incompatibility with SCIP v0.11.12 HOT 1
- MultipleObjectiveAlgorithms usage HOT 1
- Implement LazyConstraint from ConstraintHandler HOT 4
- SCIP solver -- issue in "quadratic_constraints.jl". HOT 2
- Not solving the optimization model with the SCIP solver HOT 12
- `MathOptInterface.ScalarNonlinearFunction` not supported by the solver HOT 9
- A new release is probably warranted - `is_valid()` is broken in `v0.11.14`
- How to get ConstraintDual? HOT 2
- SCIP optimizer status likely ser incorrectly. HOT 4
- Update to allow SCIP version 9?
- SCIP crashes on simple problem HOT 2
- SCIP.jl with exact-rational branch HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scip.jl.