29 #include <boost/program_options.hpp> 31 #include <boost/exception/diagnostic_information.hpp> 32 #include <boost/exception/exception.hpp> 37 #include "soplex/args.hpp" 40 #ifdef SOPLEX_WITH_EGLIB 42 #include "soplex/EGlib.h" 45 #define EGlpNumStart() {} 46 #define EGlpNumClear() {} 52 int main(
int argc,
char* argv[]);
70 R maxviol = boundviol > rowviol ? boundviol : rowviol;
72 soplex.
spxout <<
"Primal solution " << (feasible ?
"feasible" :
"infeasible")
73 <<
" in original problem (max. violation = " << std::scientific << maxviol
74 << std::setprecision(8) << std::fixed <<
").\n");
95 R maxviol = redcostviol > dualviol ? redcostviol : dualviol;
97 soplex.
spxout <<
"Dual solution " << (feasible ?
"feasible" :
"infeasible")
98 <<
" in original problem (max. violation = " << std::scientific << maxviol
99 << std::setprecision(8) << std::fixed <<
").\n" 128 Rational maxviol = boundviol > rowviol ? boundviol : rowviol;
130 soplex.
spxout <<
"Primal solution " << (feasible ?
"feasible" :
"infeasible") <<
131 " in original problem (max. violation = " <<
rationalToString(maxviol) <<
").\n" 154 Rational maxviol = redcostviol > dualviol ? redcostviol : dualviol;
156 soplex.
spxout <<
"Dual solution " << (feasible ?
"feasible" :
"infeasible") <<
157 " in original problem (max. violation = " <<
rationalToString(maxviol) <<
").\n" 192 bool real =
true,
bool rational =
false)
197 printwidth = printprec + 10;
207 for(
int i = 0; i < soplex.
numCols(); ++i)
209 if(isNotZero(primal[i]))
212 << std::setw(printwidth) << std::setprecision(printprec)
213 << primal[i] << std::endl;)
219 << std::setprecision(8) << std::fixed
220 <<
")." << std::endl;)
227 for(
int i = 0; i < soplex.
numCols(); ++i)
229 if(isNotZero(primal[i]))
232 << std::setw(printwidth) << std::setprecision(printprec)
233 << primal[i] << std::endl;)
240 << std::setprecision(8) << std::fixed
241 <<
"). Solution has " << nNonzeros <<
" nonzero entries." << std::endl;)
255 for(
int i = 0; i < soplex.
numCols(); ++i)
260 << std::setw(printwidth) << std::setprecision(printprec)
261 << primal[i] << std::endl;)
283 << nNonzeros <<
" nonzero entries." << std::endl;)
294 bool real =
true,
bool rational =
false)
299 printwidth = printprec + 10;
309 for(
int i = 0; i < soplex.
numRows(); ++i)
311 if(isNotZero(dual[i]))
314 << std::setw(printwidth) << std::setprecision(printprec)
315 << dual[i] << std::endl;)
321 << std::setprecision(8) << std::fixed <<
")." << std::endl;)
327 for(
int i = 0; i < soplex.
numRows(); ++i)
329 if(isNotZero(dual[i]))
332 << std::setw(printwidth) << std::setprecision(printprec)
333 << dual[i] << std::endl;)
339 << std::setprecision(8) << std::fixed <<
")." << std::endl;)
347 for(
int i = 0; i < soplex.
numCols(); ++i)
349 if(isNotZero(redcost[i]))
352 << std::setw(printwidth) << std::setprecision(printprec)
353 << redcost[i] << std::endl;)
359 << std::setprecision(8) << std::fixed <<
")." << std::endl;)
374 for(
int i = 0; i < soplex.
numRows(); ++i)
379 << std::setw(printwidth)
380 << std::setprecision(printprec)
381 << dual[i] << std::endl;)
406 for(
int i = 0; i < soplex.
numCols(); ++i)
422 int main(
int argc,
char* argv[])
428 auto retVal = parseArgsAndRun(argc, argv);
441 int soplex::runSoPlex(
const po::variables_map& vm)
447 std::string lpfilename, readbasname, writebasname, writefilename, writedualfilename, loadsetname,
448 savesetname, diffsetname;
451 bool printPrimal =
false;
452 bool printPrimalRational =
false;
453 bool printDual =
false;
454 bool printDualRational =
false;
455 bool displayStatistics =
false;
456 bool checkSol =
false;
461 auto readIntoString = [&vm](std::string & var,
const std::string str)
465 var = vm[str].as<std::string>();
469 readIntoString(lpfilename,
"lpfile");
470 readIntoString(readbasname,
"readbas");
471 readIntoString(writebasname,
"writebas");
472 readIntoString(writefilename,
"writefile");
473 readIntoString(writedualfilename,
"writedual");
474 readIntoString(loadsetname,
"loadset");
475 readIntoString(savesetname,
"saveset");
476 readIntoString(diffsetname,
"diffset");
497 if(vm.count(
"readmode"))
503 if(vm.count(
"solvemode"))
505 auto solvemode = vm[
"solvemode"].as<
int>();
515 else if(solvemode == 4)
537 if(vm.count(
"extsol"))
539 auto input = vm[
"extsol"].as<std::string>();
553 if(vm.count(
"iterlimit"))
559 if(vm.count(
"primfeastol"))
565 if(vm.count(
"dualfeastol"))
571 if(vm.count(
"valtol"))
573 auto str = vm[
"valtol"].as<std::string>();
578 if(vm.count(
"simplifier"))
584 if(vm.count(
"scaler"))
590 if(vm.count(
"pricer"))
596 if(vm.count(
"ratiotester"))
602 if(vm.count(
"verbosity"))
608 if(vm.count(
"printprimal"))
614 if(vm.count(
"printprimratsol"))
616 printPrimalRational =
true;
620 if(vm.count(
"printdualmult"))
626 if(vm.count(
"printdualmultrational"))
628 printDualRational =
true;
632 if(vm.count(
"dispstat"))
634 displayStatistics =
true;
638 if(vm.count(
"checkfinal"))
643 if(vm.count(
"loadset"))
649 vm[
"loadset"].as<std::string>() <<
"> . . .\n");
669 for(
int i = 0; i < SoPlexBase<R>::INTPARAM_COUNT; ++i)
675 soplex.parseSettingsString(str, vm[str].value());
679 for(
int i = 0; i < SoPlexBase<R>::REALPARAM_COUNT; ++i)
685 soplex.parseSettingsString(str, vm[str].value());
689 for(
int i = 0; i < SoPlexBase<R>::BOOLPARAM_COUNT; ++i)
695 soplex.parseSettingsString(str, vm[str].value());
706 if(vm.count(
"uint:random_seed"))
708 soplex.
setRandomSeed(vm[
"uint:random_seed"].as<unsigned int>());
715 if(lpfilename.empty() && savesetname.empty() && diffsetname.empty())
717 BOOST_THROW_EXCEPTION(
718 std::invalid_argument(
"Empty lpfilename, save setings name and diff settings name"));
724 BOOST_THROW_EXCEPTION(
725 std::invalid_argument(
"Error: manual synchronization is invalid on command line. Change parameter int:syncmode"));
729 if(!savesetname.empty())
734 if(!soplex.
saveSettingsFile(savesetname.c_str(),
false, vm[
"solvemode"].as<
int>()))
736 MSG_ERROR(std::cerr <<
"Error writing parameters to file <" << savesetname <<
">\n");
740 if(!diffsetname.empty())
743 diffsetname <<
"> . . .\n");
747 MSG_ERROR(std::cerr <<
"Error writing modified parameters to file <" << diffsetname <<
">\n");
752 if(lpfilename.empty())
755 if(loadsetname.empty() && savesetname.empty() && diffsetname.empty())
758 BOOST_THROW_EXCEPTION(
759 std::invalid_argument(
"No lpfile, settings file, save settings file or diff settings file"));
766 readingTime->start();
779 <<
" LP file <" << lpfilename <<
"> . . .\n");
781 if(!soplex.
readFile(lpfilename.c_str(), &rownames, &colnames))
783 BOOST_THROW_EXCEPTION(std::runtime_error(
"Error while reading lpfile: " + lpfilename));
787 if(!writefilename.empty())
789 if(!soplex.
writeFile(writefilename.c_str(), &rownames, &colnames))
791 BOOST_THROW_EXCEPTION(std::runtime_error(
"Error in writing to file: " + writefilename));
800 if(!writedualfilename.empty())
804 BOOST_THROW_EXCEPTION(std::runtime_error(
"Error while writing dual file: " + writedualfilename));
814 if(!readbasname.empty())
818 if(!soplex.
readBasisFile(readbasname.c_str(), &rownames, &colnames))
820 BOOST_THROW_EXCEPTION(std::runtime_error(
"Error while reading file: " + readbasname));
828 soplex.
spxout <<
"Reading took " 829 << std::fixed << std::setprecision(2) << readingTime->time()
830 << std::scientific << std::setprecision(
int(prec))
844 checkSolution<R>(soplex);
846 if(displayStatistics)
856 if(!writebasname.empty())
861 "No basis information available. Could not write file <" << writebasname <<
">\n\n");
863 else if(!soplex.
writeBasisFile(writebasname.c_str(), &rownames, &colnames))
865 BOOST_THROW_EXCEPTION(std::runtime_error(
"Error while writing file: " + writebasname));
876 MSG_ERROR(std::cerr <<
"Exception caught: " << x.
what() <<
"\n");
881 std::cout <<
"Generic exception: " << boost::current_exception_diagnostic_information() <<
"\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...
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
SPxSolverBase< R >::Status optimize()
optimize the given LP
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 getRowViolationRational(Rational &maxviol, Rational &sumviol)
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
std::ostream & getStream(const Verbosity &verbosity) const
Returns the stream for the specified verbosity level.
bool getPrimalRay(VectorBase< R > &vector)
gets the primal ray if available; returns true on success
bool hasBasis() const
is an advanced starting basis available?
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
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 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
Class for collecting statistical information.
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.
void setRandomSeed(unsigned int seed)
set the random seeds of the solver instance
static void checkSolutionRational(SoPlexBase< R > &soplex)
performs external feasibility check with rational type
void printStatistics(std::ostream &os)
prints complete statistics
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
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.
std::string rationalToString(const Rational &r, const int precision)
convert rational number to string
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 getRedCost(VectorBase< R > &vector)
gets the vector of reduced cost values if available; returns true on success
Settings * _currentSettings
void printUserSettings()
print non-default parameter values