kibaekkim / DualDecomposition.jl

An algorithmic framework for parallel dual decomposition methods in Julia
MIT License
19 stars 5 forks source link

CouplingVariableRef error #52

Closed anhphuong-ngo closed 9 months ago

anhphuong-ngo commented 9 months ago

Hi author,

My model is quite similar to an example "sslp.jl" in this repository (has only "x" variable in 1st stage), but there are two variables in 1st stage: @variable(model, x[1:J], Bin) @variable(mode, y>=0) #Only 1 variable

I tried to "push!(coupling_variables, DD.CouplingVariableRef(s, model[:y])), but it ran into error below:

ERROR: MethodError: no method matching DualDecomposition.CouplingVariableRef(::Int64, ::VariableRef)

Closest candidates are: DualDecomposition.CouplingVariableRef(::Int64, ::Any, ::VariableRef) @ DualDecomposition C:\Users\ango1.julia\packages\DualDecomposition\rqrRm\src\BlockModel.jl:25 DualDecomposition.CouplingVariableRef(::DualDecomposition.CouplingVariableKey, ::VariableRef) @ DualDecomposition C:\Users\ango1.julia\packages\DualDecomposition\rqrRm\src\BlockModel.jl:20

Stacktrace: [1] top-level scope @ c:\Users\ango1\MyDSPOpt\Testing05.jl:129


I understand there should be at least two variables to push, but If I dont use "push", how do the model determine variable "y" belongs to the first stage? Hope to hear from you. Thanks.

hideakiv commented 9 months ago

Hi! The second argument of DD.CouplingVariableRef(::Int64, ::Any, ::VariableRef) is used to distinguish the coupling variable types. You can create the coupling variable ref by DD.CouplingVariableRef(s, 'y', model[:y]) for example.

anhphuong-ngo commented 9 months ago

@hideakiv Thank you very much for your quick reply. I followed your recommendation, the initial error was disappeared. However another error arise. First stage variables:

@variable(m, z[1:J], Bin) 
@variable(m, y, lower_bound=0)

... push!(coupling_variables, DD.CouplingVariableRef(s, "y", model[:y]))

However another error arise as follows:

User-callback calls 26, time in user-callback 0.00 sec ERROR: MethodError: Cannot convert an object of type String to an object of type Int64

Closest candidates are: convert(::Type{T}, ::Base.TwicePrecision) where T<:Number @ Base twiceprecision.jl:273 convert(::Type{T}, ::AbstractChar) where T<:Number @ Base char.jl:185 convert(::Type{T}, ::CartesianIndex{1}) where T<:Number @ Base multidimensional.jl:127 ...

Stacktrace: [1] setindex!(h::Dict{Int64, Float64}, v0::Float64, key0::String) @ Base .\dict.jl:361 [2] Dict{Int64, Float64}(kv::Dict{Any, Any}) @ Base .\dict.jl:84 [3] convert @ .\abstractdict.jl:568 [inlined] [4] setproperty! @ .\Base.jl:38 [inlined] [5] run!(#unused#::Type{DualDecomposition.AllBlockHeuristic}, LD::DualDecomposition.LagrangeDual, val::Dict{Int64, SparseArrays.SparseVector{Float64}}, ub::Dict{Int64, SparseArrays.SparseVector{Float64}}, lb::Dict{Int64, SparseArrays.SparseVector{Float64}}) @ DualDecomposition C:\Users\ango1.julia\packages\DualDecomposition\rqrRm\src\PrimalHeuristics.jl:120 [6] (::DualDecomposition.var"#solveLagrangeDual#9"{DualDecomposition.LagrangeDual, Int64})(λ::Vector{Float64}) @ DualDecomposition C:\Users\ango1.julia\packages\DualDecomposition\rqrRm\src\LagrangeDual.jl:161 [7] evaluate_functions!(method::BundleMethod.ProximalMethod) @ BundleMethod C:\Users\ango1.julia\packages\BundleMethod\H864L\src\Proximal.jl:160 [8] add_initial_bundles! @ C:\Users\ango1.julia\packages\BundleMethod\H864L\src\Abstract.jl:67 [inlined] [9] run!(method::BundleMethod.ProximalMethod) @ BundleMethod C:\Users\ango1.julia\packages\BundleMethod\H864L\src\Abstract.jl:52 [10] run!(method::DualDecomposition.BundleMaster) @ DualDecomposition C:\Users\ango1.julia\packages\DualDecomposition\rqrRm\src\LagrangeMaster\BundleMethod.jl:52 [11] run!(LD::DualDecomposition.LagrangeDual, LM::DualDecomposition.BundleMaster, initial_λ::Nothing) @ DualDecomposition C:\Users\ango1.julia\packages\DualDecomposition\rqrRm\src\LagrangeDual.jl:200 [12] run!(LD::DualDecomposition.LagrangeDual, LM::DualDecomposition.BundleMaster) @ DualDecomposition C:\Users\ango1.julia\packages\DualDecomposition\rqrRm\src\LagrangeDual.jl:69 [13] top-level scope @ c:\Users\ango1\MyDSPOpt\Testing06.jl:150

hideakiv commented 9 months ago

Thank you for pointing it out. There is an implicit assumption in the primal heuristics to allow only integer coupling IDs... This needs to be fixed. For now, can you set it e.g., push!(coupling_variables, DD.CouplingVariableRef(s, J+1, model[:y])), assigning a unique integer J+1 to y?

anhphuong-ngo commented 9 months ago

@hideakiv Thank you very much for your advice. It works.