hdavid16 / DisjunctiveProgramming.jl

A JuMP extension for Generalized Disjunctive Programming
MIT License
27 stars 3 forks source link

Error ... is not a valid logical variable reference. #112

Closed schlichtanders closed 2 months ago

schlichtanders commented 4 months ago

I am trying to create a simple real-world example using DisjunctiveProgramming and am surprised that I get an error.

using JuMP, HiGHS, DisjunctiveProgramming

model_bicycle = GDPModel(HiGHS.Optimizer);

tasks = [
    "repair bycle 1 front weel"
    "repair bycle 2 light"
    "order 4 weels"
    "be at the service desk"
    "exchange old bikes with new bikes"
    "call customer Mr. Yu"
]

workers = [
    "Nora"
    "Omar"
]

@variable(model_bicycle, assign[tasks, workers], Logical)

assign[tasks[1], :]  # this works as normal

# but this fails
for task in tasks
    @disjunction(model_bicycle, assign[task, :])
end

the error message:

`@disjunction(model_bicycle, assign[task, :])`: `assign[repair bycle 1 front weel,Nora]` is not a valid logical variable reference.

Stacktrace:
 [1] error(::String, ::String)
   @ Base [./error.jl:44](https://file+.vscode-resource.vscode-cdn.net/home/ssahm/Projects/fall-in-love-with-julia-14/error.jl:44)
 [2] _macro_error(macroname::Symbol, args::Tuple{Symbol, Expr}, source::LineNumberNode, str::String)
   @ DisjunctiveProgramming [~/.julia/packages/DisjunctiveProgramming/dkMQD/src/macros.jl:7](https://file+.vscode-resource.vscode-cdn.net/home/ssahm/Projects/fall-in-love-with-julia-14/~/.julia/packages/DisjunctiveProgramming/dkMQD/src/macros.jl:7)
 [3] (::DisjunctiveProgramming.var"#_error#41"{LineNumberNode, Tuple{Symbol, Expr}})(str::String)
   @ DisjunctiveProgramming [~/.julia/packages/DisjunctiveProgramming/dkMQD/src/macros.jl:166](https://file+.vscode-resource.vscode-cdn.net/home/ssahm/Projects/fall-in-love-with-julia-14/~/.julia/packages/DisjunctiveProgramming/dkMQD/src/macros.jl:166)
 [4] _check_disjunction(_error::DisjunctiveProgramming.var"#_error#41"{LineNumberNode, Tuple{Symbol, Expr}}, lvrefs::Vector{LogicalVariableRef{Model}}, model::Model)
   @ DisjunctiveProgramming [~/.julia/packages/DisjunctiveProgramming/dkMQD/src/constraints.jl:287](https://file+.vscode-resource.vscode-cdn.net/home/ssahm/Projects/fall-in-love-with-julia-14/~/.julia/packages/DisjunctiveProgramming/dkMQD/src/constraints.jl:287)
 [5] _create_disjunction(_error::Function, model::Model, structure::Vector{LogicalVariableRef{Model}}, name::String, nested::Bool)
   @ DisjunctiveProgramming [~/.julia/packages/DisjunctiveProgramming/dkMQD/src/constraints.jl:304](https://file+.vscode-resource.vscode-cdn.net/home/ssahm/Projects/fall-in-love-with-julia-14/~/.julia/packages/DisjunctiveProgramming/dkMQD/src/constraints.jl:304)
 [6] _create_disjunction
   @ [~/.julia/packages/DisjunctiveProgramming/dkMQD/src/constraints.jl:322](https://file+.vscode-resource.vscode-cdn.net/home/ssahm/Projects/fall-in-love-with-julia-14/~/.julia/packages/DisjunctiveProgramming/dkMQD/src/constraints.jl:322) [inlined]
 [7] _disjunction(_error::DisjunctiveProgramming.var"#_error#41"{LineNumberNode, Tuple{Symbol, Expr}}, model::Model, structure::JuMP.Containers.DenseAxisArray{LogicalVariableRef{Model}, 1, Tuple{Vector{String}}, Tuple{JuMP.Containers._AxisLookup{Dict{String, Int64}}}}, name::String; exactly1::Bool, extra_kwargs::@Kwargs{})
   @ DisjunctiveProgramming [~/.julia/packages/DisjunctiveProgramming/dkMQD/src/constraints.jl:339](https://file+.vscode-resource.vscode-cdn.net/home/ssahm/Projects/fall-in-love-with-julia-14/~/.julia/packages/DisjunctiveProgramming/dkMQD/src/constraints.jl:339)
 [8] _disjunction(_error::Function, model::Model, structure::JuMP.Containers.DenseAxisArray{LogicalVariableRef{Model}, 1, Tuple{Vector{String}}, Tuple{JuMP.Containers._AxisLookup{Dict{String, Int64}}}}, name::String)
   @ DisjunctiveProgramming [~/.julia/packages/DisjunctiveProgramming/dkMQD/src/constraints.jl:326](https://file+.vscode-resource.vscode-cdn.net/home/ssahm/Projects/fall-in-love-with-julia-14/~/.julia/packages/DisjunctiveProgramming/dkMQD/src/constraints.jl:326)
 [9] top-level scope
   @ [~/Projects/fall-in-love-with-julia-14/02](https://file+.vscode-resource.vscode-cdn.net/home/ssahm/Projects/fall-in-love-with-julia-14/~/Projects/fall-in-love-with-julia-14/02) Tips and Tricks and DisjunctiveProgramming.ipynb:2

Why is this? Is this a bug? What is the alternative?

schlichtanders commented 4 months ago

This seems to have to do with the use of Strings. Symbols seem to work without problems

pulsipher commented 4 months ago

Hi @schlichtanders,

This is a bug with our old macro interface. The new interface (currently the master branch) fixes the problem and will come out with the next release. In the meantime, you can just use disjunction instead of @disjunction.