Skip to content
Browse files

Removed glpk and linprog

  • Loading branch information...
1 parent 6fef8b2 commit 33dfff5b2a6383f992bcf277826bf79fe4cb35aa @carlobaldassi carlobaldassi committed
Showing with 6 additions and 3,353 deletions.
  1. +0 −1 LICENSE.md
  2. +3 −74 deps/Makefile
  3. +0 −2 extras/.gitignore
  4. +2 −15 extras/Makefile
  5. +0 −2,552 extras/glpk.jl
  6. +0 −554 extras/linprog.jl
  7. +1 −1 test/Makefile
  8. +0 −2 test/extra.jl
  9. +0 −55 test/glpk.jl
  10. +0 −97 test/linprog.jl
View
1 LICENSE.md
@@ -54,7 +54,6 @@ External libraries, if used, include their own licenses:
- [FADDEEVA](http://ab-initio.mit.edu/Faddeeva)
- [FEMTOLISP](https://github.com/JeffBezanson/femtolisp)
- [FFTW](http://fftw.org/doc/License-and-Copyright.html)
-- [GLPK](http://www.gnu.org/software/glpk)
- [GMP](http://gmplib.org/manual/Copying.html#Copying)
- [LAPACK](http://netlib.org/lapack/LICENSE.txt)
- [LIBUNWIND](http://git.savannah.gnu.org/gitweb/?p=libunwind.git;a=blob_plain;f=LICENSE;hb=master)
View
77 deps/Makefile
@@ -18,7 +18,7 @@ CONFIG_GUESS := $(shell ./config.guess)
CONFIGURE_COMMON += --host=$(XC_HOST) --build=$(CONFIG_GUESS)
endif
-#autoconf configure-driven scripts: llvm readline pcre arpack fftw unwind gmp glpk patchelf
+#autoconf configure-driven scripts: llvm readline pcre arpack fftw unwind gmp patchelf
#custom configure-driven script: zlib nginx
#custom Makefile rules: openlibm Rmath double-conversion random gmp-wrapper suitesparse-wrapper suitesparse lapack openblas uv tk-wrapper
@@ -27,7 +27,7 @@ unexport CONFIG_SITE
STAGE1_DEPS = uv openlibm-extras random Rmath double-conversion
STAGE2_DEPS = gmp-wrapper
-STAGE3_DEPS = glpk-wrapper suitesparse-wrapper
+STAGE3_DEPS = suitesparse-wrapper
ifeq ($(USE_SYSTEM_LIBUNWIND), 0)
ifeq ($(OS), Linux)
@@ -78,10 +78,6 @@ ifeq ($(USE_SYSTEM_GMP), 0)
STAGE1_DEPS += gmp
endif
-ifeq ($(USE_SYSTEM_GLPK), 0)
-STAGE1_DEPS += glpk
-endif
-
ifeq ($(USE_SYSTEM_ZLIB), 0)
STAGE1_DEPS += zlib
endif
@@ -118,7 +114,7 @@ install: $(addprefix install-, $(LIBS))
cleanall: $(addprefix clean-, $(LIBS))
distclean: $(addprefix distclean-, $(LIBS))
rm -rf $(BUILD)
-getall: get-llvm get-readline get-uv get-pcre get-double-conversion get-openlibm get-random get-openblas get-fftw get-suitesparse get-clp get-unwind get-nginx get-gmp get-glpk get-zlib get-patchelf
+getall: get-llvm get-readline get-uv get-pcre get-double-conversion get-openlibm get-random get-openblas get-fftw get-suitesparse get-clp get-unwind get-nginx get-gmp get-zlib get-patchelf
## PATHS ##
DIRS = $(addprefix $(BUILD)/,lib include bin share etc)
@@ -1235,73 +1231,6 @@ check-gmp-wrapper:
install-gmp-wrapper: $(BUILD)/lib/libgmp_wrapper.$(SHLIB_EXT)
-## GLPK ##
-
-GLPK_SRC_TARGET = glpk-$(GLPK_VER)/src/.libs/libglpk.$(SHLIB_EXT)
-GLPK_OBJ_TARGET = $(BUILD)/lib/libglpk.$(SHLIB_EXT)
-
-glpk-$(GLPK_VER).tar.gz:
- $(WGET) http://ftp.gnu.org/gnu/glpk/$@
-glpk-$(GLPK_VER)/configure: glpk-$(GLPK_VER).tar.gz
- tar zxf $<
- touch -c $@
-glpk-$(GLPK_VER)/config.status: glpk-$(GLPK_VER)/configure
- cd glpk-$(GLPK_VER) && \
- ./configure $(CONFIGURE_COMMON)
- touch -c $@
-$(GLPK_SRC_TARGET): glpk-$(GLPK_VER)/config.status
- $(MAKE) -C glpk-$(GLPK_VER) $(LIBTOOL_CCLD)
- touch -c $@
-glpk-$(GLPK_VER)/checked: $(GLPK_SRC_TARGET)
-ifeq ($(OS),$(BUILD_OS))
- $(MAKE) -C glpk-$(GLPK_VER) $(LIBTOOL_CCLD) check
-endif
- echo 1 > $@
-$(GLPK_OBJ_TARGET): $(GLPK_SRC_TARGET) glpk-$(GLPK_VER)/checked
- $(MAKE) -C glpk-$(GLPK_VER) $(LIBTOOL_CCLD) install
- $(INSTALL_NAME_CMD)libglpk.dylib $@
- $(AUTOTOOLS_PATH_CORRECT)
- touch -c $@
-
-clean-glpk:
- -$(MAKE) -C glpk-$(GLPK_VER) uninstall || true
- -$(MAKE) -C glpk-$(GLPK_VER) clean
-distclean-glpk: clean-glpk
- -rm -rf glpk-$(GLPK_VER).tar.gz glpk-$(GLPK_VER)
-
-get-glpk: glpk-$(GLPK_VER).tar.gz
-configure-glpk: glpk-$(GLPK_VER)/config.status
-compile-glpk: $(GLPK_SRC_TARGET)
-check-glpk: glpk-$(GLPK_VER)/checked
-install-glpk: $(GLPK_OBJ_TARGET) $(BUILD)/lib/libglpk_wrapper.$(SHLIB_EXT)
-
-## GLPK Wrapper
-
-ifeq ($(USE_SYSTEM_GLPK), 1)
-GLPKW_INC = -I /usr/include/
-GLPKW_LIB = -lglpk
-else
-GLPKW_INC = -I $(BUILD)/include
-GLPKW_LIB = -L$(BUILD)/lib -lglpk
-$(BUILD)/lib/libglpk_wrapper.$(SHLIB_EXT): $(GLPK_OBJ_TARGET)
-endif
-
-$(BUILD)/lib/libglpk_wrapper.$(SHLIB_EXT): glpk_wrapper.c
- $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -O2 -shared $(fPIC) $(GLPKW_INC) glpk_wrapper.c $(GLPKW_LIB) -o $(BUILD)/lib/libglpk_wrapper.$(SHLIB_EXT) $(RPATH_ORIGIN)
- $(INSTALL_NAME_CMD)libglpk_wrapper.$(SHLIB_EXT) $@
- touch -c $@
-
-clean-glpk-wrapper:
- -rm -f $(GLPK_OBJ_TARGET) $(BUILD)/lib/libglpk_wrapper.$(SHLIB_EXT)
-distclean-glpk-wrapper: clean-glpk-wrapper
-
-get-glpk-wrapper:
-configure-glpk-wrapper:
-compile-glpk-wrapper:
-check-glpk-wrapper:
-install-glpk-wrapper: $(BUILD)/lib/libglpk_wrapper.$(SHLIB_EXT)
-
-
## ZLIB ##
ifeq ($(OS),WINNT)
View
2 extras/.gitignore
@@ -1,3 +1 @@
-/glpk-*
-/glpk_h.jl
/webrepl_msgtypes_h.jl
View
17 extras/Makefile
@@ -1,23 +1,10 @@
JULIAHOME = $(abspath ..)
include $(JULIAHOME)/Make.inc
-all: glpk_h.jl webrepl_msgtypes_h.jl
-
-GLPK_VER = 4.47
-
-GLPK_CONST = 0x[0-9a-fA-F]+|[-+]?\s*[0-9]+
-
-ifeq ($(USE_SYSTEM_GLPK), 1)
-GLPK_PREFIX = /usr/include
-else
-GLPK_PREFIX = $(JULIAHOME)/deps/glpk-$(GLPK_VER)/src
-endif
-
-glpk_h.jl:
- $(QUIET_PERL) $(CC) -E -dM $(GLPK_PREFIX)/glpk.h | perl -nle '/^\s*#define\s+GLP_(\w*)\s*\(?($(GLPK_CONST))\)?\s*$$/ and print "const $$1 = int32($$2)"' | sort > $@
+all: webrepl_msgtypes_h.jl
webrepl_msgtypes_h.jl: ../ui/webserver/message_types.h
$(QUIET_PERL) $(CC) -E -Dnotdefined $^ > $@
clean:
- rm -f glpk_h.jl webrepl_msgtypes_h.jl
+ rm -f webrepl_msgtypes_h.jl
View
2,552 extras/glpk.jl
0 additions, 2,552 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
554 extras/linprog.jl
@@ -1,554 +0,0 @@
-##
-## Linear Programming and Mixed Integer Programming interfaces
-## for optimization and constraint satisfaction problems
-##
-
-require("glpk")
-
-module LinProgGLPK
-
-import GLPK
-
-export
- linprog,
- linprog_interior,
- linprog_simplex,
- linprog_exact,
- mixintprog,
- print_linprog_flag
-
-typealias VecOrNothing GLPK.VecOrNothing
-
-# General notes: the interface is provided as a collection of
-# high-level functions which use the glpk library.
-# Most functions have almost same interface
-# as matlab's linprog, e.g.:
-#
-# (z, x, flag) = linprog(f, A, b, Aeq, beq, lb, ub, params)
-#
-# There's a function for each solving method:
-# linprog_interior
-# linprog_simplex
-# linprog_exact
-# mixintprog
-#
-# The function linprog is an alias to linprog_interior
-#
-# These functions all seek to solve the problem
-#
-# z = min_{x} (f' * x)
-#
-# where the vector x is subject to these constraints:
-#
-# A * x <= b
-# Aeq * x == beq
-# lb <= x <= ub
-#
-# The return flag is 0 in case of success, and follows
-# the glpk library convention otherwise. It can be printed as
-# a human-readable error message with the print_linprog_flag()
-# function.
-# In case of failure, z and x are set to nothing, otherwise
-# they will hold the solution found
-#
-# The parameters Aeq, beq, lb, ub and params are optional.
-# This mean they can be either passed as the constant 'nothing'
-# or as an empty vector [] or not provided at all.
-#
-# Some methods have slightly different function calls, see
-# individual notes for additional information
-
-typealias SparseOrFullMat{T} Union(Matrix{T}, SparseMatrixCSC{T})
-typealias MatOrNothing Union(Matrix, SparseMatrixCSC, Vector{None}, Nothing)
-
-# Linear Programming, Interior point method (default)
-#{{{
-
-function linprog_interior{T<:Real,P<:Union(GLPK.InteriorParam,Nothing)}(f::Vector{T}, A::SparseOrFullMat{T}, b::Vector{T},
- Aeq::SparseOrFullMat{T}, beq::Vector{T}, lb::Vector{T}, ub::Vector{T}, params::P)
-
- lp, n = linprog__setup_prob(f, A, b, Aeq, beq, lb, ub, params)
-
- ret = GLPK.interior(lp, params)
- #println("ret=$ret")
-
- if ret == 0
- z = GLPK.ipt_obj_val(lp)
- x = zeros(Float64, n)
- for c = 1 : n
- x[c] = GLPK.ipt_col_prim(lp, c)
- end
- return (z, x, ret)
- else
- # throw exception here ?
- return (nothing, nothing, ret)
- end
-end
-function linprog_interior{T<:Real,P<:Union(GLPK.InteriorParam,Nothing)}(f::Vector{T}, A::MatOrNothing, b::VecOrNothing,
- Aeq::MatOrNothing, beq::VecOrNothing, lb::VecOrNothing, ub::VecOrNothing, params::P)
-
- cA = linprog__convert_matornothing(T, A)
- cb = linprog__convert_vecornothing(T, b)
- cAeq = linprog__convert_matornothing(T, Aeq)
- cbeq = linprog__convert_vecornothing(T, beq)
- clb = linprog__convert_vecornothing(T, lb)
- cub = linprog__convert_vecornothing(T, ub)
- return linprog_interior(f, cA, cb, cAeq, cbeq, clb, cub, params)
-
-end
-
-linprog_interior{T<:Real}(f::Vector{T}, A::MatOrNothing, b::VecOrNothing) =
- linprog_interior(f, A, b, nothing, nothing, nothing, nothing, nothing)
-
-linprog_interior{T<:Real}(f::Vector{T}, A::MatOrNothing, b::VecOrNothing,
- Aeq::MatOrNothing, beq::VecOrNothing) =
- linprog_interior(f, A, b, Aeq, beq, nothing, nothing, nothing)
-
-linprog_interior{T<:Real}(f::Vector{T}, A::MatOrNothing, b::VecOrNothing,
- Aeq::MatOrNothing, beq::VecOrNothing, lb::VecOrNothing,
- ub::VecOrNothing) =
- linprog_interior(f, A, b, Aeq, beq, lb, ub, nothing)
-
-linprog = linprog_interior
-#}}}
-
-# Linear Programming, Simplex Method
-#{{{
-function linprog_simplex{T<:Real,P<:Union(GLPK.SimplexParam,Nothing)}(f::Vector{T}, A::SparseOrFullMat{T}, b::Vector{T},
- Aeq::SparseOrFullMat{T}, beq::Vector{T}, lb::Vector{T}, ub::Vector{T}, params::P)
-
- lp, n = linprog__setup_prob(f, A, b, Aeq, beq, lb, ub, params)
-
- ret = GLPK.simplex(lp, params)
- #println("ret=$ret")
-
- if ret == 0
- z = GLPK.get_obj_val(lp)
- x = zeros(Float64, n)
- for c = 1 : n
- x[c] = GLPK.get_col_prim(lp, c)
- end
- return (z, x, ret)
- else
- # throw exception here ?
- return (nothing, nothing, ret)
- end
-end
-function linprog_simplex{T<:Real,P<:Union(GLPK.SimplexParam,Nothing)}(f::Vector{T}, A::MatOrNothing, b::VecOrNothing,
- Aeq::MatOrNothing, beq::VecOrNothing, lb::VecOrNothing, ub::VecOrNothing, params::P)
-
- cA = linprog__convert_matornothing(T, A)
- cb = linprog__convert_vecornothing(T, b)
- cAeq = linprog__convert_matornothing(T, Aeq)
- cbeq = linprog__convert_vecornothing(T, beq)
- clb = linprog__convert_vecornothing(T, lb)
- cub = linprog__convert_vecornothing(T, ub)
- return linprog_simplex(f, cA, cb, cAeq, cbeq, clb, cub, params)
-
-end
-
-linprog_simplex{T<:Real}(f::Vector{T}, A::MatOrNothing, b::VecOrNothing) =
- linprog_simplex(f, A, b, nothing, nothing, nothing, nothing, nothing)
-
-linprog_simplex{T<:Real}(f::Vector{T}, A::MatOrNothing, b::VecOrNothing,
- Aeq::MatOrNothing, beq::VecOrNothing) =
- linprog_simplex(f, A, b, Aeq, beq, nothing, nothing, nothing)
-
-linprog_simplex{T<:Real}(f::Vector{T}, A::MatOrNothing, b::VecOrNothing,
- Aeq::MatOrNothing, beq::VecOrNothing, lb::VecOrNothing,
- ub::VecOrNothing) =
- linprog_simplex(f, A, b, Aeq, beq, lb, ub, nothing)
-#}}}
-
-# Linear Programming, Simplex-exact Method
-#{{{
-
-# Notes:
-# * uses GLPK.simplex as a preliminary step
-# * the exact step only accepts the "it_lim" and "tm_lim" options,
-# which means no message suppression is possible
-
-function linprog_exact{T<:Real,P<:Union(GLPK.SimplexParam,Nothing)}(f::Vector{T}, A::SparseOrFullMat{T}, b::Vector{T},
- Aeq::SparseOrFullMat{T}, beq::Vector{T}, lb::Vector{T}, ub::Vector{T}, params::P)
-
- lp, n = linprog__setup_prob(f, A, b, Aeq, beq, lb, ub, params)
-
- ret = GLPK.simplex(lp, params)
- if ret != 0
- # throw exception here ?
- return (nothing, nothing, ret)
- end
-
- ret = GLPK.exact(lp, params)
- if ret == 0
- z = GLPK.get_obj_val(lp)
- x = zeros(Float64, n)
- for c = 1 : n
- x[c] = GLPK.get_col_prim(lp, c)
- end
- return (z, x, ret)
- else
- # throw exception here ?
- return (nothing, nothing, ret)
- end
-end
-function linprog_exact{T<:Real,P<:Union(GLPK.SimplexParam,Nothing)}(f::Vector{T}, A::MatOrNothing, b::VecOrNothing,
- Aeq::MatOrNothing, beq::VecOrNothing, lb::VecOrNothing, ub::VecOrNothing, params::P)
-
- cA = linprog__convert_matornothing(T, A)
- cb = linprog__convert_vecornothing(T, b)
- cAeq = linprog__convert_matornothing(T, Aeq)
- cbeq = linprog__convert_vecornothing(T, beq)
- clb = linprog__convert_vecornothing(T, lb)
- cub = linprog__convert_vecornothing(T, ub)
- return linprog_exact(f, cA, cb, cAeq, cbeq, clb, cub, params)
-
-end
-
-linprog_exact{T<:Real}(f::Vector{T}, A::MatOrNothing, b::VecOrNothing) =
- linprog_exact(f, A, b, nothing, nothing, nothing, nothing, nothing)
-
-linprog_exact{T<:Real}(f::Vector{T}, A::MatOrNothing, b::VecOrNothing,
- Aeq::MatOrNothing, beq::VecOrNothing) =
- linprog_exact(f, A, b, Aeq, beq, nothing, nothing, nothing)
-
-linprog_exact{T<:Real}(f::Vector{T}, A::MatOrNothing, b::VecOrNothing,
- Aeq::MatOrNothing, beq::VecOrNothing, lb::VecOrNothing,
- ub::VecOrNothing) =
- linprog_exact(f, A, b, Aeq, beq, lb, ub, nothing)
-#}}}
-
-# Mixed Integer Programming
-#{{{
-
-# Notes:
-# * same syntax as linprog algorithms, with an additional col_kind vector and
-# an additional set of parameters for the presolve step; and an additional
-# return flag for the presolve step:
-#
-# (z, x, flag, ps_flag) = mixintprog(f, A, b, Aeq, beq, lb, ub, col_kind, param, ps_param)
-#
-# * the col_kind vector contains one entry per variable in x, each with value
-# GLPK.CV (continuous variable), GLPK.IV (integer variable), or
-# GLPK.BV (binary variable)
-# * if the col_kind vector is not provided, all variables default to integer
-# * if the "presolve" options is set to GLPK.OFF, then it uses linear programming
-# for presolving, via the simplex point method with parameters ps_param (if ps_param is nothing
-# or not given, uses the defaults)
-
-function mixintprog{T<:Real,Ti<:Integer,P<:Union(GLPK.IntoptParam,Nothing),Px<:Union(GLPK.SimplexParam,Nothing)}(
- f::Vector{T}, A::SparseOrFullMat{T}, b::Vector{T}, Aeq::SparseOrFullMat{T}, beq::Vector{T},
- lb::Vector{T}, ub::Vector{T}, col_kind::Vector{Ti}, params::P, params_presolve::Px)
-
- lp, n = linprog__setup_prob(f, A, b, Aeq, beq, lb, ub, params)
- mixintprog_set_col_kind(lp, n, col_kind)
-
- if params == nothing || pointer(params) == C_NULL || params["presolve"] != GLPK.ON
- ret_ps = GLPK.simplex(lp, params_presolve)
- if ret_ps != 0
- # throw exception here ?
- # XXX GLPK.ESTOP ??
- return (nothing, nothing, GLPK.ESTOP, ret_ps)
- end
- else
- ret_ps = 0
- end
-
- ret = GLPK.intopt(lp, params)
- if ret == 0
- z = GLPK.mip_obj_val(lp)
- x = zeros(Float64, n)
- for c = 1 : n
- x[c] = GLPK.mip_col_val(lp, c)
- end
- return (z, x, ret, ret_ps)
- else
- # throw exception here ?
- return (nothing, nothing, ret, ret_ps)
- end
-end
-function mixintprog{T<:Real,P<:Union(GLPK.IntoptParam,Nothing),Px<:Union(GLPK.SimplexParam,Nothing)}(
- f::Vector{T}, A::MatOrNothing, b::VecOrNothing, Aeq::MatOrNothing, beq::VecOrNothing,
- lb::VecOrNothing, ub::VecOrNothing, col_kind::VecOrNothing, params::P, params_presolve::Px)
-
- cA = linprog__convert_matornothing(T, A)
- cb = linprog__convert_vecornothing(T, b)
- cAeq = linprog__convert_matornothing(T, Aeq)
- cbeq = linprog__convert_vecornothing(T, beq)
- clb = linprog__convert_vecornothing(T, lb)
- cub = linprog__convert_vecornothing(T, ub)
- ccol_kind = linprog__convert_vecornothing(Int32, col_kind)
- return mixintprog(f, cA, cb, cAeq, cbeq, clb, cub, ccol_kind, params, params_presolve)
-
-end
-
-mixintprog{T<:Real}(f::Vector{T}, A::MatOrNothing, b::VecOrNothing) =
- mixintprog(f, A, b, nothing, nothing, nothing, nothing, nothing, nothing, nothing)
-
-mixintprog{T<:Real}(f::Vector{T}, A::MatOrNothing, b::VecOrNothing,
- Aeq::MatOrNothing, beq::VecOrNothing) =
- mixintprog(f, A, b, Aeq, beq, nothing, nothing, nothing, nothing, nothing)
-
-mixintprog{T<:Real}(f::Vector{T}, A::MatOrNothing, b::VecOrNothing,
- Aeq::MatOrNothing, beq::VecOrNothing, lb::VecOrNothing,
- ub::VecOrNothing) =
- mixintprog(f, A, b, Aeq, beq, lb, ub, nothing, nothing, nothing)
-
-mixintprog{T<:Real}(f::Vector{T}, A::MatOrNothing, b::VecOrNothing,
- Aeq::MatOrNothing, beq::VecOrNothing, lb::VecOrNothing,
- ub::VecOrNothing, col_kind::VecOrNothing) =
- mixintprog(f, A, b, Aeq, beq, lb, ub, col_kind, nothing, nothing)
-
-mixintprog{T<:Real,P<:Union(GLPK.IntoptParam,Nothing)}(f::Vector{T}, A::MatOrNothing, b::VecOrNothing,
- Aeq::MatOrNothing, beq::VecOrNothing, lb::VecOrNothing,
- ub::VecOrNothing, col_kind::VecOrNothing, params::P) =
- mixintprog(f, A, b, Aeq, beq, lb, ub, col_kind, params, nothing)
-#}}}
-
-# Output flags readout
-#{{{
-let msg_map = [
- 0 => "success",
- GLPK.EBOUND => "incurrect bounds",
- GLPK.EROOT => "no optimal basis given",
- GLPK.ENOPFS => "no primal fasible LP solution",
- GLPK.ENODFS => "no dual feasible LP solution",
- GLPK.EFAIL => "solver failure",
- GLPK.EMIPGAP => "mixed integer programming tolerance reached",
- GLPK.ETMLIM => "time limit exceeded",
- GLPK.ESTOP => "terminated by application",
- GLPK.ENOCVG => "very slow convergence, or divergence",
- GLPK.ETMLIM => "iterations limit exceeded",
- GLPK.EINSTAB => "numberical instability",
- GLPK.EBADB => "invalid base",
- GLPK.ESING => "singular matrix",
- GLPK.ECOND => "ill-conditioned matrix",
- GLPK.EOBJLL => "lower limit reached",
- GLPK.EOBJUL => "upper limit reached",
- GLPK.EDATA => "invalid data format",
- GLPK.ERANGE => "integer overflow"
- ]
-
- global print_linprog_flag
- function print_linprog_flag(io::IO, flag::Int32)
- if has(msg_map, flag)
- print(io, msg_map[flag])
- else
- error("unknown GLPK flag")
- end
- end
-end
-#}}}
-
-## Common auxiliary functions
-#{{{
-function linprog__convert_vecornothing{T}(::Type{T}, a::VecOrNothing)
- if isequal(a, nothing) || isa(a, Array{None})
- return T[]
- elseif T <: Integer
- if !(eltype(a) <: Integer)
- error("integer-valued array required, or [] or nothing")
- end
- elseif T <: Real
- if !(eltype(a) <: Real)
- error("real-valued array required, or [] or nothing")
- end
- end
- return convert(Array{T}, a)
-end
-function linprog__convert_matornothing{T}(::Type{T}, a::MatOrNothing)
- if isequal(a, nothing) || isa(a, Array{None})
- return Array(T, 0, 0)
- elseif T <: Integer
- if !(eltype(a) <: Integer)
- error("integer-valued array required, or [] or nothing")
- end
- elseif T <: Real
- if !(eltype(a) <: Real)
- error("real-valued array required, or [] or nothing")
- end
- end
- if issparse(a)
- return convert(SparseMatrixCSC{T}, a)
- else
- return convert(Array{T}, a)
- end
-end
-
-function linprog__setup_prob{T<:Real, P<:Union(GLPK.Param, Nothing)}(f::Vector{T}, A::SparseOrFullMat{T}, b::Vector{T},
- Aeq::SparseOrFullMat{T}, beq::Vector{T}, lb::Vector{T}, ub::Vector{T}, params::P)
-
- lp = GLPK.Prob()
- GLPK.set_obj_dir(lp, GLPK.MIN)
-
- n = size(f, 1)
-
- m = linprog__check_A_b(A, b, n)
- meq = linprog__check_A_b(Aeq, beq, n)
-
- has_lb, has_ub = linprog__check_lb_ub(lb, ub, n)
-
- #println("n=$n m=$m meq=$meq has_lb=$has_lb ub=$has_ub")
-
- if m > 0
- GLPK.add_rows(lp, m)
- for r = 1 : m
- #println(" r=$r b=$(b[r])")
- GLPK.set_row_bnds(lp, r, GLPK.UP, 0.0, b[r])
- end
- end
- if meq > 0
- GLPK.add_rows(lp, meq)
- for r = 1 : meq
- r0 = r + m
- #println(" r=$r r0=$r0 beq=$(beq[r])")
- GLPK.set_row_bnds(lp, r0, GLPK.FX, beq[r], beq[r])
- end
- end
-
- GLPK.add_cols(lp, n)
-
- for c = 1 : n
- GLPK.set_obj_coef(lp, c, f[c])
- #println(" c=$c f=$(f[c])")
- end
-
- if has_lb && has_ub
- for c = 1 : n
- #println(" c=$c lb=$(lb[c]) ub=$(ub[c])")
- local bounds_type
- if lb[c] == ub[c]
- bounds_type = GLPK.FX
- else
- if isinf(lb[c])
- if isinf(ub[c])
- bounds_type = GLPK.FR
- else
- bounds_type = GLPK.UP
- end
- else
- if isinf(ub[c])
- bounds_type = GLPK.LO
- else
- bounds_type = GLPK.DB
- end
- end
- end
- GLPK.set_col_bnds(lp, c, bounds_type, lb[c], ub[c])
- end
- elseif has_lb
- for c = 1 : n
- #println(" c=$c lb=$(lb[c])")
- bounds_type = isinf(lb[c]) ? GLPK.FR : GLPK.LO
- GLPK.set_col_bnds(lp, c, bounds_type, lb[c], 0.0)
- end
- elseif has_ub
- for c = 1 : n
- #println(" c=$c ub=$(ub[c])")
- bounds_type = isinf(ub[c]) ? GLPK.FR : GLPK.UP
- GLPK.set_col_bnds(lp, c, bounds_type, 0.0, ub[c])
- end
- end
-
- if (m > 0 && issparse(A)) && (meq > 0 && issparse(Aeq))
- (ia, ja, ar) = findn_nzs([A; Aeq])
- elseif (m > 0 && issparse(A)) && (meq == 0)
- (ia, ja, ar) = findn_nzs(A)
- elseif (m == 0) && (meq > 0 && issparse(Aeq))
- (ia, ja, ar) = findn_nzs(Aeq)
- else
- (ia, ja, ar) = linprog__dense_matrices_to_glpk_format(m, meq, n, A, Aeq)
- end
- #println("ia=$ia")
- #println("ja=$ja")
- #println("ar=$ar")
-
- GLPK.load_matrix(lp, ia, ja, ar)
- return (lp, n)
-end
-
-function linprog__check_A_b{T}(A::SparseOrFullMat{T}, b::Vector{T}, n::Int)
- m = 0
- if !isempty(A)
- if size(A, 2) != n
- error("invlid A size: $(size(A))")
- end
- m = size(A, 1)
- if isempty(b)
- error("b is empty but a is not")
- end
- if size(b, 1) != m
- error("invalid b size: $(size(b))")
- end
- else
- if !isempty(b)
- error("A is empty but b is not")
- end
- end
- return m
-end
-
-function linprog__check_lb_ub{T}(lb::Vector{T}, ub::Vector{T}, n::Int)
- has_lb = false
- has_ub = false
- if !isempty(lb)
- if size(lb, 1) != n
- error("invlid lb size: $(size(lb))")
- end
- has_lb = true
- end
- if !isempty(ub)
- if size(ub, 1) != n
- error("invalid ub size: $(size(ub))")
- end
- has_ub = true
- end
- return (has_lb, has_ub)
-end
-
-function linprog__dense_matrices_to_glpk_format(m, meq, n, A, Aeq)
- l = (m + meq) * n
-
- ia = zeros(Int32, l)
- ja = zeros(Int32, l)
- ar = zeros(Float64, l)
-
- k = 0
- for r = 1 : m
- for c = 1 : n
- k += 1
- ia[k] = r
- ja[k] = c
- ar[k] = A[r, c]
- end
- end
- for r = 1 : meq
- for c = 1 : n
- r0 = r + m
- k += 1
- ia[k] = r0
- ja[k] = c
- ar[k] = Aeq[r, c]
- end
- end
- return (ia, ja, ar)
-end
-
-function mixintprog_set_col_kind{Ti<:Integer}(lp::GLPK.Prob, n::Int, col_kind::Vector{Ti})
- if isempty(col_kind)
- for i = 1 : n
- GLPK.set_col_kind(lp, i, GLPK.IV)
- end
- return
- end
- if length(col_kind) != n
- error("wrong col_kind vector size")
- end
- for i = 1 : n
- GLPK.set_col_kind(lp, i, col_kind[i])
- end
-end
-
-#}}}
-
-end # module
View
2 test/Makefile
@@ -7,7 +7,7 @@ TESTS = default all extra \
core numbers strings unicode corelib hashing remote \
arrayops linalg fft dct sparse bitarray suitesparse arpack \
random math functional bigint bigfloat sorting \
-statistics glpk linprog poly file Rmath remote zlib image \
+statistics poly file Rmath remote zlib image \
iostring gzip integers spawn ccall parallel
$(TESTS) ::
View
2 test/extra.jl
@@ -1,7 +1,5 @@
runtests("suitesparse")
runtests("arpack")
-runtests("glpk")
-runtests("linprog")
runtests("bigfloat")
runtests("poly")
runtests("file")
View
55 test/glpk.jl
@@ -1,55 +0,0 @@
-cd("../extras") do
-require("glpk")
-
-# Same example as in the GLPK manual
-
-lp = GLPK.Prob()
-GLPK.set_prob_name(lp, "sample")
-GLPK.set_obj_dir(lp, GLPK.MAX)
-GLPK.add_rows(lp, 3)
-GLPK.set_row_name(lp, 1, "p")
-GLPK.set_row_bnds(lp, 1, GLPK.UP, 0.0, 100.0)
-GLPK.set_row_name(lp, 2, "q")
-GLPK.set_row_bnds(lp, 2, GLPK.UP, 0.0, 600.0)
-GLPK.set_row_name(lp, 3, "r")
-GLPK.set_row_bnds(lp, 3, GLPK.UP, 0.0, 300.0)
-GLPK.add_cols(lp, 3)
-GLPK.set_col_name(lp, 1, "x1")
-GLPK.set_col_bnds(lp, 1, GLPK.LO, 0.0, 0.0)
-GLPK.set_obj_coef(lp, 1, 10.0)
-GLPK.set_col_name(lp, 2, "x2")
-GLPK.set_col_bnds(lp, 2, GLPK.LO, 0.0, 0.0)
-GLPK.set_obj_coef(lp, 2, 6.0)
-GLPK.set_col_name(lp, 3, "x3")
-GLPK.set_col_bnds(lp, 3, GLPK.LO, 0.0, 0.0)
-GLPK.set_obj_coef(lp, 3, 4.0)
-ia = zeros(Int, 9)
-ja = zeros(Int, 9)
-ar = zeros(FloatingPoint, 9)
-ia[1] = 1; ja[1] = 1; ar[1] = 1.0
-ia[2] = 1; ja[2] = 2; ar[2] = 1.0
-ia[3] = 1; ja[3] = 3; ar[3] = 1.0
-ia[4] = 2; ja[4] = 1; ar[4] = 10.0
-ia[5] = 3; ja[5] = 1; ar[5] = 2.0
-ia[6] = 2; ja[6] = 2; ar[6] = 4.0
-ia[7] = 3; ja[7] = 2; ar[7] = 2.0
-ia[8] = 2; ja[8] = 3; ar[8] = 5.0
-ia[9] = 3; ja[9] = 3; ar[9] = 6.0
-GLPK.load_matrix(lp, 9, ia, ja, ar)
-
-glp_param = GLPK.SimplexParam()
-glp_param["msg_lev"] = GLPK.MSG_ERR
-
-flag = GLPK.simplex(lp, glp_param)
-z = GLPK.get_obj_val(lp)
-x1 = GLPK.get_col_prim(lp, 1)
-x2 = GLPK.get_col_prim(lp, 2)
-x3 = GLPK.get_col_prim(lp, 3)
-
-tol = 1e-10
-@test abs(z - 2200. / 3) < tol
-@test abs(x1 - 100. / 3) < tol
-@test abs(x2 - 200. / 3) < tol
-@test abs(x3) < tol
-
-end # cd
View
97 test/linprog.jl
@@ -1,97 +0,0 @@
-### Linear programming
-
-cd("../extras") # we can't use do-notation because of "using"
-require("linprog")
-
-using LinProgGLPK
-
-## Simplex method
-
-# Set options (disable all output
-# excpept for errors, turn on presolver)
-lps_opts = GLPK.SimplexParam()
-lps_opts["msg_lev"] = GLPK.MSG_ERR
-lps_opts["presolve"] = GLPK.ON
-lps_opts["it_lim"] = 1000
-
-# A small dense optimization problem
-
-f = [ 3.; 2. ];
-A = [ 2. 1. ;
- 1. 1. ];
-b = [ 100.; 80 ];
-lb = [ 0.; 0.];
-
-(z, x, flag) = linprog_simplex(-f, A, b, [], [], lb, [], lps_opts);
-
-@test flag == 0
-@test z == -180.0
-@test isequal(x, [20.; 60.])
-
-
-# A constraint satisfaction (matching) problem
-# passing a sparse representation
-# to linprog_simplex
-
-f = [ 3. 2. 2. ;
- 1. 0. 1. ;
- 3. 3. 5. ];
-f = reshape(f, (9,));
-Aeq = [ 1. 1. 1. 0. 0. 0. 0. 0. 0. ;
- 0. 0. 0. 1. 1. 1. 0. 0. 0. ;
- 0. 0. 0. 0. 0. 0. 1. 1. 1. ;
- 1. 0. 0. 1. 0. 0. 1. 0. 0. ;
- 0. 1. 0. 0. 1. 0. 0. 1. 0. ;
- 0. 0. 1. 0. 0. 1. 0. 0. 1. ];
-Aeq = sparse(Aeq);
-beq = ones(Float64, 6);
-lb = zeros(Float64, 9);
-ub = ones(Float64, 9);
-
-(z, x, flag) = linprog_simplex(f, [], [], Aeq, beq, lb, ub, lps_opts);
-
-@test flag == 0
-@test z == 5.
-@test isequal(x, [ 0.; 0.; 1. ;
- 0.; 1.; 0. ;
- 1.; 0.; 0. ])
-
-
-## Interior point method
-
-# Same problem and options as above
-
-lpi_opts = GLPK.InteriorParam()
-lpi_opts["msg_lev"] = GLPK.MSG_ERR
-
-(z, x, ret) = linprog(f, [], [], Aeq, beq, lb, ub, lpi_opts);
-
-tol = 1e-4
-
-@test flag == 0
-@test abs(z - 5.) < tol
-@test max(abs(x - [ 0.; 0.; 1. ;
- 0.; 1.; 0. ;
- 1.; 0.; 0. ])) < tol
-
-
-### Mixed interger progamming
-
-# Same problem and options as above
-
-mip_opts = GLPK.IntoptParam()
-mip_opts["msg_lev"] = GLPK.MSG_ERR
-mip_opts["presolve"] = GLPK.ON
-
-# Use binary variables
-colkind = int32([ GLPK.BV for i = 1 : 9 ])
-
-(z, x, ret, ret_ps) = mixintprog(f, [], [], Aeq, beq, [], [], colkind, mip_opts);
-
-@test flag == 0
-@test z == 5.
-@test isequal(x, [ 0.; 0.; 1. ;
- 0.; 1.; 0. ;
- 1.; 0.; 0. ])
-
-cd("../test")

0 comments on commit 33dfff5

Please sign in to comment.
Something went wrong with that request. Please try again.