Comments (4)
So perhaps we do need an OrderedDict
from jump.jl.
This is actually pretty nasty.
We fallback to AbstractVector
methods:
julia> using JuMP
julia> A = [[1, 2, 10], [2, 3, 30]]
2-element Vector{Vector{Int64}}:
[1, 2, 10]
[2, 3, 30]
julia> model = Model()
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.
julia> @variable(model, x[i in 1:2, j in A[i]])
JuMP.Containers.SparseAxisArray{VariableRef, 2, Tuple{Int64, Int64}} with 6 entries:
[1, 1 ] = x[1,1]
[1, 10] = x[1,10]
[1, 2 ] = x[1,2]
[2, 2 ] = x[2,2]
[2, 3 ] = x[2,3]
[2, 30] = x[2,30]
julia> @constraint(model, x[1, :] in SecondOrderCone())
[x[1,2], x[1,10], x[1,1]] ∈ MathOptInterface.SecondOrderCone(3)
julia> x[1, :] isa AbstractVector{<:AbstractJuMPScalar}
true
entry point is:
JuMP.jl/src/macros/@constraint.jl
Lines 842 to 848 in a21e616
which calls:
Lines 652 to 659 in a21e616
And eachindex
isn't ordered:
julia> y = x[1, :]
JuMP.Containers.SparseAxisArray{VariableRef, 1, Tuple{Int64}} with 3 entries:
[1 ] = x[1,1]
[10] = x[1,10]
[2 ] = x[1,2]
julia> [y[k] for k in eachindex(y)]
3-element Vector{VariableRef}:
x[1,2]
x[1,10]
x[1,1]
I don't know what a good answer is.
We can't throw an error because that will break existing code like this:
julia> @constraint(model, x[1, :] >= 0)
[x[1,2], x[1,10], x[1,1]] ∈ MathOptInterface.Nonnegatives(3)
The issue is that some vector sets are ordered, and some are not. Here's another set that is problematic:
julia> @constraint(model, x[1, :] in SecondOrderCone())
[x[1,2], x[1,10], x[1,1]] ∈ MathOptInterface.SecondOrderCone(3)
from jump.jl.
The user could still do dot(a, x[1, :])
where a is some vector of constant so I don't think this is about vector constraints. Maybe we could use an OrderedDict
from jump.jl.
Hmm:
julia> using JuMP
julia> A = [[1, 2, 10], [2, 3, 30]]
2-element Vector{Vector{Int64}}:
[1, 2, 10]
[2, 3, 30]
julia> model = Model()
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.
julia> @variable(model, x[i in 1:2, j in A[i]])
JuMP.Containers.SparseAxisArray{VariableRef, 2, Tuple{Int64, Int64}} with 6 entries:
[1, 1 ] = x[1,1]
[1, 10] = x[1,10]
[1, 2 ] = x[1,2]
[2, 2 ] = x[2,2]
[2, 3 ] = x[2,3]
[2, 30] = x[2,30]
julia> y = x[1, :]
JuMP.Containers.SparseAxisArray{VariableRef, 1, Tuple{Int64}} with 3 entries:
[1 ] = x[1,1]
[10] = x[1,10]
[2 ] = x[1,2]
julia> z = rand(3)
3-element Vector{Float64}:
0.508529766285344
0.32511007041899975
0.6771958164053773
julia> using LinearAlgebra
julia> dot(z, y)
0.508529766285344 x[1,2] + 0.32511007041899975 x[1,10] + 0.6771958164053773 x[1,1]
This is more than just a slicing issue:
julia> model = Model();
julia> @variable(model, x[i in 1:2], container = SparseAxisArray)
JuMP.Containers.SparseAxisArray{VariableRef, 1, Tuple{Int64}} with 2 entries:
[1] = x[1]
[2] = x[2]
julia> dot(1:2, x)
x[2] + 2 x[1]
from jump.jl.
Related Issues (20)
- NumFOCUS: GSoC 2024 Update HOT 1
- Error vcat(::NonlinearExpr, ::VariableRef, ::Float64) HOT 5
- Increase performance of SOC constraints HOT 4
- How to improve the speed to build a complex model? HOT 2
- Coefficients of complex variables created with a GenericModel are always Float64
- LinearAlgebra.hermitian is incorrect
- *(::Real, ::Hermitian) is not hermitian HOT 5
- Cannot `convert` an object of type Float64 to an object of type JuMP.NonlinearExpr HOT 3
- Documentation Request: List whether a solver supports Indicator Constraints HOT 4
- Bullet point alignment in bibliography HOT 9
- Multiplication of matrix expression and variables leads to stack overflow and matmul error HOT 4
- Multiple Ranges for variables HOT 3
- Y' when Y is of type ::Matrix{NonlinearExpr} HOT 1
- Poor performance in complementarity models HOT 23
- Add a method for Complex(a,b) HOT 8
- MethodError with empty summations HOT 1
- Nonlinear subexpressions HOT 4
- Should error when trying to mix `NonlinearExpression` and `GenericNonlinearExpr` HOT 1
- Support normalized_coefficient for vector-valued constraints
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 jump.jl.