GithubHelp home page GithubHelp logo

jump-dev / glpk.jl Goto Github PK

View Code? Open in Web Editor NEW
101.0 10.0 37.0 676 KB

A Julia interface to the GNU Linear Programming Kit

Home Page: https://www.gnu.org/software/glpk

License: Other

Julia 97.13% AMPL 1.82% JetBrains MPS 1.05%
julia linear-programming jump-jl

glpk.jl's Introduction

GLPK.jl

Build Status codecov

GLPK.jl is a wrapper for the GNU Linear Programming Kit library.

The wrapper has two components:

Affiliation

This wrapper is maintained by the JuMP community and is not an GNU project.

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

GLPK.jl is licensed under the GPL v3 license.

Installation

Install GLPK using Pkg.add:

import Pkg
Pkg.add("GLPK")

In addition to installing the GLPK.jl package, this will also download and install the GLPK binaries. You do not need to install GLPK separately.

To use a custom binary, read the Custom solver binaries section of the JuMP documentation.

Use with JuMP

To use GLPK with JuMP, use GLPK.Optimizer:

using JuMP, GLPK
model = Model(GLPK.Optimizer)
set_attribute(model, "tm_lim", 60 * 1_000)
set_attribute(model, "msg_lev", GLPK.GLP_MSG_OFF)

If the model is primal or dual infeasible, GLPK will attempt to find a certificate of infeasibility. This can be expensive, particularly if you do not intend to use the certificate. If this is the case, use:

model = Model(() -> GLPK.Optimizer(; want_infeasibility_certificates = false))

MathOptInterface API

The GLPK 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 for GLPK are comprehensively documented in the PDF documentation, but they are hard to find.

  • Options when solving a linear program are defined in Section 2.8.1
  • Options when solving a mixed-integer program are defined in Section 2.10.5

However, the following options are likely to be the most useful:

Parameter Example Explanation
msg_lev GLPK.GLP_MSG_ALL Message level for terminal output
presolve GLPK.GLP_ON Turn presolve on or off
tol_int 1e-5 Absolute tolerance for integer feasibility
tol_obj 1e-7 Relative objective tolerance for mixed-integer programs

Callbacks

Here is an example using GLPK's solver-specific callbacks.

using JuMP, GLPK, Test

model = Model(GLPK.Optimizer)
@variable(model, 0 <= x <= 2.5, Int)
@variable(model, 0 <= y <= 2.5, Int)
@objective(model, Max, y)
reasons = UInt8[]
function my_callback_function(cb_data)
    reason = GLPK.glp_ios_reason(cb_data.tree)
    push!(reasons, reason)
    if reason != GLPK.GLP_IROWGEN
        return
    end
    x_val = callback_value(cb_data, x)
    y_val = callback_value(cb_data, y)
    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 <= 1)
        MOI.submit(model, MOI.LazyConstraint(cb_data), con)
    end
end
MOI.set(model, GLPK.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
@show reasons

C API

The C API can be accessed via GLPK.glp_XXX functions, where the names and arguments are identical to the C API. See the /tests folder for inspiration.

Thread safety

GLPK is not thread-safe and should not be used with multithreading.

glpk.jl's People

Contributors

blegat avatar brozjak2 avatar carlobaldassi avatar carlolucibello avatar ericphanson avatar gregplowman avatar guilhermebodin avatar guimarqu avatar iainnz avatar issamt avatar jiahao avatar joaquimg avatar joehuchette avatar juan-pablo-vielma avatar juliatagbot avatar kmsquire avatar leotac avatar matbesancon avatar mlubin avatar mtanneau avatar odow avatar rafabench avatar ranjanan avatar rdeits avatar schillic avatar staticfloat avatar tkelman avatar tkoolen avatar wikunia avatar yuyichao 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

glpk.jl's Issues

GLPK build error on Centos 6: can't find gmp.h

The configure script for GLPK doesn't look in JULIA_HOME/usr/include for gmp.h, so the build fails. Not sure if this is a bug here or with BinDeps. cc: @loladiro .

INFO: Running build script for package GLPK
Array((DependencyProvider,Dict{Symbol,Any}),(2,)) [(Homebrew(HomebrewInstall("https://raw.github.com/Homebrew/homebrew-science/master/glpk.rb",[],[])),Dict{Symbol,Any}()),(Autotools(nothing,{:libtarget=>"src/.libs/libglpk.la",:configure_options=>["--with-gmp","--enable-dl"]}),[:os=>:Unix])]
INFO: Attempting to Create directory /home/kmsquire/.julia/v0.2/GLPK/deps/downloads
INFO: Downloading file http://ftp.gnu.org/gnu/glpk/glpk-4.48.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 3406k  100 3406k    0     0  1149k      0  0:00:02  0:00:02 --:--:-- 1254k
INFO: Done downloading file http://ftp.gnu.org/gnu/glpk/glpk-4.48.tar.gz
INFO: Attempting to Create directory /home/kmsquire/.julia/v0.2/GLPK/deps/src
INFO: Attempting to Create directory /home/kmsquire/.julia/v0.2/GLPK/deps
INFO: Directory /home/kmsquire/.julia/v0.2/GLPK/deps already created
INFO: Attempting to Create directory /home/kmsquire/.julia/v0.2/GLPK/deps/src/glpk-4.48
INFO: Attempting to Create directory /home/kmsquire/.julia/v0.2/GLPK/deps/builds/libglpk
INFO: Changing Directory to /home/kmsquire/.julia/v0.2/GLPK/deps/builds/libglpk
...
checking for sys/time.h... yes
checking for gettimeofday... yes
checking gmp.h usability... no
checking gmp.h presence... no
checking for gmp.h... no
configure: error: gmp.h header not found
WARNING: An exception occured while building binary dependencies.
You may have to take manual steps to complete the installation, see the error message below.
To reattempt the installation, run Pkg.fixup("GLPK").

 in build at pkg.jl:259
ERROR: failed process: Process(`/home/kmsquire/.julia/v0.2/GLPK/deps/src/glpk-4.48/configure --with-gmp --enable-dl --prefix=/home/kmsquire/.julia/v0.2/GLPK/deps/usr`, ProcessExited(1)) [1]
 in error at error.jl:22
 in pipeline_error at process.jl:436
 in run at process.jl:413
 in run at /home/kmsquire/.julia/v0.2/BinDeps/src/BinDeps.jl:431
 in run at /home/kmsquire/.julia/v0.2/BinDeps/src/BinDeps.jl:405
 in run at /home/kmsquire/.julia/v0.2/BinDeps/src/BinDeps.jl:431 (repeats 2 times)
 in satisfy! at /home/kmsquire/.julia/v0.2/BinDeps/src/dependencies.jl:399
 in anonymous at /home/kmsquire/.julia/v0.2/BinDeps/src/dependencies.jl:413
 in include at boot.jl:238
at /home/kmsquire/.julia/v0.2/GLPK/deps/build.jl:19

Move to JuliaOpt?

Hi Carlo,

We've created the @JuliaOpt organization to be a collection of high-quality optimization-related packages in Julia. GLPK.jl is a great example of such a package that already meets our packaging guidelines (http://juliaopt.org/). Are you interested in transferring the repository?

GLPK ignores msg_lev option

GLPK ignores the use of msg_lev to print the output of the solve.

GLPK_optimizer = with_optimizer(GLPK.Optimizer, msg_lev = GLPK.MSG_ALL)
# returns => OptimizerFactory(GLPK.Optimizer, (), Base.Iterators.Pairs(:msg_lev => 3))
m = Model(GLPK_optimizer)
@variable(m ,x[1:5])
@constraint(m ,sum(x) >= 10)
@objective(m, Min, sum(x))
optimize!(m)

Wrong objective bound in MIP with constant term

Consider the model

using JuMP
m = Model();
@variable(m, x >= 0, Int);
@objective(m, Min, x + 3);

The expected result would be "3.0, 3.0", but instead we get "6.0, 3.0"

using GLPK
JuMP.set_optimizer(m, with_optimizer(GLPK.Optimizer))
JuMP.optimize!(m)
println("GLPK  : ", JuMP.objective_bound(m), " ", JuMP.objective_value(m))

To problem seems to come from adding the constant term in the function LQOI.get_objective_bound(model::Optimizer), in MOI_wrapper.jl - maybe that was needed some time ago, but not anymore, as can be seen from the results below.

using LinQuadOptInterface
const LQOI = LinQuadOptInterface;

glpk_model = m.moi_backend.optimizer.model;
LQOI.get_objective_value(glpk_model)
LQOI.get_objective_bound(glpk_model)
LQOI.get_constant_objective(glpk_model)

GLPK.mip_status(glpk_model.inner) == GLPK.OPT
GLPK.mip_obj_val(glpk_model.inner)
glpk_model.objective_bound

I tested also Gurobi.jl, which indeed returns "3.0, 3.0"

Build fails on Julia 1.0 on MacOS

Building GLPK ───→ ~/.julia/packages/GLPK/thMVo/deps/build.log
┌ Error: Error building GLPK:
│ ERROR: LoadError: MethodError: no method matching replace(::String, ::String, ::String)
│ Closest candidates are:
│ replace(::String, !Matched::Pair{#s55,B} where B where #s55<:AbstractChar; count) at strings/util.jl:414
│ replace(::String, !Matched::Pair{#s52,B} where B where #s52<:Union{Tuple{Vararg{AbstractChar,N} where N}, Set{#s49} where #s49<:AbstractChar, AbstractArray{#s50,1} where #s50<:AbstractChar}; count) at strings/util.jl:419
│ replace(::String, !Matched::Pair; count) at strings/util.jl:423
│ ...
│ Stacktrace:
│ [1] top-level scope at none:0
│ [2] include at ./boot.jl:317 [inlined]
│ [3] include_relative(::Module, ::String) at ./loading.jl:1038
│ [4] include(::Module, ::String) at ./sysimg.jl:29
│ [5] include(::String) at ./client.jl:388
│ [6] top-level scope at none:0
│ in expression starting at /Users/arora/.julia/packages/GLPK/thMVo/deps/build.jl:10
└ @ Pkg.Operations ~/src/julia/usr/share/julia/stdlib/v1.0/Pkg/src/Operations.jl:1068

Possible to link GLPK.jl to existing GLPK library

Hello,

I've downloaded and built GLPK 4.65 and would rather use this than the Julia-built 4.61 version. Is there a way to build GLPK.jl against my library rather than having it download and install a new one (e.g. by using push! to add the GLPK library path to DL_LOAD_PATH prior to running Pkg.build("GLPK"))?

Thanks,

Michael

Update /docs

The docs in /docs are old and should be updated to documenter.

Ref #104

Julia 1.0.0 GLPKOptimizerMIP() not defined

First steps with Julia, starting with Julia 1.0 and trying to follow the knapsack problem example here

http://www.juliaopt.org/MathOptInterface.jl/latest/apimanual.html#A-complete-example:-solving-a-knapsack-problem-1

My attempts to make this work fail as follows:

$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.0.0 (2018-08-08)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using MathOptInterface

julia> const MOI = MathOptInterface
MathOptInterface

julia> using GLPK

julia> optimizer = GLPK.GLPKOptimizerMIP()
ERROR: UndefVarError: GLPKOptimizerMIP not defined
Stacktrace:
 [1] getproperty(::Module, ::Symbol) at ./sysimg.jl:13
 [2] top-level scope at none:0

I see in this repository that GLPK is tested against Julia 0.6 and 0.7. Perhaps it is not yet meant to work against 1.0.0?

Thanks in advance.

glp_intopt: optimal basis to initial LP relaxation not provided

This problem was working fine with GLPK last month (it was GLPKOptimizerMIP at the time) but with the recent updates, it now gives the following:

using JuMP
using GLPK
model = Model(with_optimizer(GLPK.Optimizer))
@variable(model, x, Int)
y = @variable(model)
@constraint(model, x <= 1)
@objective(model, Min, -5x + y)
JuMP.optimize!(model) # glp_intopt: optimal basis to initial LP relaxation not provided
JuMP.termination_status(model) # OtherError::TerminationStatusCode = 18
JuMP.primal_status(model) # UnknownResultStatus::ResultStatusCode = 8

This is causing failure in StructJuMP tests

make package compatible with homebrew

According to the discussion here, if GLPK uses find_library to recognize hombrew/bundled libraries, then it can be included in the Julia distribution on OS X. I have a macbook that I can use to help with testing.

passing in parameters

How does one pass in time limit, absolute optimality gap, and relative optimality gap stopping condition parameters to GPLK when using const solver = GLPKSolverMIP() ?

Support newer version of glpk

The version installed on my system is 4.55 and the soname is libglpk.so.36. Since the soname is bumped I guess there might have been a ABI breakage. Would be nice to add support for newer version of the library.

install error win 10, julia 4.2

Pkg.add("GLPK")

error:

================================[ ERROR: GLPK ]=================================

LoadError: No download agent available; install curl, wget, or fetch.
while loading C:\Users\****\.julia\v0.4\GLPK\deps\build.jl, in expression starting on line 61

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

Do we really need to install curl manually?

Use of deprecated `warn`

There is a deprecated warn in MOIWrapper.jl

This raises an UndefVarError when an invalid parameter name is passed:

julia> model = Model(with_optimizer(GLPK.Optimizer, XXX=3))

UndefVarError: warn not defined

Stacktrace:
 [1] #Optimizer#5(::Bool, ::Symbol, ::Base.Iterators.Pairs{Symbol,Int64,Tuple{Symbol},NamedTuple{(:XXX,),Tuple{Int64}}}, ::Type) at /home/mtanneau/.julia/packages/GLPK/rw631/src/MOIWrapper.jl:117
 [2] (::getfield(Core, Symbol("#kw#Type")))(::NamedTuple{(:XXX,),Tuple{Int64}}, ::Type{GLPK.Optimizer}) at ./none:0
 [3] (::OptimizerFactory)() at /home/mtanneau/.julia/packages/JuMP/5zuxr/src/JuMP.jl:116
 [4] #set_optimizer#78(::Bool, ::Function, ::Model, ::OptimizerFactory) at /home/mtanneau/.julia/packages/JuMP/5zuxr/src/optimizer_interface.jl:38
 [5] #Model#5 at ./none:0 [inlined]
 [6] Model(::OptimizerFactory) at /home/mtanneau/.julia/packages/JuMP/5zuxr/src/JuMP.jl:213
 [7] top-level scope at In[106]:1

I guess one should use Compat.@warn instead?

Happy to PR if that's a satisfactory fix.

required packages on ubuntu

I had to install libgmp-dev and libltdl3-dev to make the build work on ubuntu 12.04. Should mention this somewhere.

EXACT: no bf solution found (use GLPK.factorize)

The following code,

using GLPK
optimizer = GLPK.Optimizer(method=GLPK.EXACT)
using MathOptInterface
const MOI = MathOptInterface
λ = MOI.add_variables(optimizer, 2)
l = MOI.SingleVariable.(λ)
MOI.add_constraint(optimizer, 1.0l[1] + 1.0l[2], MOI.EqualTo(1.0))
MOI.add_constraint(optimizer, -1.0l[1], MOI.EqualTo(-1.0))
MOI.add_constraint(optimizer, l[2], MOI.EqualTo(1.0))
MOI.optimize!(optimizer)

throws the error

ERROR: LoadError: GLPKError("no bf solution found (use GLPK.factorize)")
Stacktrace:
 [1] _bf_exists at /home/blegat/.julia/packages/GLPK/3DCgA/src/GLPK_checks.jl:271 [inlined]
 [2] macro expansion at /home/blegat/.julia/packages/GLPK/3DCgA/src/GLPK_checks.jl:53 [inlined]
 [3] get_bhead(::Prob, ::Int64) at /home/blegat/.julia/packages/GLPK/3DCgA/src/GLPK.jl:1619
 [4] get_infeasibility_ray(::GLPK.Optimizer, ::Array{Float64,1}) at /home/blegat/.julia/packages/GLPK/3DCgA/src/infeasibility_certificates.jl:49
 [5] optimize!(::GLPK.Optimizer) at /home/blegat/.julia/packages/GLPK/3DCgA/src/MOI_wrapper.jl:1334

See JuliaReach/LazySets.jl#1668

build error

I am not able to resolve this build error, any help will be appreciated.

(v1.0) pkg> build GLPK
  Building GLPK  `~/.julia/packages/GLPK/rw631/deps/build.log`
┌ Error: Error building `GLPK`: 
│ ┌ Warning: platform_key() is deprecated, use platform_key_abi() from now on
│ │   caller = ip:0x0
│ └ @ Core :-1
│ [ Info: Downloading https://github.com/JuliaMath/GMPBuilder/releases/download/v6.1.2-2/GMP.v6.1.2.x86_64-apple-darwin14.tar.gz to /Users/alpersavasci/.julia/packages/GLPK/rw631/deps/usr/downloads/GMP.v6.1.2.x86_64-apple-darwin14.tar.gz...
│ ERROR: LoadError: LoadError: Could not download https://github.com/JuliaMath/GMPBuilder/releases/download/v6.1.2-2/GMP.v6.1.2.x86_64-apple-darwin14.tar.gz to /Users/alpersavasci/.julia/packages/GLPK/rw631/deps/usr/downloads/GMP.v6.1.2.x86_64-apple-darwin14.tar.gz:ErrorException("")
│ Stacktrace:
│  [1] error(::String) at ./error.jl:33
│  [2] #download#89(::Bool, ::Function, ::String, ::String) at /Users/alpersavasci/.julia/packages/BinaryProvider/4F5Hq/src/PlatformEngines.jl:498
│  [3] #download at ./none:0 [inlined]
│  [4] #download_verify#90(::Bool, ::Bool, ::Bool, ::Function, ::String, ::String, ::String) at /Users/alpersavasci/.julia/packages/BinaryProvider/4F5Hq/src/PlatformEngines.jl:567
│  [5] #download_verify at ./none:0 [inlined]
│  [6] #install#129(::Prefix, ::String, ::Bool, ::Bool, ::Bool, ::Function, ::String, ::String) at /Users/alpersavasci/.julia/packages/BinaryProvider/4F5Hq/src/Prefix.jl:314
│  [7] (::getfield(BinaryProvider, Symbol("#kw##install")))(::NamedTuple{(:prefix, :force, :verbose),Tuple{Prefix,Bool,Bool}}, ::typeof(install), ::String, ::String) at ./none:0
│  [8] top-level scope at /Users/alpersavasci/.julia/packages/GLPK/rw631/deps/build_GMP.v6.1.2.jl:36
│  [9] include at ./boot.jl:317 [inlined]
│  [10] include_relative(::Module, ::String) at ./loading.jl:1044
│  [11] include at ./sysimg.jl:29 [inlined]
│  [12] include(::String) at ./loading.jl:1079
│  [13] top-level scope at none:0
│  [14] eval at ./boot.jl:319 [inlined]
│  [15] evalfile(::String, ::Array{String,1}) at ./loading.jl:1075 (repeats 2 times)
│  [16] top-level scope at /Users/alpersavasci/.julia/packages/GLPK/rw631/deps/build.jl:37
│  [17] include at ./boot.jl:317 [inlined]
│  [18] include_relative(::Module, ::String) at ./loading.jl:1044
│  [19] include(::Module, ::String) at ./sysimg.jl:29
│  [20] include(::String) at ./client.jl:392
│  [21] top-level scope at none:0in expression starting at /Users/alpersavasci/.julia/packages/GLPK/rw631/deps/build_GMP.v6.1.2.jl:32in expression starting at /Users/alpersavasci/.julia/packages/GLPK/rw631/deps/build.jl:31
│ [19:37:41] dyld: Library not loaded: @rpath/libssl.1.0.0.dylib
│ [19:37:41]   Referenced from: /anaconda3/lib/libssh2.1.dylib
│ [19:37:41]   Reason: image not found
└ @ Pkg.Operations /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.0/Pkg/src/Operations.jl:1097

Issue installing with Pkg2 on linux

julia> Pkg2.add("GLPK")
INFO: Installing GLPK v0.2.4
INFO: Running build script for package GLPK
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 3406k  100 3406k    0     0  1094k      0  0:00:03  0:00:03 --:--:-- 1190k
WARNING: An exception occured while building binary dependencies.
You may have to take manual steps to complete the installation, see the error message below.
To reattempt the installation, run Pkg.fixup("GLPK").

 in runbuildscript at pkg2.jl:235
ERROR: no method unpack_cmd(ASCIIString,ASCIIString)
 in include_from_node1 at loading.jl:92
 in anonymous at no file:238
 in cd at file.jl:25
 in cd at pkg2/dir.jl:28
 in runbuildscript at pkg2.jl:235
 in _fixup at pkg2.jl:291
 in fixup at pkg2.jl:321
 in fixup#g154 at no file
 in fixup#g153 at no file
 in fixup#g152 at no file
 in anonymous at no file:227
 in cd at file.jl:25
 in cd at pkg2/dir.jl:28
 in resolve at pkg2.jl:147
 in resolve at no file (repeats 3 times)
 in anonymous at no file:31
 in cd at file.jl:25
 in cd at pkg2/dir.jl:28
 in edit at pkg2.jl:21
 in add at pkg2.jl:18
 in anonymous at no file:14

Setting GLPK options

I need a bit of help in setting GLPK's solver options. Specifically I want to set the MIPGAP and the time limit. I've tried the following, and it did not alter the solver behavior at all (ie - runs a long time and looks for the optimal solution).

m=Model(solver=GLPKSolverMIP())
params=GLPK.IntoptParam()
params.tm_lim=1
params.tol_obj=.5

set up the model (omitted here)

status=solve(m)

Can someone tell me what I'm doing wrong? Thanks.

travis failure

I've been playing around with travis to figure out the errors. The first issue was that we're not supposed to apt-get upgrade: travis-ci/travis-ci#1523. Now it's failing to build GLPK:

$ julia -e 'Pkg.build("GLPK")'
The command "julia -e 'Pkg.build("GLPK")'" exited with 0.

The strange thing is that Pkg.build("GLPK") should print out INFO: Building GLPK if BinDeps is called, but it doesn't print anything.

Call glpk preprocessing on GLPK.jl

GLPK 4.65 has a new API calling its preprocessor:

GLPK 4.65 Release Information
...
In this release:
The following new API routines for LP/MIP preprocessing were
added:

   glp_npp_alloc_wksp    allocate the preprocessor workspace
  glp_npp_load_prob     load original problem instance
 glp_npp_preprocess1   perform basic LP/MIP preprocessing
   glp_npp_build_prob    build resultant problem instance
  glp_npp_postprocess   postprocess solution to resultant problem
   glp_npp_obtain_sol    obtain solution to original problem
  glp_npp_free_wksp     free the preprocessor workspace
   See doc/npp.txt for detailed description of these API routines.

See more in http://lists.gnu.org/archive/html/help-glpk/2018-02/msg00009.html
@mlubin: GLPK just released this feature we were talking last week.

Would be great if GLPK.jl could make this routines available easily.

GLPK windows binary unavailable

$ wget http://downloads.sourceforge.net/project/winglpk/winglpk/GLPK-4.52/winglpk-4.52.zip
--2015-07-24 19:43:42--  http://downloads.sourceforge.net/project/winglpk/winglpk/GLPK-4.52/winglpk-4.52.zip
Resolving downloads.sourceforge.net (downloads.sourceforge.net)... 216.34.181.59
Connecting to downloads.sourceforge.net (downloads.sourceforge.net)|216.34.181.59|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2015-07-24 19:43:45 ERROR 404: Not Found.

Is this a temporary thing?
CC @tkelman

Cannot load: AbstractSparseMatrix not defined

On latest master 0.4.0-dev+3340:

julia> using GLPK

WARNING: deprecated syntax "(Uint=>Bool)[]" at /Users/huchette/.julia/v0.4/GLPK/src/GLPK_checks.jl:19.
Use "Dict{Uint,Bool}()" instead.
ERROR: LoadError: UndefVarError: AbstractSparseMatrix not defined
 in include at ./boot.jl:249
 in include_from_node1 at ./loading.jl:128
 in reload_path at ./loading.jl:152
 in _require at ./loading.jl:67
 in require at ./loading.jl:52
while loading /Users/huchette/.julia/v0.4/GLPK/src/GLPK.jl, in expression starting on line 802

Issue with adding columns

using JuMP, GLPKMathProgInterface

m = Model(solver=GLPKSolverMIP())  # Works with GLPKSolverLP

# max 1.1x + 1.0y
# st     x +    y <= 3
#     0 <= x <= 3
#     1 <= y <= 3
@defVar(m, 0 <= x <= 3)
@defVar(m, 1 <= y <= 3)
@setObjective(m, :Max, 1.1x + 1.0y)
maincon = @addConstraint(m, x + y <= 3)
solve(m)

# Test adding a variable
# max 1.1x + 1.0y + 100.0z
# st     x +    y +      z <= 3
#     0 <= x <= 3
#     1 <= y <= 3
#     0 <= z <= 5
@defVar(m, 0 <= z <= 5, 100.0, [maincon], [1.0])
solve(m)

Error

ERROR: output vector is too short
 in cbgetlpsolution at /Users/idunning/.julia/v0.3/GLPKMathProgInterface/src/GLPKInterfaceMIP.jl:173
 in _internal_callback at /Users/idunning/.julia/v0.3/GLPKMathProgInterface/src/GLPKInterfaceMIP.jl:105
 in intopt at /Users/idunning/.julia/v0.3/GLPK/src/GLPK.jl:223
 in optimize! at /Users/idunning/.julia/v0.3/GLPKMathProgInterface/src/GLPKInterfaceMIP.jl:392
 in solveLP at /Users/idunning/.julia/v0.3/JuMP/src/solvers.jl:217
 in solve at /Users/idunning/.julia/v0.3/JuMP/src/solvers.jl:37
 in include at /Applications/Julia-0.3.0.app/Contents/Resources/julia/lib/julia/sys.dylib
 in include_from_node1 at loading.jl:128
 in process_options at /Applications/Julia-0.3.0.app/Contents/Resources/julia/lib/julia/sys.dylib
 in _start at /Applications/Julia-0.3.0.app/Contents/Resources/julia/lib/julia/sys.dylib (repeats 2 times)
while loading /Users/idunning/Desktop/breakglpk.jl, in expression starting on line 22

glp_delete_prob: operation not allowed
Error detected in file /Users/idunning/.julia/v0.3/GLPK/deps/src/glpk-4.52/src/glpapi01.c at line 1564
error in running finalizer: GLPK.GLPKFatalError(msg="GLPK call failed. All GLPK objects you defined so far are now invalidated.")

Fails to build with julia 0.6.2

Provider BinDeps.BuildProcess failed to satisfy dependency libglpk
while loading /home/afh/.julia/v0.6/GLPK/deps/build.jl, in expression starting on line 49

Steps to reproduce:

  1. Get the latest julia binary (0.6.2)
  2. Run Pkg.build("GLPK")

Override default show method

The current representation doesn't fit on screen and contains too much implementation detail

julia> GLPK.Optimizer()
GLPK.Optimizer(GLPK.Prob(Ptr{Nothing} @0x0000000002b03400), "", AffineObjective::ObjectiveType = 1, nothing, MinSense::OptimizationSense = 0, 0x0000000000000000, Dict{MathOptInterface.VariableIndex,Int64}(), Dict{MathOptInterface.VariableIndex,String}(), Dict{String,Set{MathOptInterface.VariableIndex}}(), MathOptInterface.VariableIndex[], Dict{MathOptInterface.VariableIndex,LinQuadOptInterface.VariableType}(), Float64[], Float64[], 0x0000000000000000, LinQuadOptInterface.ConstraintMapping(Dict{MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.LessThan{Float64}},Int64}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.GreaterThan{Float64}},Int64}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.EqualTo{Float64}},Int64}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.Interval{Float64}},Int64}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.VectorAffineFunction{Float64},MathOptInterface.Nonnegatives},Array{Int64,1}}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.VectorAffineFunction{Float64},MathOptInterface.Nonpositives},Array{Int64,1}}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.VectorAffineFunction{Float64},MathOptInterface.Zeros},Array{Int64,1}}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.ScalarQuadraticFunction{Float64},MathOptInterface.LessThan{Float64}},Int64}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.ScalarQuadraticFunction{Float64},MathOptInterface.GreaterThan{Float64}},Int64}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.ScalarQuadraticFunction{Float64},MathOptInterface.EqualTo{Float64}},Int64}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable,MathOptInterface.LessThan{Float64}},MathOptInterface.VariableIndex}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable,MathOptInterface.GreaterThan{Float64}},MathOptInterface.VariableIndex}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable,MathOptInterface.EqualTo{Float64}},MathOptInterface.VariableIndex}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable,MathOptInterface.Interval{Float64}},MathOptInterface.VariableIndex}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.VectorOfVariables,MathOptInterface.Nonnegatives},Array{Int64,1}}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.VectorOfVariables,MathOptInterface.Nonpositives},Array{Int64,1}}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.VectorOfVariables,MathOptInterface.Zeros},Array{Int64,1}}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable,MathOptInterface.Integer},MathOptInterface.VariableIndex}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable,MathOptInterface.ZeroOne},Tuple{MathOptInterface.VariableIndex,Float64,Float64}}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.VectorOfVariables,MathOptInterface.SOS1{Float64}},Int64}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.VectorOfVariables,MathOptInterface.SOS2{Float64}},Int64}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable,MathOptInterface.Semicontinuous{Float64}},MathOptInterface.VariableIndex}(), Dict{MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable,MathOptInterface.Semiinteger{Float64}},MathOptInterface.VariableIndex}()), Float64[], Float64[], Float64[], Float64[], Float64[], Dict{MathOptInterface.ConstraintIndex,String}(), Dict{String,Set{MathOptInterface.ConstraintIndex}}(), 0.0, OtherError::TerminationStatusCode = 19, UnknownResultStatus::ResultStatusCode = 6, UnknownResultStatus::ResultStatusCode = 6, 0, 0, 0.0, false, :Simplex, GLPK.InteriorParam(1, 2, 4.2439915824e-314, 1.2731974747e-313, 4.243991585e-314, 6.365987374e-314, 1.06099789573e-313, 1.9097962121e-313, 1.9097962123e-313, 1.9097962123e-313, 1.9097962123e-313, 2.12199579146e-313, 2.54639494965e-313, 1.27319747507e-313, 2.33419537056e-313, 2.3341953706e-313, 1.69759663317e-313, 1.06099789573e-313, 1.06099789573e-313, 2.7585945285e-313, 1.06099789612e-313, 1.06099789573e-313, 1.06099789573e-313, 1.06099789573e-313, 1.06099789573e-313, 1.06099789573e-313, 1.06099789573e-313, 1.06099789573e-313, 1.06099789573e-313, 2.9707941076e-313, 1.06099789573e-313, 1.06099789573e-313, 1.06099789573e-313, 3.1829936872e-313, 1.06099789573e-313, 1.06099789573e-313, 1.06099789573e-313, 1.06099789573e-313, 1.06099789573e-313, 1.06099789573e-313, 1.06099789573e-313, 1.06099789573e-313, 1.06099789573e-313, 1.06099789573e-313, 1.06099789573e-313, 1.06099789573e-313, 4.0317920031e-313, 1.0609978964e-313, 4.2439915822e-313, 1.06099789647e-313), GLPK.IntoptParam(1, 4, 3, 1.0e-5, 1.0e-7, 2147483647, 5000, 10000, Ptr{Nothing} @0x00007fc389829230, Ptr{Nothing} @0x00007fc39bbbe2b0, 0, 2, 0.0, 0, 0, 0, 0, 0, 0, 0, 0, 60000, 1, Ptr{Int8} @0x0000000000000000, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 6.94054038908617e-310, 6.94054016886096e-310), GLPK.SimplexParam(1, 1, 34, 34, 1.0e-7, 1.0e-7, 1.0e-9, -1.7976931348623157e308, 1.7976931348623157e308, 2147483647, 2147483647, 5000, 0, 0, 4.2439915824e-314, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), -1677258752, false, GLPK.CallbackData(GLPK.Optimizer(#= circular reference @-2 =#), Ptr{Nothing} @0x0000000000000000), NaN, getfield(GLPK, Symbol("##6#7"))(), Int64[])

Bounds disabled for some variable types

Apparently the checks in this function https://github.com/JuliaOpt/LinQuadOptInterface.jl/blob/master/src/constraints/singlevariable.jl#L101

function MOI.addconstraint!(model::LinQuadOptimizer, variable::SinVar, set::S) where S <: LinSets
    __assert_supported_constraint__(model, SinVar, S)
    __check_for_conflicting__(model, variable, set,
        S, MOI.Semicontinuous{Float64}, MOI.Semiinteger{Float64}, MOI.ZeroOne)

disable bounds for some variable types. Is this behavior intended?
(I have checked the old issues, but couldn't find something related to this)

Adding lazy constraint not successful using GLPK

I am trying to follow the example for solver callbacks using JuMP, but GLPK instead of Gurobi. See the example here . Specifically, the @lazyconstraint and addlazycallback are not defined when I follow the example but using GLPK.

I am unable to use solver callback in JuMP using GLPK solver and see that my tests do fail when I try to test the GLPK package. Output as below, where the MOI_callbacks.jl test does not succeed (among others). Will there be a fix to the tests soon?

Sorry if this issue is not related to your package, I am new to Julia and unable to infer the root cause of my issues. You may see here for more details on my problem.

(v1.3) pkg> test GLPK
   Testing GLPK
 Resolving package versions...
    Status `C:\Users\espenhs\AppData\Local\Temp\jl_fwAwpf\Manifest.toml`
  [6e4b80f9] BenchmarkTools v0.4.3
  [b99e7846] BinaryProvider v0.5.8
  [523fee87] CodecBzip2 v0.6.0
  [944b1d66] CodecZlib v0.6.0
  [60bf3e95] GLPK v0.12.1
  [cd3eb016] HTTP v0.8.8
  [83e8ac13] IniFile v0.5.0
  [682c06a0] JSON v0.21.0
  [7d188eb4] JSONSchema v0.2.0
  [b8f27783] MathOptInterface v0.9.9
  [739be429] MbedTLS v0.7.0
  [d8a4904e] MutableArithmetics v0.2.2
  [bac558e1] OrderedCollections v1.1.0
  [69de0a69] Parsers v0.3.10
  [3bb67fe8] TranscodingStreams v0.9.5
  [2a0f44e3] Base64  [`@stdlib/Base64`]
  [ade2ca70] Dates  [`@stdlib/Dates`]
  [8ba89e20] Distributed  [`@stdlib/Distributed`]
  [b77e0a4c] InteractiveUtils  [`@stdlib/InteractiveUtils`]
  [8f399da3] Libdl  [`@stdlib/Libdl`]
  [37e2e46d] LinearAlgebra  [`@stdlib/LinearAlgebra`]
  [56ddb016] Logging  [`@stdlib/Logging`]
  [d6f4376e] Markdown  [`@stdlib/Markdown`]
  [a63ad114] Mmap  [`@stdlib/Mmap`]
  [de0858da] Printf  [`@stdlib/Printf`]
  [9a3f8284] Random  [`@stdlib/Random`]
  [ea8e919c] SHA  [`@stdlib/SHA`]
  [9e88b42a] Serialization  [`@stdlib/Serialization`]
  [6462fe0b] Sockets  [`@stdlib/Sockets`]
  [2f01184e] SparseArrays  [`@stdlib/SparseArrays`]
  [10745b16] Statistics  [`@stdlib/Statistics`]
  [8dfed614] Test  [`@stdlib/Test`]
  [4ec0a83e] Unicode  [`@stdlib/Unicode`]
Test Summary: | Pass  Total
C API         |  163    163
MathOptInterface: Error During Test at C:\Users\espenhs\.julia\packages\GLPK\HjJiX\test\runtests.jl:20
  Got exception outside of a @test
  LoadError: ArgumentError: Package Random not found in current path:
  - Run `import Pkg; Pkg.add("Random")` to install the Random package.

  Stacktrace:
   [1] require(::Module, ::Symbol) at .\loading.jl:887
   [2] include at .\boot.jl:328 [inlined]
   [3] include_relative(::Module, ::String) at .\loading.jl:1105
   [4] include(::Module, ::String) at .\Base.jl:31
   [5] include(::String) at .\client.jl:424
   [6] top-level scope at C:\Users\espenhs\.julia\packages\GLPK\HjJiX\test\runtests.jl:22
   [7] top-level scope at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\Test\src\Test.jl:1107
   [8] top-level scope at C:\Users\espenhs\.julia\packages\GLPK\HjJiX\test\runtests.jl:21
   [9] include at .\boot.jl:328 [inlined]
   [10] include_relative(::Module, ::String) at .\loading.jl:1105
   [11] include(::Module, ::String) at .\Base.jl:31
   [12] include(::String) at .\client.jl:424
   [13] top-level scope at none:6
   [14] eval(::Module, ::Any) at .\boot.jl:330
   [15] exec_options(::Base.JLOptions) at .\client.jl:263
   [16] _start() at .\client.jl:460
  in expression starting at C:\Users\espenhs\.julia\packages\GLPK\HjJiX\test\MOI_callbacks.jl:1

Test Summary:             | Pass  Error  Broken  Total
MathOptInterface          | 1834      1       1   1836
  Unit Tests              |  782                   782
  Linear tests            |  511                   511
  Linear Conic tests      |  135                   135
  Integer Linear tests    |   75                    75
  ModelLike tests         |  246              1    247
  Parameter setting       |    4                     4
  Issue #79               |    2                     2
  Issue #70               |    6                     6
  Infeasible bounds       |    1                     1
  RawParameter            |   15                    15
  TimeLimitSec issue #110 |    4                     4
  RelativeGap             |    2                     2
  Extra name tests        |   15                    15
  Issue #102              |    2                     2
  Issue #116              |    3                     3
  Default parameters      |    4                     4
  Duplicate names         |   20                    20
  Duals with equal bounds |    2                     2
  PR #121                 |    3                     3
  Non-ascii names         |    2                     2
ERROR: LoadError: Some tests did not pass: 1834 passed, 0 failed, 1 errored, 1 broken.
in expression starting at C:\Users\espenhs\.julia\packages\GLPK\HjJiX\test\runtests.jl:20
ERROR: Package GLPK errored during testing

TimeLimitSec is in seconds but tm_lim is in ms

The problem is that GLPK internally only accepts Int32 as the time limit but TimeLimitSec supports Real values.

In general I'm unable to find a standard regarding the datatype that should be supported by TimeLimitSec Maybe @mlubin @odow know?

The TimeLimitSec function takes in Real values
https://github.com/JuliaOpt/GLPK.jl/blob/master/src/MOI_wrapper.jl#L293
but GLPK uses Int32 for tm_lim such that setting it to a float doesn't work.

Additionally

using GLPK
model = GLPK.Optimizer(tm_lim = 60.1)

doesn't work even though in the readme

model = GLPK.Optimizer(tm_lim = 60.0)

looks like it would support floats as well.

I ran into the problem by setting TimeLimitSec inside Juniper to a floating point value.

I suggest to support Union{Nothing,Real} or Union{Nothing,Float64} as
http://www.juliaopt.org/MathOptInterface.jl/stable/apireference/#MathOptInterface.TimeLimitSec mentions that it should be possible to set it to nothing as well.

and then GLPK should floor the value and convert it to Int32 I suppose inside TimeLimitSec. I think:

model = GLPK.Optimizer(tm_lim = 60.1)

doesn't need to be supported but would change the readme to:

model = GLPK.Optimizer(tm_lim = 60)

Additionally we should mention in the MOI docs the type of the input for the set parameters if they are not clear.

If you agree I will create a PR here for the necessary changes.

segfault when reading compressed MPS file

With https://github.com/mlubin/SimplexBenchmarks/blob/master/GenerateData/greenbea.gz:

julia> using GLPK

julia> lp = Prob()
Prob(Ptr{Void} @0x00000000045670d0)

julia> read_mps(lp, GLPK.MPS_FILE,"greenbea.gz")
Reading problem data from `greenbea.gz'...
Segmentation fault (core dumped)

Gdb trace:

#0  0x00007fffecde557c in crc32_little (len=<optimized out>, 
    buf=0x5810ac0 '*' <repeats 27 times>, "\n* SET UP THE INITIAL DATA *\n", '*' <repeats 27 times>, "\nNAME          GREENBEA", ' ' <repeats 58 times>, "\n*   Problem:\n*   ********\n*   An LP"..., 
    crc=<optimized out>) at /home/mlubin/.julia/GLPK/deps/src/glpk-4.52/src/zlib/crc32.c:259
#1  zlib_crc32 (crc=<optimized out>, buf=<optimized out>, len=len@entry=16384)
    at /home/mlubin/.julia/GLPK/deps/src/glpk-4.52/src/zlib/crc32.c:218
#2  0x00007fffecdeba4a in zlib_inflate (strm=strm@entry=0x5e27ff8, flush=flush@entry=0)
    at /home/mlubin/.julia/GLPK/deps/src/glpk-4.52/src/zlib/inflate.c:1232
#3  0x00007fffecde961a in gz_decomp (state=state@entry=0x5e27f80)
    at /home/mlubin/.julia/GLPK/deps/src/glpk-4.52/src/zlib/gzread.c:189
#4  0x00007fffecde97f6 in gz_fetch (state=state@entry=0x5e27f80)
    at /home/mlubin/.julia/GLPK/deps/src/glpk-4.52/src/zlib/gzread.c:245
#5  0x00007fffecde99d8 in zlib_gzread (file=0x5e27f80, buf=buf@entry=0x7fffffffcd8f, len=len@entry=1)
    at /home/mlubin/.julia/GLPK/deps/src/glpk-4.52/src/zlib/gzread.c:339
#6  0x00007fffecde9ae3 in zlib_gzgetc (file=<optimized out>)
    at /home/mlubin/.julia/GLPK/deps/src/glpk-4.52/src/zlib/gzread.c:398
#7  0x00007fffecd656db in z_fgetc (_fh=0x60096f0)
    at /home/mlubin/.julia/GLPK/deps/src/glpk-4.52/src/glpenv07.c:580
#8  _glp_lib_xfgetc (fp=<optimized out>)
    at /home/mlubin/.julia/GLPK/deps/src/glpk-4.52/src/glpenv07.c:214
#9  0x00007fffecda265f in read_char (csa=csa@entry=0x7fffffffd260)
    at /home/mlubin/.julia/GLPK/deps/src/glpk-4.52/src/glpmps.c:167
#10 0x00007fffecda2f43 in indicator (csa=0x7fffffffd260, name=1)
    at /home/mlubin/.julia/GLPK/deps/src/glpk-4.52/src/glpmps.c:214
#11 0x00007fffecda33ed in read_name (csa=0x7fffffffd260)
    at /home/mlubin/.julia/GLPK/deps/src/glpk-4.52/src/glpmps.c:395
#12 glp_read_mps (P=0x51c11a0, fmt=<optimized out>, parm=0x7fffffffcec0, fname=0x15cef20 "greenbea.gz")
    at /home/mlubin/.julia/GLPK/deps/src/glpk-4.52/src/glpmps.c:925

This used to work at some point a few months ago. If I uncompress the file, it seems to work fine.

`change_rhs_coefficient!` also changes the constraint type

I think this has been one source of the problems I'm having in JuliaOpt/LinQuadOptInterface.jl#37 . For example, try creating a single constraint and then modifying its constraint set:

using GLPK
using MathOptInterface
const MOI = MathOptInterface
using Base.Test
const LQOI = LinQuadOptInterface

# Create a model with one variable and one constraint
model = GLPK.Optimizer()
x = MOI.addvariable!(model)
f =  MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0], [x]), 1.5)
s = MOI.LessThan(2.0)
c = MOI.addconstraint!(model, f, s)

println("before:")
@show GLPK.get_row_type(model.inner, model[c]) 
@show GLPK.get_row_lb(model.inner, model[c]) 
@show GLPK.get_row_ub(model.inner, model[c])

# Replace the constraint set
MOI.set!(model, MOI.ConstraintSet(), c, MOI.LessThan(1.0))

println("after:")
@show GLPK.get_row_type(model.inner, model[c]) 
@show GLPK.get_row_lb(model.inner, model[c]) 
@show GLPK.get_row_ub(model.inner, model[c])

This gives:

before:
GLPK.get_row_type(model.inner, model[c]) = 3
GLPK.get_row_lb(model.inner, model[c]) = -1.7976931348623157e308
GLPK.get_row_ub(model.inner, model[c]) = 0.5
after:
GLPK.get_row_type(model.inner, model[c]) = 5
GLPK.get_row_lb(model.inner, model[c]) = -0.5
GLPK.get_row_ub(model.inner, model[c]) = -0.5

after changing the RHS, the constraint has changed from type 3 (less-than) to type 5 (fixed) and the lower bound has been incorrectly modified.

I think the problem is here: https://github.com/JuliaOpt/GLPK.jl/blob/81f93202231e63d55a5b3c7ee401e87d19e15a1b/src/MOIWrapper.jl#L333

GLPK returns min double, not -Inf for unbounded variables (https://kam.mff.cuni.cz/~elias/glpk.pdf page 36), so those checks are incorrect. The result is that every one-sided constraint becomes a fixed range constraint as soon as it's touched.

Segfaults on 0.4?

Looks like this happened on PkgEvaluator, it doesn't happen every time for me and might be a base Julia gc issue, not sure.

tkelman@ygdesk:~/Julia/julia$ gdb --args usr/bin/julia-debug --check-bounds=yes -e 'include(Pkg.dir("GLPK","test","runtests.jl"))'
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from usr/bin/julia-debug...done.
(gdb) r
Starting program: /home/tkelman/Julia/julia/usr/bin/julia-debug --check-bounds=yes -e include\(Pkg.dir\(\"GLPK\",\"test\",\"runtests.jl\"\)\)
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffdf05d7700 (LWP 29398)]
Running glpk_tst_1.jl
WARNING: dlopen_e is deprecated, use Libdl.dlopen_e instead.
 in depwarn at ./deprecated.jl:40
 in dlopen_e at deprecated.jl:10
 in anonymous at /home/tkelman/.julia/v0.4/GLPK/src/../deps/deps.jl:7
 in include at ./boot.jl:250
 in include_from_node1 at ./loading.jl:129
 in include at ./boot.jl:250
 in include_from_node1 at ./loading.jl:129
 in reload_path at ./loading.jl:153
 in _require at ./loading.jl:68
 in require at ./loading.jl:51
 in include at ./boot.jl:250
 in include_from_node1 at ./loading.jl:129
 in anonymous at no file:19
 in include at ./boot.jl:250
 in include_from_node1 at ./loading.jl:129
 in process_options at ./client.jl:291
 in _start at ./client.jl:401
WARNING: parseint(s) is deprecated, use parse(Int,s) instead.
 in depwarn at ./deprecated.jl:40
 in parseint at deprecated.jl:29
 in anonymous at /home/tkelman/.julia/v0.4/GLPK/src/GLPK.jl:236
 in map at ./abstractarray.jl:1317
 in version at /home/tkelman/.julia/v0.4/GLPK/src/GLPK.jl:236
 in include at ./boot.jl:250
 in include_from_node1 at ./loading.jl:129
 in reload_path at ./loading.jl:153
 in _require at ./loading.jl:68
 in require at ./loading.jl:51
 in include at ./boot.jl:250
 in include_from_node1 at ./loading.jl:129
 in anonymous at no file:19
 in include at ./boot.jl:250
 in include_from_node1 at ./loading.jl:129
 in process_options at ./client.jl:291
 in _start at ./client.jl:401

WARNING: deprecated syntax "(Uint=>Bool)[]" at /home/tkelman/.julia/v0.4/GLPK/src/GLPK_checks.jl:19.
Use "Dict{Uint,Bool}()" instead.
Running glpk_tst_2.jl
Running glpk_tst_3.jl
Running glpk_tst_4.jl
WARNING: int(x) is deprecated, use Int(x) instead.
 in depwarn at ./deprecated.jl:40
 in int at deprecated.jl:29
 in glpk_tst_4 at /home/tkelman/.julia/v0.4/GLPK/test/glpk_tst_4.jl:62
 in include at ./boot.jl:250
 in include_from_node1 at ./loading.jl:129
 in anonymous at no file:19
 in include at ./boot.jl:250
 in include_from_node1 at ./loading.jl:129
 in process_options at ./client.jl:291
 in _start at ./client.jl:401

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6e7b189 in push_root (v=0x7fffffffb4d0, d=2, bits=3) at gc.c:1583
1583            int nf = (int)jl_tuple_len(dt->names);
(gdb) bt
#0  0x00007ffff6e7b189 in push_root (v=0x7fffffffb4d0, d=2, bits=3) at gc.c:1583
#1  0x00007ffff6e7a553 in gc_push_root (v=0x7fffffffb4d0, d=1) at gc.c:1319
#2  0x00007ffff6e7a67c in gc_mark_stack (ta=0x7ffdf3140010, s=0x7fffffffb450, offset=0, d=1)
    at gc.c:1349
#3  0x00007ffff6e7a94d in gc_mark_task_stack (ta=0x7ffdf3140010, d=1) at gc.c:1410
#4  0x00007ffff6e7aabf in gc_mark_task (ta=0x7ffdf3140010, d=1) at gc.c:1440
#5  0x00007ffff6e7b0cf in push_root (v=0x7ffdf3140010, d=1, bits=1) at gc.c:1560
#6  0x00007ffff6e7be18 in jl_gc_collect (full=0) at gc.c:2036
#7  0x00007ffff6e79419 in __pool_alloc (p=0x7ffff7daf370 <norm_pools+144>, osize=32,
    end_offset=16352) at gc.c:927
#8  0x00007ffff6e79652 in _pool_alloc (p=0x7ffff7daf370 <norm_pools+144>, osize=32) at gc.c:974
#9  0x00007ffff6e7c634 in alloc_2w () at gc.c:2280
#10 0x00007ffff6e56052 in newobj (type=0x7ffdf3100010, nfields=2) at julia_internal.h:18
#11 0x00007ffff6e576b1 in jl_alloc_tuple_uninit (n=1) at alloc.c:389
#12 0x00007ffff6e57715 in jl_alloc_tuple (n=1) at alloc.c:398
#13 0x00007ffff6ddd48c in jl_cfunction_object (f=0x7ffdf5121708, rt=0x7ffdf30fc240,
    argt=0x7ffdf54226d0) at codegen.cpp:801
#14 0x00007ffff6ddd80c in jl_function_ptr (f=0x7ffdf5121708, rt=0x7ffdf30fc240,
    argt=0x7ffdf54226d0) at codegen.cpp:860
#15 0x00007ffff7ed1393 in ?? ()
#16 0xb67b215477b7c900 in ?? ()
#17 0x0000000000000002 in ?? ()
#18 0x00007fffffffb548 in ?? ()
#19 0x00007ffdf54226d0 in ?? ()
#20 0xb67b215477b7c900 in ?? ()
#21 0x0000000000000288 in ?? ()
#22 0x00007ffff7e74450 in ?? ()
#23 0x00007ffdf5b84dc0 in ?? ()
#24 0x00007fffffffb5a0 in ?? ()
#25 0x00007ffff7ed5947 in ?? ()
#26 0x00007fffffffbaf8 in ?? ()
#27 0x00007ffdf5b84dc0 in ?? ()
#28 0x000000000000024a in ?? ()
#29 0x0000000000000006 in ?? ()
#30 0x00007fffffffb9f8 in ?? ()
#31 0x0000000000000000 in ?? ()
(gdb) q
A debugging session is active.

        Inferior 1 [process 29394] will be killed.

Quit anyway? (y or n) y
tkelman@ygdesk:~/Julia/julia$ ./julia -e 'versioninfo()'
Julia Version 0.4.0-dev+4128
Commit 9b0d15b* (2015-04-01 21:47 UTC)
DEBUG build
Platform Info:
  System: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM)2 Duo CPU     E8400  @ 3.00GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT NO_AFFINITY PENRYN)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

MOI wrapper: problems with updating constraint functions

On latest master of MOI, LQOI, and GLPK, there seem to be a few problems with the MIP solver related to updating constraints. In both of these examples, the problem is:

minimize x
s.t. x >= 0.5
     x integer

Wrong answer after updating a scalar affine constraint function

using GLPK
using MathOptInterface
using Compat.Test
const MOI = MathOptInterface

optimizer = GLPKOptimizerMIP()
x = MOI.addvariable!(optimizer)
MOI.addconstraint!(optimizer, MOI.SingleVariable(x), MOI.Integer())
f = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0)
ci = MOI.addconstraint!(optimizer, f, MOI.GreaterThan(0.5))
MOI.set!(optimizer, MOI.ObjectiveSense(), MOI.MinSense)
MOI.set!(optimizer, MOI.ObjectiveFunction{MOI.SingleVariable}(), MOI.SingleVariable(x))

# `optimize!`ing at this point is fine, but if I add:
MOI.set!(optimizer, MOI.ConstraintFunction(), ci, f)

# the following test fails (instead, the variable primal is 0.0):
MOI.optimize!(optimizer)
@test MOI.get(optimizer, MOI.VariablePrimal(), x) == 1.0

Error after updating a vector affine constraint function

Pretty similar:

using GLPK
using MathOptInterface
using Compat.Test
const MOI = MathOptInterface

optimizer = GLPKOptimizerMIP()
x = MOI.addvariable!(optimizer)
MOI.addconstraint!(optimizer, MOI.SingleVariable(x), MOI.Integer())
f = MOI.VectorAffineFunction([MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(1.0, x))], [-0.5])
ci = MOI.addconstraint!(optimizer, f, MOI.Nonnegatives(1))
MOI.set!(optimizer, MOI.ObjectiveSense(), MOI.MinSense)
MOI.set!(optimizer, MOI.ObjectiveFunction{MOI.SingleVariable}(), MOI.SingleVariable(x))

# `optimize!`ing at this point is fine, but if I add:
MOI.set!(optimizer, MOI.ConstraintFunction(), ci, f)

# the following test fails (instead, the termination status is 18, OtherError):
MOI.optimize!(optimizer)
@test MOI.get(optimizer, MOI.TerminationStatus()) == MOI.Success

cc: @rdeits

Error with ScalarAffineFunction-in-Interval constraint with equal bounds

Hello,
As a follow-up of this JuMP discussion, I'm reporting a corner case issue with ScalarAffineFunction-in-Interval constraints, when the lower and upper bounds are equal. Here is a MWE:

using JuMP
using GLPK

model = Model(with_optimizer(GLPK.Optimizer))

@variable(model, x[1:2])
xmax = [10., 0.]
@constraint(model, 0. .<= x .<= xmax)

This is the output of the @constraint macro, with the two ScalarAffineFunction-in-Interval constraints:

2-element Array{ConstraintRef{Model,MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.Interval{Float64}},ScalarShape},1}:
 x[1] ∈ [0.0, 10.0]
 x[2] ∈ [0.0, 0.0] 

Now, when solving the model,

@objective(model, Min, 0)
optimize!(model)

a GLPK error message is displayed (by the way, I'm not sure an actual Error is raised):

glp_simplex: row 2: lb = 0, ub = 0; incorrect bounds

As mentioned by @odow in the discussion, there are workarounds (e.g.: splitting the interval constraint into two, or setting the bounds inside @variable), but if it were possible to have GLPK support this syntax like other solvers do (e.g. Clp), it would be nice.

Notice that there is a possibly related discussion on GLPK mailing-list “Can we set a row with equal upper and lower bound?”.

[PkgEval] GLPK may have a testing issue on Julia 0.4 (2014-09-26)

PackageEvaluator.jl is a script that runs nightly. It attempts to load all Julia packages and run their tests (if available) on both the stable version of Julia (0.3) and the nightly build of the unstable version (0.4). The results of this script are used to generate a package listing enhanced with testing results.

On Julia 0.4

  • On 2014-09-25 the testing status was Tests pass.
  • On 2014-09-26 the testing status changed to Package doesn't load.

Tests pass. means that PackageEvaluator found the tests for your package, executed them, and they all passed.

Package doesn't load. means that PackageEvaluator did not find tests for your package. Additionally, trying to load your package with using failed.

This issue was filed because your testing status became worse. No additional issues will be filed if your package remains in this state, and no issue will be filed if it improves. If you'd like to opt-out of these status-change messages, reply to this message saying you'd like to and @IainNZ will add an exception. If you'd like to discuss PackageEvaluator.jl please file an issue at the repository. For example, your package may be untestable on the test machine due to a dependency - an exception can be added.

Test log:

>>> 'Pkg.add("GLPK")' log
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
  0 2744k    0  4080    0     0   2557      0  0:18:18  0:00:01  0:18:17  2556
100 2744k  100 2744k    0     0  1204k      0  0:00:02  0:00:02 --:--:-- 1204k
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking build system type... x86_64-unknown-linux-gnu
... truncated ...
make[2]: Entering directory '/home/idunning/pkgtest/.julia/v0.4/GLPK/deps/builds/libglpk/examples'
make[2]: Nothing to be done for 'install-data-am'.
 /usr/bin/mkdir -p '/home/idunning/pkgtest/.julia/v0.4/GLPK/deps/usr/bin'
  /bin/sh ../libtool   --mode=install /usr/bin/install -c glpsol '/home/idunning/pkgtest/.julia/v0.4/GLPK/deps/usr/bin'
libtool: install: /usr/bin/install -c .libs/glpsol /home/idunning/pkgtest/.julia/v0.4/GLPK/deps/usr/bin/glpsol
make[2]: Leaving directory '/home/idunning/pkgtest/.julia/v0.4/GLPK/deps/builds/libglpk/examples'
make[1]: Leaving directory '/home/idunning/pkgtest/.julia/v0.4/GLPK/deps/builds/libglpk/examples'
make[1]: Entering directory '/home/idunning/pkgtest/.julia/v0.4/GLPK/deps/builds/libglpk'
make[2]: Entering directory '/home/idunning/pkgtest/.julia/v0.4/GLPK/deps/builds/libglpk'
make[2]: Nothing to be done for 'install-exec-am'.
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/home/idunning/pkgtest/.julia/v0.4/GLPK/deps/builds/libglpk'
make[1]: Leaving directory '/home/idunning/pkgtest/.julia/v0.4/GLPK/deps/builds/libglpk'
INFO: Installing BinDeps v0.3.5
INFO: Installing GLPK v0.2.11
INFO: Installing SHA v0.0.3
INFO: Installing URIParser v0.0.3
INFO: Building GLPK
INFO: Attempting to Create directory /home/idunning/pkgtest/.julia/v0.4/GLPK/deps/downloads
INFO: Downloading file http://ftp.gnu.org/gnu/glpk/glpk-4.52.tar.gz
INFO: Done downloading file http://ftp.gnu.org/gnu/glpk/glpk-4.52.tar.gz
INFO: Attempting to Create directory /home/idunning/pkgtest/.julia/v0.4/GLPK/deps/src
INFO: Attempting to Create directory /home/idunning/pkgtest/.julia/v0.4/GLPK/deps
INFO: Directory /home/idunning/pkgtest/.julia/v0.4/GLPK/deps already created
INFO: Attempting to Create directory /home/idunning/pkgtest/.julia/v0.4/GLPK/deps/src/glpk-4.52
INFO: Attempting to Create directory /home/idunning/pkgtest/.julia/v0.4/GLPK/deps/builds/libglpk
INFO: Changing Directory to /home/idunning/pkgtest/.julia/v0.4/GLPK/deps/builds/libglpk
INFO: Changing Directory to /home/idunning/pkgtest/.julia/v0.4/GLPK/deps/builds/libglpk
INFO: Changing Directory to /home/idunning/pkgtest/.julia/v0.4/GLPK/deps/builds/libglpk
INFO: Package database updated

>>> 'using GLPK' log
Julia Version 0.4.0-dev+789
Commit 98c32a3 (2014-09-26 06:09 UTC)
Platform Info:
  System: Linux (x86_64-unknown-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2650 0 @ 2.00GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

ERROR: cfunction: _err_hook does not return
 in version at /home/idunning/pkgtest/.julia/v0.4/GLPK/src/GLPK.jl:221
 in include at ./boot.jl:245
 in include_from_node1 at ./loading.jl:128
 in reload_path at loading.jl:152
 in _require at loading.jl:67
 in require at loading.jl:51
 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
 in _start_3B_3605 at /home/idunning/julia04/usr/bin/../lib/julia/sys.so
while loading /home/idunning/pkgtest/.julia/v0.4/GLPK/src/GLPK.jl, in expression starting on line 254
while loading /home/idunning/pkgtest/.julia/v0.4/GLPK/testusing.jl, in expression starting on line 2

>>> test log
no tests to run
>>> end of log

Shoudn't it be Optimizer <: MOI.AbstractOptimizer ?

Right now in GLPK, the Optimizer is under MOI.ModelLike, shouldn't it be under MOI.AbstractOptimizer?

Because I cannot do that

using Clp, GLPK, CSDP, MathOptInterface
const MOIU = MathOptInterface.Utilities

MOIU.CachingOptimizer(MOIU.Model{Float64}(), GLPK.Optimizer()) # error

MOIU.CachingOptimizer(MOIU.Model{Float64}(), Clp.Optimizer()) # ok
MOIU.CachingOptimizer(MOIU.Model{Float64}(), CSDP.Optimizer()) # ok

Bounds in Binary Variables

The following model

using JuMP; using GLPK
m = Model()
@variable(m, x, binary=true, lower_bound=0, upper_bound=1)
optimize!(m, with_optimizer(GLPK.Optimizer))

results in,

ERROR: LoadError: Cannot set bounds because variable is of type: BINARY.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] add_constraints(::GLPK.Optimizer, ::Array{MathOptInterface.SingleVariable,1}, ::Array{MathOptInterface.GreaterThan{Float64},1}) at /.julia/packages/LinQuadOptInterface/ZMx9f/src/constraints/singlevariable.jl:128
 [3] add_constraints(::MathOptInterface.Bridges.LazyBridgeOptimizer{GLPK.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Bridges.AllBridgedConstraints{Float64}}}, ::Array{MathOptInterface.SingleVariable,1}, ::Array{MathOptInterface.GreaterThan{Float64},1}) at /.julia/packages/MathOptInterface/C3lip/src/Bridges/bridgeoptimizer.jl:342
...

Both CBC and Gurobi have no issue with this case. You might want to support it for consistency.

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.