34 int main(
int argc,
char* argv[]);
42 " --readbas=<basfile> read starting basis from file\n" 43 " --writebas=<basfile> write terminal basis to file\n" 44 " --writefile=<lpfile> write LP to file in LP or MPS format depending on extension\n" 45 " --writedual=<lpfile> write the dual LP to a file in LP or MPS formal depending on extension\n" 46 " --<type>:<name>=<val> change parameter value using syntax of settings file entries\n" 47 " --loadset=<setfile> load parameters from settings file (overruled by command line parameters)\n" 48 " --saveset=<setfile> save parameters to settings file\n" 49 " --diffset=<setfile> save modified parameters to settings file\n" 50 " --extsol=<value> external solution for soplex to use for validation\n" 52 "limits and tolerances:\n" 53 " -t<s> set time limit to <s> seconds\n" 54 " -i<n> set iteration limit to <n>\n" 55 " -f<eps> set primal feasibility tolerance to <eps>\n" 56 " -o<eps> set dual feasibility (optimality) tolerance to <eps>\n" 57 " -l<eps> set validation tolerance to <eps>\n" 59 "algorithmic settings (* indicates default):\n" 60 " --readmode=<value> choose reading mode for <lpfile> (0* - floating-point, 1 - rational)\n" 61 " --solvemode=<value> choose solving mode (0 - floating-point solve, 1* - auto, 2 - force iterative refinement)\n" 62 " --arithmetic=<value> choose base arithmetic type (0 - double, 1 - quadprecision, 2 - higher multiprecision)\n" 63 #ifdef SOPLEX_WITH_MPFR 64 " --precision=<value> choose precision for multiprecision solve (only active when arithmetic=2 minimal value = 50)\n" 66 #ifdef SOPLEX_WITH_CPPMPF 67 " --precision=<value> choose precision for multiprecision solve (only active when arithmetic=2, possible values 50,100,200, compile with mpfr for arbitrary precision)\n" 69 " -s<value> choose simplifier/presolver (0 - off, 1* - internal, 2*- PaPILO)\n" 70 " -g<value> choose scaling (0 - off, 1 - uni-equilibrium, 2* - bi-equilibrium, 3 - geometric, 4 - iterated geometric, 5 - least squares, 6 - geometric-equilibrium)\n" 71 " -p<value> choose pricing (0* - auto, 1 - dantzig, 2 - parmult, 3 - devex, 4 - quicksteep, 5 - steep)\n" 72 " -r<value> choose ratio tester (0 - textbook, 1 - harris, 2 - fast, 3* - boundflipping)\n" 75 " -v<level> set verbosity to <level> (0 - error, 3 - normal, 5 - high)\n" 76 " -x print primal solution\n" 77 " -y print dual multipliers\n" 78 " -X print primal solution in rational numbers\n" 79 " -Y print dual multipliers in rational numbers\n" 80 " -q display detailed statistics\n" 81 " -c perform final check of optimal solution in original problem\n" 85 std::cerr <<
"missing input file\n\n";
87 std::cerr <<
"invalid option \"" << argv[idx] <<
"\"\n\n";
89 std::cerr <<
"usage: " << argv[0] <<
" " <<
"[options] <lpfile>\n" 90 #ifdef SOPLEX_WITH_ZLIB 91 <<
" <lpfile> linear program as .mps[.gz] or .lp[.gz] file\n\n" 93 <<
" <lpfile> linear program as .mps or .lp file\n\n" 100 void freeStrings(
char*& s1,
char*& s2,
char*& s3,
char*& s4,
char*& s5)
149 R 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");
174 R maxviol = redcostviol > dualviol ? redcostviol : dualviol;
176 soplex.
spxout <<
"Dual solution " << (feasible ?
"feasible" :
"infeasible")
177 <<
" in original problem (max. violation = " << std::scientific << maxviol
178 << std::setprecision(8) << std::fixed <<
").\n" 207 Rational maxviol = boundviol > rowviol ? boundviol : rowviol;
209 soplex.
spxout <<
"Primal solution " << (feasible ?
"feasible" :
"infeasible") <<
210 " in original problem (max. violation = " << maxviol <<
").\n" 233 Rational maxviol = redcostviol > dualviol ? redcostviol : dualviol;
235 soplex.
spxout <<
"Dual solution " << (feasible ?
"feasible" :
"infeasible") <<
236 " in original problem (max. violation = " << maxviol <<
").\n" 271 bool real =
true,
bool rational =
false)
276 printwidth = printprec + 10;
286 for(
int i = 0; i < soplex.
numCols(); ++i)
288 if(isNotZero(primal[i]))
291 << std::setw(printwidth) << std::setprecision(printprec)
292 << primal[i] << std::endl;)
298 << std::setprecision(8) << std::fixed
299 <<
")." << std::endl;)
306 for(
int i = 0; i < soplex.
numCols(); ++i)
308 if(isNotZero(primal[i]))
311 << std::setw(printwidth) << std::setprecision(printprec)
312 << primal[i] << std::endl;)
319 << std::setprecision(8) << std::fixed
320 <<
"). Solution has " << nNonzeros <<
" nonzero entries." << std::endl;)
334 for(
int i = 0; i < soplex.
numCols(); ++i)
339 << std::setw(printwidth) << std::setprecision(printprec)
340 << primal[i] << std::endl;)
362 << nNonzeros <<
" nonzero entries." << std::endl;)
373 bool real =
true,
bool rational =
false)
378 printwidth = printprec + 10;
388 for(
int i = 0; i < soplex.
numRows(); ++i)
390 if(isNotZero(dual[i]))
393 << std::setw(printwidth) << std::setprecision(printprec)
394 << dual[i] << std::endl;)
400 << std::setprecision(8) << std::fixed <<
")." << std::endl;)
406 for(
int i = 0; i < soplex.
numRows(); ++i)
408 if(isNotZero(dual[i]))
411 << std::setw(printwidth) << std::setprecision(printprec)
412 << dual[i] << std::endl;)
418 << std::setprecision(8) << std::fixed <<
")." << std::endl;)
426 for(
int i = 0; i < soplex.
numCols(); ++i)
428 if(isNotZero(redcost[i]))
431 << std::setw(printwidth) << std::setprecision(printprec)
432 << redcost[i] << std::endl;)
438 << std::setprecision(8) << std::fixed <<
")." << std::endl;)
453 for(
int i = 0; i < soplex.
numRows(); ++i)
458 << std::setw(printwidth)
459 << std::setprecision(printprec)
460 << dual[i] << std::endl;)
485 for(
int i = 0; i < soplex.
numCols(); ++i)
505 Timer* readingTime =
nullptr;
509 const char* lpfilename =
nullptr;
510 char* readbasname =
nullptr;
511 char* writebasname =
nullptr;
512 char* writefilename =
nullptr;
513 char* writedualfilename =
nullptr;
514 char* loadsetname =
nullptr;
515 char* savesetname =
nullptr;
516 char* diffsetname =
nullptr;
517 bool printPrimal =
false;
518 bool printPrimalRational =
false;
519 bool printDual =
false;
520 bool printDualRational =
false;
521 bool displayStatistics =
false;
522 bool checkSol =
false;
540 validation =
nullptr;
553 for(optidx = 1; optidx < argc; optidx++)
555 char* option = argv[optidx];
560 lpfilename = argv[optidx];
566 if(option[0] !=
'-' || option[1] ==
'\0' 567 || ((option[2] ==
'\0') != (option[1] ==
'x' || option[1] ==
'X' || option[1] ==
'y' 568 || option[1] ==
'Y' || option[1] ==
'q' || option[1] ==
'c')))
572 goto TERMINATE_FREESTRINGS;
582 if(strncmp(option,
"readbas=", 8) == 0)
584 if(readbasname ==
nullptr)
586 char* filename = &option[8];
587 readbasname =
new char[strlen(filename) + 1];
588 spxSnprintf(readbasname, strlen(filename) + 1,
"%s", filename);
592 else if(strncmp(option,
"writebas=", 9) == 0)
594 if(writebasname ==
nullptr)
596 char* filename = &option[9];
597 writebasname =
new char[strlen(filename) + 1];
598 spxSnprintf(writebasname, strlen(filename) + 1,
"%s", filename);
602 else if(strncmp(option,
"writefile=", 10) == 0)
604 if(writefilename ==
nullptr)
606 char* filename = &option[10];
607 writefilename =
new char[strlen(filename) + 1];
608 spxSnprintf(writefilename, strlen(filename) + 1,
"%s", filename);
612 else if(strncmp(option,
"writedual=", 10) == 0)
614 if(writedualfilename ==
nullptr)
616 char* dualfilename = &option[10];
617 writedualfilename =
new char[strlen(dualfilename) + 1];
618 spxSnprintf(writedualfilename, strlen(dualfilename) + 1,
"%s", dualfilename);
622 else if(strncmp(option,
"loadset=", 8) == 0)
624 if(loadsetname ==
nullptr)
626 char* filename = &option[8];
627 loadsetname =
new char[strlen(filename) + 1];
628 spxSnprintf(loadsetname, strlen(filename) + 1,
"%s", filename);
634 goto TERMINATE_FREESTRINGS;
644 else if(strncmp(option,
"saveset=", 8) == 0)
646 if(savesetname ==
nullptr)
648 char* filename = &option[8];
649 savesetname =
new char[strlen(filename) + 1];
650 spxSnprintf(savesetname, strlen(filename) + 1,
"%s", filename);
654 else if(strncmp(option,
"diffset=", 8) == 0)
656 if(diffsetname ==
nullptr)
658 char* filename = &option[8];
659 diffsetname =
new char[strlen(filename) + 1];
660 spxSnprintf(diffsetname, strlen(filename) + 1,
"%s", filename);
664 else if(strncmp(option,
"readmode=", 9) == 0)
670 goto TERMINATE_FREESTRINGS;
674 else if(strncmp(option,
"solvemode=", 10) == 0)
680 goto TERMINATE_FREESTRINGS;
691 else if(strncmp(option,
"extsol=", 7) == 0)
693 char* input = &option[7];
699 goto TERMINATE_FREESTRINGS;
703 else if(strncmp(option,
"arithmetic=", 11) == 0)
708 else if(strncmp(option,
"precision=", 10) == 0)
717 goto TERMINATE_FREESTRINGS;
730 goto TERMINATE_FREESTRINGS;
742 goto TERMINATE_FREESTRINGS;
754 goto TERMINATE_FREESTRINGS;
766 goto TERMINATE_FREESTRINGS;
778 goto TERMINATE_FREESTRINGS;
790 goto TERMINATE_FREESTRINGS;
802 goto TERMINATE_FREESTRINGS;
814 goto TERMINATE_FREESTRINGS;
826 goto TERMINATE_FREESTRINGS;
838 goto TERMINATE_FREESTRINGS;
850 printPrimalRational =
true;
860 printDualRational =
true;
865 displayStatistics =
true;
878 MSG_ERROR(std::cerr <<
"Error printing parameters\n");
888 goto TERMINATE_FREESTRINGS;
896 if(lpfilename ==
nullptr && savesetname ==
nullptr && diffsetname ==
nullptr)
900 goto TERMINATE_FREESTRINGS;
907 "Error: manual synchronization is invalid on command line. Change parameter int:syncmode.\n");
909 goto TERMINATE_FREESTRINGS;
913 if(savesetname !=
nullptr)
920 MSG_ERROR(std::cerr <<
"Error writing parameters to file <" << savesetname <<
">\n");
924 if(diffsetname !=
nullptr)
927 diffsetname <<
"> . . .\n");
931 MSG_ERROR(std::cerr <<
"Error writing modified parameters to file <" << diffsetname <<
">\n");
936 if(lpfilename ==
nullptr)
938 if(loadsetname !=
nullptr || savesetname !=
nullptr || diffsetname !=
nullptr)
943 goto TERMINATE_FREESTRINGS;
947 readingTime->
start();
960 <<
" LP file <" << lpfilename <<
"> . . .\n");
962 if(!soplex->
readFile(lpfilename, &rownames, &colnames))
964 MSG_ERROR(std::cerr <<
"Error while reading file <" << lpfilename <<
">.\n");
966 goto TERMINATE_FREESTRINGS;
970 if(writefilename !=
nullptr)
972 if(!soplex->
writeFile(writefilename, &rownames, &colnames))
974 MSG_ERROR(std::cerr <<
"Error while writing file <" << writefilename <<
">.\n\n");
976 goto TERMINATE_FREESTRINGS;
985 if(writedualfilename !=
nullptr)
989 MSG_ERROR(std::cerr <<
"Error while writing dual file <" << writedualfilename <<
">.\n\n");
991 goto TERMINATE_FREESTRINGS;
1001 if(readbasname !=
nullptr)
1005 if(!soplex->
readBasisFile(readbasname, &rownames, &colnames))
1007 MSG_ERROR(std::cerr <<
"Error while reading file <" << readbasname <<
">.\n");
1009 goto TERMINATE_FREESTRINGS;
1013 readingTime->
stop();
1017 soplex->
spxout <<
"Reading took " 1018 << std::fixed << std::setprecision(2) << readingTime->
time()
1019 << std::scientific << std::setprecision(
int(prec))
1020 <<
" seconds.\n\n");
1023 << soplex->
numCols() <<
" columns and " << soplex->
numNonzeros() <<
" nonzeros.\n\n");
1033 checkSolution<R>(*soplex);
1035 if(displayStatistics)
1037 MSG_INFO1(soplex->spxout, soplex->spxout <<
"Statistics\n==========\n\n");
1038 soplex->printStatistics(soplex->spxout.getStream(
SPxOut::INFO1));
1045 if(writebasname !=
nullptr)
1047 if(!soplex->hasBasis())
1050 "No basis information available. Could not write file <" << writebasname <<
">\n\n");
1052 else if(!soplex->writeBasisFile(writebasname, &rownames, &colnames))
1054 MSG_ERROR(std::cerr <<
"Error while writing file <" << writebasname <<
">.\n\n");
1056 goto TERMINATE_FREESTRINGS;
1060 MSG_INFO1(soplex->spxout, soplex->spxout <<
"Written basis information to file <" << writebasname <<
1067 MSG_ERROR(std::cerr <<
"Exception caught: " << x.
what() <<
"\n");
1069 goto TERMINATE_FREESTRINGS;
1072 TERMINATE_FREESTRINGS:
1073 freeStrings(readbasname, writebasname, loadsetname, savesetname, diffsetname);
1080 if(
nullptr != soplex)
1086 if(
nullptr != validation)
1092 if(
nullptr != readingTime)
1117 for(optidx = 1; optidx < argc; optidx++)
1119 char* option = argv[optidx];
1122 if(option[0] !=
'-')
1127 if(option[0] !=
'-' || option[1] ==
'\0' 1128 || ((option[2] ==
'\0') != (option[1] ==
'x' || option[1] ==
'X' || option[1] ==
'y' 1129 || option[1] ==
'Y' || option[1] ==
'q' || option[1] ==
'c')))
1138 option = &option[2];
1142 if(strncmp(option,
"arithmetic=", 11) == 0)
1144 if(option[11] ==
'1')
1146 #ifndef SOPLEX_WITH_FLOAT128 1148 "Cannot set arithmetic type to quadprecision - Soplex compiled without quadprecision support\n";)
1155 else if(option[11] ==
'2')
1157 #ifndef SOPLEX_WITH_BOOST 1159 "Cannot set arithmetic type to multiprecision - Soplex compiled without boost\n";)
1173 else if(strncmp(option,
"precision=", 10) == 0)
1175 precision = atoi(option + 10);
1176 #ifndef SOPLEX_WITH_BOOST 1177 MSG_ERROR(std::cerr <<
"Setting precision to non-default value without Boost has no effect\n";)
1188 if(precision != 0 && arithmetic != 2)
1191 "Setting precision to non-default value without enabling multiprecision solve has no effect\n";)
1197 runSoPlex<Real>(argc, argv);
1200 #ifdef SOPLEX_WITH_BOOST 1201 #ifdef SOPLEX_WITH_FLOAT128 1204 #if BOOST_VERSION < 107000 1205 std::cerr <<
"Error: Boost version too old." << std:: endl <<
1206 "In order to use the quadprecision feature of SoPlex," <<
1207 " Boost Version 1.70.0 or higher is required." << std::endl << \
1208 "Included Boost version is " << BOOST_VERSION / 100000 <<
"." 1209 << BOOST_VERSION / 100 % 1000 <<
"." 1210 << BOOST_VERSION % 100
1214 using Quad = boost::multiprecision::float128;
1215 runSoPlex<Quad>(argc, argv);
1223 #if BOOST_VERSION < 107000 1224 std::cerr <<
"Error: Boost version too old." << std:: endl <<
1225 "In order to use the multiprecision feature of SoPlex," <<
1226 " Boost Version 1.70.0 or higher is required." << std::endl << \
1227 "Included Boost version is " << BOOST_VERSION / 100000 <<
"." 1228 << BOOST_VERSION / 100 % 1000 <<
"." 1229 << BOOST_VERSION % 100
1232 #ifdef SOPLEX_WITH_MPFR 1238 using multiprecision = number<mpfr_float_backend<0>, et_off>;
1239 multiprecision::default_precision(precision);
1240 runSoPlex<multiprecision>(argc, argv);
1241 #endif // SOPLEX_WITH_MPFR 1243 #ifdef SOPLEX_WITH_CPPMPF 1247 using multiprecision1 = number<cpp_dec_float<50>, et_off>;
1248 using multiprecision2 = number<cpp_dec_float<100>, et_off>;
1249 using multiprecision3 = number<cpp_dec_float<200>, et_off>;
1252 runSoPlex<multiprecision1>(argc, argv);
1253 else if(precision <= 100)
1254 runSoPlex<multiprecision2>(argc, argv);
1256 runSoPlex<multiprecision3>(argc, argv);
1258 #endif // SOPLEX_WITH_CPPMPF 1264 std::cerr <<
"Wrong value for the arithmetic mode\n";
bool writeFile(const char *filename, const NameSet *rowNames=0, const NameSet *colNames=0, const DIdxSet *intvars=0, const bool unscale=true) const
Templated write function Real writes real LP to file; LP or MPS format is chosen from the extension i...
virtual ~SoPlexBase()
destructor
number< gmp_rational, et_off > Rational
bool getBoundViolationRational(Rational &maxviol, Rational &sumviol)
Dense vector.Class VectorBase provides dense linear algebra vectors. Internally, VectorBase wraps std...
automatic sync of real and rational LP
bool getDualRational(VectorRational &vector)
int numNonzeros() const
returns number of nonzeros
int numRowsRational() const
bool getPrimalRational(VectorRational &vector)
dual feasibility tolerance
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 isDualFeasible() const
is stored dual solution feasible?
bool updateValidationTolerance(const std::string &tolerance)
updates the tolerance used for validation
static void checkSolutionReal(SoPlexBase< R > &soplex)
performs external feasibility check with real type
bool getDual(VectorBase< R > &vector)
gets the dual solution vector if available; returns true on success
bool getRowViolationRational(Rational &maxviol, Rational &sumviol)
SPxSolverBase< R >::Status optimize(volatile bool *interrupt=NULL)
optimize the given LP
bool getPrimalRay(VectorBase< R > &vector)
gets the primal ray if available; returns true on success
bool getRedCostViolation(R &maxviol, R &sumviol)
gets violation of reduced costs; returns true on success
void validateSolveReal(SoPlexBase< R > &soplex)
validates the soplex solution using the external solution
virtual const std::string what() const
returns exception message
bool parseSettingsString(char *str)
parses one setting string and returns true on success; note that string is modified ...
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.
apply standard floating-point algorithm
int main(int argc, char *argv[])
runs SoPlexBase command line
bool getDualViolationRational(Rational &maxviol, Rational &sumviol)
bool getRedCostRational(VectorRational &vector)
int runSoPlex(int argc, char *argv[])
static void printUsage(const char *const argv[], int idx)
int intParam(const IntParam param) const
returns integer parameter value
bool getDualFarkas(VectorBase< R > &vector)
gets the Farkas proof if available; returns true on success
#define MSG_ERROR(x)
Prints out message x if the verbosity level is at least SPxOut::ERROR.
Real realParam(const RealParam param) const
returns real parameter value
iteration limit (-1 if unlimited)
bool getBoundViolation(R &maxviol, R &sumviol)
gets violation of bounds; returns true on success
primal feasibility tolerance
bool hasDual() const
deprecated: use hasSol() instead
int spxSnprintf(char *t, size_t len, const char *s,...)
safe version of snprintf
bool saveSettingsFile(const char *filename, const bool onlyChanged=false, int solvemode=1) const
writes settings file; returns true on success
bool getPrimal(VectorBase< R > &vector)
gets the primal solution vector if available; returns true on success
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...
bool hasPrimal() const
deprecated: use hasSol() instead
bool getDualFarkasRational(VectorRational &vector)
int numCols() const
Templated function that returns number of columns.
static void checkSolutionRational(SoPlexBase< R > &soplex)
performs external feasibility check with rational type
virtual Real time() const =0
bool getRedCostViolationRational(Rational &maxviol, Rational &sumviol)
static Timer * createTimer(Timer::TYPE ttype)
create timers and allocate memory for them
bool setRealParam(const RealParam param, const Real value, const bool init=true)
sets real parameter value; returns true on success
Preconfigured SoPlex LP solver.
Set of strings.Class NameSet implements a symbol or name table. It allows to store or remove names (i...
bool getDualViolation(R &maxviol, R &sumviol)
gets violation of dual multipliers; returns true on success
void checkSolution(SoPlexBase< R > &soplex)
performs external feasibility check according to check mode
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.
static void printPrimalSolution(SoPlexBase< R > &soplex, NameSet &colnames, NameSet &rownames, bool real=true, bool rational=false)
mode for iterative refinement strategy
bool getRowViolation(R &maxviol, R &sumviol)
gets violation of constraints; returns true on success
int numRows() const
returns number of rows
time limit in seconds (INFTY if unlimited)
user sync of real and rational LP
#define MSG_WARNING(spxout, x)
Prints out message x if the verbosity level is at least SPxOut::WARNING.
mode for reading LP files
std::streamsize precision() const
static void printDualSolution(SoPlexBase< R > &soplex, NameSet &colnames, NameSet &rownames, bool real=true, bool rational=false)
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
~Validation()
default destructor
void printVersion() const
prints version and compilation options
bool updateExternalSolution(const std::string &solution)
updates the external solution used for validation
bool getPrimalRayRational(VectorRational &vector)
standard floating-point parsing
#define MSG_INFO1(spxout, x)
Prints out message x if the verbosity level is at least SPxOut::INFO1.
int numColsRational() const
bool isPrimalFeasible() const
is stored primal solution feasible?
Validation object for soplex solutions.
static void freeStrings(char *&s1, char *&s2, char *&s3, char *&s4, char *&s5)
bool setIntParam(const IntParam param, const int value, const bool init=true)
sets integer parameter value; returns true on success
mode for synchronizing real and rational LP
Wrapper for the system time query methods.
void spx_free(T &p)
Release memory.
bool loadSettingsFile(const char *filename)
reads settings file; returns true on success
bool getRedCost(VectorBase< R > &vector)
gets the vector of reduced cost values if available; returns true on success
void printUserSettings()
print non-default parameter values