Jump.jl: Lazy constraint macro while using bender's Decomposition with callbacks

Created on 14 Mar 2017  路  5Comments  路  Source: jump-dev/JuMP.jl

The following bug report when I'm solving a MILP with bender's Decomposition on Julia Opt:

Following is the output when lazy constraint is added:

 LoadError: MethodError: no method matching isless(::JuMP.GenericAffExpr{Float64,JuMP.Variable}, ::Float64)

Closest candidates are:
  isless(::Float64, ::Float64) at float.jl:283
  isless(::AbstractFloat, ::AbstractFloat) at operators.jl:40
  isless(::ForwardDiff.Dual{N,T<:Real}, ::AbstractFloat) at C:\Users\Loy\.julia\v0.5\ForwardDiff\src\dual.jl:160
  ...
 in <=(::Float64, ::JuMP.GenericAffExpr{Float64,JuMP.Variable}) at .\operators.jl:65
 in addBendersCut(::Gurobi.GurobiCallbackData) at C:\Users\Loy\AppData\Local\Julia-0.5.0\ccstry.jl:337
 in lazycallback(::Gurobi.GurobiCallbackData, ::JuMP.Model, ::Array{JuMP.LazyCallback,1}) at C:\Users\Loy\.julia\v0.5\JuMP\src\callbacks.jl:78
 in (::JuMP.##125#126{JuMP.Model,Array{JuMP.LazyCallback,1}})(::Gurobi.GurobiCallbackData) at C:\Users\Loy\.julia\v0.5\JuMP\src\callbacks.jl:96
 in mastercallback(::Ptr{Void}, ::Ptr{Void}, ::Int32, ::Ptr{Void}) at C:\Users\Loy\.julia\v0.5\Gurobi\src\GurobiSolverInterface.jl:566
 in optimize(::Gurobi.Model) at C:\Users\Loy\.julia\v0.5\Gurobi\src\grb_solve.jl:5
 in optimize!(::Gurobi.GurobiMathProgModel) at C:\Users\Loy\.julia\v0.5\Gurobi\src\GurobiSolverInterface.jl:294
 in #solve#97(::Bool, ::Bool, ::Bool, ::Array{Any,1}, ::Function, ::JuMP.Model) at C:\Users\Loy\.julia\v0.5\JuMP\src\solvers.jl:142
 in solve(::JuMP.Model) at C:\Users\Loy\.julia\v0.5\JuMP\src\solvers.jl:117
 in include_from_node1(::String) at .\loading.jl:488
while loading C:\Users\Loy\AppData\Local\Julia-0.5.0\ccstry.jl, in expression starting on line 351

The part of the code:

@lazyconstraint(cb,sum(capacitypipemin[d]*ItaCurrent[String[i,j]]*Select[i,j,d] for i=NODES,j=NODES,d= DIAMETER)-sum(capacitypipemax[d]*DeltaCurrent[String[i,j]]*Select[i,j,d] for i=NODES,j=NODES,d= DIAMETER)-sum(capacitys[i]*Opensource[i]*AlphaCurrent[i]for i=SOURCE)-sum(capacityr[i]*Openreservoir[i]*BetaCurrent[i]for i=RESERVOIR)+ TauCurrent*T<=0)

where following is the data and parameters generated:

T = 10
SOURCE = ["S1", "S2"]
RESERVOIR = ["R3", "R4", "R5"]
DIAMETER = ["fourinch", "sixinch"]
NODES = union(SOURCE,RESERVOIR)
#Data
fixedcosts  = Dict("S1" => 500, "S2" => 600, "R3" =>0, "R4"=>0, "R5"=>0)
variablecosts = Dict("S1" => 0.035, "S2" => 0.040,"R3" =>0, "R4"=>0,"R5"=>0)
capacitys = Dict("S1" => 13,    "S2" => 20,"R3" =>0, "R4"=>0,"R5"=>0)

fixedcostr  = Dict("S1" => 0,   "S2" => 0, "R3" =>500, "R4"=>300,   "R5"=>600)
variablecostr = Dict("S1" => 0, "S2" => 0,"R3" =>0.025, "R4"=>0.030,    "R5"=>0.025)
capacityr   = Dict("S1" => 0,   "S2" => 0,"R3" =>6, "R4"=>6,    "R5"=>6)
fixedcostpipe = Dict("fourinch"=> 100 , "sixinch"=> 150)

variablecostpipe = 315
capacitypipemax = Dict("fourinch"=> 25 , "sixinch"=> 50)
capacitypipemin = Dict("fourinch"=> 0 , "sixinch"=> 25)


@variable(masterProblemModel,Opensource[s=NODES], Bin)
@variable(masterProblemModel,Openreservoir[r=NODES], Bin)
@variable(masterProblemModel,W[a=NODES,b=NODES,d=DIAMETER]>=0)
@variable(masterProblemModel, Z>=0)



TauCurrent = getvalue(Tau)
AlphaCurrent=Dict{String,Float64}()
for i=NODES
push!(AlphaCurrent,"$(i)" =>  getvalue(Alpha[i]))
end

BetaCurrent=Dict{String,Float64}()
for i=NODES
push!(BetaCurrent,"$(i)" =>  getvalue(Beta[i]))
end

GammaCurrent=Dict{String,Float64}()
for i=NODES
push!(GammaCurrent,"$(i)" =>  getvalue(Gamma[i]))
end

DeltaCurrent = Dict{Array{String,1},Float64}()
for i = NODES
for j=NODES
push!(DeltaCurrent,["$(i)","$(j)"] => getvalue(Delta[i,j]))
        end
        end

ItaCurrent = Dict{Array{String,1},Float64}()
for i = NODES
    for j=NODES
    push!(ItaCurrent,["$(i)","$(j)"] => getvalue(Ita[i,j]))
end
end   

The code works fine until the lazy constraint macro.
Please help solve this bug.

All 5 comments

Could your replace

@lazyconstraint(cb,sum(capacitypipemin[d]*ItaCurrent[String[i,j]]*Select[i,j,d] for i=NODES,j=NODES,d= DIAMETER)-sum(capacitypipemax[d]*DeltaCurrent[String[i,j]]*Select[i,j,d] for i=NODES,j=NODES,d= DIAMETER)-sum(capacitys[i]*Opensource[i]*AlphaCurrent[i]for i=SOURCE)-sum(capacityr[i]*Openreservoir[i]*BetaCurrent[i]for i=RESERVOIR)+ TauCurrent*T<=0)

by

println(macroexpand(:(@lazyconstraint(cb,sum(capacitypipemin[d]*ItaCurrent[String[i,j]]*Select[i,j,d] for i=NODES,j=NODES,d= DIAMETER)-sum(capacitypipemax[d]*DeltaCurrent[String[i,j]]*Select[i,j,d] for i=NODES,j=NODES,d= DIAMETER)-sum(capacitys[i]*Opensource[i]*AlphaCurrent[i]for i=SOURCE)-sum(capacityr[i]*Openreservoir[i]*BetaCurrent[i]for i=RESERVOIR)+ TauCurrent*T<=0))))

and give us the output ?

This would imply that the error is coming from some other line in your code.

Yes, the issue seems to come from the line in addBendersCut(::Gurobi.GurobiCallbackData) at C:\Users\Loy\AppData\Local\Julia-0.5.0\ccstry.jl:337

I'm guessing your problem is with the if statements like

if statusSubProblem == :Optimal && fsxCurrent+sum(fixedcosts[i]*Opensource[i]for i=SOURCE)+ sum(fixedcostr[j]*Openreservoir[j]for j=RESERVOIR)+sum(Select[i,j,d]*fixedcostpipe[d] for i=NODES,j=NODES,d=DIAMETER)==fmCurrent+0.0001

since Opensource is a Variable (I think). You probably want its optimal value (use getvalue). Same goes for the other Variables.

In the future, please post usage questions on our mailing list.

Thank you so much!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dourouc05 picture dourouc05  路  7Comments

remi-garcia picture remi-garcia  路  4Comments

mlubin picture mlubin  路  9Comments

igormcoelho picture igormcoelho  路  3Comments

IssamT picture IssamT  路  4Comments