32 #ifdef SOPLEX_WITH_EGLIB
37 #define EGlpNumStart() {}
38 #define EGlpNumClear() {}
41 using namespace soplex;
49 " --readbas=<basfile> read starting basis from file\n"
50 " --writebas=<basfile> write terminal basis to file\n"
51 " --writefile=<lpfile> write LP to file in LP or MPS format depending on extension\n"
52 " --<type>:<name>=<val> change parameter value using syntax of settings file entries\n"
53 " --loadset=<setfile> load parameters from settings file (overruled by command line parameters)\n"
54 " --saveset=<setfile> save parameters to settings file\n"
55 " --diffset=<setfile> save modified parameters to settings file\n"
57 "limits and tolerances:\n"
58 " -t<s> set time limit to <s> seconds\n"
59 " -i<n> set iteration limit to <n>\n"
60 " -f<eps> set primal feasibility tolerance to <eps>\n"
61 " -o<eps> set dual feasibility (optimality) tolerance to <eps>\n"
63 "algorithmic settings (* indicates default):\n"
64 " --readmode=<value> choose reading mode for <lpfile> (0* - floating-point, 1 - rational)\n"
65 " --solvemode=<value> choose solving mode (0 - floating-point solve, 1* - auto, 2 - force iterative refinement)\n"
66 " -s<value> choose simplifier/presolver (0 - off, 1* - auto)\n"
67 " -g<value> choose scaling (0 - off, 1 - uni-equilibrium, 2* - bi-equilibrium, 3 - geometric, 4 - iterated geometric)\n"
68 " -p<value> choose pricing (0* - auto, 1 - dantzig, 2 - parmult, 3 - devex, 4 - quicksteep, 5 - steep)\n"
69 " -r<value> choose ratio tester (0 - textbook, 1 - harris, 2 - fast, 3* - boundflipping)\n"
72 " -v<level> set verbosity to <level> (0 - error, 3 - normal, 5 - high)\n"
73 " -x print primal solution\n"
74 " -y print dual multipliers\n"
75 " -q display detailed statistics\n"
76 " -c perform final check of optimal solution in original problem\n"
80 std::cerr <<
"missing input file\n\n";
82 std::cerr <<
"invalid option \"" << argv[idx] <<
"\"\n\n";
84 std::cerr <<
"usage: " << argv[0] <<
" " <<
"[options] <lpfile>\n"
85 #ifdef SOPLEX_WITH_ZLIB
86 <<
" <lpfile> linear program as .mps[.gz] or .lp[.gz] file\n\n"
88 <<
" <lpfile> linear program as .mps or .lp file\n\n"
95 void freeStrings(
char*& s1,
char*& s2,
char*& s3,
char*& s4,
char*& s5)
138 Real maxviol = boundviol > rowviol ? boundviol : rowviol;
140 soplex.
spxout <<
"Primal solution " << (feasible ?
"feasible" :
"infeasible") <<
" in original problem (max. violation = " << maxviol <<
").\n"
162 Real maxviol = redcostviol > dualviol ? redcostviol : dualviol;
164 soplex.
spxout <<
"Dual solution " << (feasible ?
"feasible" :
"infeasible") <<
" in original problem (max. violation = " << maxviol <<
").\n"
192 Rational maxviol = boundviol > rowviol ? boundviol : rowviol;
194 soplex.
spxout <<
"Primal solution " << (feasible ?
"feasible" :
"infeasible") <<
" in original problem (max. violation = " <<
rationalToString(maxviol) <<
").\n"
216 Rational maxviol = redcostviol > dualviol ? redcostviol : dualviol;
218 soplex.
spxout <<
"Dual solution " << (feasible ?
"feasible" :
"infeasible") <<
" in original problem (max. violation = " <<
rationalToString(maxviol) <<
").\n"
251 int main(
int argc,
char* argv[])
263 const char* lpfilename;
264 char* readbasname = 0;
265 char* writebasname = 0;
266 char* writefilename = 0;
267 char* loadsetname = 0;
268 char* savesetname = 0;
269 char* diffsetname = 0;
270 bool printPrimal =
false;
271 bool printDual =
false;
272 bool displayStatistics =
false;
273 bool checkSol =
false;
284 MSG_INFO1( soplex->
spxout, soplex->
spxout <<
"Copyright (c) 1996-2015 Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB)\n\n" );
297 for( optidx = 1; optidx < argc; optidx++ )
299 char* option = argv[optidx];
302 if( option[0] !=
'-' )
307 if( option[0] !=
'-' || option[1] ==
'\0'
308 || ((option[2] ==
'\0') != (option[1] ==
'x' || option[1] ==
'y' || option[1] ==
'q' || option[1] ==
'c')) )
312 goto TERMINATE_FREESTRINGS;
322 if( strncmp(option,
"readbas=", 8) == 0 )
324 if( readbasname == 0 )
326 char* filename = &option[8];
327 readbasname = strncpy(
new char[strlen(filename) + 1], filename, strlen(filename) + 1);
331 else if( strncmp(option,
"writebas=", 9) == 0 )
333 if( writebasname == 0 )
335 char* filename = &option[9];
336 writebasname = strncpy(
new char[strlen(filename) + 1], filename, strlen(filename) + 1);
340 else if( strncmp(option,
"writefile=", 10) == 0 )
342 if( writefilename == 0 )
344 char* filename = &option[10];
345 writefilename = strncpy(
new char[strlen(filename) + 1], filename, strlen(filename) + 1);
349 else if( strncmp(option,
"loadset=", 8) == 0 )
351 if( loadsetname == 0 )
353 char* filename = &option[8];
354 loadsetname = strncpy(
new char[strlen(filename) + 1], filename, strlen(filename) + 1);
359 goto TERMINATE_FREESTRINGS;
369 else if( strncmp(option,
"saveset=", 8) == 0 )
371 if( savesetname == 0 )
373 char* filename = &option[8];
374 savesetname = strncpy(
new char[strlen(filename) + 1], filename, strlen(filename) + 1);
378 else if( strncmp(option,
"diffset=", 8) == 0 )
380 if( diffsetname == 0 )
382 char* filename = &option[8];
383 diffsetname = strncpy(
new char[strlen(filename) + 1], filename, strlen(filename) + 1);
387 else if( strncmp(option,
"readmode=", 9) == 0 )
393 goto TERMINATE_FREESTRINGS;
397 else if( strncmp(option,
"solvemode=", 10) == 0 )
403 goto TERMINATE_FREESTRINGS;
418 goto TERMINATE_FREESTRINGS;
429 goto TERMINATE_FREESTRINGS;
439 goto TERMINATE_FREESTRINGS;
449 goto TERMINATE_FREESTRINGS;
459 goto TERMINATE_FREESTRINGS;
469 goto TERMINATE_FREESTRINGS;
479 goto TERMINATE_FREESTRINGS;
489 goto TERMINATE_FREESTRINGS;
499 goto TERMINATE_FREESTRINGS;
509 goto TERMINATE_FREESTRINGS;
525 displayStatistics =
true;
538 goto TERMINATE_FREESTRINGS;
546 if( optidx >= argc && savesetname == 0 && diffsetname == 0 )
550 goto TERMINATE_FREESTRINGS;
556 MSG_ERROR( std::cerr <<
"Error: manual synchronization is invalid on command line. Change parameter int:syncmode.\n" );
558 goto TERMINATE_FREESTRINGS;
562 if( savesetname != 0 )
564 MSG_INFO1( soplex->
spxout, soplex->
spxout <<
"Saving parameters to settings file <" << savesetname <<
"> . . .\n" );
567 MSG_ERROR( std::cerr <<
"Error writing parameters to file <" << savesetname <<
">\n" );
570 if( diffsetname != 0 )
572 MSG_INFO1( soplex->
spxout, soplex->
spxout <<
"Saving modified parameters to settings file <" << diffsetname <<
"> . . .\n" );
575 MSG_ERROR( std::cerr <<
"Error writing modified parameters to file <" << diffsetname <<
">\n" );
582 if( loadsetname != 0 || savesetname != 0 || diffsetname != 0 )
586 goto TERMINATE_FREESTRINGS;
590 readingTime->
start();
601 lpfilename = argv[optidx];
604 <<
" LP file <" << lpfilename <<
"> . . .\n" );
606 if( !soplex->
readFile(lpfilename, &rownames, &colnames) )
608 MSG_ERROR( std::cerr <<
"Error while reading file <" << lpfilename <<
">.\n" );
610 goto TERMINATE_FREESTRINGS;
614 if( writefilename != 0 )
616 if( !soplex->
writeFileReal(writefilename, &rownames, &colnames) )
618 MSG_ERROR( std::cerr <<
"Error while writing file <" << writefilename <<
">.\n\n" );
620 goto TERMINATE_FREESTRINGS;
629 if( readbasname != 0 )
632 if( !soplex->
readBasisFile(readbasname, &rownames, &colnames) )
634 MSG_ERROR( std::cerr <<
"Error while reading file <" << readbasname <<
">.\n" );
636 goto TERMINATE_FREESTRINGS;
644 soplex->
spxout <<
"Reading took "
645 << std::fixed << std::setprecision(2) << readingTime->
time()
646 << std::scientific << std::setprecision(
int(prec))
647 <<
" seconds.\n\n" );
667 << std::setprecision(9)
668 << primal[i] << std::endl; )
672 << std::setprecision(8) << std::fixed <<
")." << std::endl; )
689 << std::setprecision(9)
690 << dual[i] << std::endl; )
694 << std::setprecision(8) << std::fixed <<
")." << std::endl; )
703 if( displayStatistics )
710 if( writebasname != 0 )
714 MSG_WARNING( soplex->
spxout, soplex->
spxout <<
"No basis information available. Could not write file <" << writebasname <<
">\n\n" );
716 else if( !soplex->
writeBasisFile(writebasname, &rownames, &colnames) )
718 MSG_ERROR( std::cerr <<
"Error while writing file <" << writebasname <<
">.\n\n" );
720 goto TERMINATE_FREESTRINGS;
724 MSG_INFO1( soplex->
spxout, soplex->
spxout <<
"Written basis information to file <" << writebasname <<
">.\n\n" );
730 MSG_ERROR( std::cerr <<
"Exception caught: " << x.
what() <<
"\n" );
732 goto TERMINATE_FREESTRINGS;
735 TERMINATE_FREESTRINGS:
736 freeStrings(readbasname, writebasname, loadsetname, savesetname, diffsetname);
789 using namespace soplex;
794 static bool checkMode =
false;
803 class MySoPlex :
public SoPlex
807 MySoPlex(
SPxOut& outstream,
810 :
SoPlex(outstream, p_type, p_rep)
817 void displayQuality()
const
824 MSG_INFO1( (*spxout), (*spxout) <<
"IEXAMP05 Violations (max/sum)" << std::endl; )
826 m_solver.qualConstraintViolation(maxviol, sumviol);
828 MSG_INFO1( (*spxout), (*spxout) <<
"IEXAMP06 Constraints :"
829 << std::setw(16) << maxviol <<
" "
830 << std::setw(16) << sumviol << std::endl; )
832 qualConstraintViolation(maxviol, sumviol);
834 MSG_INFO1( (*spxout), (*spxout) <<
"IEXAMP07 (unscaled) :"
835 << std::setw(16) << maxviol <<
" "
836 << std::setw(16) << sumviol << std::endl; )
838 m_solver.qualBoundViolation(maxviol, sumviol);
840 MSG_INFO1( (*spxout), (*spxout) <<
"IEXAMP08 Bounds :"
841 << std::setw(16) << maxviol <<
" "
842 << std::setw(16) << sumviol << std::endl; )
844 qualBoundViolation(maxviol, sumviol);
846 MSG_INFO1( (*spxout), (*spxout) <<
"IEXAMP09 (unscaled) :"
847 << std::setw(16) << maxviol <<
" "
848 << std::setw(16) << sumviol << std::endl; )
852 m_solver.qualSlackViolation(maxviol, sumviol);
854 MSG_INFO1( (*spxout), (*spxout) <<
"IEXAMP10 Slacks :"
855 << std::setw(16) << maxviol <<
" "
856 << std::setw(16) << sumviol << std::endl; )
858 m_solver.qualRedCostViolation(maxviol, sumviol);
860 MSG_INFO1( (*spxout), (*spxout) <<
"IEXAMP11 Reduced costs :"
861 << std::setw(16) << maxviol <<
" "
862 << std::setw(16) << sumviol << std::endl; )
864 MSG_INFO1( (*spxout), (*spxout) <<
"IEXAMP12 Proven dual bound:"
866 << std::setprecision(20)
867 << m_solver.provedDualbound() << std::endl; )
873 MSG_INFO1( (*spxout), (*spxout) <<
"Violations (max/sum)" << std::endl; )
875 m_solver.qualConstraintViolation(maxviol, sumviol);
877 MSG_INFO1( (*spxout), (*spxout) <<
"Constraints :"
878 << std::setw(16) << maxviol <<
" "
879 << std::setw(16) << sumviol << std::endl; )
881 qualConstraintViolation(maxviol, sumviol);
883 MSG_INFO1( (*spxout), (*spxout) <<
" (unscaled) :"
884 << std::setw(16) << maxviol <<
" "
885 << std::setw(16) << sumviol << std::endl; )
887 m_solver.qualBoundViolation(maxviol, sumviol);
889 MSG_INFO1( (*spxout), (*spxout) <<
"Bounds :"
890 << std::setw(16) << maxviol <<
" "
891 << std::setw(16) << sumviol << std::endl; )
893 qualBoundViolation(maxviol, sumviol);
895 MSG_INFO1( (*spxout), (*spxout) <<
" (unscaled) :"
896 << std::setw(16) << maxviol <<
" "
897 << std::setw(16) << sumviol << std::endl; )
901 m_solver.qualSlackViolation(maxviol, sumviol);
903 MSG_INFO1( (*spxout), (*spxout) <<
"Slacks :"
904 << std::setw(16) << maxviol <<
" "
905 << std::setw(16) << sumviol << std::endl; )
907 m_solver.qualRedCostViolation(maxviol, sumviol);
909 MSG_INFO1( (*spxout), (*spxout) <<
"Reduced costs :"
910 << std::setw(16) << maxviol <<
" "
911 << std::setw(16) << sumviol << std::endl; )
913 MSG_INFO1( (*spxout), (*spxout) <<
"Proven dual bound:"
915 << std::setprecision(20)
916 << m_solver.provedDualbound() << std::endl; )
922 void displayInfeasibility()
const
929 if( m_solver.isProvenInfeasible() )
930 MSG_INFO1( (*spxout), (*spxout) <<
"IEXAMP13 Infeasibility is proven." << std::endl; )
932 MSG_INFO1( (*spxout), (*spxout) <<
"IEXAMP13 Infeasibility could not be proven!" << std::endl; )
936 if ( m_solver.isProvenInfeasible() )
938 MSG_INFO1( (*spxout), (*spxout) <<
"Infeasibility is proven." << std::endl; )
942 MSG_INFO1( (*spxout), (*spxout) <<
"Infeasibility could not be proven!" << std::endl; )
955 void print_version_info()
957 const char* banner1 =
958 "************************************************************************\n"
960 "* SoPlex --- the Sequential object-oriented simPlex. *\n"
963 const char* banner2 =
965 "* Copyright (C) 1996-2015 Konrad-Zuse-Zentrum *\n"
966 "* fuer Informationstechnik Berlin *\n"
968 "* SoPlex is distributed under the terms of the ZIB Academic Licence. *\n"
969 "* You should have received a copy of the ZIB Academic License *\n"
970 "* along with SoPlex; If not email to soplex@zib.de. *\n"
972 "************************************************************************\n"
976 std::cout << banner1;
978 #if (SOPLEX_SUBVERSION > 0)
980 std::cout <<
"* Version ";
982 std::cout <<
"SoPlex version ";
988 << std::setw(13) << std::setiosflags(std::ios::left) <<
getGitHash();
990 std::cout <<
" *\n" << banner2 << std::endl;
995 std::cout <<
"* Release ";
997 std::cout <<
"SoPlex release ";
1002 << std::setw(13) << std::setiosflags(std::ios::left) <<
getGitHash();
1004 std::cout <<
" *\n" << banner2 << std::endl;
1010 std::cout <<
"[NDEBUG:"
1018 std::cout <<
"[WITH_WARNINGS:"
1019 #ifdef WITH_WARNINGS
1026 std::cout <<
"[ENABLE_ADDITIONAL_CHECKS:"
1027 #ifdef ENABLE_ADDITIONAL_CHECKS
1034 std::cout <<
"[ENABLE_CONSISTENCY_CHECKS:"
1035 #ifdef ENABLE_CONSISTENCY_CHECKS
1042 std::cout <<
"[SOPLEX_WITH_GMP:"
1043 #ifdef SOPLEX_WITH_GMP
1048 <<
"]" << std::endl;
1050 std::cout << std::endl;
1055 void print_short_version_info()
1057 const char* banner1 =
1058 "************************************************************************\n"
1059 "* SoPlex --- the Sequential object-oriented simPlex. ";
1060 const char* banner2 =
1061 "* Copyright (C) 1996-2015 Konrad-Zuse-Zentrum *\n"
1062 "* fuer Informationstechnik Berlin *\n"
1063 "************************************************************************\n";
1065 std::cout << banner1;
1066 #if (SOPLEX_SUBVERSION > 0)
1067 std::cout <<
"Version "
1074 std::cout <<
"Release "
1080 std::cout << banner2 << std::endl;
1086 void print_usage_and_exit(
const char*
const argv[] )
1089 "[options] LPfile [Basfile]\n\n"
1090 " LPfile can be either in MPS or LPF format\n\n"
1091 "options: (*) indicates default\n"
1092 " (!) indicates experimental features which may give wrong results\n"
1093 " -e select entering algorithm (default is leaving)\n"
1094 " -r select row wise representation (default is column)\n"
1095 " -i select Eta-update (default is Forest-Tomlin)\n"
1096 " -x output solution vector\n"
1097 " -y output dual multipliers\n"
1098 " -q display solution quality\n"
1099 " -br read file with starting basis from Basfile\n"
1100 " -bw write file with optimal basis to Basfile\n"
1101 " -l set time limit in seconds\n"
1102 " -L set iteration limit\n"
1103 " -f set primal feasibility tolerance\n"
1104 " -o set optimality, i.e., dual feasibility tolerance\n"
1105 " -d set primal and dual feasibility tolerance to same value\n"
1106 " -zz set general zero tolerance\n"
1107 " -zf set factorization zero tolerance\n"
1108 " -zu set update zero tolerance\n"
1109 " -v set verbosity Level: from 0 (ERROR) to 5 (INFO3), default 3 (INFO1)\n"
1110 " -V show program version\n"
1111 " -C check mode (for check scripts)\n"
1112 " -h show this help\n\n"
1113 "Simplifier: Scaler: Starter: Pricer: Ratiotester:\n"
1114 " -s0 none -g0 none -c0 none* -p0 Textbook -t0 Textbook\n"
1115 " -s1 Main* -g1 uni-Equi -c1 Weight -p1 ParMult -t1 Harris\n"
1116 " -g2 bi-Equi* -c2 Sum -p2 Devex -t2 Fast\n"
1117 " -g3 bi-Equi+Geo1 -c3 Vector -p3 Hybrid! -t3 Bound Flipping*\n"
1118 " -g4 bi-Equi+Geo8 -p4 Steep*\n"
1120 " -p6 SteepExactSetup\n"
1123 std::cerr <<
"usage: " << argv[0] <<
" " << usage << std::endl;
1129 void check_parameter(
const char param,
const char*
const argv[])
1132 print_usage_and_exit( argv );
1137 void print_algorithm_parameters(
1145 MSG_INFO1( (*work.spxout), (*work.spxout)
1146 <<
"IEXAMP12 Feastol = "
1147 << std::setw(16) << work.feastol() << std::endl
1148 <<
"IEXAMP52 Opttol = "
1149 << std::setw(16) << work.opttol() << std::endl
1150 <<
"IEXAMP13 Epsilon Zero = "
1152 <<
"IEXAMP37 Epsilon Factor = "
1154 <<
"IEXAMP38 Epsilon Update = "
1158 <<
" algorithm" << std::endl
1161 <<
" representation" << std::endl
1164 <<
" update" << std::endl; )
1168 MSG_INFO1( (*work.spxout), (*work.spxout)
1169 <<
"SoPlex parameters: " << std::endl
1171 << std::setw(16) << work.feastol() << std::endl
1173 << std::setw(16) << work.opttol() << std::endl
1174 <<
"Epsilon Zero = "
1176 <<
"Epsilon Factor = "
1178 <<
"Epsilon Update = "
1181 <<
"algorithm = " << (work.type() ==
SPxSolver::ENTER ?
"Entering" :
"Leaving")
1183 <<
"representation = " << (representation ==
SPxSolver::ROW ?
"Row" :
"Column")
1185 <<
"update = " << (update ==
SLUFactor::ETA ?
"Eta" :
"Forest-Tomlin")
1222 assert(pricer != 0);
1224 #ifdef PARTIAL_PRICING
1225 MSG_INFO1( (*spxout), (*spxout) <<
"IEXAMP17 " << pricer->
getName() <<
" pricing"
1226 <<
" (partial, size = " << MAX_PRICING_CANDIDATES <<
")"
1229 MSG_INFO1( (*spxout), (*spxout) <<
"IEXAMP17 " << pricer->
getName() <<
" pricing"
1233 #ifdef PARTIAL_PRICING
1235 <<
" (partial, size = " << MAX_PRICING_CANDIDATES <<
")"
1267 assert(ratiotester != 0);
1269 MSG_INFO1( (*spxout), (*spxout) <<
"IEXAMP18 " << ratiotester->
getName() <<
" ratiotest" << std::endl; )
1271 MSG_INFO1( (*spxout), (*spxout) <<
"ratiotest = " << ratiotester->
getName() << std::endl; )
1312 MSG_INFO1( (*spxout), (*spxout) <<
"IEXAMP19 "
1313 << ((prescaler != 0) ? prescaler->
getName() :
"no")
1315 << ((postscaler != 0) ? postscaler->
getName() :
"no")
1316 <<
" scaling" << std::endl; )
1320 MSG_INFO1( (*spxout), (*spxout) <<
"scaling = "
1321 << ((prescaler != 0) ? prescaler->
getName() :
"no")
1323 << ((postscaler != 0) ? postscaler->
getName() :
"no")
1341 assert(simplifier == 0);
1346 MSG_INFO1( (*spxout), (*spxout) <<
"IEXAMP20 " << ((simplifier == 0) ?
"no" : simplifier->
getName()) <<
" simplifier" << std::endl; )
1348 MSG_INFO1( (*spxout), (*spxout) <<
"simplifier = " << ((simplifier == 0) ?
"no" : simplifier->getName()) << std::endl; )
1375 MSG_INFO1( (*spxout), (*spxout) <<
"IEXAMP21 " << ((starter == 0) ?
"no" : starter->
getName()) <<
" starter" << std::endl; )
1377 MSG_INFO1( (*spxout), (*spxout) <<
"starter = " << ((starter == 0) ?
"no" : starter->getName()) << std::endl; )
1383 #ifdef SEND_ALL_OUTPUT_TO_FILES
1385 void redirect_output(
1386 std::ostream& myerrstream,
1387 std::ostream& myinfostream
1390 myerrstream .setf( std::ios::scientific | std::ios::showpoint );
1391 myinfostream.setf( std::ios::scientific | std::ios::showpoint );
1402 void read_input_file(
1404 const char* filename,
1409 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"IEXAMP22 loading LP file " << filename << std::endl; )
1411 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"\nLoading LP file " << filename << std::endl; )
1416 if ( ! work.readFile(filename, &rownames, &colnames, 0) )
1419 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"EEXAMP23 error while reading file \"" << filename <<
"\"" << std::endl; )
1421 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"error while reading file \"" << filename <<
"\"" << std::endl; )
1424 assert(work.isConsistent());
1430 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"IEXAMP24 LP has "
1431 << work.nRows() <<
" rows "
1432 << work.nCols() <<
" columns "
1433 << work.nNzos() <<
" nonzeros"
1436 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"IEXAMP41 LP reading time: " << timer.
time() << std::endl; )
1440 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"LP has "
1441 << work.nRows() <<
" rows "
1442 << work.nCols() <<
" columns "
1443 << work.nNzos() <<
" nonzeros"
1447 std::streamsize prec = (*work.spxout).precision();
1448 (*work.spxout) <<
"LP reading time: " << std::fixed << std::setprecision(2) << timer.
time();
1449 (*work.spxout) << std::scientific << std::setprecision(
int(prec)) << std::endl; )
1455 void read_basis_file(
1457 const char* filename,
1461 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"Reading basis from file (disables simplifier)" << std::endl; )
1462 if (!work.readBasisFile(filename, rownames, colnames))
1465 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"EEXAMP25 error while reading file \"" << filename <<
"\"" << std::endl; )
1467 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"Error while reading file \"" << filename <<
"\"" << std::endl; )
1474 void solve_LP(MySoPlex& work)
1480 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"IEXAMP26 solving LP" << std::endl; )
1482 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"\nSolving LP ..." << std::endl; )
1487 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"\nSoPlex statistics:\n" << work.statistics(); )
1492 void print_solution_and_status(
1496 const int precision,
1497 const bool print_quality,
1498 const bool print_solution,
1499 const bool print_dual,
1500 const bool write_basis,
1501 const char* basisname
1508 MSG_INFO1( (*work.spxout), (*work.spxout) << std::endl; )
1513 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"IEXAMP29 solution value is: " << std::setprecision( precision ) << work.objValue() << std::endl; )
1515 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"Solution value is: " << std::setprecision( precision ) << work.objValue() << std::endl; )
1517 if ( print_quality )
1518 work.displayQuality();
1520 if ( print_solution )
1526 MSG_INFO1( (*work.spxout), (*work.spxout) << std::endl <<
"Primal solution (name, id, value):" << std::endl; )
1527 for(
int i = 0; i < work.nCols(); ++i )
1529 if (
isNotZero( objx[i], 0.001 * work.feastol() ) )
1530 MSG_INFO1( (*work.spxout), (*work.spxout) << colnames[ work.cId(i) ] <<
"\t"
1533 << std::setprecision( precision )
1534 << objx[i] << std::endl; )
1536 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"All other variables are zero (within " << std::setprecision(1) << 0.001*work.feastol() <<
")." << std::endl; )
1542 bool allzero =
true;
1546 MSG_INFO1( (*work.spxout), (*work.spxout) << std::endl <<
"Dual multipliers (name, id, value):" << std::endl; )
1547 for(
int i = 0; i < work.nRows(); ++i )
1549 if (
isNotZero( objy[i] , 0.001 * work.opttol() ) )
1551 MSG_INFO1( (*work.spxout), (*work.spxout) << rownames[ work.rId(i) ] <<
"\t"
1554 << std::setprecision( precision )
1555 << objy[i] << std::endl; )
1560 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"All " << (allzero ?
"" :
"other ") <<
"dual values are zero (within "
1561 << std::setprecision(1) << 0.001*work.opttol() <<
")." << std::endl; )
1567 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"Minimizing: a positive/negative value corresponds to left-hand (>=) resp. right-hand (<=) side."
1572 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"Maximizing: a positive/negative value corresponds to right-hand (<=) resp. left-hand (>=) side."
1580 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"Writing basis of original problem to file " << basisname << std::endl; )
1581 if ( ! work.writeBasisFile( basisname, &rownames, &colnames ) )
1584 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"EEXAMP30 error while writing file \"" << basisname <<
"\"" << std::endl; )
1586 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"Error while writing file \"" << basisname <<
"\"" << std::endl; )
1592 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"IEXAMP31 LP is unbounded" << std::endl; )
1594 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"LP is unbounded" << std::endl; )
1596 if ( print_solution )
1601 MSG_INFO1( (*work.spxout), (*work.spxout) << std::endl <<
"Primal solution (name, id, value):" << std::endl; )
1602 for(
int i = 0; i < work.nCols(); ++i )
1604 if (
isNotZero( objx[i], 0.001 * work.feastol() ) )
1605 MSG_INFO1( (*work.spxout), (*work.spxout) << colnames[ work.cId(i) ] <<
"\t"
1608 << std::setprecision( precision )
1609 << objx[i] << std::endl; )
1611 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"All other variables are zero (within " << std::setprecision(1) << 0.001*work.feastol() <<
")." << std::endl; )
1614 DVector objcoef(work.nCols());
1618 Real rayobjval = 0.0;
1620 work.getObj(objcoef);
1622 MSG_INFO1( (*work.spxout), (*work.spxout) << std::endl <<
"Primal ray (name, id, value):" << std::endl; )
1623 for(
int i = 0; i < work.nCols(); ++i )
1625 if (
isNotZero( ray[i], 0.001 * work.feastol() ) )
1627 rayobjval += ray[i] * objcoef[i];
1629 MSG_INFO1( (*work.spxout), (*work.spxout) << colnames[ work.cId(i) ] <<
"\t"
1632 << std::setprecision( precision )
1633 << ray[i] << std::endl; )
1636 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"All other variables have zero value (within " << std::setprecision(1) << 0.001*work.feastol() <<
")." << std::endl; )
1637 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"Objective change per unit along primal ray is " << rayobjval <<
"." << std::endl; )
1643 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"IEXAMP32 LP is infeasible" << std::endl; )
1645 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"LP is infeasible" << std::endl; )
1646 if ( print_solution )
1648 DVector farkasx(work.nRows());
1652 DVector proofvec(work.nCols());
1659 for(
int i = 0; i < work.nRows(); ++i )
1661 if (
isNotZero( farkasx[i], 0.001 * work.opttol() ) )
1663 MSG_INFO1( (*work.spxout), (*work.spxout) << rownames[ work.rId(i) ] <<
"\t"
1666 << std::setprecision( precision )
1667 << farkasx[i] <<
"\t"; )
1669 work.getRow(i, row);
1672 MSG_INFO1( (*work.spxout), (*work.spxout) << row.lhs() <<
" <= "; );
1674 for(
int j = 0; j < row.rowVector().size(); ++j )
1676 if( row.rowVector().value(j) > 0 )
1678 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"+"; )
1680 MSG_INFO1( (*work.spxout), (*work.spxout)
1681 << row.rowVector().value(j) <<
" "
1682 << colnames[ work.cId(row.rowVector().index(j)) ]
1687 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"<= " << row.rhs(); );
1689 MSG_INFO1( (*work.spxout), (*work.spxout) << std::endl; )
1690 if( farkasx[i] > 0.0 )
1692 lhs += farkasx[i] * row.lhs();
1693 rhs += farkasx[i] * row.rhs();
1697 lhs += farkasx[i] * row.rhs();
1698 rhs += farkasx[i] * row.lhs();
1706 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"All other row multipliers are zero (within " << std::setprecision(1) << 0.001*work.opttol() <<
")." << std::endl; )
1707 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"Farkas infeasibility proof: \t"; )
1708 MSG_INFO1( (*work.spxout), (*work.spxout) << lhs <<
" <= "; )
1710 bool nonzerofound =
false;
1711 for(
int i = 0; i < work.nCols(); ++i )
1713 if (
isNotZero( proofvec[i], 0.001 * work.opttol() ) )
1715 if( proofvec[i] > 0 )
1717 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"+"; )
1719 MSG_INFO1( (*work.spxout), (*work.spxout) << proofvec[i] <<
" " << colnames[ work.cId(i) ] <<
" "; )
1720 nonzerofound =
true;
1725 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"0 "; );
1727 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"<= " << rhs << std::endl; );
1730 if ( print_quality )
1731 work.displayInfeasibility();
1733 if ( ! work.writeBasisFile( basisname, &rownames, &colnames ) )
1736 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"EEXAMP30 error while writing file \"" << basisname <<
"\"" << std::endl; )
1738 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"Error while writing file \"" << basisname <<
"\"" << std::endl; )
1743 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"EEXAMP40 aborted due to cycling" << std::endl; )
1745 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"Aborted due to cycling" << std::endl; )
1749 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"IEXAMP33 aborted due to time limit" << std::endl; )
1751 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"Aborted due to time limit" << std::endl; )
1755 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"IEXAMP34 aborted due to iteration limit" << std::endl; )
1757 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"Aborted due to iteration limit" << std::endl; )
1761 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"IEXAMP35 aborted due to objective value limit" << std::endl; )
1763 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"Aborted due to objective value limit" << std::endl; )
1767 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"EEXAMP39 basis is singular" << std::endl; )
1769 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"Basis is singular" << std::endl; )
1773 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"EEXAMP36 An error occurred during " <<
"the solution process" << std::endl; )
1775 MSG_INFO1( (*work.spxout), (*work.spxout) <<
"An error occurred during " <<
"the solution process" << std::endl; )
1778 MSG_INFO1( (*work.spxout), (*work.spxout) << std::endl; )
1793 if ( prescaler != 0 )
1798 if ( postscaler != 0 )
1803 if ( simplifier != 0 )
1814 assert( pricer != 0 );
1818 assert( ratiotester != 0 );
1822 if ( basisname != 0 )
1823 delete [] basisname;
1831 int main(
int argc,
char* argv[])
1833 const char* filename;
1834 char* basisname = 0;
1854 int simplifying = 1;
1856 Real timelimit = -1.0;
1864 bool print_solution =
false;
1865 bool print_dual =
false;
1866 bool print_quality =
false;
1867 bool read_basis =
false;
1868 bool write_basis =
false;
1872 for(optidx = 1; optidx < argc; optidx++)
1874 if (*argv[optidx] !=
'-')
1877 switch(argv[optidx][1])
1880 check_parameter(argv[optidx][2], argv);
1881 if (argv[optidx][2] ==
'r')
1883 if (argv[optidx][2] ==
'w')
1887 check_parameter(argv[optidx][2], argv);
1888 starting = atoi(&argv[optidx][2]);
1891 check_parameter(argv[optidx][2], argv);
1892 delta = atof(&argv[optidx][2]);
1895 check_parameter(argv[optidx][2], argv);
1896 feastol = atof(&argv[optidx][2]);
1899 check_parameter(argv[optidx][2], argv);
1900 opttol = atof(&argv[optidx][2]);
1906 check_parameter(argv[optidx][2], argv);
1907 scaling = atoi(&argv[optidx][2]);
1913 if (argv[optidx][2] ==
'\0' )
1914 print_usage_and_exit( argv );
1915 timelimit = atof(&argv[optidx][2]);
1918 if (argv[optidx][2] ==
'\0' )
1919 print_usage_and_exit( argv );
1920 iterlimit = atoi(&argv[optidx][2]);
1923 check_parameter(argv[optidx][2], argv);
1924 pricing = atoi(&argv[optidx][2]);
1927 print_quality =
true;
1933 check_parameter(argv[optidx][2], argv);
1934 simplifying = atoi(&argv[optidx][2]);
1937 check_parameter(argv[optidx][2], argv);
1938 ratiotest = atoi(&argv[optidx][2]);
1941 check_parameter(argv[optidx][2], argv);
1942 if (argv[optidx][2] >=
'0' && argv[optidx][2] <=
'9')
1943 verbose = argv[optidx][2] -
'0';
1946 print_version_info();
1949 print_solution =
true;
1955 check_parameter(argv[optidx][2], argv);
1956 check_parameter(argv[optidx][3], argv);
1957 switch(argv[optidx][2])
1960 epsilon = atof(&argv[optidx][3]);
1963 epsilon_factor = atof(&argv[optidx][3]);
1966 epsilon_update = atof(&argv[optidx][3]);
1969 print_usage_and_exit( argv );
1977 print_version_info();
1980 print_usage_and_exit( argv );
1985 print_version_info();
1988 if ((argc - optidx) < 1 + (read_basis ? 1 : 0) + (write_basis ? 1 : 0))
1989 print_usage_and_exit( argv );
1990 filename = argv[optidx];
1998 if ( read_basis || write_basis )
1999 basisname = strcpy(
new char[strlen(argv[optidx]) + 1], argv[optidx] );
2008 precision = int(-log10(std::min(feastol, opttol))) + 1;
2010 std::cout.setf( std::ios::scientific | std::ios::showpoint );
2011 std::cerr.setf( std::ios::scientific | std::ios::showpoint );
2013 #ifdef SEND_ALL_OUTPUT_TO_FILES
2016 std::ofstream myerrstream (
"errwarn.txt" );
2017 std::ofstream myinfostream(
"infos.txt" );
2018 redirect_output(myerrstream, myinfostream);
2022 MySoPlex work( spxout, type, representation );
2023 work.setOutstream ( spxout );
2024 work.setUtype ( update );
2025 work.setFeastol ( std::min(feastol, delta) );
2026 work.setOpttol ( std::min(opttol, delta) );
2027 work.setTerminationTime ( timelimit );
2028 work.setTerminationIter ( iterlimit );
2029 print_algorithm_parameters( work, representation, update );
2030 assert( work.isConsistent() );
2033 work.setPricer ( pricer = get_pricer (pricing, work.spxout) );
2034 work.setStarter ( starter = get_starter (starting, work.spxout) );
2035 work.setSimplifier( simplifier = get_simplifier (simplifying, work.spxout) );
2036 work.setTester ( ratiotester = get_ratio_tester(ratiotest, work.spxout) );
2037 assert(work.isConsistent());
2040 get_scalers(prescaler, postscaler, scaling, work.spxout);
2041 work.setPreScaler (prescaler);
2042 work.setPostScaler(postscaler);
2043 assert(work.isConsistent());
2046 read_input_file(work, filename, rownames, colnames);
2050 read_basis_file(work, basisname, &rownames, &colnames);
2056 print_solution_and_status(work, rownames, colnames, precision, print_quality,
2057 print_solution, print_dual, write_basis, basisname);
2060 clean_up(prescaler, postscaler, simplifier, starter, pricer, ratiotester, basisname);
2066 std::cout <<
"exception caught : " << x.
what() << std::endl;
2067 delete [] basisname;