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)
145 Real maxviol = boundviol > rowviol ? boundviol : rowviol;
147 soplex.
spxout <<
"Primal solution " << (feasible ?
"feasible" :
"infeasible")
148 <<
" in original problem (max. violation = " << std::scientific << maxviol
149 << std::setprecision(8) << std::fixed <<
").\n" 171 Real maxviol = redcostviol > dualviol ? redcostviol : dualviol;
173 soplex.
spxout <<
"Dual solution " << (feasible ?
"feasible" :
"infeasible")
174 <<
" in original problem (max. violation = " << std::scientific << maxviol
175 << std::setprecision(8) << std::fixed <<
").\n" 203 Rational maxviol = boundviol > rowviol ? boundviol : rowviol;
205 soplex.
spxout <<
"Primal solution " << (feasible ?
"feasible" :
"infeasible") <<
" in original problem (max. violation = " <<
rationalToString(maxviol) <<
").\n" 227 Rational maxviol = redcostviol > dualviol ? redcostviol : dualviol;
229 soplex.
spxout <<
"Dual solution " << (feasible ?
"feasible" :
"infeasible") <<
" in original problem (max. violation = " <<
rationalToString(maxviol) <<
").\n" 267 printwidth = printprec + 10;
280 << std::setw(printwidth) << std::setprecision(printprec)
281 << primal[i] << std::endl; )
286 << std::setprecision(8) << std::fixed
287 <<
")." << std::endl; )
298 << std::setw(printwidth) << std::setprecision(printprec)
299 << primal[i] << std::endl; )
305 << std::setprecision(8) << std::fixed
306 <<
"). Solution has " << nNonzeros <<
" nonzero entries." << std::endl; )
323 << std::setw(printwidth) << std::setprecision(printprec)
324 << primal[i] << std::endl; )
343 << nNonzeros <<
" nonzero entries." << std::endl; )
357 printwidth = printprec + 10;
370 << std::setw(printwidth) << std::setprecision(printprec)
371 << dual[i] << std::endl; )
376 << std::setprecision(8) << std::fixed <<
")." << std::endl; )
386 << std::setw(printwidth) << std::setprecision(printprec)
387 << dual[i] << std::endl; )
392 << std::setprecision(8) << std::fixed <<
")." << std::endl; )
403 << std::setw(printwidth) << std::setprecision(printprec)
404 << redcost[i] << std::endl; )
409 << std::setprecision(8) << std::fixed <<
")." << std::endl; )
427 << std::setw(printwidth)
428 << std::setprecision(printprec)
429 << dual[i] << std::endl; )
464 int main(
int argc,
char* argv[])
472 Timer* readingTime = 0;
476 const char* lpfilename = 0;
477 char* readbasname = 0;
478 char* writebasname = 0;
479 char* writefilename = 0;
480 char* writedualfilename = 0;
481 char* loadsetname = 0;
482 char* savesetname = 0;
483 char* diffsetname = 0;
484 bool printPrimal =
false;
485 bool printPrimalRational =
false;
486 bool printDual =
false;
487 bool printDualRational =
false;
488 bool displayStatistics =
false;
489 bool checkSol =
false;
520 for( optidx = 1; optidx < argc; optidx++ )
522 char* option = argv[optidx];
525 if( option[0] !=
'-' )
527 lpfilename = argv[optidx];
533 if( option[0] !=
'-' || option[1] ==
'\0' 534 || ((option[2] ==
'\0') != (option[1] ==
'x' || option[1] ==
'X' || option[1] ==
'y' || option[1] ==
'Y' || option[1] ==
'q' || option[1] ==
'c')) )
538 goto TERMINATE_FREESTRINGS;
548 if( strncmp(option,
"readbas=", 8) == 0 )
550 if( readbasname == 0 )
552 char* filename = &option[8];
553 readbasname =
new char[strlen(filename) + 1];
554 spxSnprintf(readbasname, strlen(filename) + 1,
"%s", filename);
558 else if( strncmp(option,
"writebas=", 9) == 0 )
560 if( writebasname == 0 )
562 char* filename = &option[9];
563 writebasname =
new char[strlen(filename) + 1];
564 spxSnprintf(writebasname, strlen(filename) + 1,
"%s", filename);
568 else if( strncmp(option,
"writefile=", 10) == 0 )
570 if( writefilename == 0 )
572 char* filename = &option[10];
573 writefilename =
new char[strlen(filename) + 1];
574 spxSnprintf(writefilename, strlen(filename) + 1,
"%s", filename);
578 else if( strncmp(option,
"writedual=", 10) == 0 )
580 if( writedualfilename == 0 )
582 char* dualfilename = &option[10];
583 writedualfilename =
new char[strlen(dualfilename) + 1];
584 spxSnprintf(writedualfilename, strlen(dualfilename) + 1,
"%s", dualfilename);
588 else if( strncmp(option,
"loadset=", 8) == 0 )
590 if( loadsetname == 0 )
592 char* filename = &option[8];
593 loadsetname =
new char[strlen(filename) + 1];
594 spxSnprintf(loadsetname, strlen(filename) + 1,
"%s", filename);
599 goto TERMINATE_FREESTRINGS;
609 else if( strncmp(option,
"saveset=", 8) == 0 )
611 if( savesetname == 0 )
613 char* filename = &option[8];
614 savesetname =
new char[strlen(filename) + 1];
615 spxSnprintf(savesetname, strlen(filename) + 1,
"%s", filename);
619 else if( strncmp(option,
"diffset=", 8) == 0 )
621 if( diffsetname == 0 )
623 char* filename = &option[8];
624 diffsetname =
new char[strlen(filename) + 1];
625 spxSnprintf(diffsetname, strlen(filename) + 1,
"%s", filename);
629 else if( strncmp(option,
"readmode=", 9) == 0 )
635 goto TERMINATE_FREESTRINGS;
639 else if( strncmp(option,
"solvemode=", 10) == 0 )
645 goto TERMINATE_FREESTRINGS;
656 else if( strncmp(option,
"extsol=", 7) == 0 )
658 char* input = &option[7];
663 goto TERMINATE_FREESTRINGS;
671 goto TERMINATE_FREESTRINGS;
682 goto TERMINATE_FREESTRINGS;
692 goto TERMINATE_FREESTRINGS;
702 goto TERMINATE_FREESTRINGS;
712 goto TERMINATE_FREESTRINGS;
722 goto TERMINATE_FREESTRINGS;
732 goto TERMINATE_FREESTRINGS;
742 goto TERMINATE_FREESTRINGS;
752 goto TERMINATE_FREESTRINGS;
762 goto TERMINATE_FREESTRINGS;
772 goto TERMINATE_FREESTRINGS;
783 printPrimalRational =
true;
793 printDualRational =
true;
798 displayStatistics =
true;
810 MSG_ERROR( std::cerr <<
"Error printing parameters\n" );
819 goto TERMINATE_FREESTRINGS;
827 if( lpfilename == 0 && savesetname == 0 && diffsetname == 0 )
831 goto TERMINATE_FREESTRINGS;
837 MSG_ERROR( std::cerr <<
"Error: manual synchronization is invalid on command line. Change parameter int:syncmode.\n" );
839 goto TERMINATE_FREESTRINGS;
843 if( savesetname != 0 )
845 MSG_INFO1( soplex->
spxout, soplex->
spxout <<
"Saving parameters to settings file <" << savesetname <<
"> . . .\n" );
848 MSG_ERROR( std::cerr <<
"Error writing parameters to file <" << savesetname <<
">\n" );
851 if( diffsetname != 0 )
853 MSG_INFO1( soplex->
spxout, soplex->
spxout <<
"Saving modified parameters to settings file <" << diffsetname <<
"> . . .\n" );
856 MSG_ERROR( std::cerr <<
"Error writing modified parameters to file <" << diffsetname <<
">\n" );
861 if( lpfilename == 0 )
863 if( loadsetname != 0 || savesetname != 0 || diffsetname != 0 )
867 goto TERMINATE_FREESTRINGS;
871 readingTime->
start();
884 <<
" LP file <" << lpfilename <<
"> . . .\n" );
886 if( !soplex->
readFile(lpfilename, &rownames, &colnames) )
888 MSG_ERROR( std::cerr <<
"Error while reading file <" << lpfilename <<
">.\n" );
890 goto TERMINATE_FREESTRINGS;
894 if( writefilename != 0 )
896 if( !soplex->
writeFileReal(writefilename, &rownames, &colnames) )
898 MSG_ERROR( std::cerr <<
"Error while writing file <" << writefilename <<
">.\n\n" );
900 goto TERMINATE_FREESTRINGS;
909 if( writedualfilename != 0 )
913 MSG_ERROR( std::cerr <<
"Error while writing dual file <" << writedualfilename <<
">.\n\n" );
915 goto TERMINATE_FREESTRINGS;
919 MSG_INFO1( soplex->
spxout, soplex->
spxout <<
"Written dual LP to file <" << writedualfilename <<
">.\n\n" );
924 if( readbasname != 0 )
927 if( !soplex->
readBasisFile(readbasname, &rownames, &colnames) )
929 MSG_ERROR( std::cerr <<
"Error while reading file <" << readbasname <<
">.\n" );
931 goto TERMINATE_FREESTRINGS;
939 soplex->
spxout <<
"Reading took " 940 << std::fixed << std::setprecision(2) << readingTime->
time()
941 << std::scientific << std::setprecision(
int(prec))
942 <<
" seconds.\n\n" );
957 if( displayStatistics )
967 if( writebasname != 0 )
971 MSG_WARNING( soplex->
spxout, soplex->
spxout <<
"No basis information available. Could not write file <" << writebasname <<
">\n\n" );
973 else if( !soplex->
writeBasisFile(writebasname, &rownames, &colnames) )
975 MSG_ERROR( std::cerr <<
"Error while writing file <" << writebasname <<
">.\n\n" );
977 goto TERMINATE_FREESTRINGS;
981 MSG_INFO1( soplex->
spxout, soplex->
spxout <<
"Written basis information to file <" << writebasname <<
">.\n\n" );
987 MSG_ERROR( std::cerr <<
"Exception caught: " << x.
what() <<
"\n" );
989 goto TERMINATE_FREESTRINGS;
992 TERMINATE_FREESTRINGS:
993 freeStrings(readbasname, writebasname, loadsetname, savesetname, diffsetname);
1004 if( 0 != validation )
1011 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