jump-dev / jump-dev/PiecewiseLinearOpt.jl

Better error message for invalid coefficients

Open
#19 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
58
Forks
24
PR merge metrics
No merged PRs in 30d

Description

The code below causes an error. For some reason, the way the array dx is constructed causes a problem with:
log_x[i] = piecewiselinear(m,x[i],dx[i],log,method=method)

julia monroe4.jl
Capacity available on '10.60.129.38' - connecting...
Established 256-bit AES encrypted connection
Method: Logarithmic
ERROR: LoadError: Invalid coefficient -Inf on variable λ_1[1]
Stacktrace:
[1] assert_isfinite(::JuMP.GenericAffExpr{Float64,JuMP.Variable}) at /Users/a598124/.julia/v0.6/JuMP/src/affexpr.jl:95
[2] prepConstrMatrix(::JuMP.Model) at /Users/a598124/.julia/v0.6/JuMP/src/solvers.jl:554
[3] #build#119(::Bool, ::Bool, ::JuMP.ProblemTraits, ::Function, ::JuMP.Model) at /Users/a598124/.julia/v0.6/JuMP/src/solvers.jl:358
[4] (::JuMP.#kw##build)(::Array{Any,1}, ::JuMP.#build, ::JuMP.Model) at ./:0
[5] #solve#116(::Bool, ::Bool, ::Bool, ::Array{Any,1}, ::Function, ::JuMP.Model) at /Users/a598124/.julia/v0.6/JuMP/src/solvers.jl:168
[6] macro expansion at /Users/a598124/juliaCode/boxPacking1/monroe4.jl:71 [inlined]
[7] anonymous at ./:?
[8] include_from_node1(::String) at ./loading.jl:576
[9] include(::String) at ./sysimg.jl:14
[10] process_options(::Base.JLOptions) at ./client.jl:305
[11] _start() at ./client.jl:371
while loading /Users/a598124/juliaCode/boxPacking1/monroe4.jl, in expression starting on line 41

using PiecewiseLinearOpt
using JuMP, Cbc, Gurobi, CPLEX

# Minimize volume = x*y*z by minimizing log(x*y*z) = log(x)+log(y)+log(z) through piecewise univariate linearization of log(x), log(y), and log(z).

#const solver = CbcSolver()
env = Gurobi.Env()
const solver = GurobiSolver(env,Threads=4)
#const solver = CplexSolver();
#methods_1D = (:CC,:MC,:Logarithmic,:LogarithmicIB,:ZigZag,:ZigZagInteger,:SOS2,:GeneralizedCelaya,:SymmetricCelaya,:Incremental,:DisaggLogarithmic)
#methods_1D = (:CC,:MC,:Logarithmic,:ZigZag,:ZigZagInteger,:SOS2,:GeneralizedCelaya,:SymmetricCelaya,:Incremental)
methods_1D = (:Logarithmic,:ZigZag,:ZigZagInteger)
#methods_1D = (:SOS2,:GeneralizedCelaya,:SymmetricCelaya,:Incremental)

dx2 = Array{Array{Float64}}(3)
dx2[1] = linspace(5,2π,8)
dx2[2] = linspace(4,2π,7)
dx2[3] = linspace(3,2π,9)

lb = Array{Float64}(3)
lb[1] = 0
lb[2] = 0
lb[3] = 0
ub = Array{Float64}(3)
ub[1] = 20
ub[2] = 20
ub[3] = 20

num_seg = Array{UInt8}(3)
num_seg[1] = 32
num_seg[2] = 32
num_seg[3] = 32

dx = Array{Array{Float64}}(3)
for i=1:3
dx[i] = linspace(lb[i],ub[i],num_seg[i])
#dx[i] = linspace(lb[i],9,num_seg[i])
#dx[i] = linspace(3,2π,9)
end

for method in methods_1D
println("Method: $method")

n = 4 # number of cartons
m = Model(solver=solver)

@variable(m,x[1:3]) # dimensions of minimum volume box containing all the cartons
setlowerbound(x[1],0)
setupperbound(x[1],20)
setlowerbound(x[2],0)
setupperbound(x[2],20)
setlowerbound(x[3],0)
setupperbound(x[3],20)
#dx = Array{Array{Float64}}(3)
#for i=1:3
#dx[i] = linspace(getlowerbound(x[i]),getupperbound(x[i]),num_seg[i])
#dx[i] = linspace(lb[i],ub[i],num_seg[i])
#dx[i] = linspace(0,2π,9)
#end

@variable(m,X[1:3,1:n]) # coordinates of left-back-bottom corner of each carton
@variable(m,l[1:3,1:3,1:n],Bin) # binary variables encoding the orientation of each carton
@variable(m,a[1:6,i=1:n,(i+1):n],Bin) # binary variables enforcing non-overlapping of pairs of cartons
@variable(m,log_x[1:3]) # piecewise linear approximation of log(x)
for i=1:3
#log_x[i] = piecewiselinear(m,x[i],dx2[i],log,method=method)
log_x[i] = piecewiselinear(m,x[i],dx[i],log,method=method)
end

@objective(m,Min,sum(log_x))
solve(m) == :Optimal

println("volume = x*y*z = ",prod(getvalue(x)))
println("[x,y,z] = ",getvalue(x))
end

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.