Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message for invalid coefficients #19

Open
stumarcus314 opened this issue Dec 29, 2017 · 2 comments
Open

Better error message for invalid coefficients #19

stumarcus314 opened this issue Dec 29, 2017 · 2 comments

Comments

@stumarcus314
Copy link

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 = xyz by minimizing log(xyz) = 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

@stumarcus314
Copy link
Author

In the above JuMP code, if you comment out the dx array code and instead use the dx2 array code as per:

log_x[i] = piecewiselinear(m,x[i],dx2[i],log,method=method)
#log_x[i] = piecewiselinear(m,x[i],dx[i],log,method=method)

then the above code works properly. P.S. Is there a way to properly attach or paste Julia code into this issues editor? P.S.S. How do you get d^x and d^y (with the superscripts) to show up in the Julia code text editor, as in your example test programs?

@joehuchette
Copy link
Contributor

Your breakpoints--and function values at those breakpoints--appear in the coefficients of the problem, so log(0) #=> -Inf won't work.

You can paste a block of julia code by wrapping it with "```jl" on the preceding line, and "```" on the following line.

You need to have unicode support in your editor, but you can get it in the julia prompt by typing ``d^x```.

Leaving this open as a reminder that the error message can be improved.

@joehuchette joehuchette changed the title bug ? Better error message for invalid coefficients Dec 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants