31 #ifdef SOPLEX_WITH_EGLIB 33 #include "soplex/EGlib.h" 36 #define EGlpNumStart() {} 37 #define EGlpNumClear() {} 43 int main(
int argc,
char* argv[]);
51 " --readbas=<basfile> read starting basis from file\n" 52 " --writebas=<basfile> write terminal basis to file\n" 53 " --writefile=<lpfile> write LP to file in LP or MPS format depending on extension\n" 54 " --writedual=<lpfile> write the dual LP to a file in LP or MPS formal depending on extension\n" 55 " --<type>:<name>=<val> change parameter value using syntax of settings file entries\n" 56 " --loadset=<setfile> load parameters from settings file (overruled by command line parameters)\n" 57 " --saveset=<setfile> save parameters to settings file\n" 58 " --diffset=<setfile> save modified parameters to settings file\n" 59 " --extsol=<value> external solution for soplex to use for validation\n" 61 "limits and tolerances:\n" 62 " -t<s> set time limit to <s> seconds\n" 63 " -i<n> set iteration limit to <n>\n" 64 " -f<eps> set primal feasibility tolerance to <eps>\n" 65 " -o<eps> set dual feasibility (optimality) tolerance to <eps>\n" 66 " -l<eps> set validation tolerance to <eps>\n" 68 "algorithmic settings (* indicates default):\n" 69 " --readmode=<value> choose reading mode for <lpfile> (0* - floating-point, 1 - rational)\n" 70 " --solvemode=<value> choose solving mode (0 - floating-point solve, 1* - auto, 2 - force iterative refinement)\n" 71 " -s<value> choose simplifier/presolver (0 - off, 1* - auto)\n" 72 " -g<value> choose scaling (0 - off, 1 - uni-equilibrium, 2* - bi-equilibrium, 3 - geometric, 4 - iterated geometric, 5 - least squares, 6 - geometric-equilibrium)\n" 73 " -p<value> choose pricing (0* - auto, 1 - dantzig, 2 - parmult, 3 - devex, 4 - quicksteep, 5 - steep)\n" 74 " -r<value> choose ratio tester (0 - textbook, 1 - harris, 2 - fast, 3* - boundflipping)\n" 77 " -v<level> set verbosity to <level> (0 - error, 3 - normal, 5 - high)\n" 78 " -x print primal solution\n" 79 " -y print dual multipliers\n" 80 " -X print primal solution in rational numbers\n" 81 " -Y print dual multipliers in rational numbers\n" 82 " -q display detailed statistics\n" 83 " -c perform final check of optimal solution in original problem\n" 87 std::cerr <<
"missing input file\n\n";
89 std::cerr <<
"invalid option \"" << argv[idx] <<
"\"\n\n";
91 std::cerr <<
"usage: " << argv[0] <<
" " <<
"[options] <lpfile>\n" 92 #ifdef SOPLEX_WITH_ZLIB 93 <<
" <lpfile> linear program as .mps[.gz] or .lp[.gz] file\n\n" 95 <<
" <lpfile> linear program as .mps or .lp file\n\n" 102 void freeStrings(
char*& s1,
char*& s2,
char*& s3,
char*& s4,
char*& s5)
149 Real maxviol = boundviol > rowviol ? boundviol : rowviol;
151 soplex.
spxout <<
"Primal solution " << (feasible ?
"feasible" :
"infeasible")
152 <<
" in original problem (max. violation = " << std::scientific << maxviol
153 << std::setprecision(8) << std::fixed <<
").\n" 176 Real maxviol = redcostviol > dualviol ? redcostviol : dualviol;
178 soplex.
spxout <<
"Dual solution " << (feasible ?
"feasible" :
"infeasible")
179 <<
" in original problem (max. violation = " << std::scientific << maxviol
180 << std::setprecision(8) << std::fixed <<
").\n" 209 Rational maxviol = boundviol > rowviol ? boundviol : rowviol;
211 soplex.
spxout <<
"Primal solution " << (feasible ?
"feasible" :
"infeasible") <<
212 " in original problem (max. violation = " <<
rationalToString(maxviol) <<
").\n" 235 Rational maxviol = redcostviol > dualviol ? redcostviol : dualviol;
237 soplex.
spxout <<
"Dual solution " << (feasible ?
"feasible" :
"infeasible") <<
238 " in original problem (max. violation = " <<
rationalToString(maxviol) <<
").\n" 272 bool rational =
false)
277 printwidth = printprec + 10;
292 << std::setw(printwidth) << std::setprecision(printprec)
293 << primal[i] << std::endl;)
299 << std::setprecision(8) << std::fixed
300 <<
")." << std::endl;)
312 << std::setw(printwidth) << std::setprecision(printprec)
313 << primal[i] << std::endl;)
320 << std::setprecision(8) << std::fixed
321 <<
"). Solution has " << nNonzeros <<
" nonzero entries." << std::endl;)
340 << std::setw(printwidth) << std::setprecision(printprec)
341 << primal[i] << std::endl;)
363 << nNonzeros <<
" nonzero entries." << std::endl;)
373 bool rational =
false)
378 printwidth = printprec + 10;
393 << std::setw(printwidth) << std::setprecision(printprec)
394 << dual[i] << std::endl;)
400 << std::setprecision(8) << std::fixed <<
")." << std::endl;)
411 << std::setw(printwidth) << std::setprecision(printprec)
412 << dual[i] << std::endl;)
418 << std::setprecision(8) << std::fixed <<
")." << std::endl;)
431 << std::setw(printwidth) << std::setprecision(printprec)
432 << redcost[i] << std::endl;)
438 << std::setprecision(8) << std::fixed <<
")." << std::endl;)
458 << std::setw(printwidth)
459 << std::setprecision(printprec)
460 << dual[i] << std::endl;)
502 int main(
int argc,
char* argv[])
510 Timer* readingTime = 0;
514 const char* lpfilename = 0;
515 char* readbasname = 0;
516 char* writebasname = 0;
517 char* writefilename = 0;
518 char* writedualfilename = 0;
519 char* loadsetname = 0;
520 char* savesetname = 0;
521 char* diffsetname = 0;
522 bool printPrimal =
false;
523 bool printPrimalRational =
false;
524 bool printDual =
false;
525 bool printDualRational =
false;
526 bool displayStatistics =
false;
527 bool checkSol =
false;
558 for(optidx = 1; optidx < argc; optidx++)
560 char* option = argv[optidx];
565 lpfilename = argv[optidx];
571 if(option[0] !=
'-' || option[1] ==
'\0' 572 || ((option[2] ==
'\0') != (option[1] ==
'x' || option[1] ==
'X' || option[1] ==
'y' 573 || option[1] ==
'Y' || option[1] ==
'q' || option[1] ==
'c')))
577 goto TERMINATE_FREESTRINGS;
587 if(strncmp(option,
"readbas=", 8) == 0)
591 char* filename = &option[8];
592 readbasname =
new char[strlen(filename) + 1];
593 spxSnprintf(readbasname, strlen(filename) + 1,
"%s", filename);
597 else if(strncmp(option,
"writebas=", 9) == 0)
599 if(writebasname == 0)
601 char* filename = &option[9];
602 writebasname =
new char[strlen(filename) + 1];
603 spxSnprintf(writebasname, strlen(filename) + 1,
"%s", filename);
607 else if(strncmp(option,
"writefile=", 10) == 0)
609 if(writefilename == 0)
611 char* filename = &option[10];
612 writefilename =
new char[strlen(filename) + 1];
613 spxSnprintf(writefilename, strlen(filename) + 1,
"%s", filename);
617 else if(strncmp(option,
"writedual=", 10) == 0)
619 if(writedualfilename == 0)
621 char* dualfilename = &option[10];
622 writedualfilename =
new char[strlen(dualfilename) + 1];
623 spxSnprintf(writedualfilename, strlen(dualfilename) + 1,
"%s", dualfilename);
627 else if(strncmp(option,
"loadset=", 8) == 0)
631 char* filename = &option[8];
632 loadsetname =
new char[strlen(filename) + 1];
633 spxSnprintf(loadsetname, strlen(filename) + 1,
"%s", filename);
639 goto TERMINATE_FREESTRINGS;
649 else if(strncmp(option,
"saveset=", 8) == 0)
653 char* filename = &option[8];
654 savesetname =
new char[strlen(filename) + 1];
655 spxSnprintf(savesetname, strlen(filename) + 1,
"%s", filename);
659 else if(strncmp(option,
"diffset=", 8) == 0)
663 char* filename = &option[8];
664 diffsetname =
new char[strlen(filename) + 1];
665 spxSnprintf(diffsetname, strlen(filename) + 1,
"%s", filename);
669 else if(strncmp(option,
"readmode=", 9) == 0)
675 goto TERMINATE_FREESTRINGS;
679 else if(strncmp(option,
"solvemode=", 10) == 0)
685 goto TERMINATE_FREESTRINGS;
696 else if(strncmp(option,
"extsol=", 7) == 0)
698 char* input = &option[7];
704 goto TERMINATE_FREESTRINGS;
712 goto TERMINATE_FREESTRINGS;
725 goto TERMINATE_FREESTRINGS;
737 goto TERMINATE_FREESTRINGS;
749 goto TERMINATE_FREESTRINGS;
761 goto TERMINATE_FREESTRINGS;
773 goto TERMINATE_FREESTRINGS;
785 goto TERMINATE_FREESTRINGS;
797 goto TERMINATE_FREESTRINGS;
809 goto TERMINATE_FREESTRINGS;
821 goto TERMINATE_FREESTRINGS;
833 goto TERMINATE_FREESTRINGS;
845 printPrimalRational =
true;
855 printDualRational =
true;
860 displayStatistics =
true;
873 MSG_ERROR(std::cerr <<
"Error printing parameters\n");
883 goto TERMINATE_FREESTRINGS;
891 if(lpfilename == 0 && savesetname == 0 && diffsetname == 0)
895 goto TERMINATE_FREESTRINGS;
902 "Error: manual synchronization is invalid on command line. Change parameter int:syncmode.\n");
904 goto TERMINATE_FREESTRINGS;
915 MSG_ERROR(std::cerr <<
"Error writing parameters to file <" << savesetname <<
">\n");
922 diffsetname <<
"> . . .\n");
926 MSG_ERROR(std::cerr <<
"Error writing modified parameters to file <" << diffsetname <<
">\n");
933 if(loadsetname != 0 || savesetname != 0 || diffsetname != 0)
938 goto TERMINATE_FREESTRINGS;
942 readingTime->
start();
955 <<
" LP file <" << lpfilename <<
"> . . .\n");
957 if(!soplex->
readFile(lpfilename, &rownames, &colnames))
959 MSG_ERROR(std::cerr <<
"Error while reading file <" << lpfilename <<
">.\n");
961 goto TERMINATE_FREESTRINGS;
965 if(writefilename != 0)
967 if(!soplex->
writeFileReal(writefilename, &rownames, &colnames))
969 MSG_ERROR(std::cerr <<
"Error while writing file <" << writefilename <<
">.\n\n");
971 goto TERMINATE_FREESTRINGS;
980 if(writedualfilename != 0)
984 MSG_ERROR(std::cerr <<
"Error while writing dual file <" << writedualfilename <<
">.\n\n");
986 goto TERMINATE_FREESTRINGS;
1000 if(!soplex->
readBasisFile(readbasname, &rownames, &colnames))
1002 MSG_ERROR(std::cerr <<
"Error while reading file <" << readbasname <<
">.\n");
1004 goto TERMINATE_FREESTRINGS;
1008 readingTime->
stop();
1012 soplex->
spxout <<
"Reading took " 1013 << std::fixed << std::setprecision(2) << readingTime->
time()
1014 << std::scientific << std::setprecision(
int(prec))
1015 <<
" seconds.\n\n");
1030 if(displayStatistics)
1040 if(writebasname != 0)
1045 "No basis information available. Could not write file <" << writebasname <<
">\n\n");
1047 else if(!soplex->
writeBasisFile(writebasname, &rownames, &colnames))
1049 MSG_ERROR(std::cerr <<
"Error while writing file <" << writebasname <<
">.\n\n");
1051 goto TERMINATE_FREESTRINGS;
1055 MSG_INFO1(soplex->
spxout, soplex->
spxout <<
"Written basis information to file <" << writebasname <<
1062 MSG_ERROR(std::cerr <<
"Exception caught: " << x.
what() <<
"\n");
1064 goto TERMINATE_FREESTRINGS;
1067 TERMINATE_FREESTRINGS:
1068 freeStrings(readbasname, writebasname, loadsetname, savesetname, diffsetname);
1090 if(0 != readingTime)
bool isNotZero(Real a, Real eps=Param::epsilon())
returns true iff |a| > eps
standard floating-point parsing
void printVersion() const
prints version and compilation options
bool getDualViolationRational(Rational &maxviol, Rational &sumviol)
gets violation of dual multipliers; returns true on success
int numRowsReal() const
returns number of rows
automatic sync of real and rational LP
bool getPrimalReal(VectorReal &vector)
gets the primal solution vector if available; returns true on success
int numRowsRational() const
returns number of rows
bool writeDualFileReal(const char *filename, const NameSet *rowNames=0, const NameSet *colNames=0, const DIdxSet *intvars=0) const
writes the dual of the real LP to file; LP or MPS format is chosen from the extension in filename; if...
bool getDualRational(VectorRational &vector)
gets the dual solution vector if available; returns true on success
time limit in seconds (INFTY if unlimited)
mode for iterative refinement strategy
virtual ~SoPlex()
destructor
bool getRedCostRational(VectorRational &vector)
gets the vector of reduced cost values if available; returns true on success
primal feasibility tolerance
bool writeBasisFile(const char *filename, const NameSet *rowNames=0, const NameSet *colNames=0, const bool cpxFormat=false) const
writes basis information to filename; if rowNames and colNames are NULL, default names are used; retu...
bool readBasisFile(const char *filename, const NameSet *rowNames=0, const NameSet *colNames=0)
reads basis information from filename and returns true on success; if rowNames and colNames are NULL...
mode for reading LP files
mode for synchronizing real and rational LP
bool getDualFarkasReal(VectorReal &vector)
gets the Farkas proof if available; returns true on success
iteration limit (-1 if unlimited)
bool getRowViolationReal(Real &maxviol, Real &sumviol)
gets violation of constraints; returns true on success
decide according to READMODE
bool getRowViolationRational(Rational &maxviol, Rational &sumviol)
gets violation of constraints; returns true on success
bool updateExternalSolution(char *solution)
updates the external solution used for validation
bool readFile(const char *filename, NameSet *rowNames=0, NameSet *colNames=0, DIdxSet *intVars=0)
reads LP file in LP or MPS format according to READMODE parameter; gets row names, column names, and integer variables if desired; returns true on success
int intParam(const IntParam param) const
returns integer parameter value
Wrapper for GMP type mpq_class.We wrap mpq_class so that we can replace it by a double type if GMP is...
static void disableListMem()
disables list memory
void printStatistics(std::ostream &os)
prints complete statistics
std::ostream & getStream(const Verbosity &verbosity) const
Returns the stream for the specified verbosity level.
user sync of real and rational LP
virtual const std::string what() const
returns exception message
bool isDualFeasible() const
is stored dual solution feasible?
SPxSolver::Status optimize()
optimize the given LP
virtual void start()=0
start timer, resume accounting user, system and real time.
virtual Real stop()=0
stop timer, return accounted user time.
void spx_alloc(T &p, int n=1)
Allocate memory.
bool isPrimalFeasible() const
is stored primal solution feasible?
int main(int argc, char *argv[])
runs SoPlex command line
bool getPrimalRayReal(VectorReal &vector)
gets the primal ray if available; returns true on success
bool hasPrimal() const
is a primal feasible solution available?
static void printUsage(const char *const argv[], int idx)
void validateSolveReal(SoPlex &soplex)
validates the soplex solution using the external solution
bool hasBasis() const
is an advanced starting basis available?
#define MSG_ERROR(x)
Prints out message x if the verbosity level is at least SPxOut::ERROR.
bool getDualViolationReal(Real &maxviol, Real &sumviol)
gets violation of dual multipliers; returns true on success
int spxSnprintf(char *t, size_t len, const char *s,...)
safe version of snprintf
void printUserSettings()
print non-default parameter values
static void checkSolutionRational(SoPlex &soplex)
performs external feasibility check with rational type
static void printPrimalSolution(SoPlex &soplex, NameSet &colnames, NameSet &rownames, bool real=true, bool rational=false)
int numColsRational() const
returns number of columns
bool getPrimalRational(VectorRational &vector)
gets the primal solution vector if available; returns true on success
bool getRedCostReal(VectorReal &vector)
gets the vector of reduced cost values if available; returns true on success
Real realParam(const RealParam param) const
returns real parameter value
virtual Real time() const =0
bool hasDual() const
is a dual feasible solution available?
bool parseSettingsString(char *line)
parses one setting string and returns true on success; note that string is modified ...
static Timer * createTimer(Timer::TYPE ttype)
create timers and allocate memory for them
static void printDualSolution(SoPlex &soplex, NameSet &colnames, NameSet &rownames, bool real=true, bool rational=false)
Preconfigured SoPlex LP solver.
apply standard floating-point algorithm
Set of strings.Class NameSet implements a symbol or name table. It allows to store or remove names (i...
bool validate
should the soplex solution be validated?
Exception base class.This class implements a base class for our SoPlex exceptions We provide a what()...
Everything should be within this namespace.
bool setRealParam(const RealParam param, const Real value, const bool init=true)
sets real parameter value; returns true on success
bool loadSettingsFile(const char *filename)
reads settings file; returns true on success
int numNonzerosReal() const
returns number of nonzeros
bool getRedCostViolationRational(Rational &maxviol, Rational &sumviol)
gets violation of reduced costs; returns true on success
bool getDualReal(VectorReal &vector)
gets the dual solution vector if available; returns true on success
static void checkSolution(SoPlex &soplex)
performs external feasibility check according to check mode
Preconfigured SoPlex LP-solver.
#define MSG_WARNING(spxout, x)
Prints out message x if the verbosity level is at least SPxOut::WARNING.
std::streamsize precision() const
bool getBoundViolationReal(Real &maxviol, Real &sumviol)
gets violation of bounds; returns true on success
bool writeFileReal(const char *filename, const NameSet *rowNames=0, const NameSet *colNames=0, const DIdxSet *intvars=0, const bool unscale=true) const
writes real LP to file; LP or MPS format is chosen from the extension in filename; if rowNames and co...
mode for a posteriori feasibility checks
~Validation()
default destructor
bool getDualFarkasRational(VectorRational &vector)
gets the Farkas proof if LP is infeasible; returns true on success
#define MSG_INFO1(spxout, x)
Prints out message x if the verbosity level is at least SPxOut::INFO1.
Validation object for soplex solutions.
bool getRedCostViolationReal(Real &maxviol, Real &sumviol)
gets violation of reduced costs; returns true on success
static void freeStrings(char *&s1, char *&s2, char *&s3, char *&s4, char *&s5)
bool getPrimalRayRational(VectorRational &vector)
gets the primal ray if LP is unbounded; returns true on success
dual feasibility tolerance
bool setIntParam(const IntParam param, const int value, const bool init=true)
sets integer parameter value; returns true on success
bool saveSettingsFile(const char *filename, const bool onlyChanged=false) const
writes settings file; returns true on success
static void checkSolutionReal(SoPlex &soplex)
performs external feasibility check with real type
std::string rationalToString(const Rational &r, const int precision)
convert rational number to string
bool updateValidationTolerance(char *tolerance)
updates the tolerance used for validation
int numColsReal() const
returns number of columns
Wrapper for the system time query methods.
void spx_free(T &p)
Release memory.
bool getBoundViolationRational(Rational &maxviol, Rational &sumviol)
gets violation of bounds; returns true on success