alpar@1: /* glpapi19.c (stand-alone LP/MIP solver) */ alpar@1: alpar@1: /*********************************************************************** alpar@1: * This code is part of GLPK (GNU Linear Programming Kit). alpar@1: * alpar@1: * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, alpar@1: * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, alpar@1: * Moscow Aviation Institute, Moscow, Russia. All rights reserved. alpar@1: * E-mail: . alpar@1: * alpar@1: * GLPK is free software: you can redistribute it and/or modify it alpar@1: * under the terms of the GNU General Public License as published by alpar@1: * the Free Software Foundation, either version 3 of the License, or alpar@1: * (at your option) any later version. alpar@1: * alpar@1: * GLPK is distributed in the hope that it will be useful, but WITHOUT alpar@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY alpar@1: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public alpar@1: * License for more details. alpar@1: * alpar@1: * You should have received a copy of the GNU General Public License alpar@1: * along with GLPK. If not, see . alpar@1: ***********************************************************************/ alpar@1: alpar@1: #include "glpapi.h" alpar@1: #include "glpgmp.h" alpar@1: alpar@1: struct csa alpar@1: { /* common storage area */ alpar@1: glp_prob *prob; alpar@1: /* LP/MIP problem object */ alpar@1: glp_bfcp bfcp; alpar@1: /* basis factorization control parameters */ alpar@1: glp_smcp smcp; alpar@1: /* simplex method control parameters */ alpar@1: glp_iptcp iptcp; alpar@1: /* interior-point method control parameters */ alpar@1: glp_iocp iocp; alpar@1: /* integer optimizer control parameters */ alpar@1: glp_tran *tran; alpar@1: /* model translator workspace */ alpar@1: glp_graph *graph; alpar@1: /* network problem object */ alpar@1: int format; alpar@1: /* problem file format: */ alpar@1: #define FMT_MPS_DECK 1 /* fixed MPS */ alpar@1: #define FMT_MPS_FILE 2 /* free MPS */ alpar@1: #define FMT_LP 3 /* CPLEX LP */ alpar@1: #define FMT_GLP 4 /* GLPK LP/MIP */ alpar@1: #define FMT_MATHPROG 5 /* MathProg */ alpar@1: #define FMT_MIN_COST 6 /* DIMACS min-cost flow */ alpar@1: #define FMT_MAX_FLOW 7 /* DIMACS maximum flow */ alpar@1: const char *in_file; alpar@1: /* name of input problem file */ alpar@1: #define DATA_MAX 10 alpar@1: /* maximal number of input data files */ alpar@1: int ndf; alpar@1: /* number of input data files specified */ alpar@1: const char *in_data[1+DATA_MAX]; alpar@1: /* name(s) of input data file(s) */ alpar@1: const char *out_dpy; alpar@1: /* name of output file to send display output; NULL means the alpar@1: display output is sent to the terminal */ alpar@1: int seed; alpar@1: /* seed value to be passed to the MathProg translator; initially alpar@1: set to 1; 0x80000000 means the value is omitted */ alpar@1: int solution; alpar@1: /* solution type flag: */ alpar@1: #define SOL_BASIC 1 /* basic */ alpar@1: #define SOL_INTERIOR 2 /* interior-point */ alpar@1: #define SOL_INTEGER 3 /* mixed integer */ alpar@1: const char *in_res; alpar@1: /* name of input solution file in raw format */ alpar@1: int dir; alpar@1: /* optimization direction flag: alpar@1: 0 - not specified alpar@1: GLP_MIN - minimization alpar@1: GLP_MAX - maximization */ alpar@1: int scale; alpar@1: /* automatic problem scaling flag */ alpar@1: const char *out_sol; alpar@1: /* name of output solution file in printable format */ alpar@1: const char *out_res; alpar@1: /* name of output solution file in raw format */ alpar@1: const char *out_ranges; alpar@1: /* name of output file to write sensitivity analysis report */ alpar@1: int check; alpar@1: /* input data checking flag; no solution is performed */ alpar@1: const char *new_name; alpar@1: /* new name to be assigned to the problem */ alpar@1: const char *out_mps; alpar@1: /* name of output problem file in fixed MPS format */ alpar@1: const char *out_freemps; alpar@1: /* name of output problem file in free MPS format */ alpar@1: const char *out_cpxlp; alpar@1: /* name of output problem file in CPLEX LP format */ alpar@1: const char *out_glp; alpar@1: /* name of output problem file in GLPK format */ alpar@1: const char *out_pb; alpar@1: /* name of output problem file in OPB format */ alpar@1: const char *out_npb; alpar@1: /* name of output problem file in normalized OPB format */ alpar@1: const char *log_file; alpar@1: /* name of output file to hardcopy terminal output */ alpar@1: int crash; alpar@1: /* initial basis option: */ alpar@1: #define USE_STD_BASIS 1 /* use standard basis */ alpar@1: #define USE_ADV_BASIS 2 /* use advanced basis */ alpar@1: #define USE_CPX_BASIS 3 /* use Bixby's basis */ alpar@1: #define USE_INI_BASIS 4 /* use initial basis from ini_file */ alpar@1: const char *ini_file; alpar@1: /* name of input file containing initial basis */ alpar@1: int exact; alpar@1: /* flag to use glp_exact rather than glp_simplex */ alpar@1: int xcheck; alpar@1: /* flag to check final basis with glp_exact */ alpar@1: int nomip; alpar@1: /* flag to consider MIP as pure LP */ alpar@1: }; alpar@1: alpar@1: static void print_help(const char *my_name) alpar@1: { /* print help information */ alpar@1: xprintf("Usage: %s [options...] filename\n", my_name); alpar@1: xprintf("\n"); alpar@1: xprintf("General options:\n"); alpar@1: xprintf(" --mps read LP/MIP problem in fixed MPS fo" alpar@1: "rmat\n"); alpar@1: xprintf(" --freemps read LP/MIP problem in free MPS for" alpar@1: "mat (default)\n"); alpar@1: xprintf(" --lp read LP/MIP problem in CPLEX LP for" alpar@1: "mat\n"); alpar@1: xprintf(" --glp read LP/MIP problem in GLPK format " alpar@1: "\n"); alpar@1: xprintf(" --math read LP/MIP model written in GNU Ma" alpar@1: "thProg modeling\n"); alpar@1: xprintf(" language\n"); alpar@1: xprintf(" -m filename, --model filename\n"); alpar@1: xprintf(" read model section and optional dat" alpar@1: "a section from\n"); alpar@1: xprintf(" filename (same as --math)\n"); alpar@1: xprintf(" -d filename, --data filename\n"); alpar@1: xprintf(" read data section from filename (fo" alpar@1: "r --math only);\n"); alpar@1: xprintf(" if model file also has data section" alpar@1: ", it is ignored\n"); alpar@1: xprintf(" -y filename, --display filename\n"); alpar@1: xprintf(" send display output to filename (fo" alpar@1: "r --math only);\n"); alpar@1: xprintf(" by default the output is sent to te" alpar@1: "rminal\n"); alpar@1: xprintf(" --seed value initialize pseudo-random number gen" alpar@1: "erator used in\n"); alpar@1: xprintf(" MathProg model with specified seed " alpar@1: "(any integer);\n"); alpar@1: xprintf(" if seed value is ?, some random see" alpar@1: "d will be used\n"); alpar@1: xprintf(" --mincost read min-cost flow problem in DIMAC" alpar@1: "S format\n"); alpar@1: xprintf(" --maxflow read maximum flow problem in DIMACS" alpar@1: " format\n"); alpar@1: xprintf(" --simplex use simplex method (default)\n"); alpar@1: xprintf(" --interior use interior point method (LP only)" alpar@1: "\n"); alpar@1: xprintf(" -r filename, --read filename\n"); alpar@1: xprintf(" read solution from filename rather " alpar@1: "to find it with\n"); alpar@1: xprintf(" the solver\n"); alpar@1: xprintf(" --min minimization\n"); alpar@1: xprintf(" --max maximization\n"); alpar@1: xprintf(" --scale scale problem (default)\n"); alpar@1: xprintf(" --noscale do not scale problem\n"); alpar@1: xprintf(" -o filename, --output filename\n"); alpar@1: xprintf(" write solution to filename in print" alpar@1: "able format\n"); alpar@1: xprintf(" -w filename, --write filename\n"); alpar@1: xprintf(" write solution to filename in plain" alpar@1: " text format\n"); alpar@1: xprintf(" --ranges filename\n"); alpar@1: xprintf(" write sensitivity analysis report t" alpar@1: "o filename in\n"); alpar@1: xprintf(" printable format (simplex only)\n"); alpar@1: xprintf(" --tmlim nnn limit solution time to nnn seconds " alpar@1: "\n"); alpar@1: xprintf(" --memlim nnn limit available memory to nnn megab" alpar@1: "ytes\n"); alpar@1: xprintf(" --check do not solve problem, check input d" alpar@1: "ata only\n"); alpar@1: xprintf(" --name probname change problem name to probname\n"); alpar@1: xprintf(" --wmps filename write problem to filename in fixed " alpar@1: "MPS format\n"); alpar@1: xprintf(" --wfreemps filename\n"); alpar@1: xprintf(" write problem to filename in free M" alpar@1: "PS format\n"); alpar@1: xprintf(" --wlp filename write problem to filename in CPLEX " alpar@1: "LP format\n"); alpar@1: xprintf(" --wglp filename write problem to filename in GLPK f" alpar@1: "ormat\n"); alpar@1: #if 0 alpar@1: xprintf(" --wpb filename write problem to filename in OPB fo" alpar@1: "rmat\n"); alpar@1: xprintf(" --wnpb filename write problem to filename in normal" alpar@1: "ized OPB format\n"); alpar@1: #endif alpar@1: xprintf(" --log filename write copy of terminal output to fi" alpar@1: "lename\n"); alpar@1: xprintf(" -h, --help display this help information and e" alpar@1: "xit\n"); alpar@1: xprintf(" -v, --version display program version and exit\n") alpar@1: ; alpar@1: xprintf("\n"); alpar@1: xprintf("LP basis factorization options:\n"); alpar@1: xprintf(" --luf LU + Forrest-Tomlin update\n"); alpar@1: xprintf(" (faster, less stable; default)\n"); alpar@1: xprintf(" --cbg LU + Schur complement + Bartels-Gol" alpar@1: "ub update\n"); alpar@1: xprintf(" (slower, more stable)\n"); alpar@1: xprintf(" --cgr LU + Schur complement + Givens rota" alpar@1: "tion update\n"); alpar@1: xprintf(" (slower, more stable)\n"); alpar@1: xprintf("\n"); alpar@1: xprintf("Options specific to simplex solver:\n"); alpar@1: xprintf(" --primal use primal simplex (default)\n"); alpar@1: xprintf(" --dual use dual simplex\n"); alpar@1: xprintf(" --std use standard initial basis of all s" alpar@1: "lacks\n"); alpar@1: xprintf(" --adv use advanced initial basis (default" alpar@1: ")\n"); alpar@1: xprintf(" --bib use Bixby's initial basis\n"); alpar@1: xprintf(" --ini filename use as initial basis previously sav" alpar@1: "ed with -w\n"); alpar@1: xprintf(" (disables LP presolver)\n"); alpar@1: xprintf(" --steep use steepest edge technique (defaul" alpar@1: "t)\n"); alpar@1: xprintf(" --nosteep use standard \"textbook\" pricing\n" alpar@1: ); alpar@1: xprintf(" --relax use Harris' two-pass ratio test (de" alpar@1: "fault)\n"); alpar@1: xprintf(" --norelax use standard \"textbook\" ratio tes" alpar@1: "t\n"); alpar@1: xprintf(" --presol use presolver (default; assumes --s" alpar@1: "cale and --adv)\n"); alpar@1: xprintf(" --nopresol do not use presolver\n"); alpar@1: xprintf(" --exact use simplex method based on exact a" alpar@1: "rithmetic\n"); alpar@1: xprintf(" --xcheck check final basis using exact arith" alpar@1: "metic\n"); alpar@1: xprintf("\n"); alpar@1: xprintf("Options specific to interior-point solver:\n"); alpar@1: xprintf(" --nord use natural (original) ordering\n"); alpar@1: xprintf(" --qmd use quotient minimum degree orderin" alpar@1: "g\n"); alpar@1: xprintf(" --amd use approximate minimum degree orde" alpar@1: "ring (default)\n"); alpar@1: xprintf(" --symamd use approximate minimum degree orde" alpar@1: "ring\n"); alpar@1: xprintf("\n"); alpar@1: xprintf("Options specific to MIP solver:\n"); alpar@1: xprintf(" --nomip consider all integer variables as c" alpar@1: "ontinuous\n"); alpar@1: xprintf(" (allows solving MIP as pure LP)\n"); alpar@1: xprintf(" --first branch on first integer variable\n") alpar@1: ; alpar@1: xprintf(" --last branch on last integer variable\n"); alpar@1: xprintf(" --mostf branch on most fractional variable " alpar@1: "\n"); alpar@1: xprintf(" --drtom branch using heuristic by Driebeck " alpar@1: "and Tomlin\n"); alpar@1: xprintf(" (default)\n"); alpar@1: xprintf(" --pcost branch using hybrid pseudocost heur" alpar@1: "istic (may be\n"); alpar@1: xprintf(" useful for hard instances)\n"); alpar@1: xprintf(" --dfs backtrack using depth first search " alpar@1: "\n"); alpar@1: xprintf(" --bfs backtrack using breadth first searc" alpar@1: "h\n"); alpar@1: xprintf(" --bestp backtrack using the best projection" alpar@1: " heuristic\n"); alpar@1: xprintf(" --bestb backtrack using node with best loca" alpar@1: "l bound\n"); alpar@1: xprintf(" (default)\n"); alpar@1: xprintf(" --intopt use MIP presolver (default)\n"); alpar@1: xprintf(" --nointopt do not use MIP presolver\n"); alpar@1: xprintf(" --binarize replace general integer variables b" alpar@1: "y binary ones\n"); alpar@1: xprintf(" (assumes --intopt)\n"); alpar@1: xprintf(" --fpump apply feasibility pump heuristic\n") alpar@1: ; alpar@1: xprintf(" --gomory generate Gomory's mixed integer cut" alpar@1: "s\n"); alpar@1: xprintf(" --mir generate MIR (mixed integer roundin" alpar@1: "g) cuts\n"); alpar@1: xprintf(" --cover generate mixed cover cuts\n"); alpar@1: xprintf(" --clique generate clique cuts\n"); alpar@1: xprintf(" --cuts generate all cuts above\n"); alpar@1: xprintf(" --mipgap tol set relative mip gap tolerance to t" alpar@1: "ol\n"); alpar@1: xprintf("\n"); alpar@1: xprintf("For description of the MPS and CPLEX LP formats see Refe" alpar@1: "rence Manual.\n"); alpar@1: xprintf("For description of the modeling language see \"GLPK: Mod" alpar@1: "eling Language\n"); alpar@1: xprintf("GNU MathProg\". Both documents are included in the GLPK " alpar@1: "distribution.\n"); alpar@1: xprintf("\n"); alpar@1: xprintf("See GLPK web page at .\n"); alpar@1: xprintf("\n"); alpar@1: xprintf("Please report bugs to .\n"); alpar@1: return; alpar@1: } alpar@1: alpar@1: static void print_version(int briefly) alpar@1: { /* print version information */ alpar@1: xprintf("GLPSOL: GLPK LP/MIP Solver, v%s\n", glp_version()); alpar@1: if (briefly) goto done; alpar@1: xprintf("\n"); alpar@1: xprintf("Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, " alpar@1: "2007, 2008,\n"); alpar@1: xprintf("2009, 2010 Andrew Makhorin, Department for Applied Infor" alpar@1: "matics, Moscow\n"); alpar@1: xprintf("Aviation Institute, Moscow, Russia. All rights reserved." alpar@1: "\n"); alpar@1: xprintf("\n"); alpar@1: xprintf("This program has ABSOLUTELY NO WARRANTY.\n"); alpar@1: xprintf("\n"); alpar@1: xprintf("This program is free software; you may re-distribute it " alpar@1: "under the terms\n"); alpar@1: xprintf("of the GNU General Public License version 3 or later.\n") alpar@1: ; alpar@1: done: return; alpar@1: } alpar@1: alpar@1: static int parse_cmdline(struct csa *csa, int argc, const char *argv[]) alpar@1: { /* parse command-line parameters */ alpar@1: int k; alpar@1: #define p(str) (strcmp(argv[k], str) == 0) alpar@1: for (k = 1; k < argc; k++) alpar@1: { if (p("--mps")) alpar@1: csa->format = FMT_MPS_DECK; alpar@1: else if (p("--freemps")) alpar@1: csa->format = FMT_MPS_FILE; alpar@1: else if (p("--lp") || p("--cpxlp")) alpar@1: csa->format = FMT_LP; alpar@1: else if (p("--glp")) alpar@1: csa->format = FMT_GLP; alpar@1: else if (p("--math") || p("-m") || p("--model")) alpar@1: csa->format = FMT_MATHPROG; alpar@1: else if (p("-d") || p("--data")) alpar@1: { k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No input data file specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (csa->ndf == DATA_MAX) alpar@1: { xprintf("Too many input data files\n"); alpar@1: return 1; alpar@1: } alpar@1: csa->in_data[++(csa->ndf)] = argv[k]; alpar@1: } alpar@1: else if (p("-y") || p("--display")) alpar@1: { k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No display output file specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (csa->out_dpy != NULL) alpar@1: { xprintf("Only one display output file allowed\n"); alpar@1: return 1; alpar@1: } alpar@1: csa->out_dpy = argv[k]; alpar@1: } alpar@1: else if (p("--seed")) alpar@1: { k++; alpar@1: if (k == argc || argv[k][0] == '\0' || alpar@1: argv[k][0] == '-' && !isdigit((unsigned char)argv[k][1])) alpar@1: { xprintf("No seed value specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (strcmp(argv[k], "?") == 0) alpar@1: csa->seed = 0x80000000; alpar@1: else if (str2int(argv[k], &csa->seed)) alpar@1: { xprintf("Invalid seed value `%s'\n", argv[k]); alpar@1: return 1; alpar@1: } alpar@1: } alpar@1: else if (p("--mincost")) alpar@1: csa->format = FMT_MIN_COST; alpar@1: else if (p("--maxflow")) alpar@1: csa->format = FMT_MAX_FLOW; alpar@1: else if (p("--simplex")) alpar@1: csa->solution = SOL_BASIC; alpar@1: else if (p("--interior")) alpar@1: csa->solution = SOL_INTERIOR; alpar@1: #if 1 /* 28/V-2010 */ alpar@1: else if (p("--alien")) alpar@1: csa->iocp.alien = GLP_ON; alpar@1: #endif alpar@1: else if (p("-r") || p("--read")) alpar@1: { k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No input solution file specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (csa->in_res != NULL) alpar@1: { xprintf("Only one input solution file allowed\n"); alpar@1: return 1; alpar@1: } alpar@1: csa->in_res = argv[k]; alpar@1: } alpar@1: else if (p("--min")) alpar@1: csa->dir = GLP_MIN; alpar@1: else if (p("--max")) alpar@1: csa->dir = GLP_MAX; alpar@1: else if (p("--scale")) alpar@1: csa->scale = 1; alpar@1: else if (p("--noscale")) alpar@1: csa->scale = 0; alpar@1: else if (p("-o") || p("--output")) alpar@1: { k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No output solution file specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (csa->out_sol != NULL) alpar@1: { xprintf("Only one output solution file allowed\n"); alpar@1: return 1; alpar@1: } alpar@1: csa->out_sol = argv[k]; alpar@1: } alpar@1: else if (p("-w") || p("--write")) alpar@1: { k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No output solution file specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (csa->out_res != NULL) alpar@1: { xprintf("Only one output solution file allowed\n"); alpar@1: return 1; alpar@1: } alpar@1: csa->out_res = argv[k]; alpar@1: } alpar@1: else if (p("--ranges") || p("--bounds")) alpar@1: { k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No output file specified to write sensitivity a" alpar@1: "nalysis report\n"); alpar@1: return 1; alpar@1: } alpar@1: if (csa->out_ranges != NULL) alpar@1: { xprintf("Only one output file allowed to write sensitivi" alpar@1: "ty analysis report\n"); alpar@1: return 1; alpar@1: } alpar@1: csa->out_ranges = argv[k]; alpar@1: } alpar@1: else if (p("--tmlim")) alpar@1: { int tm_lim; alpar@1: k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No time limit specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (str2int(argv[k], &tm_lim) || tm_lim < 0) alpar@1: { xprintf("Invalid time limit `%s'\n", argv[k]); alpar@1: return 1; alpar@1: } alpar@1: if (tm_lim <= INT_MAX / 1000) alpar@1: csa->smcp.tm_lim = csa->iocp.tm_lim = 1000 * tm_lim; alpar@1: else alpar@1: csa->smcp.tm_lim = csa->iocp.tm_lim = INT_MAX; alpar@1: } alpar@1: else if (p("--memlim")) alpar@1: { int mem_lim; alpar@1: k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No memory limit specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (str2int(argv[k], &mem_lim) || mem_lim < 1) alpar@1: { xprintf("Invalid memory limit `%s'\n", argv[k]); alpar@1: return 1; alpar@1: } alpar@1: glp_mem_limit(mem_lim); alpar@1: } alpar@1: else if (p("--check")) alpar@1: csa->check = 1; alpar@1: else if (p("--name")) alpar@1: { k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No problem name specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (csa->new_name != NULL) alpar@1: { xprintf("Only one problem name allowed\n"); alpar@1: return 1; alpar@1: } alpar@1: csa->new_name = argv[k]; alpar@1: } alpar@1: else if (p("--wmps")) alpar@1: { k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No fixed MPS output file specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (csa->out_mps != NULL) alpar@1: { xprintf("Only one fixed MPS output file allowed\n"); alpar@1: return 1; alpar@1: } alpar@1: csa->out_mps = argv[k]; alpar@1: } alpar@1: else if (p("--wfreemps")) alpar@1: { k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No free MPS output file specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (csa->out_freemps != NULL) alpar@1: { xprintf("Only one free MPS output file allowed\n"); alpar@1: return 1; alpar@1: } alpar@1: csa->out_freemps = argv[k]; alpar@1: } alpar@1: else if (p("--wlp") || p("--wcpxlp") || p("--wlpt")) alpar@1: { k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No CPLEX LP output file specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (csa->out_cpxlp != NULL) alpar@1: { xprintf("Only one CPLEX LP output file allowed\n"); alpar@1: return 1; alpar@1: } alpar@1: csa->out_cpxlp = argv[k]; alpar@1: } alpar@1: else if (p("--wglp")) alpar@1: { k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No GLPK LP/MIP output file specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (csa->out_glp != NULL) alpar@1: { xprintf("Only one GLPK LP/MIP output file allowed\n"); alpar@1: return 1; alpar@1: } alpar@1: csa->out_glp = argv[k]; alpar@1: } alpar@1: else if (p("--wpb")) alpar@1: { k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No problem output file specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (csa->out_pb != NULL) alpar@1: { xprintf("Only one OPB output file allowed\n"); alpar@1: return 1; alpar@1: } alpar@1: csa->out_pb = argv[k]; alpar@1: } alpar@1: else if (p("--wnpb")) alpar@1: { k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No problem output file specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (csa->out_npb != NULL) alpar@1: { xprintf("Only one normalized OPB output file allowed\n"); alpar@1: return 1; alpar@1: } alpar@1: csa->out_npb = argv[k]; alpar@1: } alpar@1: else if (p("--log")) alpar@1: { k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No log file specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (csa->log_file != NULL) alpar@1: { xprintf("Only one log file allowed\n"); alpar@1: return 1; alpar@1: } alpar@1: csa->log_file = argv[k]; alpar@1: } alpar@1: else if (p("-h") || p("--help")) alpar@1: { print_help(argv[0]); alpar@1: return -1; alpar@1: } alpar@1: else if (p("-v") || p("--version")) alpar@1: { print_version(0); alpar@1: return -1; alpar@1: } alpar@1: else if (p("--luf")) alpar@1: csa->bfcp.type = GLP_BF_FT; alpar@1: else if (p("--cbg")) alpar@1: csa->bfcp.type = GLP_BF_BG; alpar@1: else if (p("--cgr")) alpar@1: csa->bfcp.type = GLP_BF_GR; alpar@1: else if (p("--primal")) alpar@1: csa->smcp.meth = GLP_PRIMAL; alpar@1: else if (p("--dual")) alpar@1: csa->smcp.meth = GLP_DUAL; alpar@1: else if (p("--std")) alpar@1: csa->crash = USE_STD_BASIS; alpar@1: else if (p("--adv")) alpar@1: csa->crash = USE_ADV_BASIS; alpar@1: else if (p("--bib")) alpar@1: csa->crash = USE_CPX_BASIS; alpar@1: else if (p("--ini")) alpar@1: { csa->crash = USE_INI_BASIS; alpar@1: csa->smcp.presolve = GLP_OFF; alpar@1: k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No initial basis file specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (csa->ini_file != NULL) alpar@1: { xprintf("Only one initial basis file allowed\n"); alpar@1: return 1; alpar@1: } alpar@1: csa->ini_file = argv[k]; alpar@1: } alpar@1: else if (p("--steep")) alpar@1: csa->smcp.pricing = GLP_PT_PSE; alpar@1: else if (p("--nosteep")) alpar@1: csa->smcp.pricing = GLP_PT_STD; alpar@1: else if (p("--relax")) alpar@1: csa->smcp.r_test = GLP_RT_HAR; alpar@1: else if (p("--norelax")) alpar@1: csa->smcp.r_test = GLP_RT_STD; alpar@1: else if (p("--presol")) alpar@1: csa->smcp.presolve = GLP_ON; alpar@1: else if (p("--nopresol")) alpar@1: csa->smcp.presolve = GLP_OFF; alpar@1: else if (p("--exact")) alpar@1: csa->exact = 1; alpar@1: else if (p("--xcheck")) alpar@1: csa->xcheck = 1; alpar@1: else if (p("--nord")) alpar@1: csa->iptcp.ord_alg = GLP_ORD_NONE; alpar@1: else if (p("--qmd")) alpar@1: csa->iptcp.ord_alg = GLP_ORD_QMD; alpar@1: else if (p("--amd")) alpar@1: csa->iptcp.ord_alg = GLP_ORD_AMD; alpar@1: else if (p("--symamd")) alpar@1: csa->iptcp.ord_alg = GLP_ORD_SYMAMD; alpar@1: else if (p("--nomip")) alpar@1: csa->nomip = 1; alpar@1: else if (p("--first")) alpar@1: csa->iocp.br_tech = GLP_BR_FFV; alpar@1: else if (p("--last")) alpar@1: csa->iocp.br_tech = GLP_BR_LFV; alpar@1: else if (p("--drtom")) alpar@1: csa->iocp.br_tech = GLP_BR_DTH; alpar@1: else if (p("--mostf")) alpar@1: csa->iocp.br_tech = GLP_BR_MFV; alpar@1: else if (p("--pcost")) alpar@1: csa->iocp.br_tech = GLP_BR_PCH; alpar@1: else if (p("--dfs")) alpar@1: csa->iocp.bt_tech = GLP_BT_DFS; alpar@1: else if (p("--bfs")) alpar@1: csa->iocp.bt_tech = GLP_BT_BFS; alpar@1: else if (p("--bestp")) alpar@1: csa->iocp.bt_tech = GLP_BT_BPH; alpar@1: else if (p("--bestb")) alpar@1: csa->iocp.bt_tech = GLP_BT_BLB; alpar@1: else if (p("--intopt")) alpar@1: csa->iocp.presolve = GLP_ON; alpar@1: else if (p("--nointopt")) alpar@1: csa->iocp.presolve = GLP_OFF; alpar@1: else if (p("--binarize")) alpar@1: csa->iocp.presolve = csa->iocp.binarize = GLP_ON; alpar@1: else if (p("--fpump")) alpar@1: csa->iocp.fp_heur = GLP_ON; alpar@1: else if (p("--gomory")) alpar@1: csa->iocp.gmi_cuts = GLP_ON; alpar@1: else if (p("--mir")) alpar@1: csa->iocp.mir_cuts = GLP_ON; alpar@1: else if (p("--cover")) alpar@1: csa->iocp.cov_cuts = GLP_ON; alpar@1: else if (p("--clique")) alpar@1: csa->iocp.clq_cuts = GLP_ON; alpar@1: else if (p("--cuts")) alpar@1: csa->iocp.gmi_cuts = csa->iocp.mir_cuts = alpar@1: csa->iocp.cov_cuts = csa->iocp.clq_cuts = GLP_ON; alpar@1: else if (p("--mipgap")) alpar@1: { double mip_gap; alpar@1: k++; alpar@1: if (k == argc || argv[k][0] == '\0' || argv[k][0] == '-') alpar@1: { xprintf("No relative gap tolerance specified\n"); alpar@1: return 1; alpar@1: } alpar@1: if (str2num(argv[k], &mip_gap) || mip_gap < 0.0) alpar@1: { xprintf("Invalid relative mip gap tolerance `%s'\n", alpar@1: argv[k]); alpar@1: return 1; alpar@1: } alpar@1: csa->iocp.mip_gap = mip_gap; alpar@1: } alpar@1: else if (argv[k][0] == '-' || alpar@1: (argv[k][0] == '-' && argv[k][1] == '-')) alpar@1: { xprintf("Invalid option `%s'; try %s --help\n", alpar@1: argv[k], argv[0]); alpar@1: return 1; alpar@1: } alpar@1: else alpar@1: { if (csa->in_file != NULL) alpar@1: { xprintf("Only one input problem file allowed\n"); alpar@1: return 1; alpar@1: } alpar@1: csa->in_file = argv[k]; alpar@1: } alpar@1: } alpar@1: #undef p alpar@1: return 0; alpar@1: } alpar@1: alpar@1: typedef struct { double rhs, pi; } v_data; alpar@1: typedef struct { double low, cap, cost, x; } a_data; alpar@1: alpar@1: int glp_main(int argc, const char *argv[]) alpar@1: { /* stand-alone LP/MIP solver */ alpar@1: struct csa _csa, *csa = &_csa; alpar@1: int ret; alpar@1: glp_long start; alpar@1: /* perform initialization */ alpar@1: csa->prob = glp_create_prob(); alpar@1: glp_get_bfcp(csa->prob, &csa->bfcp); alpar@1: glp_init_smcp(&csa->smcp); alpar@1: csa->smcp.presolve = GLP_ON; alpar@1: glp_init_iptcp(&csa->iptcp); alpar@1: glp_init_iocp(&csa->iocp); alpar@1: csa->iocp.presolve = GLP_ON; alpar@1: csa->tran = NULL; alpar@1: csa->graph = NULL; alpar@1: csa->format = FMT_MPS_FILE; alpar@1: csa->in_file = NULL; alpar@1: csa->ndf = 0; alpar@1: csa->out_dpy = NULL; alpar@1: csa->seed = 1; alpar@1: csa->solution = SOL_BASIC; alpar@1: csa->in_res = NULL; alpar@1: csa->dir = 0; alpar@1: csa->scale = 1; alpar@1: csa->out_sol = NULL; alpar@1: csa->out_res = NULL; alpar@1: csa->out_ranges = NULL; alpar@1: csa->check = 0; alpar@1: csa->new_name = NULL; alpar@1: csa->out_mps = NULL; alpar@1: csa->out_freemps = NULL; alpar@1: csa->out_cpxlp = NULL; alpar@1: csa->out_glp = NULL; alpar@1: csa->out_pb = NULL; alpar@1: csa->out_npb = NULL; alpar@1: csa->log_file = NULL; alpar@1: csa->crash = USE_ADV_BASIS; alpar@1: csa->ini_file = NULL; alpar@1: csa->exact = 0; alpar@1: csa->xcheck = 0; alpar@1: csa->nomip = 0; alpar@1: /* parse command-line parameters */ alpar@1: ret = parse_cmdline(csa, argc, argv); alpar@1: if (ret < 0) alpar@1: { ret = EXIT_SUCCESS; alpar@1: goto done; alpar@1: } alpar@1: if (ret > 0) alpar@1: { ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* remove all output files specified in the command line */ alpar@1: if (csa->out_dpy != NULL) remove(csa->out_dpy); alpar@1: if (csa->out_sol != NULL) remove(csa->out_sol); alpar@1: if (csa->out_res != NULL) remove(csa->out_res); alpar@1: if (csa->out_ranges != NULL) remove(csa->out_ranges); alpar@1: if (csa->out_mps != NULL) remove(csa->out_mps); alpar@1: if (csa->out_freemps != NULL) remove(csa->out_freemps); alpar@1: if (csa->out_cpxlp != NULL) remove(csa->out_cpxlp); alpar@1: if (csa->out_glp != NULL) remove(csa->out_glp); alpar@1: if (csa->out_pb != NULL) remove(csa->out_pb); alpar@1: if (csa->out_npb != NULL) remove(csa->out_npb); alpar@1: if (csa->log_file != NULL) remove(csa->log_file); alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* open log file, if required */ alpar@1: if (csa->log_file != NULL) alpar@1: { if (glp_open_tee(csa->log_file)) alpar@1: { xprintf("Unable to create log file\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: } alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* print version information */ alpar@1: print_version(1); alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* print parameters specified in the command line */ alpar@1: if (argc > 1) alpar@1: { int k, len = INT_MAX; alpar@1: xprintf("Parameter(s) specified in the command line:"); alpar@1: for (k = 1; k < argc; k++) alpar@1: { if (len > 72) alpar@1: xprintf("\n"), len = 0; alpar@1: xprintf(" %s", argv[k]); alpar@1: len += 1 + strlen(argv[k]); alpar@1: } alpar@1: xprintf("\n"); alpar@1: } alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* read problem data from the input file */ alpar@1: if (csa->in_file == NULL) alpar@1: { xprintf("No input problem file specified; try %s --help\n", alpar@1: argv[0]); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: if (csa->format == FMT_MPS_DECK) alpar@1: { ret = glp_read_mps(csa->prob, GLP_MPS_DECK, NULL, alpar@1: csa->in_file); alpar@1: if (ret != 0) alpar@1: err1: { xprintf("MPS file processing error\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: } alpar@1: else if (csa->format == FMT_MPS_FILE) alpar@1: { ret = glp_read_mps(csa->prob, GLP_MPS_FILE, NULL, alpar@1: csa->in_file); alpar@1: if (ret != 0) goto err1; alpar@1: } alpar@1: else if (csa->format == FMT_LP) alpar@1: { ret = glp_read_lp(csa->prob, NULL, csa->in_file); alpar@1: if (ret != 0) alpar@1: { xprintf("CPLEX LP file processing error\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: } alpar@1: else if (csa->format == FMT_GLP) alpar@1: { ret = glp_read_prob(csa->prob, 0, csa->in_file); alpar@1: if (ret != 0) alpar@1: { xprintf("GLPK LP/MIP file processing error\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: } alpar@1: else if (csa->format == FMT_MATHPROG) alpar@1: { int k; alpar@1: /* allocate the translator workspace */ alpar@1: csa->tran = glp_mpl_alloc_wksp(); alpar@1: /* set seed value */ alpar@1: if (csa->seed == 0x80000000) alpar@1: { csa->seed = glp_time().lo; alpar@1: xprintf("Seed value %d will be used\n", csa->seed); alpar@1: } alpar@1: _glp_mpl_init_rand(csa->tran, csa->seed); alpar@1: /* read model section and optional data section */ alpar@1: if (glp_mpl_read_model(csa->tran, csa->in_file, csa->ndf > 0)) alpar@1: err2: { xprintf("MathProg model processing error\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: /* read optional data section(s), if necessary */ alpar@1: for (k = 1; k <= csa->ndf; k++) alpar@1: { if (glp_mpl_read_data(csa->tran, csa->in_data[k])) alpar@1: goto err2; alpar@1: } alpar@1: /* generate the model */ alpar@1: if (glp_mpl_generate(csa->tran, csa->out_dpy)) goto err2; alpar@1: /* build the problem instance from the model */ alpar@1: glp_mpl_build_prob(csa->tran, csa->prob); alpar@1: } alpar@1: else if (csa->format == FMT_MIN_COST) alpar@1: { csa->graph = glp_create_graph(sizeof(v_data), sizeof(a_data)); alpar@1: ret = glp_read_mincost(csa->graph, offsetof(v_data, rhs), alpar@1: offsetof(a_data, low), offsetof(a_data, cap), alpar@1: offsetof(a_data, cost), csa->in_file); alpar@1: if (ret != 0) alpar@1: { xprintf("DIMACS file processing error\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: glp_mincost_lp(csa->prob, csa->graph, GLP_ON, alpar@1: offsetof(v_data, rhs), offsetof(a_data, low), alpar@1: offsetof(a_data, cap), offsetof(a_data, cost)); alpar@1: glp_set_prob_name(csa->prob, csa->in_file); alpar@1: } alpar@1: else if (csa->format == FMT_MAX_FLOW) alpar@1: { int s, t; alpar@1: csa->graph = glp_create_graph(sizeof(v_data), sizeof(a_data)); alpar@1: ret = glp_read_maxflow(csa->graph, &s, &t, alpar@1: offsetof(a_data, cap), csa->in_file); alpar@1: if (ret != 0) alpar@1: { xprintf("DIMACS file processing error\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: glp_maxflow_lp(csa->prob, csa->graph, GLP_ON, s, t, alpar@1: offsetof(a_data, cap)); alpar@1: glp_set_prob_name(csa->prob, csa->in_file); alpar@1: } alpar@1: else alpar@1: xassert(csa != csa); alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* change problem name, if required */ alpar@1: if (csa->new_name != NULL) alpar@1: glp_set_prob_name(csa->prob, csa->new_name); alpar@1: /* change optimization direction, if required */ alpar@1: if (csa->dir != 0) alpar@1: glp_set_obj_dir(csa->prob, csa->dir); alpar@1: /* sort elements of the constraint matrix */ alpar@1: glp_sort_matrix(csa->prob); alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* write problem data in fixed MPS format, if required */ alpar@1: if (csa->out_mps != NULL) alpar@1: { ret = glp_write_mps(csa->prob, GLP_MPS_DECK, NULL, alpar@1: csa->out_mps); alpar@1: if (ret != 0) alpar@1: { xprintf("Unable to write problem in fixed MPS format\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: } alpar@1: /* write problem data in free MPS format, if required */ alpar@1: if (csa->out_freemps != NULL) alpar@1: { ret = glp_write_mps(csa->prob, GLP_MPS_FILE, NULL, alpar@1: csa->out_freemps); alpar@1: if (ret != 0) alpar@1: { xprintf("Unable to write problem in free MPS format\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: } alpar@1: /* write problem data in CPLEX LP format, if required */ alpar@1: if (csa->out_cpxlp != NULL) alpar@1: { ret = glp_write_lp(csa->prob, NULL, csa->out_cpxlp); alpar@1: if (ret != 0) alpar@1: { xprintf("Unable to write problem in CPLEX LP format\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: } alpar@1: /* write problem data in GLPK format, if required */ alpar@1: if (csa->out_glp != NULL) alpar@1: { ret = glp_write_prob(csa->prob, 0, csa->out_glp); alpar@1: if (ret != 0) alpar@1: { xprintf("Unable to write problem in GLPK format\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: } alpar@1: /* write problem data in OPB format, if required */ alpar@1: if (csa->out_pb != NULL) alpar@1: { ret = lpx_write_pb(csa->prob, csa->out_pb, 0, 0); alpar@1: if (ret != 0) alpar@1: { xprintf("Unable to write problem in OPB format\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: } alpar@1: /* write problem data in normalized OPB format, if required */ alpar@1: if (csa->out_npb != NULL) alpar@1: { ret = lpx_write_pb(csa->prob, csa->out_npb, 1, 1); alpar@1: if (ret != 0) alpar@1: { xprintf( alpar@1: "Unable to write problem in normalized OPB format\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: } alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* if only problem data check is required, skip computations */ alpar@1: if (csa->check) alpar@1: { ret = EXIT_SUCCESS; alpar@1: goto done; alpar@1: } alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* determine the solution type */ alpar@1: if (!csa->nomip && alpar@1: glp_get_num_int(csa->prob) + glp_get_num_bin(csa->prob) > 0) alpar@1: { if (csa->solution == SOL_INTERIOR) alpar@1: { xprintf("Interior-point method is not able to solve MIP pro" alpar@1: "blem; use --simplex\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: csa->solution = SOL_INTEGER; alpar@1: } alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* if solution is provided, read it and skip computations */ alpar@1: if (csa->in_res != NULL) alpar@1: { if (csa->solution == SOL_BASIC) alpar@1: ret = glp_read_sol(csa->prob, csa->in_res); alpar@1: else if (csa->solution == SOL_INTERIOR) alpar@1: ret = glp_read_ipt(csa->prob, csa->in_res); alpar@1: else if (csa->solution == SOL_INTEGER) alpar@1: ret = glp_read_mip(csa->prob, csa->in_res); alpar@1: else alpar@1: xassert(csa != csa); alpar@1: if (ret != 0) alpar@1: { xprintf("Unable to read problem solution\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: goto skip; alpar@1: } alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* scale the problem data, if required */ alpar@1: if (csa->scale) alpar@1: { if (csa->solution == SOL_BASIC && !csa->smcp.presolve || alpar@1: csa->solution == SOL_INTERIOR || alpar@1: csa->solution == SOL_INTEGER && !csa->iocp.presolve) alpar@1: glp_scale_prob(csa->prob, GLP_SF_AUTO); alpar@1: } alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* construct starting LP basis */ alpar@1: if (csa->solution == SOL_BASIC && !csa->smcp.presolve || alpar@1: csa->solution == SOL_INTEGER && !csa->iocp.presolve) alpar@1: { if (csa->crash == USE_STD_BASIS) alpar@1: glp_std_basis(csa->prob); alpar@1: else if (csa->crash == USE_ADV_BASIS) alpar@1: glp_adv_basis(csa->prob, 0); alpar@1: else if (csa->crash == USE_CPX_BASIS) alpar@1: glp_cpx_basis(csa->prob); alpar@1: else if (csa->crash == USE_INI_BASIS) alpar@1: { ret = glp_read_sol(csa->prob, csa->ini_file); alpar@1: if (ret != 0) alpar@1: { xprintf("Unable to read initial basis\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: } alpar@1: else alpar@1: xassert(csa != csa); alpar@1: } alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* solve the problem */ alpar@1: start = xtime(); alpar@1: if (csa->solution == SOL_BASIC) alpar@1: { if (!csa->exact) alpar@1: { glp_set_bfcp(csa->prob, &csa->bfcp); alpar@1: glp_simplex(csa->prob, &csa->smcp); alpar@1: if (csa->xcheck) alpar@1: { if (csa->smcp.presolve && alpar@1: glp_get_status(csa->prob) != GLP_OPT) alpar@1: xprintf("If you need to check final basis for non-opt" alpar@1: "imal solution, use --nopresol\n"); alpar@1: else alpar@1: glp_exact(csa->prob, &csa->smcp); alpar@1: } alpar@1: if (csa->out_sol != NULL || csa->out_res != NULL) alpar@1: { if (csa->smcp.presolve && alpar@1: glp_get_status(csa->prob) != GLP_OPT) alpar@1: xprintf("If you need actual output for non-optimal solut" alpar@1: "ion, use --nopresol\n"); alpar@1: } alpar@1: } alpar@1: else alpar@1: glp_exact(csa->prob, &csa->smcp); alpar@1: } alpar@1: else if (csa->solution == SOL_INTERIOR) alpar@1: glp_interior(csa->prob, &csa->iptcp); alpar@1: else if (csa->solution == SOL_INTEGER) alpar@1: { if (!csa->iocp.presolve) alpar@1: { glp_set_bfcp(csa->prob, &csa->bfcp); alpar@1: glp_simplex(csa->prob, &csa->smcp); alpar@1: } alpar@1: #if 0 alpar@1: csa->iocp.msg_lev = GLP_MSG_DBG; alpar@1: csa->iocp.pp_tech = GLP_PP_NONE; alpar@1: #endif alpar@1: glp_intopt(csa->prob, &csa->iocp); alpar@1: } alpar@1: else alpar@1: xassert(csa != csa); alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* display statistics */ alpar@1: xprintf("Time used: %.1f secs\n", xdifftime(xtime(), start)); alpar@1: { glp_long tpeak; alpar@1: char buf[50]; alpar@1: glp_mem_usage(NULL, NULL, NULL, &tpeak); alpar@1: xprintf("Memory used: %.1f Mb (%s bytes)\n", alpar@1: xltod(tpeak) / 1048576.0, xltoa(tpeak, buf)); alpar@1: } alpar@1: /*--------------------------------------------------------------*/ alpar@1: skip: /* postsolve the model, if necessary */ alpar@1: if (csa->tran != NULL) alpar@1: { if (csa->solution == SOL_BASIC) alpar@1: ret = glp_mpl_postsolve(csa->tran, csa->prob, GLP_SOL); alpar@1: else if (csa->solution == SOL_INTERIOR) alpar@1: ret = glp_mpl_postsolve(csa->tran, csa->prob, GLP_IPT); alpar@1: else if (csa->solution == SOL_INTEGER) alpar@1: ret = glp_mpl_postsolve(csa->tran, csa->prob, GLP_MIP); alpar@1: else alpar@1: xassert(csa != csa); alpar@1: if (ret != 0) alpar@1: { xprintf("Model postsolving error\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: } alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* write problem solution in printable format, if required */ alpar@1: if (csa->out_sol != NULL) alpar@1: { if (csa->solution == SOL_BASIC) alpar@1: ret = lpx_print_sol(csa->prob, csa->out_sol); alpar@1: else if (csa->solution == SOL_INTERIOR) alpar@1: ret = lpx_print_ips(csa->prob, csa->out_sol); alpar@1: else if (csa->solution == SOL_INTEGER) alpar@1: ret = lpx_print_mip(csa->prob, csa->out_sol); alpar@1: else alpar@1: xassert(csa != csa); alpar@1: if (ret != 0) alpar@1: { xprintf("Unable to write problem solution\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: } alpar@1: /* write problem solution in printable format, if required */ alpar@1: if (csa->out_res != NULL) alpar@1: { if (csa->solution == SOL_BASIC) alpar@1: ret = glp_write_sol(csa->prob, csa->out_res); alpar@1: else if (csa->solution == SOL_INTERIOR) alpar@1: ret = glp_write_ipt(csa->prob, csa->out_res); alpar@1: else if (csa->solution == SOL_INTEGER) alpar@1: ret = glp_write_mip(csa->prob, csa->out_res); alpar@1: else alpar@1: xassert(csa != csa); alpar@1: if (ret != 0) alpar@1: { xprintf("Unable to write problem solution\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: } alpar@1: /* write sensitivity analysis report, if required */ alpar@1: if (csa->out_ranges != NULL) alpar@1: { if (csa->solution == SOL_BASIC) alpar@1: { if (glp_get_status(csa->prob) == GLP_OPT) alpar@1: { if (glp_bf_exists(csa->prob)) alpar@1: ranges: { ret = glp_print_ranges(csa->prob, 0, NULL, 0, alpar@1: csa->out_ranges); alpar@1: if (ret != 0) alpar@1: { xprintf("Unable to write sensitivity analysis repo" alpar@1: "rt\n"); alpar@1: ret = EXIT_FAILURE; alpar@1: goto done; alpar@1: } alpar@1: } alpar@1: else alpar@1: { ret = glp_factorize(csa->prob); alpar@1: if (ret == 0) goto ranges; alpar@1: xprintf("Cannot produce sensitivity analysis report d" alpar@1: "ue to error in basis factorization (glp_factorize" alpar@1: " returned %d); try --nopresol\n", ret); alpar@1: } alpar@1: } alpar@1: else alpar@1: xprintf("Cannot produce sensitivity analysis report for " alpar@1: "non-optimal basic solution\n"); alpar@1: } alpar@1: else alpar@1: xprintf("Cannot produce sensitivity analysis report for int" alpar@1: "erior-point or MIP solution\n"); alpar@1: } alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* all seems to be ok */ alpar@1: ret = EXIT_SUCCESS; alpar@1: /*--------------------------------------------------------------*/ alpar@1: done: /* delete the LP/MIP problem object */ alpar@1: if (csa->prob != NULL) alpar@1: glp_delete_prob(csa->prob); alpar@1: /* free the translator workspace, if necessary */ alpar@1: if (csa->tran != NULL) alpar@1: glp_mpl_free_wksp(csa->tran); alpar@1: /* delete the network problem object, if necessary */ alpar@1: if (csa->graph != NULL) alpar@1: glp_delete_graph(csa->graph); alpar@1: xassert(gmp_pool_count() == 0); alpar@1: gmp_free_mem(); alpar@1: /* close log file, if necessary */ alpar@1: if (csa->log_file != NULL) glp_close_tee(); alpar@1: /* check that no memory blocks are still allocated */ alpar@1: { int count; alpar@1: glp_long total; alpar@1: glp_mem_usage(&count, NULL, &total, NULL); alpar@1: if (count != 0) alpar@1: xerror("Error: %d memory block(s) were lost\n", count); alpar@1: xassert(count == 0); alpar@1: xassert(total.lo == 0 && total.hi == 0); alpar@1: } alpar@1: /* free the GLPK environment */ alpar@1: glp_free_env(); alpar@1: /* return to the control program */ alpar@1: return ret; alpar@1: } alpar@1: alpar@1: /* eof */