Giter VIP home page Giter VIP logo

cplex.jl's Introduction

CPLEX.jl

Build Status codecov

CPLEX.jl is a wrapper for the IBM® ILOG® CPLEX® Optimization Studio.

CPLEX.jl has two components:

The C API can be accessed via CPLEX.CPXxx functions, where the names and arguments are identical to the C API. See the CPLEX documentation for details.

Affiliation

This wrapper is maintained by the JuMP community and is not officially supported by IBM. However, we thank IBM for providing us with a CPLEX license to test CPLEX.jl on GitHub. If you are a commercial customer interested in official support for CPLEX in Julia, let them know.

Getting help

If you need help, please ask a question on the JuMP community forum.

If you have a reproducible example of a bug, please open a GitHub issue.

License

CPLEX.jl is licensed under the MIT License.

The underlying solver is a closed-source commercial product for which you must purchase a license.

Free CPLEX licenses are available for academics and students.

Installation

CPLEX.jl requires CPLEX version 12.10, 20.1, or 22.1.

First, obtain a license of CPLEX and install CPLEX solver, following the instructions on IBM's website.

Once installed, set the CPLEX_STUDIO_BINARIES environment variable as appropriate and run Pkg.add("CPLEX"). For example:

# On Windows, this might be:
ENV["CPLEX_STUDIO_BINARIES"] = "C:\\Program Files\\CPLEX_Studio1210\\cplex\\bin\\x86-64_win\\"
# On OSX, this might be:
ENV["CPLEX_STUDIO_BINARIES"] = "/Applications/CPLEX_Studio1210/cplex/bin/x86-64_osx/"
# On Unix, this might be:
ENV["CPLEX_STUDIO_BINARIES"] = "/opt/CPLEX_Studio1210/cplex/bin/x86-64_linux/"

import Pkg
Pkg.add("CPLEX")

!!! note The exact path may differ. Check which folder you installed CPLEX in, and update the path accordingly.

Use with JuMP

Use CPLEX.jl with JuMP as follows:

using JuMP, CPLEX
model = Model(CPLEX.Optimizer)
set_attribute(model, "CPX_PARAM_EPINT", 1e-8)

MathOptInterface API

The CPLEX optimizer supports the following constraints and attributes.

List of supported objective functions:

List of supported variable types:

List of supported constraint types:

List of supported model attributes:

Options

Options match those of the C API in the CPLEX documentation.

Set options using JuMP.set_attribute:

using JuMP, CPLEX
model = Model(CPLEX.Optimizer)
set_attribute(model, "CPX_PARAM_EPINT", 1e-8)

Callbacks

CPLEX.jl provides a solver-specific callback to CPLEX:

using JuMP, CPLEX, Test

model = direct_model(CPLEX.Optimizer())
set_silent(model)

# This is very, very important!!! Only use callbacks in single-threaded mode.
MOI.set(model, MOI.NumberOfThreads(), 1)

@variable(model, 0 <= x <= 2.5, Int)
@variable(model, 0 <= y <= 2.5, Int)
@objective(model, Max, y)
cb_calls = Clong[]
function my_callback_function(cb_data::CPLEX.CallbackContext, context_id::Clong)
    # You can reference variables outside the function as normal
    push!(cb_calls, context_id)
    # You can select where the callback is run
    if context_id != CPX_CALLBACKCONTEXT_CANDIDATE
        return
    end
    ispoint_p = Ref{Cint}()
    ret = CPXcallbackcandidateispoint(cb_data, ispoint_p)
    if ret != 0 || ispoint_p[] == 0
        return  # No candidate point available or error
    end
    # You can query CALLBACKINFO items
    valueP = Ref{Cdouble}()
    ret = CPXcallbackgetinfodbl(cb_data, CPXCALLBACKINFO_BEST_BND, valueP)
    @info "Best bound is currently: $(valueP[])"
    # As well as any other C API
    x_p = Vector{Cdouble}(undef, 2)
    obj_p = Ref{Cdouble}()
    ret = CPXcallbackgetincumbent(cb_data, x_p, 0, 1, obj_p)
    if ret == 0
        @info "Objective incumbent is: $(obj_p[])"
        @info "Incumbent solution is: $(x_p)"
        # Use CPLEX.column to map between variable references and the 1-based
        # column.
        x_col = CPLEX.column(cb_data, index(x))
        @info "x = $(x_p[x_col])"
    else
        # Unable to query incumbent.
    end

    # Before querying `callback_value`, you must call:
    CPLEX.load_callback_variable_primal(cb_data, context_id)
    x_val = callback_value(cb_data, x)
    y_val = callback_value(cb_data, y)
    # You can submit solver-independent MathOptInterface attributes such as
    # lazy constraints, user-cuts, and heuristic solutions.
    if y_val - x_val > 1 + 1e-6
        con = @build_constraint(y - x <= 1)
        MOI.submit(model, MOI.LazyConstraint(cb_data), con)
    elseif y_val + x_val > 3 + 1e-6
        con = @build_constraint(y + x <= 3)
        MOI.submit(model, MOI.LazyConstraint(cb_data), con)
    end
end
MOI.set(model, CPLEX.CallbackFunction(), my_callback_function)
optimize!(model)
@test termination_status(model) == MOI.OPTIMAL
@test primal_status(model) == MOI.FEASIBLE_POINT
@test value(x) == 1
@test value(y) == 2

Annotations for automatic Benders' decomposition

Here is an example of using the annotation feature for automatic Benders' decomposition:

using JuMP, CPLEX

function add_annotation(
    model::JuMP.Model,
    variable_classification::Dict;
    all_variables::Bool = true,
)
    num_variables = sum(length(it) for it in values(variable_classification))
    if all_variables
        @assert num_variables == JuMP.num_variables(model)
    end
    indices, annotations = CPXINT[], CPXLONG[]
    for (key, value) in variable_classification
        for variable_ref in value
            push!(indices, variable_ref.index.value - 1)
            push!(annotations, CPX_BENDERS_MASTERVALUE + key)
        end
    end
    cplex = backend(model)
    index_p = Ref{CPXINT}()
    CPXnewlongannotation(
        cplex.env,
        cplex.lp,
        CPX_BENDERS_ANNOTATION,
        CPX_BENDERS_MASTERVALUE,
    )
    CPXgetlongannotationindex(
        cplex.env,
        cplex.lp,
        CPX_BENDERS_ANNOTATION,
        index_p,
    )
    CPXsetlongannotations(
        cplex.env,
        cplex.lp,
        index_p[],
        CPX_ANNOTATIONOBJ_COL,
        length(indices),
        indices,
        annotations,
    )
    return
end

# Problem

function illustrate_full_annotation()
    c_1, c_2 = [1, 4], [2, 3]
    dim_x, dim_y = length(c_1), length(c_2)
    b = [-2; -3]
    A_1, A_2 = [1 -3; -1 -3], [1 -2; -1 -1]
    model = JuMP.direct_model(CPLEX.Optimizer())
    set_optimizer_attribute(model, "CPXPARAM_Benders_Strategy", 1)
    @variable(model, x[1:dim_x] >= 0, Bin)
    @variable(model, y[1:dim_y] >= 0)
    variable_classification = Dict(0 => [x[1], x[2]], 1 => [y[1], y[2]])
    @constraint(model, A_2 * y + A_1 * x .<= b)
    @objective(model, Min, c_1' * x + c_2' * y)
    add_annotation(model, variable_classification)
    optimize!(model)
    x_optimal = value.(x)
    y_optimal = value.(y)
    println("x: $(x_optimal), y: $(y_optimal)")
end

function illustrate_partial_annotation()
    c_1, c_2 = [1, 4], [2, 3]
    dim_x, dim_y = length(c_1), length(c_2)
    b = [-2; -3]
    A_1, A_2 = [1 -3; -1 -3], [1 -2; -1 -1]
    model = JuMP.direct_model(CPLEX.Optimizer())
    # Note that the "CPXPARAM_Benders_Strategy" has to be set to 2 if partial
    # annotation is provided. If "CPXPARAM_Benders_Strategy" is set to 1, then
    # the following error will be thrown:
    # `CPLEX Error  2002: Invalid Benders decomposition.`
    set_optimizer_attribute(model, "CPXPARAM_Benders_Strategy", 2)
    @variable(model, x[1:dim_x] >= 0, Bin)
    @variable(model, y[1:dim_y] >= 0)
    variable_classification = Dict(0 => [x[1]], 1 => [y[1], y[2]])
    @constraint(model, A_2 * y + A_1 * x .<= b)
    @objective(model, Min, c_1' * x + c_2' * y)
    add_annotation(model, variable_classification; all_variables = false)
    optimize!(model)
    x_optimal = value.(x)
    y_optimal = value.(y)
    println("x: $(x_optimal), y: $(y_optimal)")
end

cplex.jl's People

Contributors

blegat avatar chengg04 avatar dafrick avatar dourouc05 avatar emreyamangil avatar eqt avatar henriquebecker91 avatar hlyang1992 avatar issamt avatar jac0320 avatar joehuchette avatar kaarthiksundar avatar kibaekkim avatar laurentheirendt avatar leotac avatar matbesancon avatar metab0t avatar mlubin avatar mtanneau avatar nodet avatar odow avatar ontahm avatar remi-garcia avatar stefankarpinski avatar thuener avatar tkelman avatar tkoolen avatar trigaut avatar vitornesello avatar yeesian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cplex.jl's Issues

Memory leak?

I've been experiencing what looks like a memory leak when solving LPs with Cplex.
I managed to isolate and reproduce the issue, here's a gist that should do the trick. Everytime time you solve the LP (of course, starting from the second one), htop says 3 extra MBs are reserved.

It doesn't happen 100% of the time, but if you keep trying long enough, you should be able to see it. I hope it's something obvious that I'm missing. Apparently it doesn't happen with Gurobi, though.

Incumbent Callback Error

I am trying without success to use the incumbent callback functionality provided in JuMPfunction.jl. I get the following error on Julia 0.4:

using JuMP,CPLEX
m=Model(solver=CplexSolver(CPX_PARAM_MIPDISPLAY=5,CPX_PARAM_SCRIND=0,CPX_PARAM_REDUCE=0, CPX_PARAM_MIPCBREDLP=0))
G=1:30
T=1:5
@defvar(m,10>=y[G,T]>=0)
@defvar(m,x[G,T],Bin)
@addConstraint(m,_c[t=T],sum{y[i,t], i in G}>=100_rand()+50)
@addConstraint(m, _c[i=G,t=T], y[i,t]<=100_x[i,t])
@setObjective(m,Min,sum{10_rand()_x[i,t]+2 _rand()_y[i,t]^2, i in G, t=T} );
function mycallback(cb)
obj_val = cbgetnodeobjval(cb)
if obj_val>1238.0
rejectIncumbent(cb)
else
acceptIncumbent(cb)
end
end
addIncumbentCallback(m, mycallback)
solve(m)

ERROR: MethodError: convert has no method matching convert(::Type{CPLEX.CplexIncumbentCallbackData}, ::CPLEX.CallbackData, ::Symbol, ::Int32, ::Array{Float64,1}, ::Ptr{Int32}, ::Ptr{Int32})
This may have arisen from a call to the constructor CPLEX.CplexIncumbentCallbackData(...),
since type constructors fall back to convert methods.
Closest candidates are:
CPLEX.CplexIncumbentCallbackData(::CPLEX.CallbackData, ::Symbol, ::Int32, ::Array{Float64,1}, ::Ptr{Int32}, ::Ptr{Int32}, ::Array{CPLEX.BranchingChoice,1})
CPLEX.CplexIncumbentCallbackData(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any)
call{T}(::Type{T}, ::Any)
...
in masterincumbentcallback at /Users/frank/.julia/v0.4/CPLEX/src/CplexSolverInterface.jl:653
in optimize! at /Users/frank/.julia/v0.4/CPLEX/src/cpx_solve.jl:5
in optimize! at /Users/frank/.julia/v0.4/CPLEX/src/CplexSolverInterface.jl:153
in solve at /Users/frank/.julia/v0.4/JuMP/src/solvers.jl:84
in solvehook at /Users/frank/.julia/v0.4/CPLEX/src/JuMPfunctions.jl:45
in solve at /Users/frank/.julia/v0.4/JuMP/src/solvers.jl:62

julia> versioninfo()
Julia Version 0.4.0-dev+6819
Commit 4d72065* (2015-08-18 17:55 UTC)
Platform Info:
System: Darwin (x86_64-apple-darwin14.4.0)
CPU: Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
WORD_SIZE: 64
BLAS: libopenblas (DYNAMIC_ARCH NO_AFFINITY Haswell)
LAPACK: libopenblas
LIBM: libopenlibm
LLVM: libLLVM-3.3

Failing MPB tests

ERROR: `updatemodel!` has no method matching updatemodel!(::CplexMathProgModel)
 in linprogsolvertest at /home/mlubin/.julia/v0.3/MathProgBase/test/linproginterface.jl:34

What was the resolution on this?

Callback segfault

> julia simpleusercut.jl
[1]    39373 segmentation fault  julia simpleusercut.jl

Only seems to appear on first run after changing simpleusercut.jl; otherwise it runs fine. Might need to break out gdb.

MathProgCallbackData not defined

Hello. I'm trying to use CPLEX solver from Julia, but getting the following error:

julia> using Cplex
ERROR: MathProgCallbackData not defined
 in include at boot.jl:238
 in include_from_node1 at loading.jl:114
 in include at boot.jl:238
 in include_from_node1 at loading.jl:114
 in reload_path at loading.jl:140
 in _require at loading.jl:58
 in require at loading.jl:43
at D:\Documents and Settings\magistere\.julia\Cplex\src\CplexSolverCallbacksInterface.
jl:6
at D:\Documents and Settings\magistere\.julia\Cplex\src\Cplex.jl:43

But I cannot find any mentions of MathProgCallbackData in MathProgBase package. Have I missed something during installation?

How to do "cplex.setout(ofstream)"?

When using CPLEX with the concert API, to write the log to an external file; I would do
cplex.setOut(outputfilestream)
How to do a similar thing in Julia?

Help with CPLEX 12.6 in OS X

I tried to use CPLEX.jl with JuMP.

I have added
export LD_LIBRARY_PATH=“Users/username/Applications/IBM/ILOG/CPLEX_Studio126/cplex/bin/x86-64_osx/”:$LD_LIBRARY_PATH

to the bash_profile. But there is no libcplexXXX.dylib file in that directory. Do I miss something here?

After Pkg.add("CPLEX"). I got the following errors:
================================[ ERROR: CPLEX ]================================

LoadError: None of the selected providers can install dependency libcplex.
Use BinDeps.debug(package_name) to see available providers

while loading /Users/username/.julia/v0.4/CPLEX/deps/build.jl, in expression starting on line 31

================================[ BUILD ERRORS ]================================

WARNING: CPLEX had build errors.

  • packages with build errors remain installed in /Users/username/.julia/v0.4
  • build the package(s) and all dependencies with Pkg.build("CPLEX")
  • build a single package by running its deps/build.jl script

Please help me solve this problem and really appreciate it. Thank you.

library dependency with CPLEX version 126 on Mac OS X

This is the content of my CPLEX library directory on Mac OS X. CPLEX version is 12.6

convert
cplex
cplexamp
libcplex1260.jnilib
libcplex1260mpitransport.dylib
libcplex1260mpiworker.dylib
libcplex1260processtransport.dylib
libcplex1260processworker.dylib
libcplex1260remote.dylib
libcplex1260remotejni.jnilib
libcplex1260tcpiptransport.dylib
libcplex1260tcpipworker.dylib

I added push!(libnames, "cplex") in build.jl to install CPLEX.jl.

cplex fails JuMP tests

We probably missed this because these tests only run on the default solver:

 Test: model.jl
...
ERROR: assertion failed: |getDual(constraints)[2] - 1.0| <= 1.0e-6
  getDual(constraints)[2] = -1.0
  1.0 = 1.0
  difference = 2.0 > 1.0e-6
 in error at error.jl:22
 in test_approx_eq at test.jl:109
 in include at ./boot.jl:245
 in include_from_node1 at ./loading.jl:128
 in anonymous at no file:18
 in include at ./boot.jl:245
 in include_from_node1 at loading.jl:128
 in process_options at ./client.jl:285
 in _start at ./client.jl:354
while loading /home/mlubin/.julia/v0.3/JuMP/test/model.jl, in expression starting on line 162

rename to CPLEX

Before moving to metadata, we should probably rename to CPLEX.

CPLEX doesn't print to stdout

Can we reproduce this issue from a simple example in pure C? If so, it should be easy to get support to make this work. If not, we have something interesting to debug.

adding quadratic terms&constraints

Hi,
I'm running Julia 0.2.1 (64bit) on mac.
When I call test/qp_01.jl (also qp_02.jl), I got the following error message:

ERROR: access to undefined reference
in unsafe_copy! at array.jl:135
in copy! at array.jl:51
in getindex at array.jl:296
in splice! at array.jl:814
in splice! at array.jl:807
in - at sparse/sparsematrix.jl:498
in - at sparse/sparsematrix.jl:407
in add_qpterms! at /Users/yuichirowaki/.julia/CPLEX/src/cpx_quad.jl:11
in add_qpterms! at /Users/yuichirowaki/.julia/CPLEX/src/cpx_quad.jl:37
in include at boot.jl:238
in include_from_node1 at loading.jl:114
in process_options at client.jl:303
in _start at client.jl:389
at /Users/yuichirowaki/.julia/CPLEX/test/qp_01.jl:19

This was solved by changing the line 10 in src/cpx_quad.jl from
Q = Q + Q' - spdiagm(diag(Q))
to
Q = Q + Q' - spdiagm(convert(Array{Cdouble},diag(Q)))

It seems, when applied to a sparse matrix, diag returns an array of type ANY and this was causing the problem.

More examples of where library is in README

E.g. on my system I think its
/opt/ibm/ILOG/CPLEX_Studio_Preview1251/cplex/bin/x86-64_sles10_4.1

which has libcplex1251.so which I assume is the right file? Haven't got it to work yet...

Building package

Using using CPLEX_Studio1263, Julia 0.4.5 and Ubuntu 16.04:

Pkg.add("CPLEX")
INFO: Installing CPLEX v0.1.2
INFO: Building CPLEX

signal (11): Segmentation fault
strlen at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
__strdup at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
jl_uv_dlopen at /usr/bin/../lib/x86_64-linux-gnu/julia/libjulia.so (unknown line)
check_path! at /home/thuener/.julia/v0.4/BinDeps/src/dependencies.jl:559
ERROR: Build process failed.
in build! at ./pkg/entry.jl:701
[inlined code] from ./task.jl:422
in add at ./pkg/entry.jl:64

Presolve issue for SOCPs

I have a SOCP problem (@mlubin : ACOPF with SOC relaxations), which gives different objective values when I have the following model options without any other modifications:
a. With CPX_PARAM_PREIND=0
Opt obj: 721341.0797

b. Without CPX_PARAM_PREIND=0
Opt obj: 721299.7785

When I solve SOCP with outer approximation using callback, I still get opt obj = 721341.0797. Looks like there is an issue with having presolve switched on.

I am on Julia 0.4 and have updated the packages. Would this be an issue on CPLEX.jl/JuMP.jl or in CPLEX itself?

Deprecated Uint8 in cpx_quad.jl file

Hello,

It seem's there is still a deprecated Uint8 type in the cpx_quad.jl file
(line 132) :

                      Ptr{Uint8}    # name

should be replace with:

                      Ptr{UInt8}    # name

-- Maurice

Readme library path is misleading in CPLEX 12.5

Not a issue just an enhancement. In the readme the "/path/to/CPLEX/library" path is misleading, in cplex 12.5 the real path is the bin folder (/opt/ibm/ILOG/CPLEX_Studio125/cplex/bin/x86-64_sles10_4.1). That was the only way that worked for me. I try to use /opt/ibm/ILOG/CPLEX_Studio125/cplex/lib/x86-64_sles10_4.1/static_pic/lib and didn't worked.

I suggest also to put an example:
export LD_LIBRARY_PATH="/opt/ibm/ILOG/CPLEX_Studio125/cplex/bin/x86-64_sles10_4.1":$LD_LIBRARY_PATH

move to juliaopt?

It's probably time to move this to juliaopt. Should anything else be done besides documenting the windows installation issues?

May I know how to connect CPLEX with julia in 64-bit Windows?

I think the readme file mainly talks about connecting Julia with CPLEX in OS X.

May I know if there is a good way to solve this problem in Windows?

I installed the CPLEX package, and it says the package can't be loaded?

Thank you for your help!

Obtaining MIP gap within LazyCallback

How do I obtain the MIPrelativegap within a lazy callback? I tried using getobjgap(m). It throws an error. I can see that the following function is implemented

 getobjgap(m::CplexMathProgModel) = get_rel_gap(m.inner)

How do I use this function to get the gap from a lazy callback ?

Type in error checking code of `Model`

Should probably be just env instead of model.env and possibly stat[1] instead of stat:

diff --git a/src/cpx_model.jl b/src/cpx_model.jl
index ba53f3b..e29dd5a 100644
--- a/src/cpx_model.jl
+++ b/src/cpx_model.jl
@@ -17,7 +17,7 @@ function Model(env::Env, name::ASCIIString)
     stat = Array(Cint, 1)
     tmp = @cpx_ccall(createprob, Ptr{Void}, (Ptr{Void}, Ptr{Cint}, Ptr{Cchar}), env.ptr, stat, name)
     if tmp == C_NULL
-        throw(CplexError(model.env, stat))
+        throw(CplexError(env, stat[1]))
     end
     return Model(env, tmp)
 end

linprog not defined after importing CPLEX

Stumbled across the following while running one of the tests:

[yeesian@yeesian-p7h55d-m test]$ julia ma
mathprog.jl     mathprog_v2.jl  
[yeesian@yeesian-p7h55d-m test]$ julia mathprog.jl
WARNING: Package CPLEX is installed but couldn't be loaded
Testing linprog with solver CplexSolver
ERROR: linprog not defined
while loading /home/yeesian/.julia/v0.3/CPLEX/test/mathprog.jl, in expression starting on line 4

If I import CPLEX before including test/linprog.jl, linprog does not get imported:

  | | |_| | | | (_| |  |  Version 0.3.0-prerelease+3766 (2014-06-19 03:37 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 28ba276 (0 days old master)
|__/                   |  x86_64-unknown-linux-gnu

julia> import CPLEX
WARNING: Package CPLEX is installed but couldn't be loaded

julia> include(joinpath(Pkg.dir("MathProgBase"),"test","linprog.jl"))
linprogtest (generic function with 2 methods)

julia> lin
linprogtest linreg       linspace

It works in the reverse order though (only when done in the interactive session, and not by running as a script):

  | | |_| | | | (_| |  |  Version 0.3.0-prerelease+3766 (2014-06-19 03:37 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 28ba276 (0 days old master)
|__/                   |  x86_64-unknown-linux-gnu

julia> include(joinpath(Pkg.dir("MathProgBase"),"test","linprog.jl"))
linprogtest (generic function with 2 methods)

julia> lin
linprog     linprogtest  linreg       linspace
julia> import CPLEX

julia> lin
linprog     linprogtest  linreg       linspace
julia> lin

The problem does not surface with the other solvers (e.g. Clp and GLPKMathProgInterface) though.

  | | |_| | | | (_| |  |  Version 0.3.0-prerelease+3766 (2014-06-19 03:37 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 28ba276 (0 days old master)
|__/                   |  x86_64-unknown-linux-gnu

julia> using GLPKMathProgInterface

julia> include(joinpath(Pkg.dir("MathProgBase"),"test","linprog.jl"))
linprogtest (generic function with 2 methods)

julia> lin
linprog     linprogtest  linreg       linspace
julia> lin

The packages involved:

julia> Pkg.status()
...
 - CPLEX                         0.0.6
 - Clp                           0.0.7
 - GLPKMathProgInterface         0.1.4

RTLD_GLOBAL not defined error on Julia master

julia> Pkg.add("CPLEX")

...

INFO: Building CPLEX
==========================================================[ ERROR: CPLEX ]==========================================================

LoadError: UndefVarError: RTLD_GLOBAL not defined
while loading /Users/jiahao/.julia/v0.4/CPLEX/deps/build.jl, in expression starting on line 4

====================================================================================================================================

Cplex 12.6.3 is now available

Hi,

The new Cplex version, 12.6.3, is now available. We need to add this information to build.jl for the package to build with the new version.

Cheers,

melih

Inconsistent quad interface compared to Gurobi.jl

The methods to build a quadratic objective function are somewhat confusing, it is not clear when one must pass the matrix coefficients or the "term" coefficients.
Even more confusing when you consider that the convention used in CPLEX.jl is different from what is used in Gurobi.jl: add_qpterms() expects "term" coefficients in Gurobi.jl, while it expects "matrix" coefficients in CPLEX.jl.
This is probably the cause why the test qp_01.jl gives "wrong" results in CPLEX.jl compared to what is expected (the results are not actually checked in the tests) -- it was probably copied & pasted from GUROBI.jl, that uses a different convention.

Not saying that the two interfaces have to be identical -- they don't, but I found it somewhat confusing.

[Also, the MPB tests do not pass, updatemodel() doesn't exist for CPLEX.]

CPLEX install issue

julia> Pkg.add("CPLEX")
INFO: Installing CPLEX v0.1.2
INFO: Building CPLEX

signal (11): Segmentation fault
unknown function (ip: 0x34f6a811a1)
__strdup at /lib64/libc.so.6 (unknown line)
jl_uv_dlopen at /home/schalil/julia-cbe1bee3a8/bin/../lib/julia/libjulia.so (unknown line)
check_path! at /home/schalil/.julia/v0.4/BinDeps/src/dependencies.jl:558
jlcall_check_path!_21267 at  (unknown line)
jl_apply_generic at /home/schalil/julia-cbe1bee3a8/bin/../lib/julia/libjulia.so (unknown line)
_find_library at /home/schalil/.julia/v0.4/BinDeps/src/dependencies.jl:544
satisfy! at /home/schalil/.julia/v0.4/BinDeps/src/dependencies.jl:776
jl_apply_generic at /home/schalil/julia-cbe1bee3a8/bin/../lib/julia/libjulia.so (unknown line)
satisfy! at /home/schalil/.julia/v0.4/BinDeps/src/dependencies.jl:776
jl_apply_generic at /home/schalil/julia-cbe1bee3a8/bin/../lib/julia/libjulia.so (unknown line)
anonymous at /home/schalil/.julia/v0.4/BinDeps/src/dependencies.jl:831
unknown function (ip: 0x7ff0793009d3)
unknown function (ip: 0x7ff0793015ec)
jl_load at /home/schalil/julia-cbe1bee3a8/bin/../lib/julia/libjulia.so (unknown line)
include at ./boot.jl:261
jl_apply_generic at /home/schalil/julia-cbe1bee3a8/bin/../lib/julia/libjulia.so (unknown line)
include_from_node1 at ./loading.jl:304
jl_apply_generic at /home/schalil/julia-cbe1bee3a8/bin/../lib/julia/libjulia.so (unknown line)
unknown function (ip: 0x7ff0792ec253)
unknown function (ip: 0x7ff0792eb5e9)
unknown function (ip: 0x7ff07930091c)
unknown function (ip: 0x7ff079300993)
jl_toplevel_eval_in at /home/schalil/julia-cbe1bee3a8/bin/../lib/julia/libjulia.so (unknown line)
evalfile at loading.jl:320
evalfile at loading.jl:320
jl_apply_generic at /home/schalil/julia-cbe1bee3a8/bin/../lib/julia/libjulia.so (unknown line)
anonymous at none:14
cd at ./file.jl:22
jl_apply_generic at /home/schalil/julia-cbe1bee3a8/bin/../lib/julia/libjulia.so (unknown line)
anonymous at none:13
open at iostream.jl:114
jl_apply_generic at /home/schalil/julia-cbe1bee3a8/bin/../lib/julia/libjulia.so (unknown line)
unknown function (ip: 0x7ff0792ec253)
unknown function (ip: 0x7ff0792eb5e9)
unknown function (ip: 0x7ff07930091c)
unknown function (ip: 0x7ff079300993)
jl_toplevel_eval_in at /home/schalil/julia-cbe1bee3a8/bin/../lib/julia/libjulia.so (unknown line)
process_options at ./client.jl:257
_start at ./client.jl:378
unknown function (ip: 0x7ff07157b8f9)
jl_apply_generic at /home/schalil/julia-cbe1bee3a8/bin/../lib/julia/libjulia.so (unknown line)
unknown function (ip: 0x401c47)
unknown function (ip: 0x40182f)
__libc_start_main at /lib64/libc.so.6 (unknown line)
unknown function (ip: 0x401875)
ERROR: Build process failed.
 in build! at pkg/entry.jl:701
 in build at pkg/entry.jl:720
 in resolve at ./pkg/entry.jl:479
 in edit at pkg/entry.jl:26
 in anonymous at task.jl:447
 in sync_end at ./task.jl:413
 [inlined code] from task.jl:422
 in add at pkg/entry.jl:46
 in add at pkg/entry.jl:73
 in anonymous at pkg/dir.jl:31
 in cd at file.jl:22
 in cd at pkg/dir.jl:31
 in add at pkg.jl:23

I was trying to install CPLEX.jl. I have specified the path for CPLEX in bash_profile as below

PATH=$PATH:$HOME/bin:$HOME/julia-cbe1bee3a8/bin:$HOME/CPLEX/
LD_LIBRARY_PATH="/home/schalil/CPLEX":$LD_LIBRARY_PATH

export PATH
export LD_LIBRARY_PATH

My cplex file location is as below

[schalil@user001 ~]$ cd CPLEX/
[schalil@user001 CPLEX]$ ls
cplex  libcplex1263.so
[schalil@user001 CPLEX]$ pwd
/home/schalil/CPLEX
[schalil@user001 CPLEX]$ 

When I try to use CPLEX.jl, the error that i am getting is as below

julia> using CPLEX
INFO: Precompiling module CPLEX...
ERROR: LoadError: could not open file /home/schalil/.julia/v0.4/CPLEX/src/../deps/deps.jl
 in include at ./boot.jl:261
 in include_from_node1 at ./loading.jl:304
 in include at ./boot.jl:261
 in include_from_node1 at ./loading.jl:304
 [inlined code] from none:2
 in anonymous at no file:0
 in process_options at ./client.jl:257
 in _start at ./client.jl:378
while loading /home/schalil/.julia/v0.4/CPLEX/src/CPLEX.jl, in expression starting on line 8
ERROR: Failed to precompile CPLEX to /home/schalil/.julia/lib/v0.4/CPLEX.ji
 in error at ./error.jl:21
 in compilecache at loading.jl:384
 in require at ./loading.jl:250

Cplex environments are not freed

Each time Env() is called a new cplex environment is created using CPXopenCplex. Unfortunately, no finalizer is registered, so creating a lot of models as in the following example eventually eats up your memory:

using MathProgBase
using CPLEX
for i=1:10000
  local m = MathProgBase.model(CplexSolver())
end

I suggest to add a corresponding finalizer:

diff --git a/src/cpx_env.jl b/src/cpx_env.jl
index af7f19e..6c58e69 100644
--- a/src/cpx_env.jl
+++ b/src/cpx_env.jl
@@ -2,12 +2,14 @@ type Env
     ptr::Ptr{Void}

     function Env()
-      stat = Array(Cint, 1)
-      tmp = @cpx_ccall(openCPLEX, Ptr{Void}, (Ptr{Cint},), stat)
-      if tmp == C_NULL
-          error("CPLEX: Error creating environment")
-      end
-      new(tmp)
+        stat = Array(Cint, 1)
+        tmp = @cpx_ccall(openCPLEX, Ptr{Void}, (Ptr{Cint},), stat)
+        if tmp == C_NULL
+            error("CPLEX: Error creating environment")
+        end
+        env = new(tmp)
+        finalizer(env, close_CPLEX)
+        env
     end
 end

The two functions free_problem and close_CPLEX appear to have a bug: the argument of the object to be closed must be a pointer to CPXLPptr and CPXENVptr, respectively.

diff --git a/src/cpx_model.jl b/src/cpx_model.jl
index ba53f3b..2aecb99 100644
--- a/src/cpx_model.jl
+++ b/src/cpx_model.jl
@@ -136,15 +136,17 @@ function set_warm_start!(model::Model, indx::IVec, val::FVec)
 end

 function free_problem(model::Model)
-    stat = @cpx_ccall(freeprob, Cint, (Ptr{Void}, Ptr{Void}), model.env.ptr, model.lp)
+    tmp = Ptr{Void}[model.lp]
+    stat = @cpx_ccall(freeprob, Cint, (Ptr{Void}, Ptr{Void}), model.env.ptr, tmp)
     if stat != 0
         throw(CplexError(model.env, stat))
     end
 end

 function close_CPLEX(env::Env)
-    stat = @cpx_ccall(closeCPLEX, Cint, (Ptr{Void},), env.ptr)
+    tmp = Ptr{Void}[env.ptr]
+    stat = @cpx_ccall(closeCPLEX, Cint, (Ptr{Void},), tmp)
     if stat != 0
-        throw(CplexError(model.env, stat))
+        throw(CplexError(env, stat))
     end
 end

However, these changes introduce another problem: because finalizers do not seem to be run in a particular order at exit, the finalizer for the environment might be called before the finalizer of the model, leading to the following error (in free_problem):

error in running finalizer: CPLEX.CplexError(code=1002, msg="CPLEX Error  1002: No environment.")

In my tests this never happened during the run of the program, only at the end. Calling gc() right before the program exits seems to solve the problem, but I have no idea of a "clean" solution.

CPLEX Error 3003: Not a mixed-integer problem.

When calling getvartype with all variables continuous, CPLEX seems to barf and say:
CPLEX Error 3003: Not a mixed-integer problem.. This happens inside JuMP when re-solving LPs, so the user sees this confusing output.

REPL crashing on ctrl+c?

I'm sure it's a known issue, but ctrl+c causes the REPL to crash (brutal segfault).
[If it only happens to me, I'd like to find out why :)]

Related: with Gurobi, ctrl+c takes me back to the REPL but the solver keeps running in the background, until it completes (or you quit the REPL) -- only marginally less annoying than a crash. Should probably open an issue there as well, if there isn't one already.

Problem building CPLEX

Hi!
I'm starting to work with JuMP and I'm trying to build and install the CPLEX package but I'm having some troubles. In particular, when I try to build the package (Pkg.build("CPLEX")) I get the error:
================================[ ERROR: CPLEX ]================================

Libdl not defined
while loading /Users/irios/.julia/v0.3/CPLEX/deps/build.jl, in expression starting on line 4

I have already installed CPLEX and add it to the library PATH. I'm working on mac osx 10.9.4.
What can I do to fix it?

range constraint (two-sided) support

When I use a two sided range constraint in a JuMP Model, I get the following warning:

Julia Cplex interface doesn't properly support range (two-sided) constraints.

Should I be concerned when this pops up?

getsolvetime is missing

CplexMathProgModel complains that getsolvetime is not implemented, if this can be added to CPLEX.jl I would really appreciate, many thanks in advance!

"cplex.getBestObjValue()" - how to?

I am trying to get the best bound value after a certain termination criteria is satisfied. I looked up the documentation and source code. The JuMP documentation says I can do it using an infocallback which does not seem to work with CPLEX.jl.

In the source code for cplex_callbacks.jl, there is a function get_best_bound, which it tried calling in my program. It throws an error "get_best_bound not defined".

Error in tests

Pkg.test("CPLEX") eventually leads to

ERROR: LoadError: LoadError: MethodError: `updatemodel!` has no method matching updatemodel!(::CPLEX.CplexMathProgModel)
 in linprogsolvertest at /Users/dpo/.julia/v0.4/MathProgBase/test/linproginterface.jl:34
 in include at /usr/local/Cellar/julia/0.4.3/lib/julia/sys.dylib
 in include_from_node1 at /usr/local/Cellar/julia/0.4.3/lib/julia/sys.dylib
 in evalfile at loading.jl:320 (repeats 2 times)
 [inlined code] from /Users/dpo/.julia/v0.4/CPLEX/test/runtests.jl:15
 in anonymous at no file:0
 in include at /usr/local/Cellar/julia/0.4.3/lib/julia/sys.dylib
 in include_from_node1 at /usr/local/Cellar/julia/0.4.3/lib/julia/sys.dylib
 in process_options at /usr/local/Cellar/julia/0.4.3/lib/julia/sys.dylib
 in _start at /usr/local/Cellar/julia/0.4.3/lib/julia/sys.dylib
while loading /Users/dpo/.julia/v0.4/CPLEX/test/mathprog.jl, in expression starting on line 14
while loading /Users/dpo/.julia/v0.4/CPLEX/test/runtests.jl, in expression starting on line 12

I ran Pkg.update() tonight.

build problem

I am getting inconsistent results executing the following in Julia.

using JuMP,CPLEX
I=[1,2];
m2 = JuMP.Model(solver=CPLEX.CplexSolver());
JuMP.@defVar(m2, w[I], Bin);
JuMP.@defVar(m2, y[I] >= 0);
JuMP.@setObjective(m2, Min, 10*w[1]+w[2] + y[1] + y[2]);
JuMP.@addConstraint(m2,y[1] + 2*y[2]≤ 5*w[1]);
JuMP.@addConstraint(m2,3*y[1] + y[2]≤ 10*w[2]);
solve(m2)

Either the model is solved (as it should) or I get the following error:

ERROR: error compiling model: error compiling __CplexMathProgModel#1__: error compiling call: could not load library "/Users/frank/machinerie/IBM/ILOG/CPLEX_Studio1261/cplex/bin/x86-64_osx/libcplex1261.dylib"
dlopen(/Users/frank/machinerie/IBM/ILOG/CPLEX_Studio1261/cplex/bin/x86-64_osx/libcplex1261.dylib, 1): Symbol not found: __ZNSt8ios_base4InitD1Ev
  Referenced from: /Users/frank/machinerie/IBM/ILOG/CPLEX_Studio1261/cplex/bin/x86-64_osx/libcplex1261.dylib
  Expected in: flat namespace
 in /Users/frank/machinerie/IBM/ILOG/CPLEX_Studio1261/cplex/bin/x86-64_osx/libcplex1261.dylib
 in buildInternalModel at /Users/frank/.julia/v0.4/JuMP/src/solvers.jl:238
 in solve at /Users/frank/.julia/v0.4/JuMP/src/solvers.jl:79

The error systematically occurs when I start the Julia shell session with the above instructions. I am on OSX using Julia 0.4.3. The CPLEX deps.jl file points to libcplex1261.dylib:

ls -l ~/machinerie/IBM/ILOG/CPLEX_Studio1261/cplex/bin/x86-64_osx/libcplex1261.dylib
lrwxr-xr-x 1 frank staff 19 Apr 7 14:17 /Users/frank/machinerie/IBM/ILOG/CPLEX_Studio1261/cplex/bin/x86-64_osx/libcplex1261.dylib -> libcplex1261.jnilib

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.