├── NEWS ├── examples ├── web_trick │ ├── ex_relaxed_solution │ ├── guidefile │ ├── subprob_2.cplex │ ├── subprob.cplex │ ├── master.cplex │ ├── monolithic.cplex │ └── README ├── book_bertsimas │ ├── ex_relaxed_solution │ ├── guidefile │ ├── guide_double │ ├── sub2.triple.cplex │ ├── sub3.triple.cplex │ ├── sub1.doubleORtriple.cplex │ ├── guide_triple │ ├── sub2.double.cplex │ ├── master.cplex │ ├── single_sub.cplex │ ├── monolithic.cplex │ └── README ├── web_mitchell │ ├── ex_relaxed_solution │ ├── guidefile │ ├── master.cplex │ ├── subprob.cplex │ └── README ├── book_lasdon │ ├── ex_relaxed_solution │ ├── guidefile │ ├── sub1.cplex │ ├── sub2.cplex │ ├── master.cplex │ └── README ├── book_dantzig │ ├── guidefile │ ├── book_sub3.cplex │ ├── ex_relaxed_solution │ ├── book_sub1.cplex │ ├── book_sub2.cplex │ ├── book_master.cplex │ ├── book_monolithic.cplex │ └── README └── four_sea │ ├── guidefile │ └── README ├── Makefile.am ├── .gitignore ├── AUTHORS ├── .github └── workflows │ └── build.yaml ├── m4 ├── ltversion.m4 ├── ltsugar.m4 └── lt~obsolete.m4 ├── src ├── glprgr.h ├── glpipm.h ├── glpstd.h ├── amd │ ├── amd_defaults.c │ ├── amd.h │ ├── amd_control.c │ ├── amd_internal.h │ ├── amd_valid.c │ ├── amd_preprocess.c │ ├── amd_info.c │ └── amd_post_tree.c ├── glpspx.h ├── dw_phases.h ├── glpsql.h ├── colamd │ └── colamd.h ├── glpenv02.c ├── dw_blas.h ├── glpqmd.h ├── glpnet.h ├── glprng.h ├── glprng02.c ├── glpbfx.h ├── Makefile.am ├── glpbfd.h ├── dw_rounding.h ├── glpbfx.c ├── glpdmp.h ├── dw_support.h ├── dw_subprob.h ├── dw_blas.c ├── glpenv04.c ├── glpenv08.c ├── glplib.h ├── glpapi18.c ├── glptsp.h ├── glpavl.h ├── glpscf.h ├── glphbm.h ├── glpapi04.c ├── glpenv06.c ├── dw.h ├── glpspm.h ├── glpapi03.c └── glpapi05.c ├── GLPK_README ├── GLPK_AUTHORS ├── tests └── dw-tests.sh ├── ChangeLog ├── config.h.in ├── glpk-4.44.ThreadReady.patch ├── ADDITIONAL_LICENSE_TERMS ├── README.md ├── compile ├── configure.ac └── GLPK_THANKS /NEWS: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/web_trick/ex_relaxed_solution: -------------------------------------------------------------------------------- 1 | x1 3.000000 2 | x2 2.000000 3 | x3 3.000000 4 | -------------------------------------------------------------------------------- /examples/book_bertsimas/ex_relaxed_solution: -------------------------------------------------------------------------------- 1 | x1 2.000000 2 | x2 1.500000 3 | x3 2.000000 4 | -------------------------------------------------------------------------------- /examples/web_mitchell/ex_relaxed_solution: -------------------------------------------------------------------------------- 1 | x1 0.000000 2 | x2 1.000000 3 | x3 2.000000 4 | -------------------------------------------------------------------------------- /examples/book_bertsimas/guidefile: -------------------------------------------------------------------------------- 1 | 1 2 | single_sub.cplex 3 | master.cplex 4 | master.cplex 5 | -------------------------------------------------------------------------------- /examples/web_mitchell/guidefile: -------------------------------------------------------------------------------- 1 | 1 2 | subprob.cplex 3 | master.cplex 4 | master.cplex 5 | 0.0 6 | -------------------------------------------------------------------------------- /examples/book_lasdon/ex_relaxed_solution: -------------------------------------------------------------------------------- 1 | x1 8.333333 2 | x2 3.333333 3 | y1 10.000000 4 | y2 5.000000 5 | -------------------------------------------------------------------------------- /examples/book_lasdon/guidefile: -------------------------------------------------------------------------------- 1 | 2 2 | sub1.cplex 3 | sub2.cplex 4 | master.cplex 5 | master.cplex 6 | 0.0 7 | -------------------------------------------------------------------------------- /examples/web_trick/guidefile: -------------------------------------------------------------------------------- 1 | 2 2 | subprob.cplex 3 | subprob_2.cplex 4 | master.cplex 5 | monolithic.cplex 6 | 0.0 7 | -------------------------------------------------------------------------------- /examples/web_trick/subprob_2.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: x1 3 | 4 | Subject To 5 | Con1: 1 x1 <= 3 6 | 7 | end 8 | -------------------------------------------------------------------------------- /examples/book_bertsimas/guide_double: -------------------------------------------------------------------------------- 1 | 2 2 | sub1.doubleORtriple.cplex 3 | sub2.double.cplex 4 | master.cplex 5 | master.cplex 6 | 0.0 7 | -------------------------------------------------------------------------------- /examples/book_bertsimas/sub2.triple.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: - 1 x2 3 | 4 | Subject to 5 | c1: x2 <= 2 6 | c2: x2 >= 1 7 | 8 | End 9 | -------------------------------------------------------------------------------- /examples/book_bertsimas/sub3.triple.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: - 6 x3 3 | 4 | Subject to 5 | c3: x3 <= 2 6 | c4: x3 >= 1 7 | 8 | End 9 | -------------------------------------------------------------------------------- /examples/book_bertsimas/sub1.doubleORtriple.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: -4 x1 3 | 4 | Subject to 5 | c1: x1 <= 2 6 | c2: x1 >= 1 7 | 8 | end 9 | -------------------------------------------------------------------------------- /examples/book_dantzig/guidefile: -------------------------------------------------------------------------------- 1 | 3 2 | book_sub1.cplex 3 | book_sub2.cplex 4 | book_sub3.cplex 5 | book_master.cplex 6 | book_monolithic.cplex 7 | 0.0 8 | -------------------------------------------------------------------------------- /examples/book_bertsimas/guide_triple: -------------------------------------------------------------------------------- 1 | 3 2 | sub1.doubleORtriple.cplex 3 | sub2.triple.cplex 4 | sub3.triple.cplex 5 | master.cplex 6 | master.cplex 7 | 0.0 8 | -------------------------------------------------------------------------------- /examples/book_lasdon/sub1.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: - 1 x1 - 1 x2 3 | 4 | Subject to 5 | c1: x1 + 3 x2 <= 30 6 | c2: 2 x1 + 1 x2 <= 20 7 | 8 | end 9 | -------------------------------------------------------------------------------- /examples/four_sea/guidefile: -------------------------------------------------------------------------------- 1 | 4 2 | subprob_1.cplex 3 | subprob_2.cplex 4 | subprob_3.cplex 5 | subprob_4.cplex 6 | master.cplex 7 | dw_monolithic.cplex 8 | 160 9 | -------------------------------------------------------------------------------- /examples/web_trick/subprob.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: - 5 x2 - 3 x3 3 | 4 | Subject To 5 | Con1: 1 x2 + 1 x3 <= 5 6 | Con2: 2 x2 + 1 x3 <= 8 7 | 8 | end 9 | -------------------------------------------------------------------------------- /examples/web_mitchell/master.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: 1 x1 - 1 x2 - 2 x3 3 | 4 | Subject To 5 | Con1: 1 x1 + 1 x2 + 1 x3 = 3 6 | 7 | end 8 | 9 | 10 | -------------------------------------------------------------------------------- /examples/book_dantzig/book_sub3.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: 7 x13 + 10 x14 3 | 4 | Subject to 5 | c1: x13 - x14 = 1 6 | b1: x13 <= 65 7 | b2: x14 <= 65 8 | 9 | end 10 | -------------------------------------------------------------------------------- /examples/web_trick/master.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: - 7 x1 - 5 x2 - 3 x3 3 | 4 | Subject To 5 | Con1: 1 x1 + 2 x2 + 1 x3 <= 10 6 | Con2: 1 x1 <= 3 7 | 8 | end 9 | -------------------------------------------------------------------------------- /examples/book_bertsimas/sub2.double.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: - 1 x2 - 6 x3 3 | 4 | Subject to 5 | c1: x2 <= 2 6 | c2: x2 >= 1 7 | c3: x3 <= 2 8 | c4: x3 >= 1 9 | 10 | End 11 | -------------------------------------------------------------------------------- /examples/book_bertsimas/master.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: -4 x1 - 1 x2 - 6 x3 3 | 4 | Subject To 5 | Con1: 3 x1 + 2 x2 + 4 x3 = 17 6 | 7 | Bounds 8 | 0 <= DUMMY <= 1 9 | 10 | end 11 | -------------------------------------------------------------------------------- /examples/book_lasdon/sub2.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: - 2 y1 - 1 y2 3 | 4 | Subject to 5 | c1: 1 y1 <= 10 6 | c2: 1 y2 <= 10 7 | c3: 1 y1 + 1 y2 <= 15 8 | 9 | end 10 | -------------------------------------------------------------------------------- /examples/web_mitchell/subprob.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: 999 x1 3 | 4 | Subject To 5 | Con1: x1 <= 2 6 | Con2: x2 >= 0 7 | Con3: x3 <= 2 8 | AritificialUpperBound: x2 <= 99 9 | end 10 | -------------------------------------------------------------------------------- /examples/book_lasdon/master.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: - 1 x1 - 1 x2 - 2 y1 - 1 y2 3 | 4 | Subject To 5 | Con1: 1 x1 + 2 x2 + 2 y1 + 1 y2 <= 40 6 | 7 | Bounds 8 | 0 <= DUMMY <= 1 9 | 10 | end 11 | -------------------------------------------------------------------------------- /examples/book_bertsimas/single_sub.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: - 1 x2 - 6 x3 3 | 4 | Subject to 5 | c0: x1 <= 2 6 | ca: x1 >= 1 7 | c1: x2 <= 2 8 | c2: x2 >= 1 9 | c3: x3 <= 2 10 | c4: x3 >= 1 11 | 12 | End 13 | -------------------------------------------------------------------------------- /examples/web_trick/monolithic.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: - 7 x1 - 5 x2 - 3 x3 3 | 4 | Subject To 5 | Con1: 1 x1 + 2 x2 + 1 x3 <= 10 6 | Con2: 1 x2 + 1 x3 <= 5 7 | Con3: 1 x1 <= 3 8 | Con4: 2 x2 + 1 x3 <= 8 9 | 10 | end 11 | -------------------------------------------------------------------------------- /examples/book_dantzig/ex_relaxed_solution: -------------------------------------------------------------------------------- 1 | x1 2.000000 2 | x2 0.000000 3 | x3 1.000000 4 | x4 0.000000 5 | x5 1.000000 6 | x6 3.000000 7 | x7 0.000000 8 | x8 2.684211 9 | x9 1.315789 10 | x10 3.000000 11 | x11 0.315789 12 | x12 1.684211 13 | x13 2.473684 14 | x14 1.473684 15 | -------------------------------------------------------------------------------- /examples/book_bertsimas/monolithic.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: -4 x1 - 1 x2 - 6 x3 3 | 4 | Subject To 5 | Con1: 3 x1 + 2 x2 + 4 x3 = 17 6 | c0: x1 <= 2 7 | ca: x1 >= 1 8 | c1: x2 <= 2 9 | c2: x2 >= 1 10 | c3: x3 <= 2 11 | c4: x3 >= 1 12 | 13 | Bounds 14 | 0 <= DUMMY <= 1 15 | 16 | end 17 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in ## 2 | 3 | ACLOCAL_AMFLAGS=-I m4 4 | 5 | SUBDIRS = src 6 | 7 | EXTRA_DIST = examples glpk-4.44.ThreadReady.patch GLPK_INSTALL GLPK_AUTHORS \ 8 | GLPK_README GLPK_NEWS GLPK_THANKS ADDITIONAL_LICENSE_TERMS \ 9 | ChangeLog 10 | ## eof ## 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.Po 3 | *.o 4 | stamp-h1 5 | **/done.cpxlp 6 | **/out_terminal 7 | **/pre_master.cpxlp 8 | **/done.cpxlp 9 | **/relaxed_solution 10 | config.h 11 | config.log 12 | config.status 13 | libtool 14 | src/dwsolver 15 | **/Makefile 16 | *.0 17 | autom4te.cache/ 18 | **/rs_sorted 19 | examples/four_sea/pre_master.cpxlp 20 | -------------------------------------------------------------------------------- /examples/book_dantzig/book_sub1.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: 1 x1 + 2 x2 + 3 x3 + 4 x4 + 5 x5 + 6 x6 3 | 4 | Subject to 5 | c1: x1 + x2 + x3 = 3 6 | c2: x4 + x5 + x6 = 4 7 | c3: x1 + x4 = 2 8 | c4: x2 + x5 = 1 9 | c5: x3 + x6 = 4 10 | b1: x1 <= 65 11 | b2: x2 <= 65 12 | b3: x3 <= 65 13 | b4: x4 <= 65 14 | b5: x5 <= 65 15 | b6: x6 <= 65 16 | end 17 | -------------------------------------------------------------------------------- /examples/book_dantzig/book_sub2.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: 1 x7 + 2 x8 + 3 x9 + 4 x10 + 5 x11 + 6 x12 3 | 4 | Subject to 5 | c1: x7 + x8 + x9 = 4 6 | c2: x10 + x11 + x12 = 5 7 | c3: x7 + x10 = 3 8 | c4: x8 + x11 = 3 9 | c5: x9 + x12 = 3 10 | b1: x7 <= 65 11 | b2: x8 <= 65 12 | b3: x9 <= 65 13 | b4: x10 <= 65 14 | b5: x11 <= 65 15 | b6: x12 <= 65 16 | end 17 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | The DWSOLVER package was developed and programmed by Joseph Rios, Systems 2 | Modeling and Optimization Branch, Ames Research Center, National Aeronautics 3 | and Space Administration, Moffett Field, CA. 4 | 5 | Email: Joseph.L.Rios@nasa.gov 6 | 7 | Paper mail: Joseph Rios 8 | Ames Research Center 9 | Mail Stop 210-15 10 | Moffett Field, CA 94035 11 | -------------------------------------------------------------------------------- /examples/book_dantzig/book_master.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: 1 x1 + 2 x2 + 3 x3 + 4 x4 + 5 x5 + 6 x6 + 1 x7 3 | + 2 x8 + 3 x9 + 4 x10 + 5 x11 + 6 x12 + 7 x13 - 10 x14 4 | 5 | Subject To 6 | Con1: 3 x1 + 2 x2 + 1 x3 + 6 x4 + 5 x5 + 4 x6 + 8 x7 7 | + 5 x8 + 7 x9 + 3 x10 + 4 x11 + 1 x12 + 1 x13 + 2 x14 = 64 8 | Con2: 1 x1 + 8 x2 + 3 x3 + 7 x4 + 1 x5 + 4 x6 + 5 x7 9 | + 2 x8 + 5 x9 + 3 x10 + 2 x11 + 6 x12 + 3 x13 + 4 x14 = 63 10 | 11 | end 12 | -------------------------------------------------------------------------------- /examples/book_lasdon/README: -------------------------------------------------------------------------------- 1 | The problem presented in this directory is from: 2 | 3 | Lasdon, Leon. Optimization Theory for Large Systems. The MacMillan Company. 4 | 1970. 5 | 6 | Specifically, this is example 3.5 on pages 155 through 160. 7 | 8 | The solution on page 160 shows an optimal value of -110/3 (= -36.666666) 9 | with variable assignments of x1=8.3333, x2=3.3333, y1=10, y2=5. 10 | 11 | To run this example: 12 | 13 | -g guidefile 14 | -------------------------------------------------------------------------------- /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: Build C Code 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build: 10 | runs-on: macos-13 11 | 12 | steps: 13 | - uses: actions/checkout@v3 14 | 15 | - name: configure the code 16 | run: ./configure 17 | 18 | - name: Build the code 19 | run: make 20 | 21 | - name: Install the code 22 | run: make install 23 | 24 | - name: Run test script 25 | run: cd tests && ./dw-tests.sh 26 | -------------------------------------------------------------------------------- /examples/book_bertsimas/README: -------------------------------------------------------------------------------- 1 | The problem presented in this directory is from: 2 | 3 | Bertsimas, Dimitris and Tsitsiklis, John N. Introduction to Linear Optimization. 4 | Athena Scientific. 1997. 5 | 6 | Specifically, this is example 6.2 on pages 245 through 246. 7 | 8 | To run this example with a single subproblem as shown in textbook: 9 | 10 | -g guidefile 11 | 12 | To run this example with two subproblems: 13 | 14 | -g guide_double 15 | 16 | To run this example with three subproblems: 17 | 18 | -g guide_triple 19 | -------------------------------------------------------------------------------- /examples/web_mitchell/README: -------------------------------------------------------------------------------- 1 | The problem presented in this directory is from: 2 | 3 | Mitchell, John. An example of Dantzig-Wolfe Decomposition. Accessed online 4 | at http://www.rpi.edu/~mitchj/handouts/egdcmp/ on Aug 18, 2010. 5 | 6 | Note that the problem was changed slightly to avoid the unbounded subproblem. 7 | Since it was known a priori that the optimal value for the unbounded variable 8 | was 1, an upper bound on that variable was set well above that. Otherwise, 9 | the problem is implemented as described on Mitchell's website. 10 | 11 | The optimal value is -5. 12 | 13 | To run this example: 14 | 15 | -g guidefile 16 | -------------------------------------------------------------------------------- /examples/web_trick/README: -------------------------------------------------------------------------------- 1 | The problem presented in this directory is from: 2 | 3 | Trick, Michael. A Consultants Guide to Solving Large Problems. Accessed online 4 | at http://mat.gsia.cmu.edu/classes/mstc/decomp/node4.html on Sept 8, 2009. 5 | 6 | This problem is a good example of the need for every variable to exist in a 7 | subproblem. As presented online, Trick leaves x1 in the master problem. 8 | Clearly, this is mathematically reasonable, however, the dwsolver software 9 | expects no master variables except those found in subproblems. The simple 10 | fix to this problem is to create a new subproblem containing only variable 11 | x1. 12 | 13 | To run this example: 14 | 15 | -g guidefile 16 | -------------------------------------------------------------------------------- /m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # Generated from ltversion.in. 11 | 12 | # serial 3087 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.2.7a]) 16 | m4_define([LT_PACKAGE_REVISION], [1.3087]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.2.7a' 20 | macro_revision='1.3087' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /examples/book_dantzig/book_monolithic.cplex: -------------------------------------------------------------------------------- 1 | Minimize 2 | objective: 1 x1 + 2 x2 + 3 x3 + 4 x4 + 5 x5 + 6 x6 + 1 x7 3 | + 2 x8 + 3 x9 + 4 x10 + 5 x11 + 6 x12 + 7 x13 - 10 x14 4 | 5 | Subject To 6 | Con1: 3 x1 + 2 x2 + 1 x3 + 6 x4 + 5 x5 + 4 x6 + 8 x7 7 | + 5 x8 + 7 x9 + 3 x10 + 4 x11 + 1 x12 + 1 x13 + 2 x14 = 64 8 | Con2: 1 x1 + 8 x2 + 3 x3 + 7 x4 + 1 x5 + 4 x6 + 5 x7 9 | + 2 x8 + 5 x9 + 3 x10 + 2 x11 + 6 x12 + 3 x13 + 4 x14 = 63 10 | a1: x1 + x2 + x3 = 3 11 | a2: x4 + x5 + x6 = 4 12 | a3: x1 + x4 = 2 13 | a4: x2 + x5 = 1 14 | a5: x3 + x6 = 4 15 | b1: x7 + x8 + x9 = 4 16 | b2: x10 + x11 + x12 = 5 17 | b3: x7 + x10 = 3 18 | b4: x8 + x11 = 3 19 | b5: x9 + x12 = 3 20 | c1: x13 - x14 = 1 21 | 22 | Bounds 23 | 0 <= DUMMY <= 1 24 | 25 | end 26 | -------------------------------------------------------------------------------- /examples/book_dantzig/README: -------------------------------------------------------------------------------- 1 | The problem presented in this directory is from: 2 | 3 | Dantzig, George and Thapa, Mukund N. Linear Programming: Theory and Extensions. 4 | Springer. 2003. 5 | 6 | Specifically, this is example 10.5/10.6 on pages 290 through 298. 7 | 8 | Since the current implementation of dwsolver does not allow for unbounded 9 | subproblems, upper bounds have been added to the subproblem files. These bounds 10 | were chosen through quick examination of the connecting constraints in the 11 | master problem. No variable could be valued over 64 and still satisfy the 12 | connecting constraints. Thus, an upper bound of 65 is placed on all of the 13 | decision variables in each of the subproblem files. 14 | 15 | There are multiple solutions for this problem, and depending on the race between 16 | subproblem threads, you may see different assigments to the variables from run 17 | to run. 18 | 19 | To run this example: 20 | 21 | -g book_test 22 | -------------------------------------------------------------------------------- /src/glprgr.h: -------------------------------------------------------------------------------- 1 | /* glprgr.h (raster graphics) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifndef GLPRGR_H 26 | #define GLPRGR_H 27 | 28 | #define rgr_write_bmp16 _glp_rgr_write_bmp16 29 | int rgr_write_bmp16(const char *fname, int m, int n, const char map[]); 30 | /* write 16-color raster image in BMP file format */ 31 | 32 | #endif 33 | 34 | /* eof */ 35 | -------------------------------------------------------------------------------- /src/glpipm.h: -------------------------------------------------------------------------------- 1 | /* glpipm.h (primal-dual interior-point method) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifndef GLPIPM_H 26 | #define GLPIPM_H 27 | 28 | #include "glpapi.h" 29 | 30 | #define ipm_solve _glp_ipm_solve 31 | int ipm_solve(glp_prob *P, const glp_iptcp *parm); 32 | /* core LP solver based on the interior-point method */ 33 | 34 | #endif 35 | 36 | /* eof */ 37 | -------------------------------------------------------------------------------- /src/glpstd.h: -------------------------------------------------------------------------------- 1 | /* glpstd.h (standard C headers) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifndef GLPSTD_H 26 | #define GLPSTD_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #endif 42 | 43 | /* eof */ 44 | -------------------------------------------------------------------------------- /src/amd/amd_defaults.c: -------------------------------------------------------------------------------- 1 | /* ========================================================================= */ 2 | /* === AMD_defaults ======================================================== */ 3 | /* ========================================================================= */ 4 | 5 | /* ------------------------------------------------------------------------- */ 6 | /* AMD, Copyright (c) Timothy A. Davis, */ 7 | /* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ 8 | /* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */ 9 | /* web: http://www.cise.ufl.edu/research/sparse/amd */ 10 | /* ------------------------------------------------------------------------- */ 11 | 12 | /* User-callable. Sets default control parameters for AMD. See amd.h 13 | * for details. 14 | */ 15 | 16 | #include "amd_internal.h" 17 | 18 | /* ========================================================================= */ 19 | /* === AMD defaults ======================================================== */ 20 | /* ========================================================================= */ 21 | 22 | GLOBAL void AMD_defaults 23 | ( 24 | double Control [ ] 25 | ) 26 | { 27 | Int i ; 28 | 29 | if (Control != (double *) NULL) 30 | { 31 | for (i = 0 ; i < AMD_CONTROL ; i++) 32 | { 33 | Control [i] = 0 ; 34 | } 35 | Control [AMD_DENSE] = AMD_DEFAULT_DENSE ; 36 | Control [AMD_AGGRESSIVE] = AMD_DEFAULT_AGGRESSIVE ; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/glpspx.h: -------------------------------------------------------------------------------- 1 | /* glpspx.h (core simplex solvers) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifndef GLPSPX_H 26 | #define GLPSPX_H 27 | 28 | #include "glpapi.h" 29 | 30 | #define spx_primal _glp_spx_primal 31 | int spx_primal(glp_prob *lp, const glp_smcp *parm); 32 | /* core LP solver based on the primal simplex method */ 33 | 34 | #define spx_dual _glp_spx_dual 35 | int spx_dual(glp_prob *lp, const glp_smcp *parm); 36 | /* core LP solver based on the dual simplex method */ 37 | 38 | #endif 39 | 40 | /* eof */ 41 | -------------------------------------------------------------------------------- /GLPK_README: -------------------------------------------------------------------------------- 1 | Olga K. gewidmet 2 | 3 | GLPK (GNU Linear Programming Kit) Version 4.44 4 | 5 | Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 6 | 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 7 | Moscow Aviation Institute, Moscow, Russia. All rights reserved. 8 | E-mail: . 9 | 10 | GLPK is part of the GNU Project released under the aegis of GNU. 11 | 12 | GLPK is free software: you can redistribute it and/or modify it 13 | under the terms of the GNU General Public License as published by the 14 | Free Software Foundation, either version 3 of the License, or (at your 15 | option) any later version. 16 | 17 | See the file COPYING for the GNU General Public License. 18 | 19 | See the file INSTALL for compilation and installation instructions. 20 | 21 | The GLPK package is a set of routines written in ANSI C and organized 22 | in the form of a callable library. This package is intended for solving 23 | large-scale linear programming (LP), mixed integer linear programming 24 | (MIP), and other related problems. 25 | 26 | The GLPK package includes the following main components: 27 | 28 | * implementation of the simplex method; 29 | * implementation of the exact simplex method based on bignum (rational) 30 | arithmetic; 31 | * implementation of the primal-dual interior-point method; 32 | * implementation of the branch-and-cut method; 33 | * application program interface (API); 34 | * GNU MathProg modeling language (a subset of AMPL); 35 | * GLPSOL, a stand-alone LP/MIP solver. 36 | 37 | See GLPK webpage . 38 | 39 | Please report bugs to . 40 | -------------------------------------------------------------------------------- /examples/four_sea/README: -------------------------------------------------------------------------------- 1 | The problem in this directory is an instance of the model originally published 2 | by Bertsimas and Stock-Patterson for Traffic Flow Management of the National 3 | Airspace System. 4 | 5 | D. Bertsimas and S. Stock-Patterson. The Air Traffic Flow Management Problem 6 | with En Route Capacities. Operations Research, 46(3):406-422, May-June 1998. 7 | 8 | This model was implemented for the research completed in several studies by Rios 9 | and Ross: 10 | 11 | Delay Optimization for Airspace Capacity Management with Runtime and Equity 12 | Considerations. In Proceedings of AIAA Guidance, Navigation, and Control 13 | Conference and Exhibit, Hilton Head, South Carolina, August 2007. 14 | 15 | Solving High-Fidelity, Large-Scale Traffic Flow Management Problems in Reduced 16 | Time. In Proceedings of AIAA Aviation Technology, INtegration and Operations 17 | Conference, Anchorage, Alaska, September 2008. 18 | 19 | Massively Parallel Dantzig-Wolfe Decomposition Applied to Traffic Flow 20 | Scheduling. Journal of Aerospace Computing, Information, and Communication. 21 | 7(1):32-45, January 2010. 22 | 23 | 24 | The instance provided here involves 8 aircraft departing the same airport at the 25 | same time destined for the same arrival airport along the same trajectory. This 26 | is a toy example to illustrate that 2 of the flights must be held in order to 27 | satisfy the arrival capacity constraints of the arrival airport which is set to 28 | a value of 6. The two that are held per the solution will depend on the race 29 | between threads, but the total delay (i.e. the optimal solution) will remain 30 | the same. This results in a total delay of 12 minutes. 31 | 32 | -------------------------------------------------------------------------------- /GLPK_AUTHORS: -------------------------------------------------------------------------------- 1 | The GLPK package was developed and programmed by Andrew Makhorin, 2 | Department for Applied Informatics, Moscow Aviation Institute, Moscow, 3 | Russia. 4 | 5 | E-mail: 6 | 7 | Paper mail: 125871, Russia, Moscow, Volokolamskoye sh., 4, 8 | Moscow Aviation Institute, Andrew O. Makhorin 9 | 10 | -----BEGIN PGP PUBLIC KEY BLOCK----- 11 | Version: GnuPG v1.2.2 (MingW32) 12 | 13 | mQGiBD8UdT8RBAC6yWYxoa1b7U973J0jBuQpgZnhXlGJJpMZgAW9efDBD17vhkJm 14 | hPVOQBKRUeOOLcW3/a7NMoNLMdmF1Rgz1FPVy3RgBDsYj4Sp4RBCsX/o0xXh+jxe 15 | gncr4bdN0Ruk03pezVtLi9oYygdxfI51SsjZ2vwYP6BhMwv+xrIgcnc4qwCgoCit 16 | 26mTd0FoGOmsQuipo6X5LaUD/1l7NqFIjiGdWthyG3TqsiK5Ew7xF3fLEABXKPjb 17 | PMRTMucX8XXHmW8RUD1vP1uGDnEn6s+fjc3/RtaqKjqGMdLt4XgHQkImaVguNpSS 18 | IxN3LaK600BgAbwSd1bomRqWNlczAM7469VvGG9ASpCBveUUrqwerHZcUbvngL62 19 | pIcqA/41dO0xYrOTqMRhuguYMgHL2xbwB2Aj2TqRwBm697DIS25B9nE+8UsbjGRx 20 | q3EmeuHeZ5kN5RbESXkGUB8whIcYxvH16HRNmM1ZjmFoBVL2Z6S2gpa2ZUqsq7BZ 21 | s+hriElm3dfOQCt79/o852uKWu5bSjw2yiemVA2T8tG4OoN6DrQjQW5kcmV3IE1h 22 | a2hvcmluIDxtYW9AbWFpMi5yY25ldC5ydT6IWwQTEQIAGwUCPxR1PwYLCQgHAwID 23 | FQIDAxYCAQIeAQIXgAAKCRDRe/IwWYHoGKpHAJ44MmzWKr8OiTc0Bb6/RD56aekp 24 | 3wCdGznQMCfWFkehQPbeNaB5yFIs+8a5AQ0EPxR1UBAEAO3U3H5M0iYv06C4kKty 25 | 6ReWyYH4CzMAfp2lPVUKzRSjPtoAJ6SkrBSKMT+U+DahxZ4K4HbinvHq3uvlwWax 26 | xw0wKxJl4oY6EGE1Jqn3B//Ak47RaNMnrs9V739WT1YNRpQvh4wOCeMekBzksf43 27 | hm4dSV4PMQkLmrEeG2+BYaZnAAMFA/4tVHhjGRkxzcTcfHCB+Yo3PXeIQMuIs00c 28 | VKCrNReLni/3BWZC0w9tFzZSdz+URXefPWDGuAC16vLCVOD06NcIQGutPe189dUn 29 | Kf9Bl6qc9DyWsxSTdF/PbLqcLfEe9g7fHhIwdY+w/hSq2n3NEURMzHiMT1U3CvHd 30 | As5IzV/yD4hGBBgRAgAGBQI/FHVQAAoJENF78jBZgegYRZEAmwReJkMSrbs0EQs2 31 | wjyTCMd5KDh3AKCR2/RvVad9RT3ShYnUiPPYTL2/Nw== 32 | =OfLQ 33 | -----END PGP PUBLIC KEY BLOCK----- 34 | -------------------------------------------------------------------------------- /tests/dw-tests.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # Quiet down pushd and popd 4 | pushd () { 5 | command pushd "$@" > /dev/null 6 | } 7 | popd () { 8 | command popd "$@" > /dev/null 9 | } 10 | 11 | echo "Test: Bertsimas textbook example" 12 | pushd ../examples/book_bertsimas 13 | dwsolver --no-write-final-master --quiet -g guidefile 14 | sort relaxed_solution > rs_sorted 15 | if diff -w -B ex_relaxed_solution rs_sorted ; then 16 | echo " PASS: Got expected solution." 17 | echo "" 18 | else 19 | echo " FAIL: Unexpected solution. Test failed. Exiting." 20 | exit 1 21 | fi 22 | popd 23 | 24 | echo "Test: Lasdon textbook example" 25 | pushd ../examples/book_lasdon 26 | dwsolver --no-write-final-master --quiet -g guidefile 27 | sort relaxed_solution > rs_sorted 28 | if diff -w -B ex_relaxed_solution rs_sorted ; then 29 | echo " PASS: Got expected solution." 30 | echo "" 31 | else 32 | echo " FAIL: Unexpected solution. Test failed. Exiting." 33 | exit 1 34 | fi 35 | popd 36 | 37 | echo "Test: Mitchell web example" 38 | pushd ../examples/web_mitchell 39 | dwsolver --no-write-final-master --quiet -g guidefile 40 | sort relaxed_solution > rs_sorted 41 | if diff -w -B ex_relaxed_solution rs_sorted ; then 42 | echo " PASS: Got expected solution." 43 | echo "" 44 | else 45 | echo " FAIL: Unexpected solution. Test failed. Exiting." 46 | exit 1 47 | fi 48 | popd 49 | 50 | echo "Test: Trick web example" 51 | pushd ../examples/web_trick 52 | dwsolver --no-write-final-master --quiet -g guidefile 53 | sort relaxed_solution > rs_sorted 54 | if diff -w -B ex_relaxed_solution rs_sorted ; then 55 | echo " PASS: Got expected solution." 56 | echo "" 57 | else 58 | echo " FAIL: Unexpected solution. Test failed. Exiting." 59 | exit 1 60 | fi 61 | popd 62 | 63 | -------------------------------------------------------------------------------- /src/amd/amd.h: -------------------------------------------------------------------------------- 1 | /* amd.h */ 2 | 3 | /* Written by Andrew Makhorin . */ 4 | 5 | #ifndef GLPAMD_H 6 | #define GLPAMD_H 7 | 8 | #define AMD_DATE "May 31, 2007" 9 | #define AMD_VERSION_CODE(main, sub) ((main) * 1000 + (sub)) 10 | #define AMD_MAIN_VERSION 2 11 | #define AMD_SUB_VERSION 2 12 | #define AMD_SUBSUB_VERSION 0 13 | #define AMD_VERSION AMD_VERSION_CODE(AMD_MAIN_VERSION, AMD_SUB_VERSION) 14 | 15 | #define AMD_CONTROL 5 16 | #define AMD_INFO 20 17 | 18 | #define AMD_DENSE 0 19 | #define AMD_AGGRESSIVE 1 20 | 21 | #define AMD_DEFAULT_DENSE 10.0 22 | #define AMD_DEFAULT_AGGRESSIVE 1 23 | 24 | #define AMD_STATUS 0 25 | #define AMD_N 1 26 | #define AMD_NZ 2 27 | #define AMD_SYMMETRY 3 28 | #define AMD_NZDIAG 4 29 | #define AMD_NZ_A_PLUS_AT 5 30 | #define AMD_NDENSE 6 31 | #define AMD_MEMORY 7 32 | #define AMD_NCMPA 8 33 | #define AMD_LNZ 9 34 | #define AMD_NDIV 10 35 | #define AMD_NMULTSUBS_LDL 11 36 | #define AMD_NMULTSUBS_LU 12 37 | #define AMD_DMAX 13 38 | 39 | #define AMD_OK 0 40 | #define AMD_OUT_OF_MEMORY (-1) 41 | #define AMD_INVALID (-2) 42 | #define AMD_OK_BUT_JUMBLED 1 43 | 44 | #define amd_order _glp_amd_order 45 | int amd_order(int n, const int Ap[], const int Ai[], int P[], 46 | double Control[], double Info[]); 47 | 48 | #define amd_2 _glp_amd_2 49 | void amd_2(int n, int Pe[], int Iw[], int Len[], int iwlen, int pfree, 50 | int Nv[], int Next[], int Last[], int Head[], int Elen[], 51 | int Degree[], int W[], double Control[], double Info[]); 52 | 53 | #define amd_valid _glp_amd_valid 54 | int amd_valid(int n_row, int n_col, const int Ap[], const int Ai[]); 55 | 56 | #define amd_defaults _glp_amd_defaults 57 | void amd_defaults(double Control[]); 58 | 59 | #define amd_control _glp_amd_control 60 | void amd_control(double Control[]); 61 | 62 | #define amd_info _glp_amd_info 63 | void amd_info(double Info[]); 64 | 65 | #endif 66 | 67 | /* eof */ 68 | -------------------------------------------------------------------------------- /src/dw_phases.h: -------------------------------------------------------------------------------- 1 | /* ***************************************************************************** 2 | * 3 | * DWSOLVER - a general, parallel implementation of the Dantzig-Wolfe 4 | * Decomposition algorithm. 5 | * 6 | * Copyright 2010 United States Government National Aeronautics and Space 7 | * Administration (NASA). No copyright is claimed in the United States under 8 | * Title 17, U.S. Code. All Other Rights Reserved. 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * In accordance with the GNU General Public License Version 3, 29 June 2007 21 | * (GPL V3) Section 7. Additional Terms, Additional Permissions are added as 22 | * exceptions to the terms of the GPL V3 for this program. These additional 23 | * terms should have been received with this program in a file entitled 24 | * "ADDITIONAL_LICENSE_TERMS". If a copy was not provided, you may request 25 | * one from the contact author listed below. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | * 30 | * Contact: Joseph Rios 31 | * 32 | **************************************************************************** */ 33 | 34 | /* 35 | * phases.h 36 | * 37 | * Created on: Jun 3, 2009 38 | * Author: jrios 39 | */ 40 | 41 | #ifndef PHASES_H_ 42 | #define PHASES_H_ 43 | 44 | int phase_1_iteration(subprob_struct* sub_data, faux_globals*, int first_run, 45 | char** obj_names, double* obj_coefs, int* obj_count, master_data*); 46 | 47 | int phase_2_iteration(subprob_struct* sub_data, faux_globals*, master_data*) ; 48 | 49 | #endif /* PHASES_H_ */ 50 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | Change log for DWSOLVER. 2 | 3 | -------------------------------------------------------------------------------- 4 | - Version 1.2 5 | - Released October 22, 2010 6 | - Contact Joseph.L.Rios@nasa.gov 7 | -------------------------------------------------------------------------------- 8 | 9 | Found and fixed a memory allocation error in the subproblem thread. Error 10 | was only visible when there were more rows in the master problem than there 11 | were variables in a given subproblem. None of the prior examples exhibited this 12 | behavior. 13 | 14 | Added command line option to enforce integral constraints in the subproblems. 15 | This is important if experimenting with the integerization heuristic (-i flag). 16 | 17 | Added some comments throughout. 18 | 19 | -------------------------------------------------------------------------------- 20 | - Version 1.1 21 | - Released October 15, 2010 22 | - Contact Joseph.L.Rios@nasa.gov 23 | -------------------------------------------------------------------------------- 24 | 25 | Fixed distribution package which was missing a header file. Added automatic 26 | detection of OSX build so that the --enable-named-semaphores flag is now not 27 | necessary when building on Mac (it will be set automatically). 28 | 29 | 30 | -------------------------------------------------------------------------------- 31 | - Version 1.0 32 | - Released September 8, 2010 33 | - Contact Joseph.L.Rios@nasa.gov 34 | -------------------------------------------------------------------------------- 35 | 36 | Initial release. Dantzig-Wolfe Solver (DWSOLVER) is a general, parallel 37 | implementation of the Dantzig-Wolfe Decomposition algorithm built upon the 38 | GNU Linear Programming Kit (GLPK). This is a command-line only tool. All 39 | input and output is file-based. The user must supply a decomposed linear 40 | program as input. For details, execute "dwsolver --help". For examples, see 41 | the "examples" directory. Current major limitations include the necessity of 42 | bounded subproblems, necessity of every master variable appearing in exactly 43 | one subproblem. For a large number of problems, these are not major issues. 44 | For other problems, there are some workarounds as described in the examples. -------------------------------------------------------------------------------- /src/amd/amd_control.c: -------------------------------------------------------------------------------- 1 | /* ========================================================================= */ 2 | /* === AMD_control ========================================================= */ 3 | /* ========================================================================= */ 4 | 5 | /* ------------------------------------------------------------------------- */ 6 | /* AMD, Copyright (c) Timothy A. Davis, */ 7 | /* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ 8 | /* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */ 9 | /* web: http://www.cise.ufl.edu/research/sparse/amd */ 10 | /* ------------------------------------------------------------------------- */ 11 | 12 | /* User-callable. Prints the control parameters for AMD. See amd.h 13 | * for details. If the Control array is not present, the defaults are 14 | * printed instead. 15 | */ 16 | 17 | #include "amd_internal.h" 18 | 19 | GLOBAL void AMD_control 20 | ( 21 | double Control [ ] 22 | ) 23 | { 24 | double alpha ; 25 | Int aggressive ; 26 | 27 | if (Control != (double *) NULL) 28 | { 29 | alpha = Control [AMD_DENSE] ; 30 | aggressive = Control [AMD_AGGRESSIVE] != 0 ; 31 | } 32 | else 33 | { 34 | alpha = AMD_DEFAULT_DENSE ; 35 | aggressive = AMD_DEFAULT_AGGRESSIVE ; 36 | } 37 | 38 | PRINTF (("\nAMD version %d.%d.%d, %s: approximate minimum degree ordering\n" 39 | " dense row parameter: %g\n", AMD_MAIN_VERSION, AMD_SUB_VERSION, 40 | AMD_SUBSUB_VERSION, AMD_DATE, alpha)) ; 41 | 42 | if (alpha < 0) 43 | { 44 | PRINTF ((" no rows treated as dense\n")) ; 45 | } 46 | else 47 | { 48 | PRINTF (( 49 | " (rows with more than max (%g * sqrt (n), 16) entries are\n" 50 | " considered \"dense\", and placed last in output permutation)\n", 51 | alpha)) ; 52 | } 53 | 54 | if (aggressive) 55 | { 56 | PRINTF ((" aggressive absorption: yes\n")) ; 57 | } 58 | else 59 | { 60 | PRINTF ((" aggressive absorption: no\n")) ; 61 | } 62 | 63 | PRINTF ((" size of AMD integer: %d\n\n", sizeof (Int))) ; 64 | } 65 | -------------------------------------------------------------------------------- /src/glpsql.h: -------------------------------------------------------------------------------- 1 | /* glpsql.h */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Author: Heinrich Schuchardt . 7 | * 8 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 9 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 10 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 11 | * E-mail: . 12 | * 13 | * GLPK is free software: you can redistribute it and/or modify it 14 | * under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation, either version 3 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 19 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 21 | * License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with GLPK. If not, see . 25 | ***********************************************************************/ 26 | 27 | #ifndef GLPSQL_H 28 | #define GLPSQL_H 29 | 30 | #define db_iodbc_open _glp_db_iodbc_open 31 | void *db_iodbc_open(TABDCA *dca, int mode); 32 | /* open iODBC database connection */ 33 | 34 | #define db_iodbc_read _glp_db_iodbc_read 35 | int db_iodbc_read(TABDCA *dca, void *link); 36 | /* read data from iODBC */ 37 | 38 | #define db_iodbc_write _glp_db_iodbc_write 39 | int db_iodbc_write(TABDCA *dca, void *link); 40 | /* write data to iODBC */ 41 | 42 | #define db_iodbc_close _glp_db_iodbc_close 43 | int db_iodbc_close(TABDCA *dca, void *link); 44 | /* close iODBC database connection */ 45 | 46 | #define db_mysql_open _glp_db_mysql_open 47 | void *db_mysql_open(TABDCA *dca, int mode); 48 | /* open MySQL database connection */ 49 | 50 | #define db_mysql_read _glp_db_mysql_read 51 | int db_mysql_read(TABDCA *dca, void *link); 52 | /* read data from MySQL */ 53 | 54 | #define db_mysql_write _glp_db_mysql_write 55 | int db_mysql_write(TABDCA *dca, void *link); 56 | /* write data to MySQL */ 57 | 58 | #define db_mysql_close _glp_db_mysql_close 59 | int db_mysql_close(TABDCA *dca, void *link); 60 | /* close MySQL database connection */ 61 | 62 | #endif 63 | 64 | /* eof */ 65 | -------------------------------------------------------------------------------- /src/colamd/colamd.h: -------------------------------------------------------------------------------- 1 | /* colamd.h */ 2 | 3 | /* Written by Andrew Makhorin . */ 4 | 5 | #ifndef COLAMD_H 6 | #define COLAMD_H 7 | 8 | #define _GLPSTD_STDIO 9 | #include "glpenv.h" 10 | 11 | #define COLAMD_DATE "Nov 1, 2007" 12 | #define COLAMD_VERSION_CODE(main, sub) ((main) * 1000 + (sub)) 13 | #define COLAMD_MAIN_VERSION 2 14 | #define COLAMD_SUB_VERSION 7 15 | #define COLAMD_SUBSUB_VERSION 1 16 | #define COLAMD_VERSION \ 17 | COLAMD_VERSION_CODE(COLAMD_MAIN_VERSION, COLAMD_SUB_VERSION) 18 | 19 | #define COLAMD_KNOBS 20 20 | #define COLAMD_STATS 20 21 | #define COLAMD_DENSE_ROW 0 22 | #define COLAMD_DENSE_COL 1 23 | #define COLAMD_AGGRESSIVE 2 24 | #define COLAMD_DEFRAG_COUNT 2 25 | #define COLAMD_STATUS 3 26 | #define COLAMD_INFO1 4 27 | #define COLAMD_INFO2 5 28 | #define COLAMD_INFO3 6 29 | 30 | #define COLAMD_OK (0) 31 | #define COLAMD_OK_BUT_JUMBLED (1) 32 | #define COLAMD_ERROR_A_not_present (-1) 33 | #define COLAMD_ERROR_p_not_present (-2) 34 | #define COLAMD_ERROR_nrow_negative (-3) 35 | #define COLAMD_ERROR_ncol_negative (-4) 36 | #define COLAMD_ERROR_nnz_negative (-5) 37 | #define COLAMD_ERROR_p0_nonzero (-6) 38 | #define COLAMD_ERROR_A_too_small (-7) 39 | #define COLAMD_ERROR_col_length_negative (-8) 40 | #define COLAMD_ERROR_row_index_out_of_bounds (-9) 41 | #define COLAMD_ERROR_out_of_memory (-10) 42 | #define COLAMD_ERROR_internal_error (-999) 43 | 44 | #define colamd_recommended _glp_colamd_recommended 45 | size_t colamd_recommended(int nnz, int n_row, int n_col); 46 | 47 | #define colamd_set_defaults _glp_colamd_set_defaults 48 | void colamd_set_defaults(double knobs [COLAMD_KNOBS]); 49 | 50 | #define colamd _glp_colamd 51 | int colamd(int n_row, int n_col, int Alen, int A[], int p[], 52 | double knobs[COLAMD_KNOBS], int stats[COLAMD_STATS]); 53 | 54 | #define symamd _glp_symamd 55 | int symamd(int n, int A[], int p[], int perm[], 56 | double knobs[COLAMD_KNOBS], int stats[COLAMD_STATS], 57 | void *(*allocate)(size_t, size_t), void(*release)(void *)); 58 | 59 | #define colamd_report _glp_colamd_report 60 | void colamd_report(int stats[COLAMD_STATS]); 61 | 62 | #define symamd_report _glp_symamd_report 63 | void symamd_report(int stats[COLAMD_STATS]); 64 | 65 | #define colamd_printf xprintf 66 | 67 | #endif 68 | 69 | /* eof */ 70 | -------------------------------------------------------------------------------- /src/glpenv02.c: -------------------------------------------------------------------------------- 1 | /* glpenv02.c (thread local storage) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #include "glpenv.h" 26 | 27 | static void *tls = NULL; 28 | /* in a re-entrant version of the package this variable must be placed 29 | in the Thread Local Storage (TLS) */ 30 | 31 | /*********************************************************************** 32 | * NAME 33 | * 34 | * tls_set_ptr - store global pointer in TLS 35 | * 36 | * SYNOPSIS 37 | * 38 | * #include "glpenv.h" 39 | * void tls_set_ptr(void *ptr); 40 | * 41 | * DESCRIPTION 42 | * 43 | * The routine tls_set_ptr stores a pointer specified by the parameter 44 | * ptr in the Thread Local Storage (TLS). */ 45 | 46 | void tls_set_ptr(void *ptr) 47 | { tls = ptr; 48 | return; 49 | } 50 | 51 | /*********************************************************************** 52 | * NAME 53 | * 54 | * tls_get_ptr - retrieve global pointer from TLS 55 | * 56 | * SYNOPSIS 57 | * 58 | * #include "glpenv.h" 59 | * void *tls_get_ptr(void); 60 | * 61 | * RETURNS 62 | * 63 | * The routine tls_get_ptr returns a pointer previously stored by the 64 | * routine tls_set_ptr. If the latter has not been called yet, NULL is 65 | * returned. */ 66 | 67 | void *tls_get_ptr(void) 68 | { void *ptr; 69 | ptr = tls; 70 | return ptr; 71 | } 72 | 73 | /* eof */ 74 | -------------------------------------------------------------------------------- /src/dw_blas.h: -------------------------------------------------------------------------------- 1 | /* ***************************************************************************** 2 | * 3 | * DWSOLVER - a general, parallel implementation of the Dantzig-Wolfe 4 | * Decomposition algorithm. 5 | * 6 | * Copyright 2010 United States Government National Aeronautics and Space 7 | * Administration (NASA). No copyright is claimed in the United States under 8 | * Title 17, U.S. Code. All Other Rights Reserved. 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * In accordance with the GNU General Public License Version 3, 29 June 2007 21 | * (GPL V3) Section 7. Additional Terms, Additional Permissions are added as 22 | * exceptions to the terms of the GPL V3 for this program. These additional 23 | * terms should have been received with this program in a file entitled 24 | * "ADDITIONAL_LICENSE_TERMS". If a copy was not provided, you may request 25 | * one from the contact author listed below. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | * 30 | * Contact: Joseph Rios 31 | * 32 | **************************************************************************** */ 33 | 34 | /* 35 | * dw_blas.h 36 | * 37 | * Created on: Sep 2, 2009 38 | * Author: jrios 39 | */ 40 | 41 | #ifndef DW_BLAS_H_ 42 | #define DW_BLAS_H_ 43 | 44 | void dw_daxpy(const int len, const double alpha, const double* x, double* y); 45 | double dw_ddot(const int len, const double* x, const double* y); 46 | double dw_ddoti(const int nz, const double* x, const int* ind_x, 47 | const double* y); 48 | void dw_dcopy(const int len, const double* x, double* y); 49 | void dw_dcoogemv(const int m, const int k, const double *val, 50 | const int *indx, const int *jndx, const int nnz, const double *b, 51 | double *c); 52 | 53 | #endif /* DW_BLAS_H_ */ 54 | -------------------------------------------------------------------------------- /src/glpqmd.h: -------------------------------------------------------------------------------- 1 | /* glpqmd.h (quotient minimum degree algorithm) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifndef GLPQMD_H 26 | #define GLPQMD_H 27 | 28 | #define genqmd _glp_qmd_genqmd 29 | void genqmd(int *neqns, int xadj[], int adjncy[], int perm[], 30 | int invp[], int deg[], int marker[], int rchset[], int nbrhd[], 31 | int qsize[], int qlink[], int *nofsub); 32 | /* GENeral Quotient Minimum Degree algorithm */ 33 | 34 | #define qmdrch _glp_qmd_qmdrch 35 | void qmdrch(int *root, int xadj[], int adjncy[], int deg[], 36 | int marker[], int *rchsze, int rchset[], int *nhdsze, 37 | int nbrhd[]); 38 | /* Quotient MD ReaCHable set */ 39 | 40 | #define qmdqt _glp_qmd_qmdqt 41 | void qmdqt(int *root, int xadj[], int adjncy[], int marker[], 42 | int *rchsze, int rchset[], int nbrhd[]); 43 | /* Quotient MD Quotient graph Transformation */ 44 | 45 | #define qmdupd _glp_qmd_qmdupd 46 | void qmdupd(int xadj[], int adjncy[], int *nlist, int list[], 47 | int deg[], int qsize[], int qlink[], int marker[], int rchset[], 48 | int nbrhd[]); 49 | /* Quotient MD UPDate */ 50 | 51 | #define qmdmrg _glp_qmd_qmdmrg 52 | void qmdmrg(int xadj[], int adjncy[], int deg[], int qsize[], 53 | int qlink[], int marker[], int *deg0, int *nhdsze, int nbrhd[], 54 | int rchset[], int ovrlp[]); 55 | /* Quotient MD MeRGe */ 56 | 57 | #endif 58 | 59 | /* eof */ 60 | -------------------------------------------------------------------------------- /src/glpnet.h: -------------------------------------------------------------------------------- 1 | /* glpnet.h (graph and network algorithms) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifndef GLPNET_H 26 | #define GLPNET_H 27 | 28 | #define mc21a _glp_mc21a 29 | int mc21a(int n, const int icn[], const int ip[], const int lenr[], 30 | int iperm[], int pr[], int arp[], int cv[], int out[]); 31 | /* permutations for zero-free diagonal */ 32 | 33 | #define mc13d _glp_mc13d 34 | int mc13d(int n, const int icn[], const int ip[], const int lenr[], 35 | int ior[], int ib[], int lowl[], int numb[], int prev[]); 36 | /* permutations to block triangular form */ 37 | 38 | #define okalg _glp_okalg 39 | int okalg(int nv, int na, const int tail[], const int head[], 40 | const int low[], const int cap[], const int cost[], int x[], 41 | int pi[]); 42 | /* out-of-kilter algorithm */ 43 | 44 | #define ffalg _glp_ffalg 45 | void ffalg(int nv, int na, const int tail[], const int head[], 46 | int s, int t, const int cap[], int x[], char cut[]); 47 | /* Ford-Fulkerson algorithm */ 48 | 49 | #define wclique _glp_wclique 50 | int wclique(int n, const int w[], const unsigned char a[], int ind[]); 51 | /* find maximum weight clique with Ostergard's algorithm */ 52 | 53 | #define kellerman _glp_kellerman 54 | int kellerman(int n, int (*func)(void *info, int i, int ind[]), 55 | void *info, void /* glp_graph */ *H); 56 | /* cover edges by cliques with Kellerman's heuristic */ 57 | 58 | #endif 59 | 60 | /* eof */ 61 | -------------------------------------------------------------------------------- /src/glprng.h: -------------------------------------------------------------------------------- 1 | /* glprng.h (pseudo-random number generator) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifndef GLPRNG_H 26 | #define GLPRNG_H 27 | 28 | typedef struct RNG RNG; 29 | 30 | struct RNG 31 | { /* Knuth's portable pseudo-random number generator */ 32 | int A[56]; 33 | /* pseudo-random values */ 34 | int *fptr; 35 | /* the next A value to be exported */ 36 | }; 37 | 38 | #define rng_create_rand _glp_rng_create_rand 39 | RNG *rng_create_rand(void); 40 | /* create pseudo-random number generator */ 41 | 42 | #define rng_init_rand _glp_rng_init_rand 43 | void rng_init_rand(RNG *rand, int seed); 44 | /* initialize pseudo-random number generator */ 45 | 46 | #define rng_next_rand _glp_rng_next_rand 47 | int rng_next_rand(RNG *rand); 48 | /* obtain pseudo-random integer in the range [0, 2^31-1] */ 49 | 50 | #define rng_unif_rand _glp_rng_unif_rand 51 | int rng_unif_rand(RNG *rand, int m); 52 | /* obtain pseudo-random integer in the range [0, m-1] */ 53 | 54 | #define rng_delete_rand _glp_rng_delete_rand 55 | void rng_delete_rand(RNG *rand); 56 | /* delete pseudo-random number generator */ 57 | 58 | #define rng_unif_01 _glp_rng_unif_01 59 | double rng_unif_01(RNG *rand); 60 | /* obtain pseudo-random number in the range [0, 1] */ 61 | 62 | #define rng_uniform _glp_rng_uniform 63 | double rng_uniform(RNG *rand, double a, double b); 64 | /* obtain pseudo-random number in the range [a, b] */ 65 | 66 | #endif 67 | 68 | /* eof */ 69 | -------------------------------------------------------------------------------- /config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* N/A */ 4 | #undef HAVE_DLFCN 5 | 6 | /* Define to 1 if you have the header file. */ 7 | #undef HAVE_DLFCN_H 8 | 9 | /* N/A */ 10 | #undef HAVE_GETTIMEOFDAY 11 | 12 | /* N/A */ 13 | #undef HAVE_GMP 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_INTTYPES_H 17 | 18 | /* Define to 1 if you have the 'm' library (-lm). */ 19 | #undef HAVE_LIBM 20 | 21 | /* Define to 1 if you have the 'pthread' library (-lpthread). */ 22 | #undef HAVE_LIBPTHREAD 23 | 24 | /* N/A */ 25 | #undef HAVE_LTDL 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #undef HAVE_STDINT_H 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #undef HAVE_STDIO_H 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #undef HAVE_STDLIB_H 35 | 36 | /* Define to 1 if you have the header file. */ 37 | #undef HAVE_STRINGS_H 38 | 39 | /* Define to 1 if you have the header file. */ 40 | #undef HAVE_STRING_H 41 | 42 | /* Define to 1 if you have the header file. */ 43 | #undef HAVE_SYS_STAT_H 44 | 45 | /* N/A */ 46 | #undef HAVE_SYS_TIME_H 47 | 48 | /* Define to 1 if you have the header file. */ 49 | #undef HAVE_SYS_TYPES_H 50 | 51 | /* Define to 1 if you have the header file. */ 52 | #undef HAVE_UNISTD_H 53 | 54 | /* N/A */ 55 | #undef HAVE_ZLIB 56 | 57 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 58 | */ 59 | #undef LT_OBJDIR 60 | 61 | /* N/A */ 62 | #undef MYSQL_DLNAME 63 | 64 | /* N/A */ 65 | #undef ODBC_DLNAME 66 | 67 | /* Name of package */ 68 | #undef PACKAGE 69 | 70 | /* Define to the address where bug reports for this package should be sent. */ 71 | #undef PACKAGE_BUGREPORT 72 | 73 | /* Define to the full name of this package. */ 74 | #undef PACKAGE_NAME 75 | 76 | /* Define to the full name and version of this package. */ 77 | #undef PACKAGE_STRING 78 | 79 | /* Define to the one symbol short name of this package. */ 80 | #undef PACKAGE_TARNAME 81 | 82 | /* Define to the home page for this package. */ 83 | #undef PACKAGE_URL 84 | 85 | /* Define to the version of this package. */ 86 | #undef PACKAGE_VERSION 87 | 88 | /* Define to 1 if all of the C89 standard headers exist (not just the ones 89 | required in a freestanding environment). This macro is provided for 90 | backward compatibility; new code need not use it. */ 91 | #undef STDC_HEADERS 92 | 93 | /* Version number of package */ 94 | #undef VERSION 95 | -------------------------------------------------------------------------------- /src/glprng02.c: -------------------------------------------------------------------------------- 1 | /* glprng02.c */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #include "glpenv.h" 26 | #include "glprng.h" 27 | #define xfault xerror 28 | 29 | /*********************************************************************** 30 | * NAME 31 | * 32 | * rng_unif_01 - obtain pseudo-random number in the range [0, 1] 33 | * 34 | * SYNOPSIS 35 | * 36 | * #include "glprng.h" 37 | * double rng_unif_01(RNG *rand); 38 | * 39 | * RETURNS 40 | * 41 | * The routine rng_unif_01 returns a next pseudo-random number which is 42 | * uniformly distributed in the range [0, 1]. */ 43 | 44 | double rng_unif_01(RNG *rand) 45 | { double x; 46 | x = (double)rng_next_rand(rand) / 2147483647.0; 47 | xassert(0.0 <= x && x <= 1.0); 48 | return x; 49 | } 50 | 51 | /*********************************************************************** 52 | * NAME 53 | * 54 | * rng_uniform - obtain pseudo-random number in the range [a, b] 55 | * 56 | * SYNOPSIS 57 | * 58 | * #include "glprng.h" 59 | * double rng_uniform(RNG *rand, double a, double b); 60 | * 61 | * RETURNS 62 | * 63 | * The routine rng_uniform returns a next pseudo-random number which is 64 | * uniformly distributed in the range [a, b]. */ 65 | 66 | double rng_uniform(RNG *rand, double a, double b) 67 | { double x; 68 | if (a >= b) 69 | xfault("rng_uniform: a = %g, b = %g; invalid range\n", a, b); 70 | x = rng_unif_01(rand); 71 | x = a * (1.0 - x) + b * x; 72 | xassert(a <= x && x <= b); 73 | return x; 74 | } 75 | 76 | /* eof */ 77 | -------------------------------------------------------------------------------- /src/glpbfx.h: -------------------------------------------------------------------------------- 1 | /* glpbfx.h (basis factorization interface, bignum arithmetic) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifndef GLPBFX_H 26 | #define GLPBFX_H 27 | 28 | #include "glpgmp.h" 29 | 30 | #ifndef GLPBFX_DEFINED 31 | #define GLPBFX_DEFINED 32 | typedef struct { double _opaque_bfx; } BFX; 33 | #endif 34 | 35 | #define bfx_create_binv _glp_bfx_create_binv 36 | #define bfx_is_valid _glp_bfx_is_valid 37 | #define bfx_invalidate _glp_bfx_invalidate 38 | #define bfx_factorize _glp_bfx_factorize 39 | #define bfx_ftran _glp_bfx_ftran 40 | #define bfx_btran _glp_bfx_btran 41 | #define bfx_update _glp_bfx_update 42 | #define bfx_delete_binv _glp_bfx_delete_binv 43 | 44 | BFX *bfx_create_binv(void); 45 | /* create factorization of the basis matrix */ 46 | 47 | int bfx_is_valid(BFX *binv); 48 | /* check if factorization is valid */ 49 | 50 | void bfx_invalidate(BFX *binv); 51 | /* invalidate factorization of the basis matrix */ 52 | 53 | int bfx_factorize(BFX *binv, int m, int (*col)(void *info, int j, 54 | int ind[], mpq_t val[]), void *info); 55 | /* compute factorization of the basis matrix */ 56 | 57 | void bfx_ftran(BFX *binv, mpq_t x[], int save); 58 | /* perform forward transformation (FTRAN) */ 59 | 60 | void bfx_btran(BFX *binv, mpq_t x[]); 61 | /* perform backward transformation (BTRAN) */ 62 | 63 | int bfx_update(BFX *binv, int j); 64 | /* update factorization of the basis matrix */ 65 | 66 | void bfx_delete_binv(BFX *binv); 67 | /* delete factorization of the basis matrix */ 68 | 69 | #endif 70 | 71 | /* eof */ 72 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in ## 2 | 3 | #INCLUDES = -I$(srcdir)/../include 4 | 5 | bin_PROGRAMS = dwsolver 6 | 7 | dwsolver_SOURCES = \ 8 | glpapi01.c \ 9 | glpapi02.c \ 10 | glpapi03.c \ 11 | glpapi04.c \ 12 | glpapi05.c \ 13 | glpapi06.c \ 14 | glpapi07.c \ 15 | glpapi08.c \ 16 | glpapi09.c \ 17 | glpapi10.c \ 18 | glpapi11.c \ 19 | glpapi12.c \ 20 | glpapi13.c \ 21 | glpapi14.c \ 22 | glpapi15.c \ 23 | glpapi16.c \ 24 | glpapi17.c \ 25 | glpapi18.c \ 26 | glpapi19.c \ 27 | glpavl.c \ 28 | glpbfd.c \ 29 | glpbfx.c \ 30 | glpcpx.c \ 31 | glpdmp.c \ 32 | glpdmx.c \ 33 | glpenv01.c \ 34 | glpenv02.c \ 35 | glpenv03.c \ 36 | glpenv04.c \ 37 | glpenv05.c \ 38 | glpenv06.c \ 39 | glpenv07.c \ 40 | glpenv08.c \ 41 | glpfhv.c \ 42 | glpgmp.c \ 43 | glphbm.c \ 44 | glpini01.c \ 45 | glpini02.c \ 46 | glpios01.c \ 47 | glpios02.c \ 48 | glpios03.c \ 49 | glpios04.c \ 50 | glpios05.c \ 51 | glpios06.c \ 52 | glpios07.c \ 53 | glpios08.c \ 54 | glpios09.c \ 55 | glpios10.c \ 56 | glpios11.c \ 57 | glpios12.c \ 58 | glpipm.c \ 59 | glplib01.c \ 60 | glplib02.c \ 61 | glplib03.c \ 62 | glplpf.c \ 63 | glplpx01.c \ 64 | glplpx02.c \ 65 | glplpx03.c \ 66 | glpluf.c \ 67 | glplux.c \ 68 | glpmat.c \ 69 | glpmpl01.c \ 70 | glpmpl02.c \ 71 | glpmpl03.c \ 72 | glpmpl04.c \ 73 | glpmpl05.c \ 74 | glpmpl06.c \ 75 | glpmps.c \ 76 | glpnet01.c \ 77 | glpnet02.c \ 78 | glpnet03.c \ 79 | glpnet04.c \ 80 | glpnet05.c \ 81 | glpnet06.c \ 82 | glpnet07.c \ 83 | glpnet08.c \ 84 | glpnet09.c \ 85 | glpnpp01.c \ 86 | glpnpp02.c \ 87 | glpnpp03.c \ 88 | glpnpp04.c \ 89 | glpnpp05.c \ 90 | glpqmd.c \ 91 | glprgr.c \ 92 | glprng01.c \ 93 | glprng02.c \ 94 | glpscf.c \ 95 | glpscl.c \ 96 | glpsdf.c \ 97 | glpspm.c \ 98 | glpspx01.c \ 99 | glpspx02.c \ 100 | glpsql.c \ 101 | glpssx01.c \ 102 | glpssx02.c \ 103 | glptsp.c \ 104 | amd/amd_1.c \ 105 | amd/amd_2.c \ 106 | amd/amd_aat.c \ 107 | amd/amd_control.c \ 108 | amd/amd_defaults.c \ 109 | amd/amd_dump.c \ 110 | amd/amd_info.c \ 111 | amd/amd_order.c \ 112 | amd/amd_post_tree.c \ 113 | amd/amd_postorder.c \ 114 | amd/amd_preprocess.c \ 115 | amd/amd_valid.c \ 116 | colamd/colamd.c \ 117 | dw_blas.c \ 118 | dw_support.c \ 119 | dw_phases.c \ 120 | dw_subprob.c \ 121 | dw_rounding.c \ 122 | dw_main.c 123 | 124 | dwsolver_CFLAGS = $(AM_CFLAGS) 125 | 126 | EXTRA_DIST = amd/amd.h amd/amd_internal.h colamd/colamd.h \ 127 | dw_blas.h glpapi.h glpfhv.h glplib.h glpnet.h glpspm.h \ 128 | dw.h glpavl.h glpgmp.h glplpf.h glpnpp.h glpspx.h \ 129 | dw_phases.h glpbfd.h glphbm.h glpluf.h glpqmd.h glpsql.h \ 130 | dw_rounding.h glpbfx.h glpios.h glplux.h glprgr.h glpssx.h \ 131 | dw_subprob.h glpdmp.h glpipm.h glpmat.h glprng.h glpstd.h \ 132 | dw_support.h glpenv.h glpmpl.h glpscf.h glptsp.h glpk.h 133 | 134 | ## eof ## 135 | -------------------------------------------------------------------------------- /src/glpbfd.h: -------------------------------------------------------------------------------- 1 | /* glpbfd.h (LP basis factorization driver) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifndef GLPBFD_H 26 | #define GLPBFD_H 27 | 28 | #ifndef GLPBFD_PRIVATE 29 | typedef struct { double _opaque_bfd[100]; } BFD; 30 | #endif 31 | 32 | /* return codes: */ 33 | #define BFD_ESING 1 /* singular matrix */ 34 | #define BFD_ECOND 2 /* ill-conditioned matrix */ 35 | #define BFD_ECHECK 3 /* insufficient accuracy */ 36 | #define BFD_ELIMIT 4 /* update limit reached */ 37 | #define BFD_EROOM 5 /* SVA overflow */ 38 | 39 | #define bfd_create_it _glp_bfd_create_it 40 | BFD *bfd_create_it(void); 41 | /* create LP basis factorization */ 42 | 43 | #define bfd_set_parm _glp_bfd_set_parm 44 | void bfd_set_parm(BFD *bfd, const void *parm); 45 | /* change LP basis factorization control parameters */ 46 | 47 | #define bfd_factorize _glp_bfd_factorize 48 | int bfd_factorize(BFD *bfd, int m, const int bh[], int (*col) 49 | (void *info, int j, int ind[], double val[]), void *info); 50 | /* compute LP basis factorization */ 51 | 52 | #define bfd_ftran _glp_bfd_ftran 53 | void bfd_ftran(BFD *bfd, double x[]); 54 | /* perform forward transformation (solve system B*x = b) */ 55 | 56 | #define bfd_btran _glp_bfd_btran 57 | void bfd_btran(BFD *bfd, double x[]); 58 | /* perform backward transformation (solve system B'*x = b) */ 59 | 60 | #define bfd_update_it _glp_bfd_update_it 61 | int bfd_update_it(BFD *bfd, int j, int bh, int len, const int ind[], 62 | const double val[]); 63 | /* update LP basis factorization */ 64 | 65 | #define bfd_get_count _glp_bfd_get_count 66 | int bfd_get_count(BFD *bfd); 67 | /* determine factorization update count */ 68 | 69 | #define bfd_delete_it _glp_bfd_delete_it 70 | void bfd_delete_it(BFD *bfd); 71 | /* delete LP basis factorization */ 72 | 73 | #endif 74 | 75 | /* eof */ 76 | -------------------------------------------------------------------------------- /src/dw_rounding.h: -------------------------------------------------------------------------------- 1 | /* ***************************************************************************** 2 | * 3 | * DWSOLVER - a general, parallel implementation of the Dantzig-Wolfe 4 | * Decomposition algorithm. 5 | * 6 | * Copyright 2010 United States Government National Aeronautics and Space 7 | * Administration (NASA). No copyright is claimed in the United States under 8 | * Title 17, U.S. Code. All Other Rights Reserved. 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * In accordance with the GNU General Public License Version 3, 29 June 2007 21 | * (GPL V3) Section 7. Additional Terms, Additional Permissions are added as 22 | * exceptions to the terms of the GPL V3 for this program. These additional 23 | * terms should have been received with this program in a file entitled 24 | * "ADDITIONAL_LICENSE_TERMS". If a copy was not provided, you may request 25 | * one from the contact author listed below. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | * 30 | * Contact: Joseph Rios 31 | * 32 | **************************************************************************** */ 33 | 34 | /* 35 | * dw_rounding.h 36 | * 37 | * Created on: Dec 15, 2008 38 | * Author: jrios 39 | */ 40 | 41 | #ifndef ROUNDING_H_ 42 | #define ROUNDING_H_ 43 | 44 | #define DW_MODE_PRINT_RELAXED 91 45 | #define DW_MODE_ROUND_SOL 92 46 | #define DW_MODE_INT_SOL 93 47 | 48 | typedef struct solution_info sol_info; 49 | 50 | #define ROUNDED_ZEROS_FILE "zeros_rounded" 51 | #define INTEGERIZED_ZEROS_FILE "integerized_zeros" 52 | #define RELAXED_SOLN_FILE "relaxed_solution" 53 | 54 | struct solution_info { 55 | int subprob; 56 | int iteration; 57 | double value; 58 | sol_info* next; 59 | }; 60 | 61 | typedef struct { 62 | sol_info* si; 63 | int num_si; 64 | int id; 65 | FILE* zero_file; 66 | subprob_struct sub_data; 67 | } int_thread_data; 68 | 69 | void* rounding_thread(void* arg) ; 70 | void* solution_printing_thread(void* arg) ; 71 | void check_broken_constraints(); 72 | void print_zeros(int_thread_data*); 73 | void print_zeros_simple(int_thread_data*); 74 | int round_solution(subprob_struct* sub_data, char* zero_file_name); 75 | int process_solution(subprob_struct* sub_data, char* out_file_name, int mode); 76 | 77 | #endif /* ROUNDING_H_ */ 78 | -------------------------------------------------------------------------------- /src/glpbfx.c: -------------------------------------------------------------------------------- 1 | /* glpbfx.c */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | typedef struct BFX BFX; 26 | #define GLPBFX_DEFINED 27 | #include "glpbfx.h" 28 | #include "glpenv.h" 29 | #include "glplux.h" 30 | 31 | struct BFX 32 | { int valid; 33 | LUX *lux; 34 | }; 35 | 36 | BFX *bfx_create_binv(void) 37 | { /* create factorization of the basis matrix */ 38 | BFX *bfx; 39 | bfx = xmalloc(sizeof(BFX)); 40 | bfx->valid = 0; 41 | bfx->lux = NULL; 42 | return bfx; 43 | } 44 | 45 | int bfx_factorize(BFX *binv, int m, int (*col)(void *info, int j, 46 | int ind[], mpq_t val[]), void *info) 47 | { /* compute factorization of the basis matrix */ 48 | int ret; 49 | xassert(m > 0); 50 | if (binv->lux != NULL && binv->lux->n != m) 51 | { lux_delete(binv->lux); 52 | binv->lux = NULL; 53 | } 54 | if (binv->lux == NULL) 55 | binv->lux = lux_create(m); 56 | ret = lux_decomp(binv->lux, col, info); 57 | binv->valid = (ret == 0); 58 | return ret; 59 | } 60 | 61 | void bfx_ftran(BFX *binv, mpq_t x[], int save) 62 | { /* perform forward transformation (FTRAN) */ 63 | xassert(binv->valid); 64 | lux_solve(binv->lux, 0, x); 65 | xassert(save == save); 66 | return; 67 | } 68 | 69 | void bfx_btran(BFX *binv, mpq_t x[]) 70 | { /* perform backward transformation (BTRAN) */ 71 | xassert(binv->valid); 72 | lux_solve(binv->lux, 1, x); 73 | return; 74 | } 75 | 76 | int bfx_update(BFX *binv, int j) 77 | { /* update factorization of the basis matrix */ 78 | xassert(binv->valid); 79 | xassert(1 <= j && j <= binv->lux->n); 80 | return 1; 81 | } 82 | 83 | void bfx_delete_binv(BFX *binv) 84 | { /* delete factorization of the basis matrix */ 85 | if (binv->lux != NULL) 86 | lux_delete(binv->lux); 87 | xfree(binv); 88 | return; 89 | } 90 | 91 | /* eof */ 92 | -------------------------------------------------------------------------------- /src/glpdmp.h: -------------------------------------------------------------------------------- 1 | /* glpdmp.h (dynamic memory pool) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifndef GLPDMP_H 26 | #define GLPDMP_H 27 | 28 | #include "glpenv.h" 29 | 30 | typedef struct DMP DMP; 31 | 32 | #define DMP_BLK_SIZE 8000 33 | /* size of memory blocks, in bytes, allocated for memory pools */ 34 | 35 | struct DMP 36 | { /* dynamic memory pool */ 37 | #if 0 38 | int size; 39 | /* size of atoms, in bytes, 1 <= size <= 256; if size = 0, atoms 40 | may have different sizes */ 41 | #endif 42 | void *avail[32]; 43 | /* avail[k], 0 <= k <= 31, is a pointer to the first available 44 | (free) cell of (k+1)*8 bytes long; in the beginning of each 45 | free cell there is a pointer to another free cell of the same 46 | length */ 47 | void *block; 48 | /* pointer to the most recently allocated memory block; in the 49 | beginning of each allocated memory block there is a pointer to 50 | the previously allocated memory block */ 51 | int used; 52 | /* number of bytes used in the most recently allocated memory 53 | block */ 54 | glp_long count; 55 | /* number of atoms which are currently in use */ 56 | }; 57 | 58 | #define dmp_create_pool _glp_dmp_create_pool 59 | DMP *dmp_create_pool(void); 60 | /* create dynamic memory pool */ 61 | 62 | #define dmp_get_atom _glp_dmp_get_atom 63 | void *dmp_get_atom(DMP *pool, int size); 64 | /* get free atom from dynamic memory pool */ 65 | 66 | #define dmp_free_atom _glp_dmp_free_atom 67 | void dmp_free_atom(DMP *pool, void *atom, int size); 68 | /* return atom to dynamic memory pool */ 69 | 70 | #define dmp_in_use _glp_dmp_in_use 71 | glp_long dmp_in_use(DMP *pool); 72 | /* determine how many atoms are still in use */ 73 | 74 | #define dmp_delete_pool _glp_dmp_delete_pool 75 | void dmp_delete_pool(DMP *pool); 76 | /* delete dynamic memory pool */ 77 | 78 | #endif 79 | 80 | /* eof */ 81 | -------------------------------------------------------------------------------- /src/dw_support.h: -------------------------------------------------------------------------------- 1 | /* ***************************************************************************** 2 | * 3 | * DWSOLVER - a general, parallel implementation of the Dantzig-Wolfe 4 | * Decomposition algorithm. 5 | * 6 | * Copyright 2010 United States Government National Aeronautics and Space 7 | * Administration (NASA). No copyright is claimed in the United States under 8 | * Title 17, U.S. Code. All Other Rights Reserved. 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * In accordance with the GNU General Public License Version 3, 29 June 2007 21 | * (GPL V3) Section 7. Additional Terms, Additional Permissions are added as 22 | * exceptions to the terms of the GPL V3 for this program. These additional 23 | * terms should have been received with this program in a file entitled 24 | * "ADDITIONAL_LICENSE_TERMS". If a copy was not provided, you may request 25 | * one from the contact author listed below. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | * 30 | * Contact: Joseph Rios 31 | * 32 | **************************************************************************** */ 33 | 34 | /* 35 | * support_functions.h 36 | * 37 | * Created on: Jun 3, 2009 38 | * Author: jrios 39 | */ 40 | 41 | #ifndef SUPPORT_FUNCTIONS_H_ 42 | #define SUPPORT_FUNCTIONS_H_ 43 | 44 | //struct faux_globals; 45 | 46 | void solve(glp_prob *prob, glp_smcp *params, const char* solution_file); 47 | int process_cmdline(int argc, char* argv[], faux_globals*); 48 | void free_globals(faux_globals* fg, master_data* md); 49 | //int phase_1_iteration(subprob_struct* sub_data, int, char**, double*, int*); 50 | //int phase_2_iteration(subprob_struct* sub_data); 51 | void dw_printf(int,char*,...); 52 | void test_matrix_math(); 53 | void get_solution(); 54 | void print_timing( time_t start_time, clock_t start_clock ) ; 55 | void free_sub_data(subprob_struct* sub_data, faux_globals*) ; 56 | int check_col_integrality() ; 57 | void check_aux_vars(); 58 | void write_basis(int); 59 | void check_degeneracy(); 60 | void purge_nonbasics(); 61 | int dirty_feas_check(); 62 | void init_pthread_data(faux_globals*); 63 | void init_globals(faux_globals*); 64 | void init_signals(faux_globals*); 65 | void prepare_D(int, int*, double*); 66 | void prepare_md(master_data* md); 67 | void buffer_overflow(char* str, int len); 68 | int parse_zero_var(double value, int index, glp_prob* lp, FILE* zero_file); 69 | 70 | #endif /* SUPPORT_FUNCTIONS_H_ */ 71 | -------------------------------------------------------------------------------- /src/dw_subprob.h: -------------------------------------------------------------------------------- 1 | /* ***************************************************************************** 2 | * 3 | * DWSOLVER - a general, parallel implementation of the Dantzig-Wolfe 4 | * Decomposition algorithm. 5 | * 6 | * Copyright 2010 United States Government National Aeronautics and Space 7 | * Administration (NASA). No copyright is claimed in the United States under 8 | * Title 17, U.S. Code. All Other Rights Reserved. 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * In accordance with the GNU General Public License Version 3, 29 June 2007 21 | * (GPL V3) Section 7. Additional Terms, Additional Permissions are added as 22 | * exceptions to the terms of the GPL V3 for this program. These additional 23 | * terms should have been received with this program in a file entitled 24 | * "ADDITIONAL_LICENSE_TERMS". If a copy was not provided, you may request 25 | * one from the contact author listed below. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | * 30 | * Contact: Joseph Rios 31 | * 32 | **************************************************************************** */ 33 | 34 | #ifndef SUBPROB_THREAD_H_ 35 | #define SUBPROB_THREAD_H_ 36 | 37 | #define COMMAND_NULL 0 38 | #define COMMAND_GO 1 39 | #define COMMAND_STOP 2 40 | #define COMMAND_WAIT 3 41 | 42 | typedef struct { 43 | char* infile_name; 44 | int my_id; 45 | glp_prob* lp; 46 | glp_smcp *simplex_control_params; 47 | 48 | //glp_prob* master_read_only; 49 | 50 | int* col_translate; 51 | /* Other stuff relating to a subproblem... F, c, etc. */ 52 | pthread_mutex_t translate_ready_mutex; 53 | pthread_mutex_t objective_mutex; 54 | int translate_ready; 55 | 56 | int local_iteration; 57 | 58 | int phase_one; 59 | 60 | int* ind; 61 | double* val; 62 | int len; 63 | 64 | double* double_vector; 65 | 66 | int command; 67 | 68 | double** D; 69 | double* c; 70 | 71 | double* D_vals; 72 | int* D_row_coords; 73 | int* D_col_coords; 74 | int D_nnz; 75 | 76 | double* condensed_x; 77 | 78 | double* current_solution; 79 | 80 | int num_cols; 81 | int num_cols_plus; 82 | double r; 83 | double obj; 84 | double new_obj_coeff; 85 | 86 | int unbounded; 87 | 88 | faux_globals* globals; 89 | master_data* md; 90 | } subprob_struct; 91 | 92 | void* subproblem_thread(void* arg); 93 | int signal_availability(subprob_struct* my_data); 94 | void prepare_column(double*, double*, subprob_struct* data); 95 | void organize_solution(subprob_struct*, double*, int); 96 | void printD(); 97 | 98 | #endif /*SUBPROB_THREAD_H_*/ 99 | -------------------------------------------------------------------------------- /glpk-4.44.ThreadReady.patch: -------------------------------------------------------------------------------- 1 | --- /home/jrios/temp/glpk-4.44/src/glpenv05.c 2010-06-03 01:00:00.000000000 -0700 2 | +++ src/glpenv05.c 2010-07-01 16:43:08.000000000 -0700 3 | @@ -54,7 +54,7 @@ 4 | * To free this block the routine glp_free (not free!) must be used. */ 5 | 6 | void *glp_malloc(int size) 7 | -{ ENV *env = get_env_ptr(); 8 | +{ /*ENV *env = get_env_ptr(); 9 | MEM *desc; 10 | int size_of_desc = align_datasize(sizeof(MEM)); 11 | if (size < 1 || size > INT_MAX - size_of_desc) 12 | @@ -81,7 +81,8 @@ 13 | env->mem_total = xladd(env->mem_total, xlset(size)); 14 | if (xlcmp(env->mem_tpeak, env->mem_total) < 0) 15 | env->mem_tpeak = env->mem_total; 16 | - return (void *)((char *)desc + size_of_desc); 17 | + return (void *)((char *)desc + size_of_desc);*/ 18 | + return malloc(size); 19 | } 20 | 21 | /*********************************************************************** 22 | @@ -107,14 +108,15 @@ 23 | * To free this block the routine glp_free (not free!) must be used. */ 24 | 25 | void *glp_calloc(int n, int size) 26 | -{ if (n < 1) 27 | +{ /*if (n < 1) 28 | xerror("glp_calloc: n = %d; invalid parameter\n", n); 29 | if (size < 1) 30 | xerror("glp_calloc: size = %d; invalid parameter\n", size); 31 | if (n > INT_MAX / size) 32 | xerror("glp_calloc: n = %d; size = %d; array too big\n", n, 33 | size); 34 | - return xmalloc(n * size); 35 | + return xmalloc(n * size);*/ 36 | + return calloc(n, size); 37 | } 38 | 39 | /*********************************************************************** 40 | @@ -132,7 +134,7 @@ 41 | * was previuosly allocated by the routine glp_malloc or glp_calloc. */ 42 | 43 | void glp_free(void *ptr) 44 | -{ ENV *env = get_env_ptr(); 45 | +{ /*ENV *env = get_env_ptr(); 46 | MEM *desc; 47 | int size_of_desc = align_datasize(sizeof(MEM)); 48 | if (ptr == NULL) 49 | @@ -155,7 +157,8 @@ 50 | env->mem_total = xlsub(env->mem_total, xlset(desc->size)); 51 | memset(desc, '?', size_of_desc); 52 | free(desc); 53 | - return; 54 | + return;*/ 55 | + free(ptr); 56 | } 57 | 58 | /*********************************************************************** 59 | @@ -173,11 +176,13 @@ 60 | * dynamic allocation (in GLPK routines) to limit megabytes. */ 61 | 62 | void glp_mem_limit(int limit) 63 | -{ ENV *env = get_env_ptr(); 64 | +{ /*ENV *env = get_env_ptr(); 65 | if (limit < 0) 66 | xerror("glp_mem_limit: limit = %d; invalid parameter\n", 67 | limit); 68 | - env->mem_limit = xlmul(xlset(limit), xlset(1 << 20)); 69 | + env->mem_limit = xlmul(xlset(limit), xlset(1 << 20));*/ 70 | + printf("glp_mem_limit: not implemented in this version of glpk."); 71 | + printf(" Thread safety.\n"); 72 | return; 73 | } 74 | 75 | @@ -214,11 +219,13 @@ 76 | 77 | void glp_mem_usage(int *count, int *cpeak, glp_long *total, 78 | glp_long *tpeak) 79 | -{ ENV *env = get_env_ptr(); 80 | +{ /*ENV *env = get_env_ptr(); 81 | if (count != NULL) *count = env->mem_count; 82 | if (cpeak != NULL) *cpeak = env->mem_cpeak; 83 | if (total != NULL) *total = env->mem_total; 84 | - if (tpeak != NULL) *tpeak = env->mem_tpeak; 85 | + if (tpeak != NULL) *tpeak = env->mem_tpeak;*/ 86 | + printf("glp_mem_usage: not implemented in this version of glpk."); 87 | + printf(" Thread safety.\n"); 88 | return; 89 | } 90 | 91 | -------------------------------------------------------------------------------- /ADDITIONAL_LICENSE_TERMS: -------------------------------------------------------------------------------- 1 | In accordance with the GNU General Public License Version 3, 29 June 2007 2 | (GPL V3) Section 7. Additional Terms, the following Additional Permissions are 3 | added as exceptions to the terms of the GPL V3 for "DWSOLVER Software" 4 | (ARC-16342) 5 | 6 | 1. DISCLAIMER OF WARRANTIES AND LIABILITIES; WAIVER AND INDEMNIFICATION 7 | 8 | A. No Warranty: NASA PROVIDES THE COVERED WORKS "AS IS" WITHOUT ANY 9 | WARRANTY OF ANY KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, 10 | BUT NOT LIMITED TO, ANY WARRANTY THAT THE COVERED WORKS WILL CONFORM 11 | TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR 12 | A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT 13 | THE COVERED WORKS WILL BE ERROR FREE, OR ANY WARRANTY THAT 14 | DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE COVERED WORKS. THIS 15 | AGREEMENT DOES NOT, IN ANY MANNER, CONSTITUTE AN ENDORSEMENT BY NASA 16 | OR ANY OTHER RECIPIENT OF ANY RESULTS, RESULTING DESIGNS, HARDWARE, 17 | SOFTWARE PRODUCTS OR ANY OTHER APPLICATIONS RESULTING FROM USE OF THE 18 | COVERED WORKS. FURTHER, NASA DISCLAIMS ALL WARRANTIES AND LIABILITIES 19 | REGARDING THIRD-PARTY SOFTWARE, IF PRESENT IN THE ORIGINAL SOFTWARE, 20 | AND DISTRIBUTES IT "AS IS." 21 | 22 | B. Waiver and Indemnity: YOU AGREE TO WAIVE ANY AND ALL CLAIMS AGAINST THE 23 | UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS 24 | WELL AS ANY OTHER RECIPIENT. IF YOUR USE OF THE COVERED WORKS RESULTS 25 | IN ANY LIABILITIES, DEMANDS, DAMAGES, EXPENSES OR LOSSES ARISING FROM 26 | SUCH USE, INCLUDING ANY DAMAGES FROM PRODUCTS BASED ON, OR RESULTING 27 | FROM, YOUR USE OF THE COVERED WORKS, YOU SHALL INDEMNIFY AND HOLD 28 | HARMLESS THE UNITED STATES GOVERNMENT, ITS CONTRACTORS AND 29 | SUBCONTRACTORS, AS WELL AS ANY OTHER RECIPIENT, TO THE EXTENT PERMITTED 30 | BY LAW. YOUR SOLE REMEDY FOR ANY SUCH MATTER SHALL BE THE IMMEDIATE, 31 | UNILATERAL TERMINATION OF THIS AGREEMENT. 32 | 33 | 2. You must ensure that the following copyright notice appears prominently in 34 | the covered works: 35 | 36 | Copyright 2010 United States Government National Aeronautics and Space 37 | Administration (NASA). No copyright is claimed in the United States under 38 | Title 17, U.S. Code. All Other Rights Reserved. 39 | 40 | 3. You must characterize Your alteration of the covered works as a Modification 41 | or Contribution and must identify Yourself as the originator of Your 42 | Modification or Contribution in a manner that reasonably allows subsequent 43 | Recipients to identify the originator of the Modification or Contribution. In 44 | fulfillment of these requirements, You must include a file (e.g., a change log 45 | file) that describes the alterations made and the date of the alterations, 46 | identifies You as originator of the alterations, and consents to 47 | characterization of the alterations as a Modification or Contribution, for 48 | example, by including a statement that the Modification or Contribution is 49 | derived, directly or indirectly, from covered work provided by NASA. Once 50 | consent is granted, it may not thereafter be revoked. 51 | 52 | 4. You may not make any representation in the covered works or in any 53 | promotional, advertising or other material that may be construed as an 54 | endorsement by NASA or by any other Recipient of any product or service provided 55 | by You, or that may seek to obtain commercial advantage of NASA's or any other 56 | Recipient's participation in this License. 57 | -------------------------------------------------------------------------------- /src/amd/amd_internal.h: -------------------------------------------------------------------------------- 1 | /* amd_internal.h */ 2 | 3 | /* Written by Andrew Makhorin . */ 4 | 5 | #ifndef AMD_INTERNAL_H 6 | #define AMD_INTERNAL_H 7 | 8 | /* AMD will be exceedingly slow when running in debug mode. */ 9 | #if 1 10 | #define NDEBUG 11 | #endif 12 | 13 | #include "amd.h" 14 | #define _GLPSTD_STDIO 15 | #include "glpenv.h" 16 | 17 | #define Int int 18 | #define ID "%d" 19 | #define Int_MAX INT_MAX 20 | 21 | #define SIZE_T_MAX ((size_t)(-1)) 22 | 23 | #define EMPTY (-1) 24 | #define FLIP(i) (-(i)-2) 25 | #define UNFLIP(i) ((i < EMPTY) ? FLIP (i) : (i)) 26 | 27 | #define MAX(a,b) (((a) > (b)) ? (a) : (b)) 28 | #define MIN(a,b) (((a) < (b)) ? (a) : (b)) 29 | 30 | #define IMPLIES(p, q) (!(p) || (q)) 31 | 32 | #define GLOBAL 33 | 34 | #define AMD_order amd_order 35 | #define AMD_defaults amd_defaults 36 | #define AMD_control amd_control 37 | #define AMD_info amd_info 38 | #define AMD_1 amd_1 39 | #define AMD_2 amd_2 40 | #define AMD_valid amd_valid 41 | #define AMD_aat amd_aat 42 | #define AMD_postorder amd_postorder 43 | #define AMD_post_tree amd_post_tree 44 | #define AMD_dump amd_dump 45 | #define AMD_debug amd_debug 46 | #define AMD_debug_init amd_debug_init 47 | #define AMD_preprocess amd_preprocess 48 | 49 | #define amd_malloc xmalloc 50 | #if 0 /* 24/V-2009 */ 51 | #define amd_free xfree 52 | #else 53 | #define amd_free(ptr) { if ((ptr) != NULL) xfree(ptr); } 54 | #endif 55 | #define amd_printf xprintf 56 | 57 | #define PRINTF(params) { amd_printf params; } 58 | 59 | #ifndef NDEBUG 60 | #define ASSERT(expr) xassert(expr) 61 | #define AMD_DEBUG0(params) { PRINTF(params); } 62 | #define AMD_DEBUG1(params) { if (AMD_debug >= 1) PRINTF(params); } 63 | #define AMD_DEBUG2(params) { if (AMD_debug >= 2) PRINTF(params); } 64 | #define AMD_DEBUG3(params) { if (AMD_debug >= 3) PRINTF(params); } 65 | #define AMD_DEBUG4(params) { if (AMD_debug >= 4) PRINTF(params); } 66 | #else 67 | #define ASSERT(expression) 68 | #define AMD_DEBUG0(params) 69 | #define AMD_DEBUG1(params) 70 | #define AMD_DEBUG2(params) 71 | #define AMD_DEBUG3(params) 72 | #define AMD_DEBUG4(params) 73 | #endif 74 | 75 | #define amd_aat _glp_amd_aat 76 | size_t AMD_aat(Int n, const Int Ap[], const Int Ai[], Int Len[], 77 | Int Tp[], double Info[]); 78 | 79 | #define amd_1 _glp_amd_1 80 | void AMD_1(Int n, const Int Ap[], const Int Ai[], Int P[], Int Pinv[], 81 | Int Len[], Int slen, Int S[], double Control[], double Info[]); 82 | 83 | #define amd_postorder _glp_amd_postorder 84 | void AMD_postorder(Int nn, Int Parent[], Int Npiv[], Int Fsize[], 85 | Int Order[], Int Child[], Int Sibling[], Int Stack[]); 86 | 87 | #define amd_post_tree _glp_amd_post_tree 88 | #ifndef NDEBUG 89 | Int AMD_post_tree(Int root, Int k, Int Child[], const Int Sibling[], 90 | Int Order[], Int Stack[], Int nn); 91 | #else 92 | Int AMD_post_tree(Int root, Int k, Int Child[], const Int Sibling[], 93 | Int Order[], Int Stack[]); 94 | #endif 95 | 96 | #define amd_preprocess _glp_amd_preprocess 97 | void AMD_preprocess(Int n, const Int Ap[], const Int Ai[], Int Rp[], 98 | Int Ri[], Int W[], Int Flag[]); 99 | 100 | #define amd_debug _glp_amd_debug 101 | extern Int AMD_debug; 102 | 103 | #define amd_debug_init _glp_amd_debug_init 104 | void AMD_debug_init(char *s); 105 | 106 | #define amd_dump _glp_amd_dump 107 | void AMD_dump(Int n, Int Pe[], Int Iw[], Int Len[], Int iwlen, 108 | Int pfree, Int Nv[], Int Next[], Int Last[], Int Head[], 109 | Int Elen[], Int Degree[], Int W[], Int nel); 110 | 111 | #endif 112 | 113 | /* eof */ 114 | -------------------------------------------------------------------------------- /src/amd/amd_valid.c: -------------------------------------------------------------------------------- 1 | /* ========================================================================= */ 2 | /* === AMD_valid =========================================================== */ 3 | /* ========================================================================= */ 4 | 5 | /* ------------------------------------------------------------------------- */ 6 | /* AMD, Copyright (c) Timothy A. Davis, */ 7 | /* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ 8 | /* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */ 9 | /* web: http://www.cise.ufl.edu/research/sparse/amd */ 10 | /* ------------------------------------------------------------------------- */ 11 | 12 | /* Check if a column-form matrix is valid or not. The matrix A is 13 | * n_row-by-n_col. The row indices of entries in column j are in 14 | * Ai [Ap [j] ... Ap [j+1]-1]. Required conditions are: 15 | * 16 | * n_row >= 0 17 | * n_col >= 0 18 | * nz = Ap [n_col] >= 0 number of entries in the matrix 19 | * Ap [0] == 0 20 | * Ap [j] <= Ap [j+1] for all j in the range 0 to n_col. 21 | * Ai [0 ... nz-1] must be in the range 0 to n_row-1. 22 | * 23 | * If any of the above conditions hold, AMD_INVALID is returned. If the 24 | * following condition holds, AMD_OK_BUT_JUMBLED is returned (a warning, 25 | * not an error): 26 | * 27 | * row indices in Ai [Ap [j] ... Ap [j+1]-1] are not sorted in ascending 28 | * order, and/or duplicate entries exist. 29 | * 30 | * Otherwise, AMD_OK is returned. 31 | * 32 | * In v1.2 and earlier, this function returned TRUE if the matrix was valid 33 | * (now returns AMD_OK), or FALSE otherwise (now returns AMD_INVALID or 34 | * AMD_OK_BUT_JUMBLED). 35 | */ 36 | 37 | #include "amd_internal.h" 38 | 39 | GLOBAL Int AMD_valid 40 | ( 41 | /* inputs, not modified on output: */ 42 | Int n_row, /* A is n_row-by-n_col */ 43 | Int n_col, 44 | const Int Ap [ ], /* column pointers of A, of size n_col+1 */ 45 | const Int Ai [ ] /* row indices of A, of size nz = Ap [n_col] */ 46 | ) 47 | { 48 | Int nz, j, p1, p2, ilast, i, p, result = AMD_OK ; 49 | 50 | if (n_row < 0 || n_col < 0 || Ap == NULL || Ai == NULL) 51 | { 52 | return (AMD_INVALID) ; 53 | } 54 | nz = Ap [n_col] ; 55 | if (Ap [0] != 0 || nz < 0) 56 | { 57 | /* column pointers must start at Ap [0] = 0, and Ap [n] must be >= 0 */ 58 | AMD_DEBUG0 (("column 0 pointer bad or nz < 0\n")) ; 59 | return (AMD_INVALID) ; 60 | } 61 | for (j = 0 ; j < n_col ; j++) 62 | { 63 | p1 = Ap [j] ; 64 | p2 = Ap [j+1] ; 65 | AMD_DEBUG2 (("\nColumn: "ID" p1: "ID" p2: "ID"\n", j, p1, p2)) ; 66 | if (p1 > p2) 67 | { 68 | /* column pointers must be ascending */ 69 | AMD_DEBUG0 (("column "ID" pointer bad\n", j)) ; 70 | return (AMD_INVALID) ; 71 | } 72 | ilast = EMPTY ; 73 | for (p = p1 ; p < p2 ; p++) 74 | { 75 | i = Ai [p] ; 76 | AMD_DEBUG3 (("row: "ID"\n", i)) ; 77 | if (i < 0 || i >= n_row) 78 | { 79 | /* row index out of range */ 80 | AMD_DEBUG0 (("index out of range, col "ID" row "ID"\n", j, i)); 81 | return (AMD_INVALID) ; 82 | } 83 | if (i <= ilast) 84 | { 85 | /* row index unsorted, or duplicate entry present */ 86 | AMD_DEBUG1 (("index unsorted/dupl col "ID" row "ID"\n", j, i)); 87 | result = AMD_OK_BUT_JUMBLED ; 88 | } 89 | ilast = i ; 90 | } 91 | } 92 | return (result) ; 93 | } 94 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DWSOLVER (Dantzig-Wolfe Solver) 2 | 3 | ## Overview 4 | The Dantzig-Wolfe Solver program is a stand-alone implementation of the 5 | Dantzig-Wolfe Decomposition algorithm. The GNU Linear Programming Kit provides 6 | the functions for all of the necessary linear programming (reading in problems, 7 | performing the simplex algorithm, querying various LP data strucures, etc.). 8 | This software also uses POSIX Threads (pthreads) for parallel solving of 9 | subproblems. The implementation is general in that any linear program that can 10 | be presented to the software in block-angular form (with some current 11 | limitations) can be solved. 12 | 13 | ## Known Limitations 14 | This repo was updated to take advantage of GH Actions over a decade after it was 15 | previously touched. I could only get the MacOS runner to work properly. Using the 16 | Ubuntu runner gives errors at the linking phase due to some loose usage of variable 17 | definitions within [dw.h](./src/dw.h). Trying a few things to fix old C code like 18 | trying to make vars static, using externs, etc. This was a fools errand. Trying to update multithreaded C code from years ago may be the most dangerous game known to programmers. That said, I would happily take any PRs that show this code being built by a GH Action on an Ubuntu runner. 19 | 20 | ## Examples and Tests 21 | There is a an [examples](./examples/) directory with several problems plucked from popular textbooks and some websites. There is also a toy version of the problem that initiated the writing of this code related to air traffic management. Each example has a README and should run successfully with a properly built dwsolver executable. There is also a new [tests](./tests/) directory that contains a [test script](./tests/dw-tests.sh) that runs most of the examples. A couple of the examples have non-deterministic solutions (but deterministic optimum values), and I didn't take the time to write tests that check for the correct optimum for those problems. Again, happy for any PR that runs those examples, parses the output files to pluck out the optimum, and shows it is the expected value. 22 | 23 | ## Copyright 24 | Copyright 2010 United States Government National Aeronautics and Space 25 | Administration (NASA). No copyright is claimed in the United States under 26 | Title 17, U.S. Code. All Other Rights Reserved. 27 | 28 | ## Legal 29 | This program is free software: you can redistribute it and/or modify 30 | it under the terms of the GNU General Public License as published by 31 | the Free Software Foundation, either version 3 of the License, or 32 | (at your option) any later version. 33 | 34 | This program is distributed in the hope that it will be useful, 35 | but WITHOUT ANY WARRANTY; without even the implied warranty of 36 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 37 | GNU General Public License for more details. 38 | 39 | In accordance with the GNU General Public License Version 3, 29 June 2007 40 | (GPL V3) Section 7. Additional Terms, Additional Permissions are added as 41 | exceptions to the terms of the GPL V3 for this program. These additional 42 | terms should have been received with this program in a file entitled 43 | ["ADDITIONAL_LICENSE_TERMS"](./ADDITIONAL_LICENSE_TERMS). If a copy was not provided, you may request 44 | one from the contact author listed below. 45 | 46 | You should have received a copy of the GNU General Public License 47 | along with this program. If not, see . 48 | 49 | ## Additional Info 50 | See the file [COPYING](COPYING) for the GNU Public License. 51 | 52 | See the file [INSTALL](INSTALL) for compilation and installation instructions. 53 | 54 | All Dantzig-Wolfe source files created by the author begins with the prefix 55 | "dw" while all other source files in the src/ directory are GLPK files. All 56 | GLPK files are provided as published by the author(s) of GLPK except for those 57 | specified in the .patch file provided with this release. The changes to GLPK 58 | were made to implement a thread-friendly version of GLPK necessary for 59 | implementation of a parallel Dantzig-Wolfe algorithm. 60 | 61 | ~~Please report bugs/comments/suggestions/patches to Joseph.L.Rios@nasa.gov.~~ 62 | I'm not longer with NASA, so best to just submit through GitHub as an issue. 63 | -------------------------------------------------------------------------------- /src/dw_blas.c: -------------------------------------------------------------------------------- 1 | /* ***************************************************************************** 2 | * 3 | * DWSOLVER - a general, parallel implementation of the Dantzig-Wolfe 4 | * Decomposition algorithm. 5 | * 6 | * Copyright 2010 United States Government National Aeronautics and Space 7 | * Administration (NASA). No copyright is claimed in the United States under 8 | * Title 17, U.S. Code. All Other Rights Reserved. 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * In accordance with the GNU General Public License Version 3, 29 June 2007 21 | * (GPL V3) Section 7. Additional Terms, Additional Permissions are added as 22 | * exceptions to the terms of the GPL V3 for this program. These additional 23 | * terms should have been received with this program in a file entitled 24 | * "ADDITIONAL_LICENSE_TERMS". If a copy was not provided, you may request 25 | * one from the contact author listed below. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | * 30 | * Contact: Joseph Rios 31 | * 32 | **************************************************************************** */ 33 | 34 | /* 35 | * dw_blas.c 36 | * 37 | * Created on: Sep 2, 2009 38 | * Author: jrios 39 | * 40 | * I wrote these to obviate the need for further libraries. Granted, you may 41 | * get better performance if you use a tested/proven BLAS/SparseBLAS library, 42 | * but making the whole project more portable/usable seemed more important. 43 | * 44 | * Search through the code for calls to these functions and you'll see how 45 | * simple it would be to use a standard BLAS library call if you wanted to 46 | * make the changes. 47 | */ 48 | 49 | /* y <- alpha*x + y */ 50 | void dw_daxpy(const int len, const double alpha, const double* x, double* y) { 51 | int i; 52 | 53 | /* Rely on compiler for loop unrolling. */ 54 | for( i = 0; i < len; i++ ) { 55 | y[i] = alpha*x[i] + y[i]; 56 | } 57 | } 58 | 59 | /* return x dot y 60 | * Note there is no "increment" value for the vectors as there would be in a 61 | * compliant BLAS implementation. 62 | */ 63 | double dw_ddot(const int len, const double* x, const double* y) { 64 | double ret = 0.0; 65 | int i; 66 | 67 | /* Rely on compiler for loop unrolling. */ 68 | for( i = 0; i < len; i++ ) { 69 | ret += x[i]*y[i]; 70 | } 71 | 72 | return ret; 73 | } 74 | 75 | /* return x dot y 76 | * where x is in a compressed format. 77 | * Note there is not increment value for y as there would be in a compliant 78 | * BLAS implementation. 79 | */ 80 | double dw_ddoti(const int nz, const double* x, const int* ind_x, 81 | const double* y) { 82 | double ret = 0.0; 83 | int i; 84 | 85 | /* Rely on compiler for loop unrolling. */ 86 | for( i = 0; i < nz; i++ ) { 87 | ret += x[i]*y[ind_x[i]]; 88 | } 89 | 90 | return ret; 91 | } 92 | 93 | /* y <- x */ 94 | void dw_dcopy(const int len, const double* x, double* y) { 95 | int i; 96 | 97 | /* Rely on compiler for loop unrolling. */ 98 | for( i = 0; i < len; i++ ) { 99 | y[i] = x[i]; 100 | } 101 | } 102 | 103 | /* A*b = c where A is stored in coordinate format. */ 104 | void dw_dcoogemv(const int m, const int k, const double *val, 105 | const int *indx, const int *jndx, const int nnz, const double *b, 106 | double *c) { 107 | 108 | int i,j; 109 | double *temp_c = c; 110 | 111 | /* Zero-out the product vector. */ 112 | for ( i = 0; i < m; i++ ) temp_c[i] = 0; 113 | 114 | /* Indices are arbitrarily ordered. Use components of product vector as 115 | * accumulators. 116 | */ 117 | for( j = 0; j < nnz; j++ ) { 118 | c[indx[j]] += b[jndx[j]] * val[j]; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /compile: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Wrapper for compilers which do not understand `-c -o'. 3 | 4 | scriptversion=2009-10-06.20; # UTC 5 | 6 | # Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009 Free Software 7 | # Foundation, Inc. 8 | # Written by Tom Tromey . 9 | # 10 | # This program is free software; you can redistribute it and/or modify 11 | # it under the terms of the GNU General Public License as published by 12 | # the Free Software Foundation; either version 2, or (at your option) 13 | # any later version. 14 | # 15 | # This program is distributed in the hope that it will be useful, 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | # GNU General Public License for more details. 19 | # 20 | # You should have received a copy of the GNU General Public License 21 | # along with this program. If not, see . 22 | 23 | # As a special exception to the GNU General Public License, if you 24 | # distribute this file as part of a program that contains a 25 | # configuration script generated by Autoconf, you may include it under 26 | # the same distribution terms that you use for the rest of that program. 27 | 28 | # This file is maintained in Automake, please report 29 | # bugs to or send patches to 30 | # . 31 | 32 | case $1 in 33 | '') 34 | echo "$0: No command. Try \`$0 --help' for more information." 1>&2 35 | exit 1; 36 | ;; 37 | -h | --h*) 38 | cat <<\EOF 39 | Usage: compile [--help] [--version] PROGRAM [ARGS] 40 | 41 | Wrapper for compilers which do not understand `-c -o'. 42 | Remove `-o dest.o' from ARGS, run PROGRAM with the remaining 43 | arguments, and rename the output as expected. 44 | 45 | If you are trying to build a whole package this is not the 46 | right script to run: please start by reading the file `INSTALL'. 47 | 48 | Report bugs to . 49 | EOF 50 | exit $? 51 | ;; 52 | -v | --v*) 53 | echo "compile $scriptversion" 54 | exit $? 55 | ;; 56 | esac 57 | 58 | ofile= 59 | cfile= 60 | eat= 61 | 62 | for arg 63 | do 64 | if test -n "$eat"; then 65 | eat= 66 | else 67 | case $1 in 68 | -o) 69 | # configure might choose to run compile as `compile cc -o foo foo.c'. 70 | # So we strip `-o arg' only if arg is an object. 71 | eat=1 72 | case $2 in 73 | *.o | *.obj) 74 | ofile=$2 75 | ;; 76 | *) 77 | set x "$@" -o "$2" 78 | shift 79 | ;; 80 | esac 81 | ;; 82 | *.c) 83 | cfile=$1 84 | set x "$@" "$1" 85 | shift 86 | ;; 87 | *) 88 | set x "$@" "$1" 89 | shift 90 | ;; 91 | esac 92 | fi 93 | shift 94 | done 95 | 96 | if test -z "$ofile" || test -z "$cfile"; then 97 | # If no `-o' option was seen then we might have been invoked from a 98 | # pattern rule where we don't need one. That is ok -- this is a 99 | # normal compilation that the losing compiler can handle. If no 100 | # `.c' file was seen then we are probably linking. That is also 101 | # ok. 102 | exec "$@" 103 | fi 104 | 105 | # Name of file we expect compiler to create. 106 | cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 107 | 108 | # Create the lock directory. 109 | # Note: use `[/\\:.-]' here to ensure that we don't use the same name 110 | # that we are using for the .o file. Also, base the name on the expected 111 | # object file name, since that is what matters with a parallel build. 112 | lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 113 | while true; do 114 | if mkdir "$lockdir" >/dev/null 2>&1; then 115 | break 116 | fi 117 | sleep 1 118 | done 119 | # FIXME: race condition here if user kills between mkdir and trap. 120 | trap "rmdir '$lockdir'; exit 1" 1 2 15 121 | 122 | # Run the compile. 123 | "$@" 124 | ret=$? 125 | 126 | if test -f "$cofile"; then 127 | test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 128 | elif test -f "${cofile}bj"; then 129 | test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 130 | fi 131 | 132 | rmdir "$lockdir" 133 | exit $ret 134 | 135 | # Local Variables: 136 | # mode: shell-script 137 | # sh-indentation: 2 138 | # eval: (add-hook 'write-file-hooks 'time-stamp) 139 | # time-stamp-start: "scriptversion=" 140 | # time-stamp-format: "%:y-%02m-%02d.%02H" 141 | # time-stamp-time-zone: "UTC" 142 | # time-stamp-end: "; # UTC" 143 | # End: 144 | -------------------------------------------------------------------------------- /src/glpenv04.c: -------------------------------------------------------------------------------- 1 | /* glpenv04.c (error handling) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #include "glpapi.h" 26 | 27 | /*********************************************************************** 28 | * NAME 29 | * 30 | * glp_error - display error message and terminate execution 31 | * 32 | * SYNOPSIS 33 | * 34 | * void glp_error(const char *fmt, ...); 35 | * 36 | * DESCRIPTION 37 | * 38 | * The routine glp_error (implemented as a macro) formats its 39 | * parameters using the format control string fmt, writes the formatted 40 | * message to the terminal, and abnormally terminates the program. */ 41 | 42 | static void error(const char *fmt, ...) 43 | { ENV *env = get_env_ptr(); 44 | va_list arg; 45 | env->term_out = GLP_ON; 46 | va_start(arg, fmt); 47 | xvprintf(fmt, arg); 48 | va_end(arg); 49 | xprintf("Error detected in file %s at line %d\n", env->err_file, 50 | env->err_line); 51 | if (env->err_hook != NULL) 52 | env->err_hook(env->err_info); 53 | abort(); 54 | exit(EXIT_FAILURE); 55 | /* no return */ 56 | } 57 | 58 | _glp_error glp_error_(const char *file, int line) 59 | { ENV *env = get_env_ptr(); 60 | env->err_file = file; 61 | env->err_line = line; 62 | return error; 63 | } 64 | 65 | /*********************************************************************** 66 | * NAME 67 | * 68 | * glp_assert - check for logical condition 69 | * 70 | * SYNOPSIS 71 | * 72 | * #include "glplib.h" 73 | * void glp_assert(int expr); 74 | * 75 | * DESCRIPTION 76 | * 77 | * The routine glp_assert (implemented as a macro) checks for a logical 78 | * condition specified by the parameter expr. If the condition is false 79 | * (i.e. the value of expr is zero), the routine writes a message to 80 | * the terminal and abnormally terminates the program. */ 81 | 82 | void glp_assert_(const char *expr, const char *file, int line) 83 | { glp_error_(file, line)("Assertion failed: %s\n", expr); 84 | /* no return */ 85 | } 86 | 87 | /*********************************************************************** 88 | * NAME 89 | * 90 | * glp_error_hook - install hook to intercept abnormal termination 91 | * 92 | * SYNOPSIS 93 | * 94 | * void glp_error_hook(void (*func)(void *info), void *info); 95 | * 96 | * DESCRIPTION 97 | * 98 | * The routine glp_error_hook installs a user-defined hook routine to 99 | * intercept abnormal termination. 100 | * 101 | * The parameter func specifies the user-defined hook routine. It is 102 | * called from the routine glp_error before the latter calls the abort 103 | * function to abnormally terminate the application program because of 104 | * fatal error. The parameter info is a transit pointer, specified in 105 | * the corresponding call to the routine glp_error_hook; it may be used 106 | * to pass some information to the hook routine. 107 | * 108 | * To uninstall the hook routine the parameters func and info should be 109 | * specified as NULL. */ 110 | 111 | void glp_error_hook(void (*func)(void *info), void *info) 112 | { ENV *env = get_env_ptr(); 113 | if (func == NULL) 114 | { env->err_hook = NULL; 115 | env->err_info = NULL; 116 | } 117 | else 118 | { env->err_hook = func; 119 | env->err_info = info; 120 | } 121 | return; 122 | } 123 | 124 | /* eof */ 125 | -------------------------------------------------------------------------------- /src/glpenv08.c: -------------------------------------------------------------------------------- 1 | /* glpenv08.c (shared library support) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include 27 | #endif 28 | 29 | #include "glpenv.h" 30 | 31 | /* GNU version ********************************************************/ 32 | 33 | #if defined(HAVE_LTDL) 34 | 35 | #include 36 | 37 | void *xdlopen(const char *module) 38 | { void *h = NULL; 39 | if (lt_dlinit() != 0) 40 | { lib_err_msg(lt_dlerror()); 41 | goto done; 42 | } 43 | h = lt_dlopen(module); 44 | if (h == NULL) 45 | { lib_err_msg(lt_dlerror()); 46 | if (lt_dlexit() != 0) 47 | xerror("xdlopen: %s\n", lt_dlerror()); 48 | } 49 | done: return h; 50 | } 51 | 52 | void *xdlsym(void *h, const char *symbol) 53 | { void *ptr; 54 | xassert(h != NULL); 55 | ptr = lt_dlsym(h, symbol); 56 | if (ptr == NULL) 57 | xerror("xdlsym: %s: %s\n", symbol, lt_dlerror()); 58 | return ptr; 59 | } 60 | 61 | void xdlclose(void *h) 62 | { xassert(h != NULL); 63 | if (lt_dlclose(h) != 0) 64 | xerror("xdlclose: %s\n", lt_dlerror()); 65 | if (lt_dlexit() != 0) 66 | xerror("xdlclose: %s\n", lt_dlerror()); 67 | return; 68 | } 69 | 70 | /* POSIX version ******************************************************/ 71 | 72 | #elif defined(HAVE_DLFCN) 73 | 74 | #include 75 | 76 | void *xdlopen(const char *module) 77 | { void *h; 78 | h = dlopen(module, RTLD_NOW); 79 | if (h == NULL) 80 | lib_err_msg(dlerror()); 81 | return h; 82 | } 83 | 84 | void *xdlsym(void *h, const char *symbol) 85 | { void *ptr; 86 | xassert(h != NULL); 87 | ptr = dlsym(h, symbol); 88 | if (ptr == NULL) 89 | xerror("xdlsym: %s: %s\n", symbol, dlerror()); 90 | return ptr; 91 | } 92 | 93 | void xdlclose(void *h) 94 | { xassert(h != NULL); 95 | if (dlclose(h) != 0) 96 | xerror("xdlclose: %s\n", dlerror()); 97 | return; 98 | } 99 | 100 | /* Windows version ****************************************************/ 101 | 102 | #elif defined(__WOE__) 103 | 104 | #include 105 | 106 | void *xdlopen(const char *module) 107 | { void *h; 108 | h = LoadLibrary(module); 109 | if (h == NULL) 110 | { char msg[20]; 111 | sprintf(msg, "Error %d", GetLastError()); 112 | lib_err_msg(msg); 113 | } 114 | return h; 115 | } 116 | 117 | void *xdlsym(void *h, const char *symbol) 118 | { void *ptr; 119 | xassert(h != NULL); 120 | ptr = GetProcAddress(h, symbol); 121 | if (ptr == NULL) 122 | xerror("xdlsym: %s: Error %d\n", symbol, GetLastError()); 123 | return ptr; 124 | } 125 | 126 | void xdlclose(void *h) 127 | { xassert(h != NULL); 128 | if (!FreeLibrary(h)) 129 | xerror("xdlclose: Error %d\n", GetLastError()); 130 | return; 131 | } 132 | 133 | /* NULL version *******************************************************/ 134 | 135 | #else 136 | 137 | void *xdlopen(const char *module) 138 | { xassert(module == module); 139 | lib_err_msg("Shared libraries not supported"); 140 | return NULL; 141 | } 142 | 143 | void *xdlsym(void *h, const char *symbol) 144 | { xassert(h != h); 145 | xassert(symbol != symbol); 146 | return NULL; 147 | } 148 | 149 | void xdlclose(void *h) 150 | { xassert(h != h); 151 | return; 152 | } 153 | 154 | #endif 155 | 156 | /* eof */ 157 | -------------------------------------------------------------------------------- /src/glplib.h: -------------------------------------------------------------------------------- 1 | /* glplib.h (miscellaneous library routines) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifndef GLPLIB_H 26 | #define GLPLIB_H 27 | 28 | #define bigmul _glp_lib_bigmul 29 | void bigmul(int n, int m, unsigned short x[], unsigned short y[]); 30 | /* multiply unsigned integer numbers of arbitrary precision */ 31 | 32 | #define bigdiv _glp_lib_bigdiv 33 | void bigdiv(int n, int m, unsigned short x[], unsigned short y[]); 34 | /* divide unsigned integer numbers of arbitrary precision */ 35 | 36 | #ifndef GLP_LONG_DEFINED 37 | #define GLP_LONG_DEFINED 38 | typedef struct { int lo, hi; } glp_long; 39 | /* long integer data type */ 40 | #endif 41 | 42 | typedef struct { glp_long quot, rem; } glp_ldiv; 43 | /* result of long integer division */ 44 | 45 | #define xlset _glp_lib_xlset 46 | glp_long xlset(int x); 47 | /* expand integer to long integer */ 48 | 49 | #define xlneg _glp_lib_xlneg 50 | glp_long xlneg(glp_long x); 51 | /* negate long integer */ 52 | 53 | #define xladd _glp_lib_xladd 54 | glp_long xladd(glp_long x, glp_long y); 55 | /* add long integers */ 56 | 57 | #define xlsub _glp_lib_xlsub 58 | glp_long xlsub(glp_long x, glp_long y); 59 | /* subtract long integers */ 60 | 61 | #define xlcmp _glp_lib_xlcmp 62 | int xlcmp(glp_long x, glp_long y); 63 | /* compare long integers */ 64 | 65 | #define xlmul _glp_lib_xlmul 66 | glp_long xlmul(glp_long x, glp_long y); 67 | /* multiply long integers */ 68 | 69 | #define xldiv _glp_lib_xldiv 70 | glp_ldiv xldiv(glp_long x, glp_long y); 71 | /* divide long integers */ 72 | 73 | #define xltod _glp_lib_xltod 74 | double xltod(glp_long x); 75 | /* convert long integer to double */ 76 | 77 | #define xltoa _glp_lib_xltoa 78 | char *xltoa(glp_long x, char *s); 79 | /* convert long integer to character string */ 80 | 81 | #define str2int _glp_lib_str2int 82 | int str2int(const char *str, int *val); 83 | /* convert character string to value of int type */ 84 | 85 | #define str2num _glp_lib_str2num 86 | int str2num(const char *str, double *val); 87 | /* convert character string to value of double type */ 88 | 89 | #define strspx _glp_lib_strspx 90 | char *strspx(char *str); 91 | /* remove all spaces from character string */ 92 | 93 | #define strtrim _glp_lib_strtrim 94 | char *strtrim(char *str); 95 | /* remove trailing spaces from character string */ 96 | 97 | #define strrev _glp_lib_strrev 98 | char *strrev(char *s); 99 | /* reverse character string */ 100 | 101 | #define gcd _glp_lib_gcd 102 | int gcd(int x, int y); 103 | /* find greatest common divisor of two integers */ 104 | 105 | #define gcdn _glp_lib_gcdn 106 | int gcdn(int n, int x[]); 107 | /* find greatest common divisor of n integers */ 108 | 109 | #define lcm _glp_lib_lcm 110 | int lcm(int x, int y); 111 | /* find least common multiple of two integers */ 112 | 113 | #define lcmn _glp_lib_lcmn 114 | int lcmn(int n, int x[]); 115 | /* find least common multiple of n integers */ 116 | 117 | #define round2n _glp_lib_round2n 118 | double round2n(double x); 119 | /* round floating-point number to nearest power of two */ 120 | 121 | #define fp2rat _glp_lib_fp2rat 122 | int fp2rat(double x, double eps, double *p, double *q); 123 | /* convert floating-point number to rational number */ 124 | 125 | #define jday _glp_lib_jday 126 | int jday(int d, int m, int y); 127 | /* convert calendar date to Julian day number */ 128 | 129 | #define jdate _glp_lib_jdate 130 | int jdate(int j, int *d, int *m, int *y); 131 | /* convert Julian day number to calendar date */ 132 | 133 | #endif 134 | 135 | /* eof */ 136 | -------------------------------------------------------------------------------- /src/amd/amd_preprocess.c: -------------------------------------------------------------------------------- 1 | /* ========================================================================= */ 2 | /* === AMD_preprocess ====================================================== */ 3 | /* ========================================================================= */ 4 | 5 | /* ------------------------------------------------------------------------- */ 6 | /* AMD, Copyright (c) Timothy A. Davis, */ 7 | /* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ 8 | /* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */ 9 | /* web: http://www.cise.ufl.edu/research/sparse/amd */ 10 | /* ------------------------------------------------------------------------- */ 11 | 12 | /* Sorts, removes duplicate entries, and transposes from the nonzero pattern of 13 | * a column-form matrix A, to obtain the matrix R. The input matrix can have 14 | * duplicate entries and/or unsorted columns (AMD_valid (n,Ap,Ai) must not be 15 | * AMD_INVALID). 16 | * 17 | * This input condition is NOT checked. This routine is not user-callable. 18 | */ 19 | 20 | #include "amd_internal.h" 21 | 22 | /* ========================================================================= */ 23 | /* === AMD_preprocess ====================================================== */ 24 | /* ========================================================================= */ 25 | 26 | /* AMD_preprocess does not check its input for errors or allocate workspace. 27 | * On input, the condition (AMD_valid (n,n,Ap,Ai) != AMD_INVALID) must hold. 28 | */ 29 | 30 | GLOBAL void AMD_preprocess 31 | ( 32 | Int n, /* input matrix: A is n-by-n */ 33 | const Int Ap [ ], /* size n+1 */ 34 | const Int Ai [ ], /* size nz = Ap [n] */ 35 | 36 | /* output matrix R: */ 37 | Int Rp [ ], /* size n+1 */ 38 | Int Ri [ ], /* size nz (or less, if duplicates present) */ 39 | 40 | Int W [ ], /* workspace of size n */ 41 | Int Flag [ ] /* workspace of size n */ 42 | ) 43 | { 44 | 45 | /* --------------------------------------------------------------------- */ 46 | /* local variables */ 47 | /* --------------------------------------------------------------------- */ 48 | 49 | Int i, j, p, p2 ; 50 | 51 | ASSERT (AMD_valid (n, n, Ap, Ai) != AMD_INVALID) ; 52 | 53 | /* --------------------------------------------------------------------- */ 54 | /* count the entries in each row of A (excluding duplicates) */ 55 | /* --------------------------------------------------------------------- */ 56 | 57 | for (i = 0 ; i < n ; i++) 58 | { 59 | W [i] = 0 ; /* # of nonzeros in row i (excl duplicates) */ 60 | Flag [i] = EMPTY ; /* Flag [i] = j if i appears in column j */ 61 | } 62 | for (j = 0 ; j < n ; j++) 63 | { 64 | p2 = Ap [j+1] ; 65 | for (p = Ap [j] ; p < p2 ; p++) 66 | { 67 | i = Ai [p] ; 68 | if (Flag [i] != j) 69 | { 70 | /* row index i has not yet appeared in column j */ 71 | W [i]++ ; /* one more entry in row i */ 72 | Flag [i] = j ; /* flag row index i as appearing in col j*/ 73 | } 74 | } 75 | } 76 | 77 | /* --------------------------------------------------------------------- */ 78 | /* compute the row pointers for R */ 79 | /* --------------------------------------------------------------------- */ 80 | 81 | Rp [0] = 0 ; 82 | for (i = 0 ; i < n ; i++) 83 | { 84 | Rp [i+1] = Rp [i] + W [i] ; 85 | } 86 | for (i = 0 ; i < n ; i++) 87 | { 88 | W [i] = Rp [i] ; 89 | Flag [i] = EMPTY ; 90 | } 91 | 92 | /* --------------------------------------------------------------------- */ 93 | /* construct the row form matrix R */ 94 | /* --------------------------------------------------------------------- */ 95 | 96 | /* R = row form of pattern of A */ 97 | for (j = 0 ; j < n ; j++) 98 | { 99 | p2 = Ap [j+1] ; 100 | for (p = Ap [j] ; p < p2 ; p++) 101 | { 102 | i = Ai [p] ; 103 | if (Flag [i] != j) 104 | { 105 | /* row index i has not yet appeared in column j */ 106 | Ri [W [i]++] = j ; /* put col j in row i */ 107 | Flag [i] = j ; /* flag row index i as appearing in col j*/ 108 | } 109 | } 110 | } 111 | 112 | #ifndef NDEBUG 113 | ASSERT (AMD_valid (n, n, Rp, Ri) == AMD_OK) ; 114 | for (j = 0 ; j < n ; j++) 115 | { 116 | ASSERT (W [j] == Rp [j+1]) ; 117 | } 118 | #endif 119 | } 120 | -------------------------------------------------------------------------------- /src/glpapi18.c: -------------------------------------------------------------------------------- 1 | /* glpapi18.c (maximum clique problem) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #include "glpapi.h" 26 | #include "glpnet.h" 27 | 28 | static void set_edge(int nv, unsigned char a[], int i, int j) 29 | { int k; 30 | xassert(1 <= j && j < i && i <= nv); 31 | k = ((i - 1) * (i - 2)) / 2 + (j - 1); 32 | a[k / CHAR_BIT] |= 33 | (unsigned char)(1 << ((CHAR_BIT - 1) - k % CHAR_BIT)); 34 | return; 35 | } 36 | 37 | int glp_wclique_exact(glp_graph *G, int v_wgt, double *sol, int v_set) 38 | { /* find maximum weight clique with exact algorithm */ 39 | glp_arc *e; 40 | int i, j, k, len, x, *w, *ind, ret = 0; 41 | unsigned char *a; 42 | double s, t; 43 | if (v_wgt >= 0 && v_wgt > G->v_size - (int)sizeof(double)) 44 | xerror("glp_wclique_exact: v_wgt = %d; invalid parameter\n", 45 | v_wgt); 46 | if (v_set >= 0 && v_set > G->v_size - (int)sizeof(int)) 47 | xerror("glp_wclique_exact: v_set = %d; invalid parameter\n", 48 | v_set); 49 | if (G->nv == 0) 50 | { /* empty graph has only empty clique */ 51 | if (sol != NULL) *sol = 0.0; 52 | return 0; 53 | } 54 | /* allocate working arrays */ 55 | w = xcalloc(1+G->nv, sizeof(int)); 56 | ind = xcalloc(1+G->nv, sizeof(int)); 57 | len = G->nv; /* # vertices */ 58 | len = len * (len - 1) / 2; /* # entries in lower triangle */ 59 | len = (len + (CHAR_BIT - 1)) / CHAR_BIT; /* # bytes needed */ 60 | a = xcalloc(len, sizeof(char)); 61 | memset(a, 0, len * sizeof(char)); 62 | /* determine vertex weights */ 63 | s = 0.0; 64 | for (i = 1; i <= G->nv; i++) 65 | { if (v_wgt >= 0) 66 | { memcpy(&t, (char *)G->v[i]->data + v_wgt, sizeof(double)); 67 | if (!(0.0 <= t && t <= (double)INT_MAX && t == floor(t))) 68 | { ret = GLP_EDATA; 69 | goto done; 70 | } 71 | w[i] = (int)t; 72 | } 73 | else 74 | w[i] = 1; 75 | s += (double)w[i]; 76 | } 77 | if (s > (double)INT_MAX) 78 | { ret = GLP_EDATA; 79 | goto done; 80 | } 81 | /* build the adjacency matrix */ 82 | for (i = 1; i <= G->nv; i++) 83 | { for (e = G->v[i]->in; e != NULL; e = e->h_next) 84 | { j = e->tail->i; 85 | /* there exists edge (j,i) in the graph */ 86 | if (i > j) set_edge(G->nv, a, i, j); 87 | } 88 | for (e = G->v[i]->out; e != NULL; e = e->t_next) 89 | { j = e->head->i; 90 | /* there exists edge (i,j) in the graph */ 91 | if (i > j) set_edge(G->nv, a, i, j); 92 | } 93 | } 94 | /* find maximum weight clique in the graph */ 95 | len = wclique(G->nv, w, a, ind); 96 | /* compute the clique weight */ 97 | s = 0.0; 98 | for (k = 1; k <= len; k++) 99 | { i = ind[k]; 100 | xassert(1 <= i && i <= G->nv); 101 | s += (double)w[i]; 102 | } 103 | if (sol != NULL) *sol = s; 104 | /* mark vertices included in the clique */ 105 | if (v_set >= 0) 106 | { x = 0; 107 | for (i = 1; i <= G->nv; i++) 108 | memcpy((char *)G->v[i]->data + v_set, &x, sizeof(int)); 109 | x = 1; 110 | for (k = 1; k <= len; k++) 111 | { i = ind[k]; 112 | memcpy((char *)G->v[i]->data + v_set, &x, sizeof(int)); 113 | } 114 | } 115 | done: /* free working arrays */ 116 | xfree(w); 117 | xfree(ind); 118 | xfree(a); 119 | return ret; 120 | } 121 | 122 | /* eof */ 123 | -------------------------------------------------------------------------------- /src/glptsp.h: -------------------------------------------------------------------------------- 1 | /* glptsp.h (TSP format) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifndef GLPTSP_H 26 | #define GLPTSP_H 27 | 28 | typedef struct TSP TSP; 29 | 30 | struct TSP 31 | { /* TSP (or related problem) instance in the format described in 32 | the report [G.Reinelt, TSPLIB 95] */ 33 | /*--------------------------------------------------------------*/ 34 | /* the specification part */ 35 | char *name; 36 | /* identifies the data file */ 37 | int type; 38 | /* specifies the type of data: */ 39 | #define TSP_UNDEF 0 /* undefined */ 40 | #define TSP_TSP 1 /* symmetric TSP */ 41 | #define TSP_ATSP 2 /* asymmetric TSP */ 42 | #define TSP_TOUR 3 /* collection of tours */ 43 | char *comment; 44 | /* additional comments (usually the name of the contributor or 45 | creator of the problem instance is given here) */ 46 | int dimension; 47 | /* for a TSP or ATSP, the dimension is the number of its nodes 48 | for a TOUR it is the dimension of the corresponding problem */ 49 | int edge_weight_type; 50 | /* specifies how the edge weights (or distances) are given: */ 51 | #define TSP_UNDEF 0 /* undefined */ 52 | #define TSP_EXPLICIT 1 /* listed explicitly */ 53 | #define TSP_EUC_2D 2 /* Eucl. distances in 2-D */ 54 | #define TSP_CEIL_2D 3 /* Eucl. distances in 2-D rounded up */ 55 | #define TSP_GEO 4 /* geographical distances */ 56 | #define TSP_ATT 5 /* special distance function */ 57 | int edge_weight_format; 58 | /* describes the format of the edge weights if they are given 59 | explicitly: */ 60 | #define TSP_UNDEF 0 /* undefined */ 61 | #define TSP_FUNCTION 1 /* given by a function */ 62 | #define TSP_FULL_MATRIX 2 /* given by a full matrix */ 63 | #define TSP_UPPER_ROW 3 /* upper triangulat matrix (row-wise 64 | without diagonal entries) */ 65 | #define TSP_LOWER_DIAG_ROW 4 /* lower triangular matrix (row-wise 66 | including diagonal entries) */ 67 | int display_data_type; 68 | /* specifies how a graphical display of the nodes can be 69 | obtained: */ 70 | #define TSP_UNDEF 0 /* undefined */ 71 | #define TSP_COORD_DISPLAY 1 /* display is generated from the node 72 | coordinates */ 73 | #define TSP_TWOD_DISPLAY 2 /* explicit coordinates in 2-D are 74 | given */ 75 | /*--------------------------------------------------------------*/ 76 | /* data part */ 77 | /* NODE_COORD_SECTION: */ 78 | double *node_x_coord; /* double node_x_coord[1+dimension]; */ 79 | double *node_y_coord; /* double node_y_coord[1+dimension]; */ 80 | /* DISPLAY_DATA_SECTION: */ 81 | double *dply_x_coord; /* double dply_x_coord[1+dimension]; */ 82 | double *dply_y_coord; /* double dply_y_coord[1+dimension]; */ 83 | /* TOUR_SECTION: */ 84 | int *tour; /* int tour[1+dimension]; */ 85 | /* EDGE_WEIGHT_SECTION: */ 86 | int *edge_weight; /* int edge_weight[1+dimension*dimension]; */ 87 | }; 88 | 89 | #define tsp_read_data _glp_tsp_read_data 90 | #define tsp_free_data _glp_tsp_free_data 91 | #define tsp_distance _glp_tsp_distance 92 | 93 | TSP *tsp_read_data(char *fname); 94 | /* read TSP instance data */ 95 | 96 | void tsp_free_data(TSP *tsp); 97 | /* free TSP instance data */ 98 | 99 | int tsp_distance(TSP *tsp, int i, int j); 100 | /* compute distance between two nodes */ 101 | 102 | #endif 103 | 104 | /* eof */ 105 | -------------------------------------------------------------------------------- /src/glpavl.h: -------------------------------------------------------------------------------- 1 | /* glpavl.h (binary search tree) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifndef GLPAVL_H 26 | #define GLPAVL_H 27 | 28 | #include "glpdmp.h" 29 | 30 | typedef struct AVL AVL; 31 | typedef struct AVLNODE AVLNODE; 32 | 33 | struct AVL 34 | { /* AVL tree (Adelson-Velsky & Landis binary search tree) */ 35 | DMP *pool; 36 | /* memory pool for allocating nodes */ 37 | AVLNODE *root; 38 | /* pointer to the root node */ 39 | int (*fcmp)(void *info, const void *key1, const void *key2); 40 | /* application-defined key comparison routine */ 41 | void *info; 42 | /* transit pointer passed to the routine fcmp */ 43 | int size; 44 | /* the tree size (the total number of nodes) */ 45 | int height; 46 | /* the tree height */ 47 | }; 48 | 49 | struct AVLNODE 50 | { /* node of AVL tree */ 51 | const void *key; 52 | /* pointer to the node key (data structure for representing keys 53 | is supplied by the application) */ 54 | int rank; 55 | /* node rank = relative position of the node in its own subtree = 56 | the number of nodes in the left subtree plus one */ 57 | int type; 58 | /* reserved for the application specific information */ 59 | void *link; 60 | /* reserved for the application specific information */ 61 | AVLNODE *up; 62 | /* pointer to the parent node */ 63 | short int flag; 64 | /* node flag: 65 | 0 - this node is the left child of its parent (or this node is 66 | the root of the tree and has no parent) 67 | 1 - this node is the right child of its parent */ 68 | short int bal; 69 | /* node balance = the difference between heights of the right and 70 | left subtrees: 71 | -1 - the left subtree is higher than the right one; 72 | 0 - the left and right subtrees have the same height; 73 | +1 - the left subtree is lower than the right one */ 74 | AVLNODE *left; 75 | /* pointer to the root of the left subtree */ 76 | AVLNODE *right; 77 | /* pointer to the root of the right subtree */ 78 | }; 79 | 80 | #define avl_create_tree _glp_avl_create_tree 81 | AVL *avl_create_tree(int (*fcmp)(void *info, const void *key1, 82 | const void *key2), void *info); 83 | /* create AVL tree */ 84 | 85 | #define avl_strcmp _glp_avl_strcmp 86 | int avl_strcmp(void *info, const void *key1, const void *key2); 87 | /* compare character string keys */ 88 | 89 | #define avl_insert_node _glp_avl_insert_node 90 | AVLNODE *avl_insert_node(AVL *tree, const void *key); 91 | /* insert new node into AVL tree */ 92 | 93 | #define avl_set_node_type _glp_avl_set_node_type 94 | void avl_set_node_type(AVLNODE *node, int type); 95 | /* assign the type field of specified node */ 96 | 97 | #define avl_set_node_link _glp_avl_set_node_link 98 | void avl_set_node_link(AVLNODE *node, void *link); 99 | /* assign the link field of specified node */ 100 | 101 | #define avl_find_node _glp_avl_find_node 102 | AVLNODE *avl_find_node(AVL *tree, const void *key); 103 | /* find node in AVL tree */ 104 | 105 | #define avl_get_node_type _glp_avl_get_node_type 106 | int avl_get_node_type(AVLNODE *node); 107 | /* retrieve the type field of specified node */ 108 | 109 | #define avl_get_node_link _glp_avl_get_node_link 110 | void *avl_get_node_link(AVLNODE *node); 111 | /* retrieve the link field of specified node */ 112 | 113 | #define avl_delete_node _glp_avl_delete_node 114 | void avl_delete_node(AVL *tree, AVLNODE *node); 115 | /* delete specified node from AVL tree */ 116 | 117 | #define avl_delete_tree _glp_avl_delete_tree 118 | void avl_delete_tree(AVL *tree); 119 | /* delete AVL tree */ 120 | 121 | #endif 122 | 123 | /* eof */ 124 | -------------------------------------------------------------------------------- /m4/ltsugar.m4: -------------------------------------------------------------------------------- 1 | # ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- 2 | # 3 | # Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. 4 | # Written by Gary V. Vaughan, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # serial 6 ltsugar.m4 11 | 12 | # This is to help aclocal find these macros, as it can't see m4_define. 13 | AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) 14 | 15 | 16 | # lt_join(SEP, ARG1, [ARG2...]) 17 | # ----------------------------- 18 | # Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their 19 | # associated separator. 20 | # Needed until we can rely on m4_join from Autoconf 2.62, since all earlier 21 | # versions in m4sugar had bugs. 22 | m4_define([lt_join], 23 | [m4_if([$#], [1], [], 24 | [$#], [2], [[$2]], 25 | [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) 26 | m4_define([_lt_join], 27 | [m4_if([$#$2], [2], [], 28 | [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) 29 | 30 | 31 | # lt_car(LIST) 32 | # lt_cdr(LIST) 33 | # ------------ 34 | # Manipulate m4 lists. 35 | # These macros are necessary as long as will still need to support 36 | # Autoconf-2.59 which quotes differently. 37 | m4_define([lt_car], [[$1]]) 38 | m4_define([lt_cdr], 39 | [m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], 40 | [$#], 1, [], 41 | [m4_dquote(m4_shift($@))])]) 42 | m4_define([lt_unquote], $1) 43 | 44 | 45 | # lt_append(MACRO-NAME, STRING, [SEPARATOR]) 46 | # ------------------------------------------ 47 | # Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'. 48 | # Note that neither SEPARATOR nor STRING are expanded; they are appended 49 | # to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). 50 | # No SEPARATOR is output if MACRO-NAME was previously undefined (different 51 | # than defined and empty). 52 | # 53 | # This macro is needed until we can rely on Autoconf 2.62, since earlier 54 | # versions of m4sugar mistakenly expanded SEPARATOR but not STRING. 55 | m4_define([lt_append], 56 | [m4_define([$1], 57 | m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) 58 | 59 | 60 | 61 | # lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) 62 | # ---------------------------------------------------------- 63 | # Produce a SEP delimited list of all paired combinations of elements of 64 | # PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list 65 | # has the form PREFIXmINFIXSUFFIXn. 66 | # Needed until we can rely on m4_combine added in Autoconf 2.62. 67 | m4_define([lt_combine], 68 | [m4_if(m4_eval([$# > 3]), [1], 69 | [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl 70 | [[m4_foreach([_Lt_prefix], [$2], 71 | [m4_foreach([_Lt_suffix], 72 | ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, 73 | [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) 74 | 75 | 76 | # lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) 77 | # ----------------------------------------------------------------------- 78 | # Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited 79 | # by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. 80 | m4_define([lt_if_append_uniq], 81 | [m4_ifdef([$1], 82 | [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], 83 | [lt_append([$1], [$2], [$3])$4], 84 | [$5])], 85 | [lt_append([$1], [$2], [$3])$4])]) 86 | 87 | 88 | # lt_dict_add(DICT, KEY, VALUE) 89 | # ----------------------------- 90 | m4_define([lt_dict_add], 91 | [m4_define([$1($2)], [$3])]) 92 | 93 | 94 | # lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) 95 | # -------------------------------------------- 96 | m4_define([lt_dict_add_subkey], 97 | [m4_define([$1($2:$3)], [$4])]) 98 | 99 | 100 | # lt_dict_fetch(DICT, KEY, [SUBKEY]) 101 | # ---------------------------------- 102 | m4_define([lt_dict_fetch], 103 | [m4_ifval([$3], 104 | m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), 105 | m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) 106 | 107 | 108 | # lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) 109 | # ----------------------------------------------------------------- 110 | m4_define([lt_if_dict_fetch], 111 | [m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], 112 | [$5], 113 | [$6])]) 114 | 115 | 116 | # lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) 117 | # -------------------------------------------------------------- 118 | m4_define([lt_dict_filter], 119 | [m4_if([$5], [], [], 120 | [lt_join(m4_quote(m4_default([$4], [[, ]])), 121 | lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), 122 | [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl 123 | ]) 124 | -------------------------------------------------------------------------------- /src/amd/amd_info.c: -------------------------------------------------------------------------------- 1 | /* ========================================================================= */ 2 | /* === AMD_info ============================================================ */ 3 | /* ========================================================================= */ 4 | 5 | /* ------------------------------------------------------------------------- */ 6 | /* AMD, Copyright (c) Timothy A. Davis, */ 7 | /* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ 8 | /* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */ 9 | /* web: http://www.cise.ufl.edu/research/sparse/amd */ 10 | /* ------------------------------------------------------------------------- */ 11 | 12 | /* User-callable. Prints the output statistics for AMD. See amd.h 13 | * for details. If the Info array is not present, nothing is printed. 14 | */ 15 | 16 | #include "amd_internal.h" 17 | 18 | #define PRI(format,x) { if (x >= 0) { PRINTF ((format, x)) ; }} 19 | 20 | GLOBAL void AMD_info 21 | ( 22 | double Info [ ] 23 | ) 24 | { 25 | double n, ndiv, nmultsubs_ldl, nmultsubs_lu, lnz, lnzd ; 26 | 27 | PRINTF (("\nAMD version %d.%d.%d, %s, results:\n", 28 | AMD_MAIN_VERSION, AMD_SUB_VERSION, AMD_SUBSUB_VERSION, AMD_DATE)) ; 29 | 30 | if (!Info) 31 | { 32 | return ; 33 | } 34 | 35 | n = Info [AMD_N] ; 36 | ndiv = Info [AMD_NDIV] ; 37 | nmultsubs_ldl = Info [AMD_NMULTSUBS_LDL] ; 38 | nmultsubs_lu = Info [AMD_NMULTSUBS_LU] ; 39 | lnz = Info [AMD_LNZ] ; 40 | lnzd = (n >= 0 && lnz >= 0) ? (n + lnz) : (-1) ; 41 | 42 | /* AMD return status */ 43 | PRINTF ((" status: ")) ; 44 | if (Info [AMD_STATUS] == AMD_OK) 45 | { 46 | PRINTF (("OK\n")) ; 47 | } 48 | else if (Info [AMD_STATUS] == AMD_OUT_OF_MEMORY) 49 | { 50 | PRINTF (("out of memory\n")) ; 51 | } 52 | else if (Info [AMD_STATUS] == AMD_INVALID) 53 | { 54 | PRINTF (("invalid matrix\n")) ; 55 | } 56 | else if (Info [AMD_STATUS] == AMD_OK_BUT_JUMBLED) 57 | { 58 | PRINTF (("OK, but jumbled\n")) ; 59 | } 60 | else 61 | { 62 | PRINTF (("unknown\n")) ; 63 | } 64 | 65 | /* statistics about the input matrix */ 66 | PRI (" n, dimension of A: %.20g\n", n); 67 | PRI (" nz, number of nonzeros in A: %.20g\n", 68 | Info [AMD_NZ]) ; 69 | PRI (" symmetry of A: %.4f\n", 70 | Info [AMD_SYMMETRY]) ; 71 | PRI (" number of nonzeros on diagonal: %.20g\n", 72 | Info [AMD_NZDIAG]) ; 73 | PRI (" nonzeros in pattern of A+A' (excl. diagonal): %.20g\n", 74 | Info [AMD_NZ_A_PLUS_AT]) ; 75 | PRI (" # dense rows/columns of A+A': %.20g\n", 76 | Info [AMD_NDENSE]) ; 77 | 78 | /* statistics about AMD's behavior */ 79 | PRI (" memory used, in bytes: %.20g\n", 80 | Info [AMD_MEMORY]) ; 81 | PRI (" # of memory compactions: %.20g\n", 82 | Info [AMD_NCMPA]) ; 83 | 84 | /* statistics about the ordering quality */ 85 | PRINTF (("\n" 86 | " The following approximate statistics are for a subsequent\n" 87 | " factorization of A(P,P) + A(P,P)'. They are slight upper\n" 88 | " bounds if there are no dense rows/columns in A+A', and become\n" 89 | " looser if dense rows/columns exist.\n\n")) ; 90 | 91 | PRI (" nonzeros in L (excluding diagonal): %.20g\n", 92 | lnz) ; 93 | PRI (" nonzeros in L (including diagonal): %.20g\n", 94 | lnzd) ; 95 | PRI (" # divide operations for LDL' or LU: %.20g\n", 96 | ndiv) ; 97 | PRI (" # multiply-subtract operations for LDL': %.20g\n", 98 | nmultsubs_ldl) ; 99 | PRI (" # multiply-subtract operations for LU: %.20g\n", 100 | nmultsubs_lu) ; 101 | PRI (" max nz. in any column of L (incl. diagonal): %.20g\n", 102 | Info [AMD_DMAX]) ; 103 | 104 | /* total flop counts for various factorizations */ 105 | 106 | if (n >= 0 && ndiv >= 0 && nmultsubs_ldl >= 0 && nmultsubs_lu >= 0) 107 | { 108 | PRINTF (("\n" 109 | " chol flop count for real A, sqrt counted as 1 flop: %.20g\n" 110 | " LDL' flop count for real A: %.20g\n" 111 | " LDL' flop count for complex A: %.20g\n" 112 | " LU flop count for real A (with no pivoting): %.20g\n" 113 | " LU flop count for complex A (with no pivoting): %.20g\n\n", 114 | n + ndiv + 2*nmultsubs_ldl, 115 | ndiv + 2*nmultsubs_ldl, 116 | 9*ndiv + 8*nmultsubs_ldl, 117 | ndiv + 2*nmultsubs_lu, 118 | 9*ndiv + 8*nmultsubs_lu)) ; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/amd/amd_post_tree.c: -------------------------------------------------------------------------------- 1 | /* ========================================================================= */ 2 | /* === AMD_post_tree ======================================================= */ 3 | /* ========================================================================= */ 4 | 5 | /* ------------------------------------------------------------------------- */ 6 | /* AMD, Copyright (c) Timothy A. Davis, */ 7 | /* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ 8 | /* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */ 9 | /* web: http://www.cise.ufl.edu/research/sparse/amd */ 10 | /* ------------------------------------------------------------------------- */ 11 | 12 | /* Post-ordering of a supernodal elimination tree. */ 13 | 14 | #include "amd_internal.h" 15 | 16 | GLOBAL Int AMD_post_tree 17 | ( 18 | Int root, /* root of the tree */ 19 | Int k, /* start numbering at k */ 20 | Int Child [ ], /* input argument of size nn, undefined on 21 | * output. Child [i] is the head of a link 22 | * list of all nodes that are children of node 23 | * i in the tree. */ 24 | const Int Sibling [ ], /* input argument of size nn, not modified. 25 | * If f is a node in the link list of the 26 | * children of node i, then Sibling [f] is the 27 | * next child of node i. 28 | */ 29 | Int Order [ ], /* output order, of size nn. Order [i] = k 30 | * if node i is the kth node of the reordered 31 | * tree. */ 32 | Int Stack [ ] /* workspace of size nn */ 33 | #ifndef NDEBUG 34 | , Int nn /* nodes are in the range 0..nn-1. */ 35 | #endif 36 | ) 37 | { 38 | Int f, head, h, i ; 39 | 40 | #if 0 41 | /* --------------------------------------------------------------------- */ 42 | /* recursive version (Stack [ ] is not used): */ 43 | /* --------------------------------------------------------------------- */ 44 | 45 | /* this is simple, but can caouse stack overflow if nn is large */ 46 | i = root ; 47 | for (f = Child [i] ; f != EMPTY ; f = Sibling [f]) 48 | { 49 | k = AMD_post_tree (f, k, Child, Sibling, Order, Stack, nn) ; 50 | } 51 | Order [i] = k++ ; 52 | return (k) ; 53 | #endif 54 | 55 | /* --------------------------------------------------------------------- */ 56 | /* non-recursive version, using an explicit stack */ 57 | /* --------------------------------------------------------------------- */ 58 | 59 | /* push root on the stack */ 60 | head = 0 ; 61 | Stack [0] = root ; 62 | 63 | while (head >= 0) 64 | { 65 | /* get head of stack */ 66 | ASSERT (head < nn) ; 67 | i = Stack [head] ; 68 | AMD_DEBUG1 (("head of stack "ID" \n", i)) ; 69 | ASSERT (i >= 0 && i < nn) ; 70 | 71 | if (Child [i] != EMPTY) 72 | { 73 | /* the children of i are not yet ordered */ 74 | /* push each child onto the stack in reverse order */ 75 | /* so that small ones at the head of the list get popped first */ 76 | /* and the biggest one at the end of the list gets popped last */ 77 | for (f = Child [i] ; f != EMPTY ; f = Sibling [f]) 78 | { 79 | head++ ; 80 | ASSERT (head < nn) ; 81 | ASSERT (f >= 0 && f < nn) ; 82 | } 83 | h = head ; 84 | ASSERT (head < nn) ; 85 | for (f = Child [i] ; f != EMPTY ; f = Sibling [f]) 86 | { 87 | ASSERT (h > 0) ; 88 | Stack [h--] = f ; 89 | AMD_DEBUG1 (("push "ID" on stack\n", f)) ; 90 | ASSERT (f >= 0 && f < nn) ; 91 | } 92 | ASSERT (Stack [h] == i) ; 93 | 94 | /* delete child list so that i gets ordered next time we see it */ 95 | Child [i] = EMPTY ; 96 | } 97 | else 98 | { 99 | /* the children of i (if there were any) are already ordered */ 100 | /* remove i from the stack and order it. Front i is kth front */ 101 | head-- ; 102 | AMD_DEBUG1 (("pop "ID" order "ID"\n", i, k)) ; 103 | Order [i] = k++ ; 104 | ASSERT (k <= nn) ; 105 | } 106 | 107 | #ifndef NDEBUG 108 | AMD_DEBUG1 (("\nStack:")) ; 109 | for (h = head ; h >= 0 ; h--) 110 | { 111 | Int j = Stack [h] ; 112 | AMD_DEBUG1 ((" "ID, j)) ; 113 | ASSERT (j >= 0 && j < nn) ; 114 | } 115 | AMD_DEBUG1 (("\n\n")) ; 116 | ASSERT (head < nn) ; 117 | #endif 118 | 119 | } 120 | return (k) ; 121 | } 122 | -------------------------------------------------------------------------------- /src/glpscf.h: -------------------------------------------------------------------------------- 1 | /* glpscf.h (Schur complement factorization) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifndef GLPSCF_H 26 | #define GLPSCF_H 27 | 28 | /*********************************************************************** 29 | * The structure SCF defines the following factorization of a square 30 | * nxn matrix C (which is the Schur complement): 31 | * 32 | * F * C = U * P, 33 | * 34 | * where F is a square transforming matrix, U is an upper triangular 35 | * matrix, P is a permutation matrix. 36 | * 37 | * It is assumed that matrix C is small and dense, so matrices F and U 38 | * are stored in the dense format by rows as follows: 39 | * 40 | * 1 n n_max 1 n n_max 41 | * 1 * * * * * * x x x x 1 * * * * * * x x x x 42 | * * * * * * * x x x x . * * * * * x x x x 43 | * * * * * * * x x x x . . * * * * x x x x 44 | * * * * * * * x x x x . . . * * * x x x x 45 | * * * * * * * x x x x . . . . * * x x x x 46 | * n * * * * * * x x x x n . . . . . * x x x x 47 | * x x x x x x x x x x . . . . . . x x x x 48 | * x x x x x x x x x x . . . . . . . x x x 49 | * x x x x x x x x x x . . . . . . . . x x 50 | * n_max x x x x x x x x x x n_max . . . . . . . . . x 51 | * 52 | * matrix F matrix U 53 | * 54 | * where '*' are matrix elements, 'x' are reserved locations. 55 | * 56 | * Permutation matrix P is stored in row-like format. 57 | * 58 | * Matrix C normally is not stored. 59 | * 60 | * REFERENCES 61 | * 62 | * 1. M.A.Saunders, "LUSOL: A basis package for constrained optimiza- 63 | * tion," SCCM, Stanford University, 2006. 64 | * 65 | * 2. M.A.Saunders, "Notes 5: Basis Updates," CME 318, Stanford Univer- 66 | * sity, Spring 2006. 67 | * 68 | * 3. M.A.Saunders, "Notes 6: LUSOL---a Basis Factorization Package," 69 | * ibid. */ 70 | 71 | typedef struct SCF SCF; 72 | 73 | struct SCF 74 | { /* Schur complement factorization */ 75 | int n_max; 76 | /* maximal order of matrices C, F, U, P; n_max >= 1 */ 77 | int n; 78 | /* current order of matrices C, F, U, P; n >= 0 */ 79 | double *f; /* double f[1+n_max*n_max]; */ 80 | /* matrix F stored by rows */ 81 | double *u; /* double u[1+n_max*(n_max+1)/2]; */ 82 | /* upper triangle of matrix U stored by rows */ 83 | int *p; /* int p[1+n_max]; */ 84 | /* matrix P; p[i] = j means that P[i,j] = 1 */ 85 | int t_opt; 86 | /* type of transformation used to restore triangular structure of 87 | matrix U: */ 88 | #define SCF_TBG 1 /* Bartels-Golub elimination */ 89 | #define SCF_TGR 2 /* Givens plane rotation */ 90 | int rank; 91 | /* estimated rank of matrices C and U */ 92 | double *c; /* double c[1+n_max*n_max]; */ 93 | /* matrix C stored in the same format as matrix F and used only 94 | for debugging; normally this array is not allocated */ 95 | double *w; /* double w[1+n_max]; */ 96 | /* working array */ 97 | }; 98 | 99 | /* return codes: */ 100 | #define SCF_ESING 1 /* singular matrix */ 101 | #define SCF_ELIMIT 2 /* update limit reached */ 102 | 103 | #define scf_create_it _glp_scf_create_it 104 | SCF *scf_create_it(int n_max); 105 | /* create Schur complement factorization */ 106 | 107 | #define scf_update_exp _glp_scf_update_exp 108 | int scf_update_exp(SCF *scf, const double x[], const double y[], 109 | double z); 110 | /* update factorization on expanding C */ 111 | 112 | #define scf_solve_it _glp_scf_solve_it 113 | void scf_solve_it(SCF *scf, int tr, double x[]); 114 | /* solve either system C * x = b or C' * x = b */ 115 | 116 | #define scf_reset_it _glp_scf_reset_it 117 | void scf_reset_it(SCF *scf); 118 | /* reset factorization for empty matrix C */ 119 | 120 | #define scf_delete_it _glp_scf_delete_it 121 | void scf_delete_it(SCF *scf); 122 | /* delete Schur complement factorization */ 123 | 124 | #endif 125 | 126 | /* eof */ 127 | -------------------------------------------------------------------------------- /src/glphbm.h: -------------------------------------------------------------------------------- 1 | /* glphbm.h (Harwell-Boeing sparse matrix format) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifndef GLPHBM_H 26 | #define GLPHBM_H 27 | 28 | typedef struct HBM HBM; 29 | 30 | struct HBM 31 | { /* sparse matrix in Harwell-Boeing format; for details see the 32 | report: I.S.Duff, R.G.Grimes, J.G.Lewis. User's Guide for the 33 | Harwell-Boeing Sparse Matrix Collection (Release I), 1992 */ 34 | char title[72+1]; 35 | /* matrix title (informative) */ 36 | char key[8+1]; 37 | /* matrix key (informative) */ 38 | char mxtype[3+1]; 39 | /* matrix type: 40 | R.. real matrix 41 | C.. complex matrix 42 | P.. pattern only (no numerical values supplied) 43 | .S. symmetric (lower triangle + main diagonal) 44 | .U. unsymmetric 45 | .H. hermitian (lower triangle + main diagonal) 46 | .Z. skew symmetric (lower triangle only) 47 | .R. rectangular 48 | ..A assembled 49 | ..E elemental (unassembled) */ 50 | char rhstyp[3+1]; 51 | /* optional types: 52 | F.. right-hand sides in dense format 53 | M.. right-hand sides in same format as matrix 54 | .G. starting vector(s) (guess) is supplied 55 | ..X exact solution vector(s) is supplied */ 56 | char ptrfmt[16+1]; 57 | /* format for pointers */ 58 | char indfmt[16+1]; 59 | /* format for row (or variable) indices */ 60 | char valfmt[20+1]; 61 | /* format for numerical values of coefficient matrix */ 62 | char rhsfmt[20+1]; 63 | /* format for numerical values of right-hand sides */ 64 | int totcrd; 65 | /* total number of cards excluding header */ 66 | int ptrcrd; 67 | /* number of cards for ponters */ 68 | int indcrd; 69 | /* number of cards for row (or variable) indices */ 70 | int valcrd; 71 | /* number of cards for numerical values */ 72 | int rhscrd; 73 | /* number of lines for right-hand sides; 74 | including starting guesses and solution vectors if present; 75 | zero indicates no right-hand side data is present */ 76 | int nrow; 77 | /* number of rows (or variables) */ 78 | int ncol; 79 | /* number of columns (or elements) */ 80 | int nnzero; 81 | /* number of row (or variable) indices; 82 | equal to number of entries for assembled matrix */ 83 | int neltvl; 84 | /* number of elemental matrix entries; 85 | zero in case of assembled matrix */ 86 | int nrhs; 87 | /* number of right-hand sides */ 88 | int nrhsix; 89 | /* number of row indices; 90 | ignored in case of unassembled matrix */ 91 | int nrhsvl; 92 | /* total number of entries in all right-hand sides */ 93 | int nguess; 94 | /* total number of entries in all starting guesses */ 95 | int nexact; 96 | /* total number of entries in all solution vectors */ 97 | int *colptr; /* alias: eltptr */ 98 | /* column pointers (in case of assembled matrix); 99 | elemental matrix pointers (in case of unassembled matrix) */ 100 | int *rowind; /* alias: varind */ 101 | /* row indices (in case of assembled matrix); 102 | variable indices (in case of unassembled matrix) */ 103 | int *rhsptr; 104 | /* right-hand side pointers */ 105 | int *rhsind; 106 | /* right-hand side indices */ 107 | double *values; 108 | /* matrix values */ 109 | double *rhsval; 110 | /* right-hand side values */ 111 | double *sguess; 112 | /* starting guess values */ 113 | double *xexact; 114 | /* solution vector values */ 115 | }; 116 | 117 | #define hbm_read_mat _glp_hbm_read_mat 118 | HBM *hbm_read_mat(const char *fname); 119 | /* read sparse matrix in Harwell-Boeing format */ 120 | 121 | #define hbm_free_mat _glp_hbm_free_mat 122 | void hbm_free_mat(HBM *hbm); 123 | /* free sparse matrix in Harwell-Boeing format */ 124 | 125 | #endif 126 | 127 | /* eof */ 128 | -------------------------------------------------------------------------------- /src/glpapi04.c: -------------------------------------------------------------------------------- 1 | /* glpapi04.c (problem scaling routines) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #include "glpapi.h" 26 | 27 | /*********************************************************************** 28 | * NAME 29 | * 30 | * glp_set_rii - set (change) row scale factor 31 | * 32 | * SYNOPSIS 33 | * 34 | * void glp_set_rii(glp_prob *lp, int i, double rii); 35 | * 36 | * DESCRIPTION 37 | * 38 | * The routine glp_set_rii sets (changes) the scale factor r[i,i] for 39 | * i-th row of the specified problem object. */ 40 | 41 | void glp_set_rii(glp_prob *lp, int i, double rii) 42 | { if (!(1 <= i && i <= lp->m)) 43 | xerror("glp_set_rii: i = %d; row number out of range\n", i); 44 | if (rii <= 0.0) 45 | xerror("glp_set_rii: i = %d; rii = %g; invalid scale factor\n", 46 | i, rii); 47 | if (lp->valid && lp->row[i]->rii != rii) 48 | { GLPAIJ *aij; 49 | for (aij = lp->row[i]->ptr; aij != NULL; aij = aij->r_next) 50 | { if (aij->col->stat == GLP_BS) 51 | { /* invalidate the basis factorization */ 52 | lp->valid = 0; 53 | break; 54 | } 55 | } 56 | } 57 | lp->row[i]->rii = rii; 58 | return; 59 | } 60 | 61 | /*********************************************************************** 62 | * NAME 63 | * 64 | * glp_set sjj - set (change) column scale factor 65 | * 66 | * SYNOPSIS 67 | * 68 | * void glp_set_sjj(glp_prob *lp, int j, double sjj); 69 | * 70 | * DESCRIPTION 71 | * 72 | * The routine glp_set_sjj sets (changes) the scale factor s[j,j] for 73 | * j-th column of the specified problem object. */ 74 | 75 | void glp_set_sjj(glp_prob *lp, int j, double sjj) 76 | { if (!(1 <= j && j <= lp->n)) 77 | xerror("glp_set_sjj: j = %d; column number out of range\n", j); 78 | if (sjj <= 0.0) 79 | xerror("glp_set_sjj: j = %d; sjj = %g; invalid scale factor\n", 80 | j, sjj); 81 | if (lp->valid && lp->col[j]->sjj != sjj && lp->col[j]->stat == 82 | GLP_BS) 83 | { /* invalidate the basis factorization */ 84 | lp->valid = 0; 85 | } 86 | lp->col[j]->sjj = sjj; 87 | return; 88 | } 89 | 90 | /*********************************************************************** 91 | * NAME 92 | * 93 | * glp_get_rii - retrieve row scale factor 94 | * 95 | * SYNOPSIS 96 | * 97 | * double glp_get_rii(glp_prob *lp, int i); 98 | * 99 | * RETURNS 100 | * 101 | * The routine glp_get_rii returns current scale factor r[i,i] for i-th 102 | * row of the specified problem object. */ 103 | 104 | double glp_get_rii(glp_prob *lp, int i) 105 | { if (!(1 <= i && i <= lp->m)) 106 | xerror("glp_get_rii: i = %d; row number out of range\n", i); 107 | return lp->row[i]->rii; 108 | } 109 | 110 | /*********************************************************************** 111 | * NAME 112 | * 113 | * glp_get_sjj - retrieve column scale factor 114 | * 115 | * SYNOPSIS 116 | * 117 | * double glp_get_sjj(glp_prob *lp, int j); 118 | * 119 | * RETURNS 120 | * 121 | * The routine glp_get_sjj returns current scale factor s[j,j] for j-th 122 | * column of the specified problem object. */ 123 | 124 | double glp_get_sjj(glp_prob *lp, int j) 125 | { if (!(1 <= j && j <= lp->n)) 126 | xerror("glp_get_sjj: j = %d; column number out of range\n", j); 127 | return lp->col[j]->sjj; 128 | } 129 | 130 | /*********************************************************************** 131 | * NAME 132 | * 133 | * glp_unscale_prob - unscale problem data 134 | * 135 | * SYNOPSIS 136 | * 137 | * void glp_unscale_prob(glp_prob *lp); 138 | * 139 | * DESCRIPTION 140 | * 141 | * The routine glp_unscale_prob performs unscaling of problem data for 142 | * the specified problem object. 143 | * 144 | * "Unscaling" means replacing the current scaling matrices R and S by 145 | * unity matrices that cancels the scaling effect. */ 146 | 147 | void glp_unscale_prob(glp_prob *lp) 148 | { int m = glp_get_num_rows(lp); 149 | int n = glp_get_num_cols(lp); 150 | int i, j; 151 | for (i = 1; i <= m; i++) glp_set_rii(lp, i, 1.0); 152 | for (j = 1; j <= n; j++) glp_set_sjj(lp, j, 1.0); 153 | return; 154 | } 155 | 156 | /* eof */ 157 | -------------------------------------------------------------------------------- /src/glpenv06.c: -------------------------------------------------------------------------------- 1 | /* glpenv06.c (standard time) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include 27 | #endif 28 | 29 | #include "glpapi.h" 30 | 31 | /*********************************************************************** 32 | * NAME 33 | * 34 | * glp_time - determine current universal time 35 | * 36 | * SYNOPSIS 37 | * 38 | * glp_long glp_time(void); 39 | * 40 | * RETURNS 41 | * 42 | * The routine glp_time returns the current universal time (UTC), in 43 | * milliseconds, elapsed since 00:00:00 GMT January 1, 1970. */ 44 | 45 | static const int epoch = 2440588; /* = jday(1, 1, 1970) */ 46 | 47 | /* POSIX version ******************************************************/ 48 | 49 | #if 0 //defined(HAVE_SYS_TIME_H) && defined(HAVE_GETTIMEOFDAY) 50 | 51 | #include 52 | #include 53 | 54 | glp_long glp_time(void) 55 | { struct timeval tv; 56 | struct tm *tm; 57 | glp_long t; 58 | int j; 59 | gettimeofday(&tv, NULL); 60 | tm = gmtime(&tv.tv_sec); 61 | j = jday(tm->tm_mday, tm->tm_mon + 1, 1900 + tm->tm_year); 62 | xassert(j >= 0); 63 | t = xlset(j - epoch); 64 | t = xlmul(t, xlset(24)); 65 | t = xladd(t, xlset(tm->tm_hour)); 66 | t = xlmul(t, xlset(60)); 67 | t = xladd(t, xlset(tm->tm_min)); 68 | t = xlmul(t, xlset(60)); 69 | t = xladd(t, xlset(tm->tm_sec)); 70 | t = xlmul(t, xlset(1000)); 71 | t = xladd(t, xlset(tv.tv_usec / 1000)); 72 | return t; 73 | } 74 | 75 | /* Windows version ****************************************************/ 76 | 77 | #elif 0 //defined(__WOE__) 78 | 79 | #include 80 | 81 | glp_long glp_time(void) 82 | { SYSTEMTIME st; 83 | glp_long t; 84 | int j; 85 | GetSystemTime(&st); 86 | j = jday(st.wDay, st.wMonth, st.wYear); 87 | xassert(j >= 0); 88 | t = xlset(j - epoch); 89 | t = xlmul(t, xlset(24)); 90 | t = xladd(t, xlset(st.wHour)); 91 | t = xlmul(t, xlset(60)); 92 | t = xladd(t, xlset(st.wMinute)); 93 | t = xlmul(t, xlset(60)); 94 | t = xladd(t, xlset(st.wSecond)); 95 | t = xlmul(t, xlset(1000)); 96 | t = xladd(t, xlset(st.wMilliseconds)); 97 | return t; 98 | } 99 | 100 | /* portable ISO C version *********************************************/ 101 | 102 | #else 103 | 104 | #include 105 | 106 | glp_long glp_time(void) 107 | { /* time_t timer; 108 | struct tm *tm; 109 | glp_long t; 110 | int j; 111 | timer = time(NULL); 112 | tm = gmtime(&timer); 113 | j = jday(tm->tm_mday, tm->tm_mon + 1, 1900 + tm->tm_year); 114 | xassert(j >= 0); 115 | t = xlset(j - epoch); 116 | t = xlmul(t, xlset(24)); 117 | t = xladd(t, xlset(tm->tm_hour)); 118 | t = xlmul(t, xlset(60)); 119 | t = xladd(t, xlset(tm->tm_min)); 120 | t = xlmul(t, xlset(60)); 121 | t = xladd(t, xlset(tm->tm_sec)); 122 | t = xlmul(t, xlset(1000)); */ 123 | glp_long t = xlset(0); 124 | return t; 125 | } 126 | 127 | #endif 128 | 129 | /*********************************************************************** 130 | * NAME 131 | * 132 | * glp_difftime - compute difference between two time values 133 | * 134 | * SYNOPSIS 135 | * 136 | * double glp_difftime(glp_long t1, glp_long t0); 137 | * 138 | * RETURNS 139 | * 140 | * The routine glp_difftime returns the difference between two time 141 | * values t1 and t0, expressed in seconds. */ 142 | 143 | double glp_difftime(glp_long t1, glp_long t0) 144 | { return 145 | xltod(xlsub(t1, t0)) / 1000.0; 146 | } 147 | 148 | /**********************************************************************/ 149 | 150 | #if 0 151 | int main(void) 152 | { glp_long t; 153 | glp_ldiv d; 154 | int ttt, ss, mm, hh, day, month, year; 155 | char s[50]; 156 | t = glp_time(); 157 | xprintf("t = %s\n", xltoa(t, s)); 158 | d = xldiv(t, xlset(1000)); 159 | ttt = d.rem.lo, t = d.quot; 160 | d = xldiv(t, xlset(60)); 161 | ss = d.rem.lo, t = d.quot; 162 | d = xldiv(t, xlset(60)); 163 | mm = d.rem.lo, t = d.quot; 164 | d = xldiv(t, xlset(24)); 165 | hh = d.rem.lo, t = d.quot; 166 | xassert(jdate(t.lo + epoch, &day, &month, &year) == 0); 167 | xprintf("%04d-%02d-%02d %02d:%02d:%02d.%03d\n", year, month, day, 168 | hh, mm, ss, ttt); 169 | return 0; 170 | } 171 | #endif 172 | 173 | /* eof */ 174 | -------------------------------------------------------------------------------- /src/dw.h: -------------------------------------------------------------------------------- 1 | /* ***************************************************************************** 2 | * 3 | * DWSOLVER - a general, parallel implementation of the Dantzig-Wolfe 4 | * Decomposition algorithm. 5 | * 6 | * Copyright 2010 United States Government National Aeronautics and Space 7 | * Administration (NASA). No copyright is claimed in the United States under 8 | * Title 17, U.S. Code. All Other Rights Reserved. 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * In accordance with the GNU General Public License Version 3, 29 June 2007 21 | * (GPL V3) Section 7. Additional Terms, Additional Permissions are added as 22 | * exceptions to the terms of the GPL V3 for this program. These additional 23 | * terms should have been received with this program in a file entitled 24 | * "ADDITIONAL_LICENSE_TERMS". If a copy was not provided, you may request 25 | * one from the contact author listed below. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | * 30 | * Contact: Joseph Rios 31 | * 32 | **************************************************************************** */ 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #ifndef DECOMPOSE_H_ 42 | #define DECOMPOSE_H_ 43 | 44 | #define BUFF_SIZE 200 45 | 46 | #define TOLERANCE 0.000001 47 | 48 | #define STACKMEM 2500000 49 | #define DW_INFINITY 1000000.0 50 | #define MAX_PHASE2_ITERATIONS 3000 51 | #define MAX_PHASE1_ITERATIONS 100 52 | 53 | /* The 'verbosity' of the output will be determined by the user at launch 54 | * time. Default value is OUTPUT_NORMAL. 55 | */ 56 | #define OUTPUT_SILENT -1 57 | #define OUTPUT_QUIET 0 58 | #define OUTPUT_NORMAL 5 59 | #define OUTPUT_VERBOSE 10 60 | #define OUTPUT_ALL 15 61 | 62 | /* Each print statement will include an 'importance' value. When compared 63 | * with the 'verbosity' the statement may or may not be executed. Specifically, 64 | * if importance <= verbosity, then the message will be printed. 65 | */ 66 | #define IMPORTANCE_DIAG 15 67 | #define IMPORTANCE_MIN 10 68 | #define IMPORTANCE_AVG 5 69 | #define IMPORTANCE_VITAL 0 70 | 71 | #define DEFAULT_MIP_GAP 0.01 72 | 73 | /* All of these used to be global variables. I shoved all of them into this 74 | * struct, created an instance of this struct in main then passed it around 75 | * one way or another to the functions that needed it. There are some 76 | * unfortunate pointer chains as a result in some places, but that is the 77 | * trade-off, I suppose. 78 | */ 79 | typedef struct { 80 | double shift; 81 | double mip_gap; 82 | int num_clients; 83 | int integerize_flag; 84 | int rounding_flag; 85 | int enforce_sub_integrality; 86 | int verbosity; 87 | int print_timing_data; 88 | int print_final_master; 89 | int print_relaxed_sol; 90 | int perturb; 91 | int max_phase1_iterations; 92 | int max_phase2_iterations; 93 | int head_service_queue; 94 | int tail_service_queue; 95 | int write_bases; 96 | int write_intermediate_opt_files; 97 | int get_monolithic_file; 98 | int* service_queue; 99 | char** subproblem_names; 100 | char* master_name; 101 | char* monolithic_name; 102 | double* final_x; 103 | double* relaxed_x; 104 | double*** x; 105 | } faux_globals; 106 | 107 | /* Globally available variables. Look into minimizing or eliminating them? */ 108 | 109 | pthread_attr_t attr; 110 | pthread_mutex_t master_lp_ready_mutex; 111 | pthread_cond_t master_lp_ready_cv; 112 | pthread_mutex_t service_queue_mutex; 113 | pthread_mutex_t next_iteration_mutex; 114 | pthread_cond_t next_iteration_cv; 115 | pthread_mutex_t master_mutex; 116 | pthread_mutex_t reduced_cost_mutex; 117 | pthread_mutex_t glpk_mutex; 118 | pthread_mutex_t fputs_mutex; 119 | pthread_mutex_t* sub_data_mutex; 120 | #ifdef USE_NAMED_SEMAPHORES 121 | sem_t* customers; 122 | #define CUST_NAMED_SEMAPHORE "/tmp/dw_customers" 123 | #else 124 | sem_t customers; 125 | #endif 126 | glp_prob* original_master_lp; 127 | glp_prob* master_lp; 128 | glp_iocp* parm; 129 | glp_smcp* simplex_control_params; 130 | 131 | typedef struct { 132 | int cols; 133 | int rows; 134 | double* row_duals; 135 | double* c; 136 | } master_data; 137 | 138 | typedef struct D_matrix { 139 | double* values; 140 | int* columns; 141 | int* pointerB; 142 | int* pointerE; 143 | int rows; 144 | int cols; 145 | int rows_plus; 146 | } D_matrix; 147 | D_matrix* D; 148 | 149 | typedef struct hook_struct{ 150 | char* outfile_name; 151 | FILE* outfile; 152 | 153 | } hook_struct; 154 | 155 | typedef struct new_column{ 156 | char* name; 157 | int non_zeros; 158 | int* ind; 159 | double* val; 160 | } new_column; 161 | 162 | typedef struct signal_data{ 163 | int master_lp_ready; 164 | int next_iteration_ready; 165 | int current_iteration; 166 | } signal_data; 167 | signal_data* signals; 168 | 169 | 170 | #endif /*DECOMPOSE_H_*/ 171 | -------------------------------------------------------------------------------- /src/glpspm.h: -------------------------------------------------------------------------------- 1 | /* glpspm.h (general sparse matrix) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #ifndef GLPSPM_H 26 | #define GLPSPM_H 27 | 28 | #include "glpdmp.h" 29 | 30 | typedef struct SPM SPM; 31 | typedef struct SPME SPME; 32 | 33 | struct SPM 34 | { /* general sparse matrix */ 35 | int m; 36 | /* number of rows, m >= 0 */ 37 | int n; 38 | /* number of columns, n >= 0 */ 39 | DMP *pool; 40 | /* memory pool to store matrix elements */ 41 | SPME **row; /* SPME *row[1+m]; */ 42 | /* row[i], 1 <= i <= m, is a pointer to i-th row list */ 43 | SPME **col; /* SPME *col[1+n]; */ 44 | /* col[j], 1 <= j <= n, is a pointer to j-th column list */ 45 | }; 46 | 47 | struct SPME 48 | { /* sparse matrix element */ 49 | int i; 50 | /* row number */ 51 | int j; 52 | /* column number */ 53 | double val; 54 | /* element value */ 55 | SPME *r_prev; 56 | /* pointer to previous element in the same row */ 57 | SPME *r_next; 58 | /* pointer to next element in the same row */ 59 | SPME *c_prev; 60 | /* pointer to previous element in the same column */ 61 | SPME *c_next; 62 | /* pointer to next element in the same column */ 63 | }; 64 | 65 | typedef struct PER PER; 66 | 67 | struct PER 68 | { /* permutation matrix */ 69 | int n; 70 | /* matrix order, n >= 0 */ 71 | int *row; /* int row[1+n]; */ 72 | /* row[i] = j means p[i,j] = 1 */ 73 | int *col; /* int col[1+n]; */ 74 | /* col[j] = i means p[i,j] = 1 */ 75 | }; 76 | 77 | #define spm_create_mat _glp_spm_create_mat 78 | SPM *spm_create_mat(int m, int n); 79 | /* create general sparse matrix */ 80 | 81 | #define spm_new_elem _glp_spm_new_elem 82 | SPME *spm_new_elem(SPM *A, int i, int j, double val); 83 | /* add new element to sparse matrix */ 84 | 85 | #define spm_delete_mat _glp_spm_delete_mat 86 | void spm_delete_mat(SPM *A); 87 | /* delete general sparse matrix */ 88 | 89 | #define spm_test_mat_e _glp_spm_test_mat_e 90 | SPM *spm_test_mat_e(int n, int c); 91 | /* create test sparse matrix of E(n,c) class */ 92 | 93 | #define spm_test_mat_d _glp_spm_test_mat_d 94 | SPM *spm_test_mat_d(int n, int c); 95 | /* create test sparse matrix of D(n,c) class */ 96 | 97 | #define spm_show_mat _glp_spm_show_mat 98 | int spm_show_mat(const SPM *A, const char *fname); 99 | /* write sparse matrix pattern in BMP file format */ 100 | 101 | #define spm_read_hbm _glp_spm_read_hbm 102 | SPM *spm_read_hbm(const char *fname); 103 | /* read sparse matrix in Harwell-Boeing format */ 104 | 105 | #define spm_count_nnz _glp_spm_count_nnz 106 | int spm_count_nnz(const SPM *A); 107 | /* determine number of non-zeros in sparse matrix */ 108 | 109 | #define spm_drop_zeros _glp_spm_drop_zeros 110 | int spm_drop_zeros(SPM *A, double eps); 111 | /* remove zero elements from sparse matrix */ 112 | 113 | #define spm_read_mat _glp_spm_read_mat 114 | SPM *spm_read_mat(const char *fname); 115 | /* read sparse matrix from text file */ 116 | 117 | #define spm_write_mat _glp_spm_write_mat 118 | int spm_write_mat(const SPM *A, const char *fname); 119 | /* write sparse matrix to text file */ 120 | 121 | #define spm_transpose _glp_spm_transpose 122 | SPM *spm_transpose(const SPM *A); 123 | /* transpose sparse matrix */ 124 | 125 | #define spm_add_sym _glp_spm_add_sym 126 | SPM *spm_add_sym(const SPM *A, const SPM *B); 127 | /* add two sparse matrices (symbolic phase) */ 128 | 129 | #define spm_add_num _glp_spm_add_num 130 | void spm_add_num(SPM *C, double alfa, const SPM *A, double beta, 131 | const SPM *B); 132 | /* add two sparse matrices (numeric phase) */ 133 | 134 | #define spm_add_mat _glp_spm_add_mat 135 | SPM *spm_add_mat(double alfa, const SPM *A, double beta, 136 | const SPM *B); 137 | /* add two sparse matrices (driver routine) */ 138 | 139 | #define spm_mul_sym _glp_spm_mul_sym 140 | SPM *spm_mul_sym(const SPM *A, const SPM *B); 141 | /* multiply two sparse matrices (symbolic phase) */ 142 | 143 | #define spm_mul_num _glp_spm_mul_num 144 | void spm_mul_num(SPM *C, const SPM *A, const SPM *B); 145 | /* multiply two sparse matrices (numeric phase) */ 146 | 147 | #define spm_mul_mat _glp_spm_mul_mat 148 | SPM *spm_mul_mat(const SPM *A, const SPM *B); 149 | /* multiply two sparse matrices (driver routine) */ 150 | 151 | #define spm_create_per _glp_spm_create_per 152 | PER *spm_create_per(int n); 153 | /* create permutation matrix */ 154 | 155 | #define spm_check_per _glp_spm_check_per 156 | void spm_check_per(PER *P); 157 | /* check permutation matrix for correctness */ 158 | 159 | #define spm_delete_per _glp_spm_delete_per 160 | void spm_delete_per(PER *P); 161 | /* delete permutation matrix */ 162 | 163 | #endif 164 | 165 | /* eof */ 166 | -------------------------------------------------------------------------------- /src/glpapi03.c: -------------------------------------------------------------------------------- 1 | /* glpapi03.c (row and column searching routines) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #include "glpapi.h" 26 | 27 | /*********************************************************************** 28 | * NAME 29 | * 30 | * glp_create_index - create the name index 31 | * 32 | * SYNOPSIS 33 | * 34 | * void glp_create_index(glp_prob *lp); 35 | * 36 | * DESCRIPTION 37 | * 38 | * The routine glp_create_index creates the name index for the 39 | * specified problem object. The name index is an auxiliary data 40 | * structure, which is intended to quickly (i.e. for logarithmic time) 41 | * find rows and columns by their names. 42 | * 43 | * This routine can be called at any time. If the name index already 44 | * exists, the routine does nothing. */ 45 | 46 | void glp_create_index(glp_prob *lp) 47 | { GLPROW *row; 48 | GLPCOL *col; 49 | int i, j; 50 | /* create row name index */ 51 | if (lp->r_tree == NULL) 52 | { lp->r_tree = avl_create_tree(avl_strcmp, NULL); 53 | for (i = 1; i <= lp->m; i++) 54 | { row = lp->row[i]; 55 | xassert(row->node == NULL); 56 | if (row->name != NULL) 57 | { row->node = avl_insert_node(lp->r_tree, row->name); 58 | avl_set_node_link(row->node, row); 59 | } 60 | } 61 | } 62 | /* create column name index */ 63 | if (lp->c_tree == NULL) 64 | { lp->c_tree = avl_create_tree(avl_strcmp, NULL); 65 | for (j = 1; j <= lp->n; j++) 66 | { col = lp->col[j]; 67 | xassert(col->node == NULL); 68 | if (col->name != NULL) 69 | { col->node = avl_insert_node(lp->c_tree, col->name); 70 | avl_set_node_link(col->node, col); 71 | } 72 | } 73 | } 74 | return; 75 | } 76 | 77 | /*********************************************************************** 78 | * NAME 79 | * 80 | * glp_find_row - find row by its name 81 | * 82 | * SYNOPSIS 83 | * 84 | * int glp_find_row(glp_prob *lp, const char *name); 85 | * 86 | * RETURNS 87 | * 88 | * The routine glp_find_row returns the ordinal number of a row, 89 | * which is assigned (by the routine glp_set_row_name) the specified 90 | * symbolic name. If no such row exists, the routine returns 0. */ 91 | 92 | int glp_find_row(glp_prob *lp, const char *name) 93 | { AVLNODE *node; 94 | int i = 0; 95 | if (lp->r_tree == NULL) 96 | xerror("glp_find_row: row name index does not exist\n"); 97 | if (!(name == NULL || name[0] == '\0' || strlen(name) > 255)) 98 | { node = avl_find_node(lp->r_tree, name); 99 | if (node != NULL) 100 | i = ((GLPROW *)avl_get_node_link(node))->i; 101 | } 102 | return i; 103 | } 104 | 105 | /*********************************************************************** 106 | * NAME 107 | * 108 | * glp_find_col - find column by its name 109 | * 110 | * SYNOPSIS 111 | * 112 | * int glp_find_col(glp_prob *lp, const char *name); 113 | * 114 | * RETURNS 115 | * 116 | * The routine glp_find_col returns the ordinal number of a column, 117 | * which is assigned (by the routine glp_set_col_name) the specified 118 | * symbolic name. If no such column exists, the routine returns 0. */ 119 | 120 | int glp_find_col(glp_prob *lp, const char *name) 121 | { AVLNODE *node; 122 | int j = 0; 123 | if (lp->c_tree == NULL) 124 | xerror("glp_find_col: column name index does not exist\n"); 125 | if (!(name == NULL || name[0] == '\0' || strlen(name) > 255)) 126 | { node = avl_find_node(lp->c_tree, name); 127 | if (node != NULL) 128 | j = ((GLPCOL *)avl_get_node_link(node))->j; 129 | } 130 | return j; 131 | } 132 | 133 | /*********************************************************************** 134 | * NAME 135 | * 136 | * glp_delete_index - delete the name index 137 | * 138 | * SYNOPSIS 139 | * 140 | * void glp_delete_index(glp_prob *lp); 141 | * 142 | * DESCRIPTION 143 | * 144 | * The routine glp_delete_index deletes the name index previously 145 | * created by the routine glp_create_index and frees the memory 146 | * allocated to this auxiliary data structure. 147 | * 148 | * This routine can be called at any time. If the name index does not 149 | * exist, the routine does nothing. */ 150 | 151 | void glp_delete_index(glp_prob *lp) 152 | { int i, j; 153 | /* delete row name index */ 154 | if (lp->r_tree != NULL) 155 | { for (i = 1; i <= lp->m; i++) lp->row[i]->node = NULL; 156 | avl_delete_tree(lp->r_tree), lp->r_tree = NULL; 157 | } 158 | /* delete column name index */ 159 | if (lp->c_tree != NULL) 160 | { for (j = 1; j <= lp->n; j++) lp->col[j]->node = NULL; 161 | avl_delete_tree(lp->c_tree), lp->c_tree = NULL; 162 | } 163 | return; 164 | } 165 | 166 | /* eof */ 167 | -------------------------------------------------------------------------------- /m4/lt~obsolete.m4: -------------------------------------------------------------------------------- 1 | # lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- 2 | # 3 | # Copyright (C) 2004, 2005, 2007, 2009 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004. 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # serial 4 lt~obsolete.m4 11 | 12 | # These exist entirely to fool aclocal when bootstrapping libtool. 13 | # 14 | # In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN) 15 | # which have later been changed to m4_define as they aren't part of the 16 | # exported API, or moved to Autoconf or Automake where they belong. 17 | # 18 | # The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN 19 | # in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us 20 | # using a macro with the same name in our local m4/libtool.m4 it'll 21 | # pull the old libtool.m4 in (it doesn't see our shiny new m4_define 22 | # and doesn't know about Autoconf macros at all.) 23 | # 24 | # So we provide this file, which has a silly filename so it's always 25 | # included after everything else. This provides aclocal with the 26 | # AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything 27 | # because those macros already exist, or will be overwritten later. 28 | # We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. 29 | # 30 | # Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. 31 | # Yes, that means every name once taken will need to remain here until 32 | # we give up compatibility with versions before 1.7, at which point 33 | # we need to keep only those names which we still refer to. 34 | 35 | # This is to help aclocal find these macros, as it can't see m4_define. 36 | AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) 37 | 38 | m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) 39 | m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) 40 | m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) 41 | m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) 42 | m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) 43 | m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) 44 | m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) 45 | m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) 46 | m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) 47 | m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) 48 | m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) 49 | m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) 50 | m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) 51 | m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) 52 | m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) 53 | m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) 54 | m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) 55 | m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) 56 | m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) 57 | m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) 58 | m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) 59 | m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) 60 | m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) 61 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) 62 | m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) 63 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) 64 | m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) 65 | m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) 66 | m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) 67 | m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) 68 | m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) 69 | m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) 70 | m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) 71 | m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) 72 | m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) 73 | m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) 74 | m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) 75 | m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) 76 | m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) 77 | m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) 78 | m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) 79 | m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) 80 | m4_ifndef([AC_LIBTOOL_RC], [AC_DEFUN([AC_LIBTOOL_RC])]) 81 | m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) 82 | m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) 83 | m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) 84 | m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) 85 | m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) 86 | m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) 87 | m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) 88 | m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) 89 | m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) 90 | m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) 91 | m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) 92 | m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) 93 | m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS], [AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])]) 94 | m4_ifndef([_LT_AC_PROG_CXXCPP], [AC_DEFUN([_LT_AC_PROG_CXXCPP])]) 95 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | dnl Process this file with autoconf to produce a configure script 2 | 3 | AC_INIT([dwsolver], [1.2.1], [Joseph.L.Rios@nasa.gov]) 4 | 5 | dnl AC_CONFIG_SRCDIR([include/glpk.h]) 6 | 7 | AC_CONFIG_MACRO_DIR([m4]) 8 | 9 | AM_INIT_AUTOMAKE 10 | 11 | AC_CONFIG_HEADERS([config.h]) 12 | 13 | AC_ARG_ENABLE(named_semaphores, 14 | AC_HELP_STRING([--enable-named-semaphores], 15 | [enable named semaphores (probably needed on Mac) [[default=no]]]), 16 | [case $enableval in 17 | yes | no) ;; 18 | *) AC_MSG_ERROR([invalid value `$withval' for --enable-named-semaphores]);; 19 | esac], 20 | [enable_named_semaphores=no]) 21 | 22 | AC_ARG_ENABLE(recursive_mutex, 23 | AC_HELP_STRING([--enable-recursive-mutex], 24 | [enable use of recursive mutices (probably needed on Mac) [[default=no]]]), 25 | [case $enableval in 26 | yes | no) ;; 27 | *) AC_MSG_ERROR([invalid value `$withval' for --enable-recursive-mutex]);; 28 | esac], 29 | [enable_recursive_mutex=no]) 30 | 31 | AC_ARG_WITH(gmp, 32 | AC_HELP_STRING([--with-gmp], 33 | [use GNU MP bignum library [[default=no]]]), 34 | [case $withval in 35 | yes | no) ;; 36 | *) AC_MSG_ERROR([invalid value `$withval' for --with-gmp]);; 37 | esac], 38 | [with_gmp=no]) 39 | 40 | AC_ARG_WITH(zlib, 41 | AC_HELP_STRING([--with-zlib], 42 | [use zlib data compression library [[default=no]]]), 43 | [case $withval in 44 | yes | no) ;; 45 | *) AC_MSG_ERROR([invalid value `$withval' for --with-zlib]);; 46 | esac], 47 | [with_zlib=no]) 48 | 49 | AC_ARG_ENABLE(dl, 50 | AC_HELP_STRING([--enable-dl], 51 | [enable shared library support [[default=no]]]), 52 | [case $enableval in 53 | yes | ltdl | dlfcn | no) ;; 54 | *) AC_MSG_ERROR([invalid value `$enableval' for --enable-dl]);; 55 | esac], 56 | [enable_dl=no]) 57 | 58 | AC_ARG_ENABLE(odbc, 59 | AC_HELP_STRING([--enable-odbc], 60 | [enable MathProg ODBC support [[default=no]]]), 61 | [case $enableval in 62 | yes | unix | no) ;; 63 | *) AC_MSG_ERROR([invalid value `$enableval' for --enable-odbc]);; 64 | esac], 65 | [enable_odbc=no]) 66 | 67 | AC_ARG_ENABLE(mysql, 68 | AC_HELP_STRING([--enable-mysql], 69 | [enable MathProg MySQL support [[default=no]]]), 70 | [case $enableval in 71 | yes | no) ;; 72 | *) AC_MSG_ERROR([invalid value `$enableval' for --enable-mysql]);; 73 | esac], 74 | [enable_mysql=no]) 75 | 76 | dnl Disable unnecessary libtool tests 77 | define([AC_LIBTOOL_LANG_CXX_CONFIG], [:]) 78 | define([AC_LIBTOOL_LANG_F77_CONFIG], [:]) 79 | define([AC_LIBTOOL_LANG_GCJ_CONFIG], [:]) 80 | 81 | dnl Check for programs 82 | AC_PROG_CC 83 | AC_PROG_INSTALL 84 | AC_PROG_LIBTOOL 85 | AM_PROG_CC_C_O 86 | 87 | dnl Check for math library 88 | AC_CHECK_LIB([m], [exp]) 89 | AC_CHECK_LIB([pthread], [sem_wait]) 90 | 91 | dnl Check for header 92 | AC_CHECK_HEADER([sys/time.h], 93 | AC_DEFINE([HAVE_SYS_TIME_H], [1], [N/A])) 94 | 95 | dnl Check for gettimeofday function 96 | AC_CHECK_FUNC([gettimeofday], 97 | AC_DEFINE([HAVE_GETTIMEOFDAY], [1], [N/A])) 98 | 99 | dnl Check if we should use named semaphores. Can do this based on OS name? 100 | AC_MSG_CHECKING([whether to use named semaphores]) 101 | if test "$enable_named_semaphores" = "yes"; then 102 | AC_MSG_RESULT([yes]) 103 | CFLAGS="-DUSE_NAMED_SEMAPHORES $CFLAGS" 104 | else 105 | AC_MSG_RESULT([no]) 106 | fi 107 | 108 | AC_MSG_CHECKING([whether to use recursive mutices]) 109 | if test "$enable_recursive_mutex" = "yes"; then 110 | AC_MSG_RESULT([yes]) 111 | CFLAGS="-DUSE_RECURSIVE_MUTEX $CFLAGS" 112 | else 113 | AC_MSG_RESULT([no]) 114 | fi 115 | 116 | AC_MSG_CHECKING([whether to use GNU MP bignum library]) 117 | if test "$with_gmp" = "yes"; then 118 | AC_MSG_RESULT([yes]) 119 | AC_DEFINE([HAVE_GMP], [1], [N/A]) 120 | LIBS="-lgmp $LIBS" 121 | else 122 | AC_MSG_RESULT([no]) 123 | fi 124 | 125 | AC_MSG_CHECKING([whether to use zlib data compression library]) 126 | if test "$with_zlib" = "yes"; then 127 | AC_MSG_RESULT([yes]) 128 | AC_DEFINE([HAVE_ZLIB], [1], [N/A]) 129 | LIBS="-lz $LIBS" 130 | else 131 | AC_MSG_RESULT([no]) 132 | fi 133 | 134 | AC_MSG_CHECKING([whether to enable shared library support]) 135 | if test "$enable_dl" = "yes"; then 136 | AC_MSG_RESULT([ltdl]) 137 | AC_DEFINE([HAVE_LTDL], [1], [N/A]) 138 | LIBS="-lltdl $LIBS" 139 | elif test "$enable_dl" = "ltdl"; then 140 | AC_MSG_RESULT([ltdl]) 141 | AC_DEFINE([HAVE_LTDL], [1], [N/A]) 142 | LIBS="-lltdl $LIBS" 143 | elif test "$enable_dl" = "dlfcn"; then 144 | AC_MSG_RESULT([dlfcn]) 145 | AC_DEFINE([HAVE_DLFCN], [1], [N/A]) 146 | else 147 | AC_MSG_RESULT([no]) 148 | fi 149 | 150 | case $host_os in 151 | darwin* | macosx*) 152 | LIBIODBC="libiodbc.dylib" 153 | LIBODBC="libodbc.dylib" 154 | LIBMYSQL="libmysqlclient.dylib" 155 | CFLAGS="-DUSE_NAMED_SEMAPHORES $CFLAGS" 156 | ;; 157 | *) 158 | LIBIODBC="libiodbc.so" 159 | LIBODBC="libodbc.so" 160 | LIBMYSQL="libmysqlclient.so" 161 | ;; 162 | esac 163 | 164 | AC_MSG_CHECKING([whether to enable MathProg ODBC support]) 165 | if test "$enable_odbc" = "yes"; then 166 | if test "$enable_dl" = "no"; then 167 | AC_MSG_ERROR([--enable-odbc requires --enable-dl]) 168 | fi 169 | AC_MSG_RESULT([yes]) 170 | AC_DEFINE_UNQUOTED([ODBC_DLNAME], ["$LIBIODBC"], [N/A]) 171 | elif test "$enable_odbc" = "unix"; then 172 | if test "$enable_dl" = "no"; then 173 | AC_MSG_ERROR([--enable-odbc requires --enable-dl]) 174 | fi 175 | AC_MSG_RESULT([unix]) 176 | AC_DEFINE_UNQUOTED([ODBC_DLNAME], ["$LIBODBC"], [N/A]) 177 | else 178 | AC_MSG_RESULT([no]) 179 | fi 180 | 181 | AC_MSG_CHECKING([whether to enable MathProg MySQL support]) 182 | if test "$enable_mysql" = "yes"; then 183 | if test "$enable_dl" = "no"; then 184 | AC_MSG_ERROR([--enable-mysql requires --enable-dl]) 185 | fi 186 | AC_MSG_RESULT([yes]) 187 | CPPFLAGS="-I/usr/include/mysql $CPPFLAGS" 188 | AC_DEFINE_UNQUOTED([MYSQL_DLNAME], ["$LIBMYSQL"], [N/A]) 189 | else 190 | AC_MSG_RESULT([no]) 191 | fi 192 | 193 | AC_CONFIG_FILES( 194 | dnl [include/Makefile src/Makefile Makefile]) 195 | [src/Makefile Makefile]) 196 | AC_OUTPUT 197 | 198 | dnl eof 199 | -------------------------------------------------------------------------------- /GLPK_THANKS: -------------------------------------------------------------------------------- 1 | Noli Sicad for testing glpk under Mac OS. 2 | 3 | Pietro Scionti for report typos found in 4 | the reference manual. 5 | 6 | Noli Sicad for example model in MathProg. 7 | 8 | Nigel Galloway for example model in 9 | MathProg. 10 | 11 | Xypron for contribution and testing batch scripts 12 | to build Glpk with MS Visual Studio 2010. 13 | 14 | Xypron for improving the SQL table driver. 15 | 16 | Stefan Vigerske for bug report. 17 | 18 | Uday Venkatadri for bug report. 19 | 20 | Xypron for bug fixing and some improvments in the 21 | FPUMP module. 22 | 23 | Niels Klitgord for bug report. 24 | 25 | Thomas Kahle for some suggestions. 26 | 27 | Jonathan Senning for bug report. 28 | 29 | Xypron for testing GLPK on 64-bit platforms and 30 | for maintaining Windows versions of the package. 31 | 32 | Nelson H. F. Beebe for bug report. 33 | 34 | Larry D'Agostino for example model in 35 | MathProg. 36 | 37 | Marco Atzeri for bug report. 38 | 39 | Robert Wood for example model in MathProg. 40 | 41 | Sebastien Briais for bug report. 42 | 43 | Kelly Westbrooks for suggestions. 44 | 45 | Nigel Galloway for example models in 46 | MathProg. 47 | 48 | Xypron for bug patch. 49 | 50 | Sebastian Nowozin for example models in MathProg. 51 | 52 | Stefan Vigerske for bug report. 53 | 54 | Luiz Bettoni for some suggestions. 55 | 56 | Nigel Galloway for bug report. 57 | 58 | Peter Ingerfeld for bug report. 59 | 60 | Heinrich Schuchardt for contribution of 61 | makefiles and testing the package under 64-bit Windows. 62 | 63 | Oscar Gustafsson for contribution of a new version 64 | of the routine to write data in OPB (pseudo boolean) format. 65 | 66 | Heinrich Schuchardt for some patches for 67 | the MathProg translator. 68 | 69 | Markus Pilz for bug report. 70 | 71 | Anne-Laurence Putz for bug 72 | report. 73 | 74 | Robbie Morrison for correcting the glpk manual. 75 | 76 | Axel Simon for bug report. 77 | 78 | Vijay Patil for testing the package under 79 | Windows XP. 80 | 81 | Heinrich Schuchardt for contribution of 82 | two MathProg table drivers for iODBC and MySQL. 83 | 84 | Rafael Laboissiere for useful advices concerning 85 | shared library support under GNU/Linux. 86 | 87 | Nigel Galloway for an example program 88 | in C#. 89 | 90 | Enric Rodriguez for bug report. 91 | 92 | Nigel Galloway for an example MathProg 93 | model. 94 | 95 | Roberto Bagnara (Department of Mathematics, 96 | University of Parma, Italy) for bug report. 97 | 98 | Peter T. Breuer for bug report. 99 | 100 | Graham Rockwell for bug report. 101 | 102 | Cedric[FR] for bug report. 103 | 104 | Cameron Kellough for bug report. 105 | 106 | Oscar Gustafsson for contribution of a routine to 107 | write data in OPB (pseudo boolean) format. 108 | 109 | Boris Wirtz for bug report. 110 | 111 | Sebastian Nowozin for three example MathProg 112 | models. 113 | 114 | Rafael Laboissiere for useful advices concerning 115 | shared library support. 116 | 117 | Dr. Harley Mackenzie for two example MathProg 118 | models (curve fitting problem). 119 | 120 | Minh Ha Duong for fixing doc typos. 121 | 122 | Brady Hunsaker for some suggestions concerning 123 | MIP routines. 124 | 125 | Karel Zimmermann for bug report. 126 | 127 | Christophe Caron for bug report. 128 | 129 | Nicolo Giorgetti for contribution of GLPKMEX, 130 | a Matlab MEX interface. 131 | 132 | Harley Mackenzie for contribution of GLPK FAQ. 133 | 134 | Andre Girard for bug report. 135 | 136 | Morten Welinder for bug report. 137 | 138 | Brady Hunsaker for contribution of a routine 139 | for bounds sensitivity analysis. 140 | 141 | Chris Rosebrugh for contribution of a new version of 142 | GLPK JNI (Java Native Interface). 143 | 144 | Ivo van Baren for contribution of GLPK DELI 145 | (Delphi Interface). 146 | 147 | Andrew Hamilton-Wright for bug report. 148 | 149 | Jiri Spitz for bug report. 150 | 151 | Giles Thompson for bug report. 152 | 153 | Sebastien de Menten for bug report. 154 | 155 | Kendall Demaree for bug report. 156 | 157 | Bernhard Schmidt for bug report. 158 | 159 | Yuri Victorovich for contribution of GLPK Java binding. 160 | 161 | Olivier for bug report. 162 | 163 | Kjell Eikland for bug report. 164 | 165 | Ivan Luzzi for comments concerning CPLEX LP format. 166 | 167 | Peter Lee for example LP model and bug report. 168 | 169 | Morten Welinder for bug report. 170 | 171 | Vlahos Kiriakos for bug report. 172 | 173 | Flavio Keidi Miyazawa for bug report. 174 | 175 | Hans Schwengeler for bug report. 176 | 177 | Sami Farin for bug report. 178 | 179 | Peter A. Huegler for bug report. 180 | 181 | Alexandre Oliva for bug report. 182 | 183 | Andrew Hood for bug report. 184 | -------------------------------------------------------------------------------- /src/glpapi05.c: -------------------------------------------------------------------------------- 1 | /* glpapi05.c (LP basis constructing routines) */ 2 | 3 | /*********************************************************************** 4 | * This code is part of GLPK (GNU Linear Programming Kit). 5 | * 6 | * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 7 | * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, 8 | * Moscow Aviation Institute, Moscow, Russia. All rights reserved. 9 | * E-mail: . 10 | * 11 | * GLPK is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * GLPK is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 19 | * License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with GLPK. If not, see . 23 | ***********************************************************************/ 24 | 25 | #include "glpapi.h" 26 | 27 | /*********************************************************************** 28 | * NAME 29 | * 30 | * glp_set_row_stat - set (change) row status 31 | * 32 | * SYNOPSIS 33 | * 34 | * void glp_set_row_stat(glp_prob *lp, int i, int stat); 35 | * 36 | * DESCRIPTION 37 | * 38 | * The routine glp_set_row_stat sets (changes) status of the auxiliary 39 | * variable associated with i-th row. 40 | * 41 | * The new status of the auxiliary variable should be specified by the 42 | * parameter stat as follows: 43 | * 44 | * GLP_BS - basic variable; 45 | * GLP_NL - non-basic variable; 46 | * GLP_NU - non-basic variable on its upper bound; if the variable is 47 | * not double-bounded, this means the same as GLP_NL (only in 48 | * case of this routine); 49 | * GLP_NF - the same as GLP_NL (only in case of this routine); 50 | * GLP_NS - the same as GLP_NL (only in case of this routine). */ 51 | 52 | void glp_set_row_stat(glp_prob *lp, int i, int stat) 53 | { GLPROW *row; 54 | if (!(1 <= i && i <= lp->m)) 55 | xerror("glp_set_row_stat: i = %d; row number out of range\n", 56 | i); 57 | if (!(stat == GLP_BS || stat == GLP_NL || stat == GLP_NU || 58 | stat == GLP_NF || stat == GLP_NS)) 59 | xerror("glp_set_row_stat: i = %d; stat = %d; invalid status\n", 60 | i, stat); 61 | row = lp->row[i]; 62 | if (stat != GLP_BS) 63 | { switch (row->type) 64 | { case GLP_FR: stat = GLP_NF; break; 65 | case GLP_LO: stat = GLP_NL; break; 66 | case GLP_UP: stat = GLP_NU; break; 67 | case GLP_DB: if (stat != GLP_NU) stat = GLP_NL; break; 68 | case GLP_FX: stat = GLP_NS; break; 69 | default: xassert(row != row); 70 | } 71 | } 72 | if (row->stat == GLP_BS && stat != GLP_BS || 73 | row->stat != GLP_BS && stat == GLP_BS) 74 | { /* invalidate the basis factorization */ 75 | lp->valid = 0; 76 | } 77 | row->stat = stat; 78 | return; 79 | } 80 | 81 | /*********************************************************************** 82 | * NAME 83 | * 84 | * glp_set_col_stat - set (change) column status 85 | * 86 | * SYNOPSIS 87 | * 88 | * void glp_set_col_stat(glp_prob *lp, int j, int stat); 89 | * 90 | * DESCRIPTION 91 | * 92 | * The routine glp_set_col_stat sets (changes) status of the structural 93 | * variable associated with j-th column. 94 | * 95 | * The new status of the structural variable should be specified by the 96 | * parameter stat as follows: 97 | * 98 | * GLP_BS - basic variable; 99 | * GLP_NL - non-basic variable; 100 | * GLP_NU - non-basic variable on its upper bound; if the variable is 101 | * not double-bounded, this means the same as GLP_NL (only in 102 | * case of this routine); 103 | * GLP_NF - the same as GLP_NL (only in case of this routine); 104 | * GLP_NS - the same as GLP_NL (only in case of this routine). */ 105 | 106 | void glp_set_col_stat(glp_prob *lp, int j, int stat) 107 | { GLPCOL *col; 108 | if (!(1 <= j && j <= lp->n)) 109 | xerror("glp_set_col_stat: j = %d; column number out of range\n" 110 | , j); 111 | if (!(stat == GLP_BS || stat == GLP_NL || stat == GLP_NU || 112 | stat == GLP_NF || stat == GLP_NS)) 113 | xerror("glp_set_col_stat: j = %d; stat = %d; invalid status\n", 114 | j, stat); 115 | col = lp->col[j]; 116 | if (stat != GLP_BS) 117 | { switch (col->type) 118 | { case GLP_FR: stat = GLP_NF; break; 119 | case GLP_LO: stat = GLP_NL; break; 120 | case GLP_UP: stat = GLP_NU; break; 121 | case GLP_DB: if (stat != GLP_NU) stat = GLP_NL; break; 122 | case GLP_FX: stat = GLP_NS; break; 123 | default: xassert(col != col); 124 | } 125 | } 126 | if (col->stat == GLP_BS && stat != GLP_BS || 127 | col->stat != GLP_BS && stat == GLP_BS) 128 | { /* invalidate the basis factorization */ 129 | lp->valid = 0; 130 | } 131 | col->stat = stat; 132 | return; 133 | } 134 | 135 | /*********************************************************************** 136 | * NAME 137 | * 138 | * glp_std_basis - construct standard initial LP basis 139 | * 140 | * SYNOPSIS 141 | * 142 | * void glp_std_basis(glp_prob *lp); 143 | * 144 | * DESCRIPTION 145 | * 146 | * The routine glp_std_basis builds the "standard" (trivial) initial 147 | * basis for the specified problem object. 148 | * 149 | * In the "standard" basis all auxiliary variables are basic, and all 150 | * structural variables are non-basic. */ 151 | 152 | void glp_std_basis(glp_prob *lp) 153 | { int i, j; 154 | /* make all auxiliary variables basic */ 155 | for (i = 1; i <= lp->m; i++) 156 | glp_set_row_stat(lp, i, GLP_BS); 157 | /* make all structural variables non-basic */ 158 | for (j = 1; j <= lp->n; j++) 159 | { GLPCOL *col = lp->col[j]; 160 | if (col->type == GLP_DB && fabs(col->lb) > fabs(col->ub)) 161 | glp_set_col_stat(lp, j, GLP_NU); 162 | else 163 | glp_set_col_stat(lp, j, GLP_NL); 164 | } 165 | return; 166 | } 167 | 168 | /* eof */ 169 | --------------------------------------------------------------------------------