GLPK is a package for solving linear programming and mixed integer programming problems.
The Chicken GLPK egg provides a Scheme interface to a large subset of the GLPK procedures for problem setup and solving. Below is a list of procedures that are included in this egg, along with brief descriptions. This egg has been tested with GLPK version 4.28.
This procedure creates a new problem that has no rows or columns.
This procedure creates a new problem with the specified parameters.
'(unbounded) | Free (unbounded) variable, -Inf <= x <= +Inf |
'(lower-bound LB) | Variable with lower bound, LB <= x <= +Inf |
'(upper-bound UB) | Variable with upper bound, -Inf <= x <= UB |
'(double-bounded LB UB) | Double-bounded variable, LB <= x <= UB |
'(fixed LB UB) | Fixed variable, LB = x = UB |
Returns true if the given object was created by lpx:empty-problem or lpx:make-problem, false otherwise.
'(unbounded) | Free (unbounded) variable, -Inf <= x <= +Inf |
'(lower-bound LB) | Variable with lower bound, LB <= x <= +Inf |
'(upper-bound UB) | Variable with upper bound, -Inf <= x <= UB |
'(double-bounded LB UB) | Double-bounded variable, LB <= x <= UB |
'(fixed LB UB) | Fixed variable, LB = x = UB |
'(unbounded) | Free (unbounded) variable, -Inf <= x <= +Inf |
'(lower-bound LB) | Variable with lower bound, LB <= x <= +Inf |
'(upper-bound UB) | Variable with upper bound, -Inf <= x <= UB |
'(double-bounded LB UB) | Double-bounded variable, LB <= x <= UB |
'(fixed LB UB) | Fixed variable, LB = x = UB |
'iv | integer variable |
'cv | continuous variable |
The procedures in this section retrieve or set control parameters of GLPK problem object. If a procedure is invoked only with a problem object as an argument, it will return the value of its respective control parameter. If it is invoked with an additional argument, that argument is used to set a new value for the control parameter.
LPX_E_OK | the LP problem has been successfully solved |
LPX_E_BADB | Unable to start the search, because the initial basis specified in the problem object is invalid--the number of basic (auxiliary and structural) variables is not the same as the number of rows in the problem object. |
LPX_E_SING | Unable to start the search, because the basis matrix corresponding to the initial basis is singular within the working precision. |
LPX_E_COND | Unable to start the search, because the basis matrix corresponding to the initial basis is ill-conditioned, i.e. its condition number is too large. |
LPX_E_BOUND | Unable to start the search, because some double-bounded (auxiliary or structural) variables have incorrect bounds. |
LPX_E_FAIL | The search was prematurely terminated due to the solver failure. |
LPX_E_OBJLL | The search was prematurely terminated, because the objective function being maximized has reached its lower limit and continues decreasing (the dual simplex only). |
LPX_E_OBJUL | The search was prematurely terminated, because the objective function being minimized has reached its upper limit and continues increasing (the dual simplex only). |
LPX_E_ITLIM | The search was prematurely terminated, because the simplex iteration limit has been exceeded. |
LPX_E_TMLIM | The search was prematurely terminated, because the time limit has been exceeded. |
LPX_E_NOPFS | The LP problem instance has no primal feasible solution (only if the LP presolver is used). |
LPX_E_NODFS | The LP problem instance has no dual feasible solution (only if the LP presolver is used). |
;; ;; Two Mines Linear programming example from ;; ;; http://people.brunel.ac.uk/~mastjjb/jeb/or/basicor.html#twomines ;; ;; Two Mines Company ;; ;; The Two Mines Company owns two different mines that produce an ore ;; which, after being crushed, is graded into three classes: high, ;; medium and low-grade. The company has contracted to provide a ;; smelting plant with 12 tons of high-grade, 8 tons of medium-grade ;; and 24 tons of low-grade ore per week. The two mines have different ;; operating characteristics as detailed below. ;; ;; Mine Cost per day ($'000) Production (tons/day) ;; High Medium Low ;; X 180 6 3 4 ;; Y 160 1 1 6 ;; ;; Production (tons/week) ;; High Medium Low ;; Contract 12 8 24 ;; ;; How many days per week should each mine be operated to fulfill the ;; smelting plant contract? ;; (require-extension srfi-4) (require-extension glpk) ;; (1) Unknown variables ;; ;; x = number of days per week mine X is operated ;; y = number of days per week mine Y is operated ;; ;; (2) Constraints ;; ;; ;; * ore production constraints - balance the amount produced with ;; the quantity required under the smelting plant contract ;; ;; High 6x + 1y >= 12 ;; Medium 3x + 1y >= 8 ;; Low 4x + 6y >= 24 ;; ;; (3) Objective ;; ;; The objective is to minimise cost which is given by 180x + 160y. ;; ;; minimise 180x + 160y ;; subject to ;; 6x + y >= 12 ;; 3x + y >= 8 ;; 4x + 6y >= 24 ;; x <= 5 ;; y <= 5 ;; x,y >= 0 ;; ;; (4) Auxiliary variables (rows) ;; ;; p = 6x + y ;; q = 3x + y ;; r = 4x + 6y ;; ;; 12 <= p < +inf ;; 8 <= q < +inf ;; 24 <= r < +inf (define pbounds `((lower-bound 12) (lower-bound 8) (lower-bound 24))) ;; (5) Structural variables (columns) ;; ;; 0 <= x <= 5 ;; 0 <= y <= 5 (define xbounds `((double-bounded 0 5) (double-bounded 0 5))) ;; (6) Objective coefficients: 180, 160 (define objcoefs (list 180 160)) ;; Constraints matrix (in row-major order) ;; ;; 6 1 ;; 3 1 ;; 4 6 (define constraints (f64vector 6 1 3 1 4 6)) ;; Create the problem definition & run the solver (let ((lpp (lpx:make-problem 'minimize pbounds xbounds objcoefs constraints))) (lpx:scale-problem lpp) (lpx:use_presolver lpp #t) (let ((status (lpx:simplex lpp))) (print "solution status = " status) (print "objective value = " (lpx:get-objective-value lpp)) (print "primals = " (lpx:get-column-primals lpp))))
Copyright Ivan Raikov and the Okinawa Institute of Science and Technology. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A full copy of the GPL license can be found at <http://www.gnu.org/licenses/>.