45 #ifdef UG_DEBUG_SOLUTION 46 #ifndef WITH_DEBUG_SOLUTION 47 #define WITH_DEBUG_SOLUTION 49 #include "scip/debug.h" 62 #if ( defined(_COMM_PTH) || defined(_COMM_CPP11) ) 66 static int parseLine(
char* line){
70 while (*p <'0' || *p >
'9') p++;
76 static long long getVmSize(){
77 FILE* file = fopen(
"/proc/self/status",
"r");
78 long long result = -1;
81 while (fgets(line, 128, file) != NULL){
82 if (strncmp(line,
"VmSize:", 7) == 0){
83 result = parseLine(line);
94 ScipParaInitiator::addRootNodeCuts(
97 SCIP_Longint originalLimitsNodes;
98 SCIP_CALL_ABORT( SCIPgetLongintParam(scip,
"limits/nodes", &originalLimitsNodes) );
99 SCIP_CALL_ABORT( SCIPsetLongintParam(scip,
"limits/nodes", 1) );
100 if( scipDiffParamSetRoot ) scipDiffParamSetRoot->setParametersInScip(scip);
103 double timeRemains = std::max( 0.0, (paraParams->getRealParamValue(
UG::TimeLimit) - timer->getElapsedTime()) );
105 SCIP_CALL_ABORT( SCIPsetRealParam(scip,
"limits/time", timeRemains) );
107 SCIP_RETCODE ret = SCIPsolve(scip);
108 if( ret != SCIP_OKAY )
110 #ifndef SCIP_THREADSAFE_MESSAGEHDLRS 111 SCIPprintError(ret, NULL);
119 SCIP_CALL_ABORT( SCIPresetParams(scip) );
122 SCIP_CALL_ABORT( SCIPsetIntParam(scip,
"presolving/maxrounds", 0));
128 SCIP_CALL_ABORT( SCIPreadParams(scip, settingsNameLC) );
133 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"misc/catchctrlc", FALSE) );
135 SCIP_STATUS status = SCIPgetStatus(scip);
136 if( status == SCIP_STATUS_OPTIMAL )
142 if( status == SCIP_STATUS_MEMLIMIT )
144 std::cout <<
"Warning: SCIP was interrupted because the memory limit was reached" << std::endl;
148 timer->getElapsedTime() > paraParams->getRealParamValue(
UG::TimeLimit) )
159 cuts = SCIPgetPoolCuts(scip);
160 ncuts = SCIPgetNPoolCuts(scip);
161 for(
int c = 0; c < ncuts; ++c )
165 row = SCIPcutGetRow(cuts[c]);
166 assert(!SCIProwIsLocal(row));
167 assert(!SCIProwIsModifiable(row));
168 if( SCIPcutGetAge(cuts[c]) == 0 && SCIProwIsInLP(row) )
170 char name[SCIP_MAXSTRLEN];
178 cols = SCIProwGetCols(row);
179 ncols = SCIProwGetNNonz(row);
181 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &vars, ncols) );
182 for( i = 0; i < ncols; ++i )
183 vars[i] = SCIPcolGetVar(cols[i]);
185 (void) SCIPsnprintf(name, SCIP_MAXSTRLEN,
"%s_%d", SCIProwGetName(row), SCIPgetNRuns(scip));
186 SCIP_CALL_ABORT( SCIPcreateConsLinear(scip, &cons, name, ncols, vars, SCIProwGetVals(row),
187 SCIProwGetLhs(row) - SCIProwGetConstant(row), SCIProwGetRhs(row) - SCIProwGetConstant(row),
188 TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE) );
189 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
190 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
192 SCIPfreeBufferArray(scip, &vars);
205 ScipParaInitiator::init(
213 #if ( defined(_COMM_PTH) || defined(_COMM_CPP11) ) 214 bool noUpgrade =
false;
216 paraParams = inParaParams;
239 for( i = 3; i < argc; ++i )
242 if( strcmp(argv[i],
"-l") == 0 )
249 std::cerr <<
"missing log filename after parameter '-l'" << std::endl;
253 else if( strcmp(argv[i],
"-q") == 0 )
255 else if( strcmp(argv[i],
"-s") == 0 )
259 settingsName = argv[i];
262 std::cerr <<
"missing settings filename after parameter '-s'" << std::endl;
266 else if( strcmp(argv[i],
"-sr") == 0 )
270 settingsNameRoot = argv[i];
273 std::cerr <<
"missing settings filename after parameter '-sr'" << std::endl;
277 else if( strcmp(argv[i],
"-sl") == 0 )
281 settingsNameLC = argv[i];
284 std::cerr <<
"missing settings filename after parameter '-sl'" << std::endl;
288 else if( strcmp(argv[i],
"-w") == 0)
294 prefixWarm = argv[i];
295 char nodesFileName[SCIP_MAXSTRLEN];
296 (void) SCIPsnprintf(nodesFileName, SCIP_MAXSTRLEN,
"%s_nodes_LC0.gz", prefixWarm);
297 checkpointTasksStream.open(nodesFileName, std::ios::in | std::ios::binary);
298 if( !checkpointTasksStream.good() ){
299 std::cerr <<
"ERROR: Opening file `" << nodesFileName <<
"' failed.\n";
305 std::cerr <<
"missing settings filename after parameter '-w'" << std::endl;
309 std::cerr <<
"Cannot work with parameter '-w' compiling without zlib" << std::endl;
313 else if( strcmp(argv[i],
"-racing") == 0 )
318 racingSettingsName = argv[i];
322 std::cerr <<
"missing settings filename after parameter '-racing'" << std::endl;
326 else if ( strcmp(argv[i],
"-isol") == 0 )
335 std::cerr <<
"missing settings filename after parameter '-isol'" << std::endl;
339 else if( strcmp(argv[i],
"-objlimit") == 0 )
344 objlimit = atof(argv[i]);
348 std::cerr <<
"missing objective limit after parameter '-objlimit'" << std::endl;
352 else if ( strcmp(argv[i],
"-sth") == 0 )
356 else if ( strcmp(argv[i],
"-fsol" ) == 0 )
361 solutionFileName = argv[i];
365 std::cerr <<
"missing solution filename after parameter '-fsol'" << std::endl;
369 #if ( defined(_COMM_PTH) || defined(_COMM_CPP11) ) 370 else if ( strcmp(argv[i],
"-nou" ) == 0 )
376 else if( strcmp(argv[i],
"-ugsc") == 0 )
381 else if ( strcmp(argv[i],
"-omit1" ) == 0 )
384 else if ( strcmp(argv[i],
"-omit2" ) == 0 )
398 SCIP_CALL( SCIPcreate(&scip) );
403 SCIP_CALL_ABORT( SCIPsetIntParam(scip,
"timing/clocktype", 2) );
406 double timeRemains = std::max( 0.0, (paraParams->getRealParamValue(
UG::TimeLimit) - timer->getElapsedTime()) );
407 SCIP_CALL_ABORT( SCIPsetRealParam(scip,
"limits/time", timeRemains) );
414 SCIP_CALL( SCIPincludeDefaultPlugins(scip) );
416 includeUserPlugins(scip);
420 finalDualBound = -SCIPinfinity(scip);
422 printSolverVersion(NULL);
427 SCIP_RETCODE paramretcode = SCIPsetBoolParam(scip,
"constraints/orbisack/forceconscopy", TRUE);
428 if( paramretcode != SCIP_OKAY && paramretcode != SCIP_PARAMETERUNKNOWN )
430 SCIP_CALL_ABORT( paramretcode );
432 paramretcode = SCIPsetBoolParam(scip,
"constraints/orbitope/forceconscopy", TRUE);
433 if( paramretcode != SCIP_OKAY && paramretcode != SCIP_PARAMETERUNKNOWN )
435 SCIP_CALL_ABORT( paramretcode );
437 paramretcode = SCIPsetBoolParam(scip,
"constraints/symresack/forceconscopy", TRUE);
438 if( paramretcode != SCIP_OKAY && paramretcode != SCIP_PARAMETERUNKNOWN )
440 SCIP_CALL_ABORT( paramretcode );
447 if( paraParams->getBoolParamValue(
Quiet) )
450 SCIP_CALL_ABORT( SCIPcreateObjMessagehdlr(&messagehdlr, objmessagehdlr, TRUE) );
451 #ifndef SCIP_THREADSAFE_MESSAGEHDLRS 452 SCIP_CALL_ABORT( SCIPsetMessagehdlr(messagehdlr) );
454 SCIP_CALL_ABORT( SCIPsetMessagehdlr(scip, messagehdlr) );
455 SCIP_CALL_ABORT( SCIPmessagehdlrRelease(&messagehdlr));
457 SCIPmessageSetErrorPrinting(ParaSCIP::scip_errorfunction, (
void*) objmessagehdlr);
461 if( logname != NULL || quiet )
463 if( logname != NULL )
465 std::ostringstream os;
466 os << logname << paraComm->getRank();
467 logfile = fopen(os.str().c_str(),
"a");
468 if( logfile == NULL )
475 SCIP_CALL_ABORT( SCIPcreateObjMessagehdlr(&messagehdlr, objmessagehdlr, TRUE) );
476 #ifndef SCIP_THREADSAFE_MESSAGEHDLRS 477 SCIP_CALL_ABORT( SCIPsetMessagehdlr(messagehdlr) );
479 SCIP_CALL_ABORT( SCIPsetMessagehdlr(scip, messagehdlr) );
480 SCIP_CALL_ABORT( SCIPmessagehdlrRelease(&messagehdlr));
482 SCIPmessageSetErrorPrinting(ParaSCIP::scip_errorfunction, (
void*) objmessagehdlr);
486 if( probname != NULL )
491 #ifndef SCIP_THREADSAFE_MESSAGEHDLRS 492 SCIPprintVersion(NULL);
494 SCIPprintVersion(scip, NULL);
496 SCIPinfoMessage(scip, NULL,
"\n");
502 if( !(settingsName == NULL && settingsNameRoot == NULL && settingsNameLC == NULL ) )
505 SCIP_CALL( SCIPcreate(¶mScip) );
507 SCIP_CALL( SCIPincludeDefaultPlugins(paramScip) );
509 includeUserPlugins(paramScip);
512 if( settingsName != NULL )
514 SCIP_CALL_ABORT( SCIPreadParams(paramScip, settingsName) );
515 scipDiffParamSet = scipParaComm->createScipDiffParamSet(paramScip);
519 scipDiffParamSet = scipParaComm->createScipDiffParamSet(scip);
522 if( settingsNameRoot != NULL )
524 SCIP_CALL_ABORT( SCIPreadParams(scip, settingsNameRoot) );
526 SCIP_CALL_ABORT( SCIPreadParams(paramScip, settingsNameRoot) );
527 scipDiffParamSetRoot = scipParaComm->createScipDiffParamSet(paramScip);
533 scipDiffParamSetRoot = scipParaComm->createScipDiffParamSet(scip);
536 if( settingsNameLC != NULL )
539 SCIP_CALL_ABORT( SCIPreadParams(scip, settingsNameLC) );
540 std::cout <<
"** applied absolute gap = " << getAbsgapValue() << std::endl;
541 std::cout <<
"** applied relative gap = " << getGapValue() << std::endl;
547 std::cout <<
"** RampUpPhaseProcess is switched to 1, since gap is specified" << std::endl;
555 SCIP_CALL_ABORT( SCIPfree(¶mScip) );
568 SCIP_RETCODE retcode = SCIPreadProb(scip, probname, NULL);
569 if( retcode != SCIP_OKAY )
571 std::cout <<
"error reading file <" << probname <<
">" << std::endl;
572 SCIP_CALL( SCIPfreeProb(scip) );
577 SCIP_CALL_ABORT( SCIPtransformProb(scip));
585 SCIP_CALL_ABORT( SCIPreadProb(scip, isolname, 0) );
589 char *probNameFromFileName;
590 char *temp =
new char[strlen(probname)+1];
591 (void) strcpy(temp, probname);
592 SCIPsplitFilename(temp, NULL, &probNameFromFileName, NULL, NULL);
593 SCIP_CALL_ABORT( SCIPsetProbName(scip, probNameFromFileName));
599 if( SCIPfindConshdlr(scip,
"pseudoboolean") == NULL || SCIPconshdlrGetNConss(SCIPfindConshdlr(scip,
"pseudoboolean")) == 0 )
601 SCIP_CALL_ABORT( SCIPsetIntParam(scip,
"presolving/maxrounds", 0) );
602 std::cout <<
"No LC presolving is specified." << std::endl;
606 std::cout <<
"Default LC presolving (default)." << std::endl;
613 SCIP_CALL_ABORT( SCIPreadParams(scip, settingsNameLC) );
614 std::cout <<
"LC presolving settings file is specified." << std::endl;
619 std::cout <<
"Default LC presolving (default)." << std::endl;
626 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"misc/catchctrlc", FALSE) );
631 SCIP_CALL_ABORT( SCIPsetObjlimit(scip, objlimit) );
639 SCIP_Bool originalUpgradeKnapsack;
640 SCIP_Bool originalUpgradeLogicor;
641 SCIP_Bool originalUpgradeSetppc;
642 SCIP_Bool originalUpgradeVarbound;
643 bool onlyLinearConss = onlyLinearConsHandler();
644 #ifdef _COMM_MPI_WORLD 645 if( onlyLinearConss )
647 std::cout <<
"** Original problem has only linear constraints" << std::endl;
651 std::cout <<
"** Original problem has non-linear constraints" << std::endl;
655 if( onlyLinearConss )
657 SCIP_CALL_ABORT( SCIPgetBoolParam(scip,
"constraints/linear/upgrade/knapsack", &originalUpgradeKnapsack));
658 SCIP_CALL_ABORT( SCIPgetBoolParam(scip,
"constraints/linear/upgrade/logicor", &originalUpgradeLogicor));
659 SCIP_CALL_ABORT( SCIPgetBoolParam(scip,
"constraints/linear/upgrade/setppc", &originalUpgradeSetppc));
660 SCIP_CALL_ABORT( SCIPgetBoolParam(scip,
"constraints/linear/upgrade/varbound", &originalUpgradeVarbound));
661 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/knapsack", FALSE));
662 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/logicor", FALSE));
663 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/setppc", FALSE));
664 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/varbound", FALSE));
670 SCIP_CALL_ABORT( SCIPgetBoolParam(scip,
"constraints/linear/upgrade/knapsack", &originalUpgradeKnapsack));
671 SCIP_CALL_ABORT( SCIPgetBoolParam(scip,
"constraints/linear/upgrade/logicor", &originalUpgradeLogicor));
672 SCIP_CALL_ABORT( SCIPgetBoolParam(scip,
"constraints/linear/upgrade/setppc", &originalUpgradeSetppc));
673 SCIP_CALL_ABORT( SCIPgetBoolParam(scip,
"constraints/linear/upgrade/varbound", &originalUpgradeVarbound));
674 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/knapsack", FALSE));
675 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/logicor", FALSE));
676 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/setppc", FALSE));
677 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/varbound", FALSE));
681 #ifdef UG_DEBUG_SOLUTION 682 SCIPdebugSolDisable(scip);
687 instance = scipParaComm->createScipParaInstance(scip, paraParams->getIntParamValue(
InstanceTransferMethod));
689 std::ostringstream os;
690 if( solutionFileName )
692 os << solutionFileName;
697 os << instance->getProbName() <<
".sol";
699 solutionFile = fopen(os.str().c_str(),
"a");
700 if( solutionFile == NULL )
705 #if defined(_COMM_PTH) || defined (_COMM_CPP11) 707 long long vmSizeBeforePresolving = getVmSize();
708 virtualMemUsedAtLc = std::max(vmSizeBeforePresolving, (SCIPgetMemTotal(scip) + SCIPgetMemExternEstim(scip)));
709 std::cout <<
"** Before presolving: virtualMemUsedAtLc = " <<
virtualMemUsedAtLc <<
", getVmSize() = " << getVmSize() <<
", SCIPgetMemUsed() = " << SCIPgetMemUsed(scip) <<
", SCIPgetMemTotal() = " << SCIPgetMemTotal(scip) <<
", SCIPgetMemExternEstim() = " << SCIPgetMemExternEstim(scip) << std::endl;
712 std::cout <<
"** Before presolving: virtualMemUsedAtLc = " <<
virtualMemUsedAtLc <<
", SCIPgetMemUsed() = " << SCIPgetMemUsed(scip) <<
", SCIPgetMemTotal() = " << SCIPgetMemTotal(scip) <<
", SCIPgetMemExternEstim() = " << SCIPgetMemExternEstim(scip) << std::endl;
722 SCIP_CALL_ABORT( SCIPsetIntParam(scip,
"presolving/maxrounds", 0) );
723 std::cout <<
"** No LC presolving is applied, since memory limit becomes " 730 SCIP_CALL( SCIPpresolve(scip) );
734 std::cout <<
"=== solved at Init ===" << std::endl;
735 finalDualBound = instance->convertToInternalValue(SCIPgetDualbound(scip));
736 writeSolution(
"Final Solution");
742 SCIP_CALL_ABORT( SCIPsetRealParam(scip,
"limits/memory", dynamic_cast<ScipParaParamSet *>(paraParams)->getRealParamValue(
MemoryLimit)) );
743 std::cout <<
"** set memory limit for presolving in LC and solvers to " <<
dynamic_cast<ScipParaParamSet *
>(paraParams)->getRealParamValue(
MemoryLimit) <<
" for each SCIP **" << std::endl;
746 #if SCIP_APIVERSION >= 101 747 if( SCIPfindPresol(scip,
"milp") != NULL )
749 #ifdef _COMM_MPI_WORLD 750 SCIP_CALL_ABORT( SCIPsetIntParam(scip,
"presolving/milp/threads", 0) );
752 SCIP_CALL_ABORT( SCIPsetIntParam(scip,
"presolving/milp/threads", (paraComm->getSize() - 1)) );
759 double timeRemains = std::max( 0.0, (paraParams->getRealParamValue(
UG::TimeLimit) - timer->getElapsedTime()) );
760 SCIP_CALL_ABORT( SCIPsetIntParam(scip,
"timing/clocktype", 2) );
761 SCIP_CALL_ABORT( SCIPsetRealParam(scip,
"limits/time", timeRemains) );
764 SCIP_CALL( SCIPpresolve(scip) );
765 SCIP_STATUS scipStatus = SCIPgetStatus(scip);
767 if( scipStatus == SCIP_STATUS_OPTIMAL ||
768 scipStatus == SCIP_STATUS_INFEASIBLE )
773 std::cout <<
"=== solved at Init ===" << std::endl;
774 finalDualBound = instance->convertToInternalValue(SCIPgetDualbound(scip));
775 writeSolution(
"Final Solution");
778 else if( scipStatus == SCIP_STATUS_MEMLIMIT )
783 std::cout <<
"=== solved at Init ===" << std::endl;
784 finalDualBound = instance->convertToInternalValue(SCIPgetDualbound(scip));
785 writeSolution(
"Final Solution");
790 if( scipStatus == SCIP_STATUS_TIMELIMIT )
795 std::cout <<
"=== solved at Init ===" << std::endl;
796 finalDualBound = instance->convertToInternalValue(SCIPgetDualbound(scip));
797 writeSolution(
"Final Solution");
805 if( !addRootNodeCuts() )
810 std::cout <<
"=== solved at Init ===" << std::endl;
811 finalDualBound = instance->convertToInternalValue(SCIPgetDualbound(scip));
812 writeSolution(
"Final Solution");
818 timer->getElapsedTime() > paraParams->getRealParamValue(
UG::TimeLimit) )
823 std::cout <<
"=== solved at Init ===" << std::endl;
824 finalDualBound = instance->convertToInternalValue(SCIPgetDualbound(scip));
825 writeSolution(
"Final Solution");
833 #if defined(_COMM_PTH) || defined (_COMM_CPP11) 836 long long vmSize = getVmSize();
837 long long vmSizeForSolver = (vmSize - vmSizeBeforePresolving)/paraComm->getSize() + vmSizeBeforePresolving;
839 std::cout <<
"** Estimated virtualMemUsedAtSolver = " <<
virtualMemUsedAtLc <<
", getVmSize() = " << vmSize <<
", SCIPgetMemUsed() = " << SCIPgetMemUsed(scip) <<
", SCIPgetMemTotal() = " << SCIPgetMemTotal(scip) <<
", SCIPgetMemExternEstim() = " << SCIPgetMemExternEstim(scip) << std::endl;
842 std::cout <<
"** Estimated virtualMemUsedAtSolver = " <<
virtualMemUsedAtLc <<
", SCIPgetMemUsed() = " << SCIPgetMemUsed(scip) <<
", SCIPgetMemTotal() = " << SCIPgetMemTotal(scip) <<
", SCIPgetMemExternEstim() = " << SCIPgetMemExternEstim(scip) << std::endl;
846 std::cout <<
"** set memory limit for solvers to " <<
memoryLimitOfSolverSCIP <<
" for each SCIP **" << std::endl;
852 std::cout <<
"=== solved at Init ===" << std::endl;
853 finalDualBound = instance->convertToInternalValue(SCIPgetDualbound(scip));
854 writeSolution(
"Final Solution");
860 int nNonLinearConsHdlrs = 0;
861 outputProblemInfo(&nNonLinearConsHdlrs);
862 #ifdef _COMM_MPI_WORLD 863 if( SCIPgetNActiveBenders(scip) > 0 ) nNonLinearConsHdlrs++;
865 paraComm->bcast( &nNonLinearConsHdlrs, 1,
ParaINT, 0 )
867 if( nNonLinearConsHdlrs > 0 )
872 std::cout <<
"** Instance transfer method used: " << paraParams->getIntParamValue(
InstanceTransferMethod) << std::endl;
874 if( SCIPgetNVars(scip) == 0 )
876 SCIP_CALL( SCIPsolve(scip) );
880 std::cout <<
"=== solved at Init ===" << std::endl;
881 finalDualBound = instance->convertToInternalValue(SCIPgetDualbound(scip));
882 writeSolution(
"Final Solution");
887 SCIP_SOL *sol = SCIPgetBestSol(scip);
893 if( ( SCIPgetObjsense(scip) == SCIP_OBJSENSE_MINIMIZE && SCIPgetSolOrigObj(scip, sol) < objlimit ) ||
894 ( SCIPgetObjsense(scip) == SCIP_OBJSENSE_MAXIMIZE && SCIPgetSolOrigObj(scip, sol) > objlimit ) )
896 int nVars = SCIPgetNVars(scip);
897 SCIP_VAR **vars = SCIPgetVars(scip);
898 SCIP_Real *vals =
new SCIP_Real[nVars];
899 SCIP_CALL_ABORT( SCIPgetSolVals(scip, sol, nVars, vars, vals) );
900 solution = scipParaComm->createScipParaSolution(
902 SCIPgetSolTransObj(scip, sol),
911 solution = scipParaComm->createScipParaSolution(
913 ( ( objlimit / ( SCIPgetTransObjscale(scip) * SCIPgetObjsense(scip) ) ) - SCIPgetTransObjoffset(scip) ),
922 int nVars = SCIPgetNVars(scip);
923 SCIP_VAR **vars = SCIPgetVars(scip);
924 SCIP_Real *vals =
new SCIP_Real[nVars];
925 SCIP_CALL_ABORT( SCIPgetSolVals(scip, sol, nVars, vars, vals) );
926 solution = scipParaComm->createScipParaSolution(
928 SCIPgetSolTransObj(scip, sol),
940 solution = scipParaComm->createScipParaSolution(
942 ( ( objlimit / ( SCIPgetTransObjscale(scip) * SCIPgetObjsense(scip) ) ) - SCIPgetTransObjoffset(scip) ),
953 #ifdef _COMM_MPI_WORLD 956 instance = scipParaComm->createScipParaInstance(scip, paraParams->getIntParamValue(
InstanceTransferMethod));
974 #ifdef _COMM_MPI_WORLD 978 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/knapsack", originalUpgradeKnapsack));
979 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/logicor", originalUpgradeLogicor));
980 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/setppc", originalUpgradeSetppc));
981 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/varbound", originalUpgradeVarbound));
986 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/knapsack", originalUpgradeKnapsack));
987 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/logicor", originalUpgradeLogicor));
988 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/setppc", originalUpgradeSetppc));
989 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/varbound", originalUpgradeVarbound));
994 SCIP_CALL_ABORT( SCIPgetIntParam(scip,
"presolving/maxrounds", &maxrounds));
995 if( !paraParams->getBoolParamValue(
Quiet) && maxrounds != 0 )
998 transSolutionFile = fopen(os.str().c_str(),
"a");
999 if( transSolutionFile == NULL )
1006 std::ostringstream os2;
1008 if( onlyLinearConss )
1010 os2 << instance->getProbName() <<
"_presolved.lp";
1014 os2 << instance->getProbName() <<
"_presolved.cip";
1016 SCIP_CALL_ABORT( SCIPwriteTransProblem(scip, os2.str().c_str(), NULL, FALSE));
1021 std::cout << std::endl;
1022 std::cout <<
"syntax: " << argv[0] <<
"#solvers ppscip_param_file problem_file_name " 1023 <<
"[-l <logfile>] [-q] [-sl <settings>] [-s <settings>] [-sr <root_settings>] [-w <prefix_warm>] [-sth <number>]" << std::endl;
1024 std::cout <<
" -l <logfile> : copy output into log file" << std::endl;
1025 std::cout <<
" -q : suppress screen messages" << std::endl;
1026 std::cout <<
" -sl <settings> : load parameter settings (.set) file for LC presolving" << std::endl;
1027 std::cout <<
" -s <settings> : load parameter settings (.set) file for solvers" << std::endl;
1028 std::cout <<
" -sr <root_settings> : load parameter settings (.set) file for root" << std::endl;
1029 std::cout <<
" -w <prefix_warm> : warm start file prefix ( prefix_warm_nodes.gz and prefix_warm_solution.txt are read )" << std::endl;
1030 std::cout <<
" -sth <number> : the number of solver threads used(FiberSCIP)" << std::endl;
1036 if( !paraParams->getBoolParamValue(
Quiet) )
1042 writeSolution(
"Updated");
1051 ScipParaInitiator::reInit(
1052 int nRestartedRacing
1056 char initSolFileName[SCIP_MAXSTRLEN];
1060 (void) SCIPsnprintf(initSolFileName, SCIP_MAXSTRLEN,
"%s.%d", isolname, nRestartedRacing);
1061 if( !rename( isolname, initSolFileName ) )
1063 std::cout <<
"Warning: initial solution file name cannot rename: " << isolname <<
", " << nRestartedRacing <<
"'th restarted file." << std::endl;
1067 if( !generatedIsolname )
1069 (void) SCIPsnprintf(initSolFileName, SCIP_MAXSTRLEN,
"%s", isolname);
1070 generatedIsolname =
new char[strlen(initSolFileName)+1];
1071 (void) strcpy(generatedIsolname, initSolFileName);
1076 if( !generatedIsolname )
1078 (void) SCIPsnprintf(initSolFileName, SCIP_MAXSTRLEN,
"i_%s.sol", instance->getProbName());
1079 generatedIsolname =
new char[strlen(initSolFileName)+1];
1080 (void) strcpy(generatedIsolname, initSolFileName);
1084 FILE *fp = fopen(generatedIsolname,
"w");
1087 std::cout <<
"Could not open " << generatedIsolname <<
" file to reinitialize for restart." << std::endl;
1090 assert( SCIPgetBestSol(scip) );
1091 SCIP_CALL_ABORT( SCIPprintBestSol( scip, fp, FALSE) );
1095 SCIP_RETCODE retcode = SCIPreadProb(scip, probname, NULL);
1096 if( retcode != SCIP_OKAY )
1098 std::cout <<
"error reading file <" << probname <<
">" << std::endl;
1099 SCIP_CALL( SCIPfreeProb(scip) );
1105 SCIP_CALL_ABORT( SCIPtransformProb(scip));
1108 SCIP_CALL_ABORT( SCIPreadSol(scip, generatedIsolname) );
1111 char *probNameFromFileName;
1112 char *temp =
new char[strlen(probname)+1];
1113 (void) strcpy(temp, probname);
1114 SCIPsplitFilename(temp, NULL, &probNameFromFileName, NULL, NULL);
1115 SCIP_CALL_ABORT( SCIPsetProbName(scip, probNameFromFileName));
1118 #if ( defined(_COMM_PTH) || defined(_COMM_CPP11) ) 1119 SCIP_CALL( SCIPsetBoolParam(scip,
"misc/catchctrlc", FALSE) );
1122 #ifdef _COMM_MPI_WORLD 1123 SCIP_Bool originalUpgradeKnapsack;
1124 SCIP_Bool originalUpgradeLogicor;
1125 SCIP_Bool originalUpgradeSetppc;
1126 SCIP_Bool originalUpgradeVarbound;
1127 bool onlyLinearConss = onlyLinearConsHandler();
1128 if( onlyLinearConss )
1130 SCIP_CALL_ABORT( SCIPgetBoolParam(scip,
"constraints/linear/upgrade/knapsack", &originalUpgradeKnapsack));
1131 SCIP_CALL_ABORT( SCIPgetBoolParam(scip,
"constraints/linear/upgrade/logicor", &originalUpgradeLogicor));
1132 SCIP_CALL_ABORT( SCIPgetBoolParam(scip,
"constraints/linear/upgrade/setppc", &originalUpgradeSetppc));
1133 SCIP_CALL_ABORT( SCIPgetBoolParam(scip,
"constraints/linear/upgrade/varbound", &originalUpgradeVarbound));
1134 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/knapsack", FALSE));
1135 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/logicor", FALSE));
1136 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/setppc", FALSE));
1137 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/varbound", FALSE));
1141 SCIP_CALL( SCIPpresolve(scip) );
1142 SCIP_STATUS scipStatus = SCIPgetStatus(scip);
1145 int nNonLinearConsHdlrs = 0;
1146 outputProblemInfo(&nNonLinearConsHdlrs);
1148 if( scipStatus == SCIP_STATUS_OPTIMAL ||
1149 scipStatus == SCIP_STATUS_INFEASIBLE )
1151 solvedAtReInit =
true;
1154 std::cout <<
"=== solved at reInit ===" << std::endl;
1155 finalDualBound = instance->convertToInternalValue(SCIPgetDualbound(scip));
1156 writeSolution(
"Final Solution");
1164 if( !addRootNodeCuts() )
1166 solvedAtReInit =
true;
1169 std::cout <<
"=== solved at reInit ===" << std::endl;
1170 finalDualBound = instance->convertToInternalValue(SCIPgetDualbound(scip));
1171 writeSolution(
"Final Solution");
1177 if( SCIPgetNVars(scip) == 0 )
1179 SCIP_CALL( SCIPsolve(scip) );
1180 solvedAtReInit =
true;
1183 std::cout <<
"=== solved at reInit ===" << std::endl;
1184 finalDualBound = instance->convertToInternalValue(SCIPgetDualbound(scip));
1185 writeSolution(
"Final Solution");
1191 SCIP_SOL *sol = SCIPgetBestSol(scip);
1193 int nVars = SCIPgetNVars(scip);
1194 SCIP_VAR **vars = SCIPgetVars(scip);
1195 SCIP_Real *vals =
new SCIP_Real[nVars];
1196 SCIP_CALL_ABORT( SCIPgetSolVals(scip, sol, nVars, vars, vals) );
1199 solution = scipParaComm->createScipParaSolution(
1201 SCIPgetSolTransObj(scip, sol),
1206 if( !paraParams->getBoolParamValue(
Quiet) )
1208 writeSolution(
"[Reinitialize]");
1214 instance = scipParaComm->createScipParaInstance(scip, paraParams->getIntParamValue(
InstanceTransferMethod));
1229 #ifdef _COMM_MPI_WORLD 1230 if( onlyLinearConss )
1233 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/knapsack", originalUpgradeKnapsack));
1234 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/logicor", originalUpgradeLogicor));
1235 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/setppc", originalUpgradeSetppc));
1236 SCIP_CALL_ABORT( SCIPsetBoolParam(scip,
"constraints/linear/upgrade/varbound", originalUpgradeVarbound));
1245 ScipParaInitiator::tryToSetIncumbentSolution(
1262 if( checksol && SCIPgetNActiveBenders(scip) > 0 )
1270 paraComm->lockApp();
1277 SCIP_VAR** vars = 0;
1293 if( checksol && SCIPgetNVars(scip) > tempSol->
getNVars() )
1295 std::cout <<
"*** You should check the solution! ***" << std::endl;
1296 std::cout <<
"checksol = " << checksol << std::endl;
1297 std::cout <<
"SCIPgetNVars(scip) = " << SCIPgetNVars(scip) <<
", " << tempSol->
getNVars() << std::endl;
1301 assert(SCIPgetNVars(scip) <= tempSol->
getNVars());
1302 SCIP_CALL_ABORT( SCIPcreateSol(scip, &newsol, 0) );
1303 vars = SCIPgetVars(scip);
1309 int n = SCIPgetNVars(scip);
1310 SCIP_Real *orgSolValues =
new SCIP_Real[tempSol->
getNVars()];
1314 for( i = 0; i < n; i++ )
1317 SCIP_CALL_ABORT( SCIPsetSolVal(scip, newsol, vars[i], orgSolValues[i]) );
1328 delete [] orgSolValues;
1333 assert( SCIPgetNVars(scip) <= tempSol->
getNVars() );
1343 for( i = 0; i < tempSol->
getNVars(); i++ )
1393 bool primalValueUpdated =
false;
1400 #if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) ) 1401 SCIP_CALL_ABORT( SCIPtrySolFree(scip, &newsol, FALSE, TRUE, TRUE, TRUE, &success) );
1403 SCIP_CALL_ABORT( SCIPtrySolFree(scip, &newsol, FALSE, TRUE, TRUE, TRUE, TRUE, &success) );
1408 if( SCIPisTransformed(scip) && SCIPgetNSols(scip) > 0 )
1410 double prevValue = SCIPgetPrimalbound(scip);
1411 SCIP_CALL_ABORT( SCIPaddSolFree(scip, &newsol, &success) );
1413 if( !
EPSEQ( SCIPgetPrimalbound(scip), prevValue, getEpsilon() ) )
1415 primalValueUpdated =
true;
1420 SCIP_CALL_ABORT( SCIPaddSolFree(scip, &newsol, &success) );
1421 primalValueUpdated =
true;
1429 paraComm->unlockApp();
1431 if( success && primalValueUpdated )
1438 if( !paraParams->getBoolParamValue(
Quiet) )
1444 writeSolution(
"Updated");
1448 if( !
EPSEQ( SCIPgetUpperbound(scip), solution->getObjectiveFunctionValue(), SCIPfeastol(scip) ) )
1450 std::cout <<
"*** A new solution generated in a Solver does not match with the upperbound in LC ***" << std::endl;
1451 std::cout <<
"SCIPgetUpperbound(scip) = " << SCIPgetUpperbound(scip) << std::endl;
1452 std::cout <<
"solution->getObjectiveFunctionValue() = " << solution->getObjectiveFunctionValue() << std::endl;
1453 std::cout <<
"Difference = " << (SCIPgetUpperbound(scip) - solution->getObjectiveFunctionValue())
1454 <<
", SCIPfeastol(scip) = " << SCIPfeastol(scip) << std::endl;
1462 SCIP_CALL_ABORT( SCIPcreateOrigSol(scip, &newsol, 0) );
1463 vars = SCIPgetOrigVars(scip);
1466 for( i = 0; i < tempSol->
getNVars(); i++ )
1471 if( probindex < 0 )
continue;
1475 SCIP_CALL_ABORT( SCIPsetSolVal(scip, newsol, vars[probindex], tempSol->
getValues()[i]) );
1480 for( i = 0; i < tempSol->
getNVars(); i++ )
1483 SCIP_CALL_ABORT( SCIPsetSolVal(scip, newsol, vars[i], tempSol->
getValues()[i]) );
1497 #if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) ) 1498 SCIP_CALL_ABORT( SCIPtrySolFree(scip, &newsol, FALSE, TRUE, TRUE, TRUE, &success) );
1500 SCIP_CALL_ABORT( SCIPtrySolFree(scip, &newsol, FALSE, TRUE, TRUE, TRUE, TRUE, &success) );
1510 if( !paraParams->getBoolParamValue(
Quiet) )
1516 writeSolution(
"Updated");
1518 assert(
EPSEQ( SCIPgetUpperbound(scip), solution->getObjectiveFunctionValue(), SCIPfeastol(scip) ) );
1542 #if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) ) 1543 SCIP_CALL_ABORT( SCIPtrySolFree(scip, &newsol, FALSE, TRUE, TRUE, TRUE, &success) );
1545 SCIP_CALL_ABORT( SCIPtrySolFree(scip, &newsol, FALSE, TRUE, TRUE, TRUE, TRUE, &success) );
1556 if( !paraParams->getBoolParamValue(
Quiet) )
1562 writeSolution(
"Updated");
1564 paraComm->unlockApp();
1565 assert(
EPSEQ( SCIPgetUpperbound(scip), solution->getObjectiveFunctionValue(), SCIPfeastol(scip) ) );
1571 for( i = 0; i < tempSol->
getNVars(); i++ )
1576 if( probindex < 0 )
continue;
1578 assert(i == probindex);
1580 var = vars[probindex];
1582 if( SCIPvarGetType(var) == SCIP_VARTYPE_CONTINUOUS )
continue;
1591 SCIP_CALL_ABORT( SCIPsetSolVal(scip, newsol, var, tempSol->
getValues()[i]) );
1594 #if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) ) 1595 SCIP_CALL_ABORT( SCIPtrySol(scip, newsol, FALSE, TRUE, TRUE, TRUE, &success) );
1597 SCIP_CALL_ABORT( SCIPtrySol(scip, newsol, FALSE, TRUE, TRUE, TRUE, TRUE, &success) );
1602 SCIP_CALL_ABORT( SCIPfreeSol(scip, &newsol) );
1608 if( !paraParams->getBoolParamValue(
Quiet) )
1614 writeSolution(
"Updated");
1616 paraComm->unlockApp();
1617 assert(
EPSEQ( SCIPgetUpperbound(scip), solution->getObjectiveFunctionValue(), SCIPfeastol(scip) ) );
1622 fprintf(solutionFile,
"*** Rejected Solution ***\n");
1623 SCIP_CALL_ABORT(SCIPprintSol(scip, newsol, solutionFile, FALSE));
1624 if( transSolutionFile )
1626 fprintf(transSolutionFile,
"*** Rejected Solution ***\n");
1627 SCIP_CALL_ABORT(SCIPprintTransSol(scip, newsol, transSolutionFile, FALSE));
1633 std::cout <<
"Current scip primal value = " << SCIPgetPrimalbound(scip) << std::endl;
1635 std::cout <<
"Initiator did not accept solution!" << std::endl;
1638 SCIP_CALL_ABORT( SCIPfreeSol(scip, &newsol) );
1640 paraComm->unlockApp();
1648 ScipParaInitiator::sendSolverInitializationMessage(
1651 assert(scipDiffParamSetRoot && scipDiffParamSet);
1652 scipDiffParamSetRoot->bcast(paraComm, 0);
1653 scipDiffParamSet->bcast(paraComm, 0);
1654 int warmStarted = 0;
1655 if( isWarmStarted() )
1659 paraComm->bcast(&warmStarted,1,
ParaINT, 0);
1660 double incumbentValue;
1663 incumbentValue = solution->getObjectiveFunctionValue();
1667 SCIP_SOL *sol = SCIPgetBestSol(scip);
1670 int nVars = SCIPgetNVars(scip);
1671 SCIP_VAR **vars = SCIPgetVars(scip);
1672 SCIP_Real *vals =
new SCIP_Real[nVars];
1673 SCIP_CALL_ABORT( SCIPgetSolVals(scip, sol, nVars, vars, vals) );
1675 solution = scipParaComm->createScipParaSolution(
1677 SCIPgetSolTransObj(scip,sol),
1683 incumbentValue = solution->getObjectiveFunctionValue();
1687 incumbentValue = DBL_MAX;
1690 paraComm->bcast(&incumbentValue, 1,
ParaDOUBLE, 0);
1694 int solutionExists = 0;
1695 paraComm->bcast(&solutionExists, 1,
ParaINT, 0);
1703 int solutionExists = 0;
1707 paraComm->bcast(&solutionExists, 1,
ParaINT, 0);
1708 solution->bcast(paraComm, 0);
1712 paraComm->bcast(&solutionExists, 1,
ParaINT, 0);
1722 assert( instance->getNVars() > 0 );
1723 assert( instance->getVarIndexRange() > 0 );
1725 tightenedVarLbs =
new double[instance->getVarIndexRange()];
1726 tightenedVarUbs =
new double[instance->getVarIndexRange()];
1727 for(
int i = 0; i < instance->getVarIndexRange(); i++ )
1729 tightenedVarLbs[i] = -DBL_MAX;
1730 tightenedVarUbs[i] = DBL_MAX;
1738 ScipParaInitiator::getAbsgap(
1739 double dualBoundValue
1742 if( !solution )
return SCIPinfinity(scip);
1743 SCIP_Real primalbound = instance->convertToExternalValue(solution->getObjectiveFunctionValue());
1744 SCIP_Real dualbound = instance->convertToExternalValue(dualBoundValue);
1745 return REALABS((primalbound - dualbound));
1750 ScipParaInitiator::getGap(
1751 double dualBoundValue
1754 if( !solution )
return SCIPinfinity(scip);
1755 SCIP_Real primalbound = instance->convertToExternalValue(solution->getObjectiveFunctionValue());
1756 SCIP_Real dualbound = instance->convertToExternalValue(dualBoundValue);
1758 if( SCIPisEQ(scip, primalbound, dualbound) )
1760 else if( SCIPisZero(scip, dualbound)
1761 || SCIPisZero(scip, primalbound)
1762 || SCIPisInfinity(scip,
REALABS(primalbound))
1763 || SCIPisInfinity(scip,
REALABS(dualbound))
1764 || primalbound * dualbound < 0.0 )
1765 return SCIPinfinity(scip);
1772 ScipParaInitiator::getEpsilon(
1776 SCIP_CALL_ABORT( SCIPgetRealParam(scip,
"numerics/epsilon", &epsilon));
1781 ScipParaInitiator::writeSolution(
1782 const std::string& message
1785 std::ostringstream osold;
1786 if( message ==
"Final Solution" )
1788 #ifndef SCIP_THREADSAFE_MESSAGEHDLRS 1789 if( paraParams->getBoolParamValue(
Quiet) )
1791 SCIPmessageSetDefaultHandler();
1794 if( solvedAtInit || (!paraParams->getBoolParamValue(
Quiet)) )
1796 fprintf(solutionFile,
"[ Final Solution ]\n");
1798 if( transSolutionFile )
1800 fprintf(transSolutionFile,
"[ Final Solution ]\n");
1803 else if ( message ==
"Updated" )
1805 assert( solutionFileName || (paraParams->getBoolParamValue(
Quiet) && !solutionFileName ) );
1806 fclose(solutionFile);
1807 std::ostringstream os;
1808 if( solutionFileName )
1810 osold << solutionFileName <<
".old";
1811 os << solutionFileName;
1816 osold << instance->getProbName() <<
".sol.old";
1818 os << instance->getProbName() <<
".sol";
1821 if( rename(os.str().c_str(), osold.str().c_str()) )
1823 std::cerr <<
"Rename falied from " <<
"File Name: " << os.str().c_str() <<
" to " << osold.str().c_str() << std::endl;
1826 solutionFile = fopen(os.str().c_str(),
"a");
1827 fprintf(solutionFile,
"[ Final Solution ]\n");
1831 fprintf(solutionFile,
"%s\n",message.c_str());
1832 if( transSolutionFile )
1834 fprintf(transSolutionFile,
"%s\n", message.c_str());
1837 SCIP_SOL* sol = SCIPgetBestSol(scip);
1840 if( solvedAtInit || (!(message ==
"Final Solution")) || (!paraParams->getBoolParamValue(
Quiet)) )
1842 SCIP_CALL_ABORT( SCIPprintBestSol( scip, solutionFile, FALSE) );
1844 if( transSolutionFile )
1846 if( SCIPsolGetOrigin(sol) != SCIP_SOLORIGIN_ORIGINAL )
1851 SCIP_CALL_ABORT( SCIPprintBestSol( scipInstance->
getParaInstanceScip(), transSolutionFile, FALSE) );
1855 SCIP_CALL_ABORT( SCIPprintBestTransSol( scip, transSolutionFile, FALSE) );
1860 fprintf(transSolutionFile,
"best solution is defined in original space - cannot print it as transformed solution\n");
1872 fprintf(solutionFile,
"No Solution\n");
1873 if( transSolutionFile )
1875 fprintf(transSolutionFile,
"No Solution\n");
1878 if ( message ==
"Updated" )
1880 remove(osold.str().c_str());
1885 ScipParaInitiator::writeParaInstance(
1886 const std::string& filename
1889 FILE *file = fopen(filename.c_str(),
"a");
1892 std::cout <<
"file : " << filename <<
"cannot open." << std::endl;
1898 SCIP_CALL_ABORT( SCIPprintOrigProblem(scipInstance->
getParaInstanceScip(), file,
"lp", FALSE) );
1902 SCIP_CALL_ABORT( SCIPprintTransProblem(scip, file,
"lp", FALSE) );
1908 ScipParaInitiator::writeSolverParameters(
1912 if( scipDiffParamSetRoot->nDiffParams() == 0 )
1914 *os <<
"[ SCIP parameters for root Solver are all default values ]" << std::endl;
1918 *os <<
"[ Not default SCIP parameters for root Solver are as follows ]" << std::endl;
1919 *os << scipDiffParamSetRoot->toString();
1922 if( scipDiffParamSet->nDiffParams() == 0 )
1924 *os <<
"[ SCIP parameters for NOT root Solvers are all default values ]" << std::endl;
1928 *os <<
"[ Not default SCIP parameters for NOT root Solvers are as follows ]" << std::endl;
1929 *os << scipDiffParamSet->toString();
1937 ScipParaInitiator::writeCheckpointSolution(
1938 const std::string& filename
1941 gzstream::ogzstream checkpointSolutionStream;
1942 checkpointSolutionStream.open(filename.c_str(), std::ios::out | std::ios::binary);
1943 if( !checkpointSolutionStream )
1945 std::cout <<
"Checkpoint file for solution cannot open. file name = " << filename << std::endl;
1949 solution->write(checkpointSolutionStream);
1950 checkpointSolutionStream.close();
1956 ScipParaInitiator::readSolutionFromCheckpointFile(
1957 char *afterCheckpointingSolutionFileName
1960 char tempSolutionFileName[SCIP_MAXSTRLEN];
1961 (void) SCIPsnprintf(tempSolutionFileName, SCIP_MAXSTRLEN,
"%s_solution.gz", prefixWarm);
1962 gzstream::igzstream checkpointSolutionStream;
1963 checkpointSolutionStream.open(tempSolutionFileName, std::ios::in | std::ios::binary);
1964 if( !checkpointSolutionStream )
1966 std::cout <<
"checkpoint solution file cannot open: file name = " << tempSolutionFileName << std::endl;
1972 if( sol->read(paraComm, checkpointSolutionStream) )
1987 solution =
dynamic_cast<ScipParaSolution*
>(paraComm->createParaSolution());
1988 if( !solution->read(paraComm, checkpointSolutionStream) )
1992 checkpointSolutionStream.close();
1995 checkpointSolutionStream.close();
1998 if( !tryToSetIncumbentSolution(dynamic_cast<BbParaSolution *>(solution->clone(paraComm)),
true) )
2000 std::cout <<
"***** Given solution is wrong! ***************************" << std::endl;
2001 std::cout <<
"***** If the solution was given from checkpoint file, ***" << std::endl;
2002 std::cout <<
"***** it might be generated in original problem space **" << std::endl;
2003 std::cout <<
"***** Only primal value is used. *************************" << std::endl;
2004 std::cout <<
"***** You should better to use -isol option. ************" << std::endl;
2005 std::cout <<
"***** Or, better to use no distribute solution option. ***" << std::endl;
2010 checkpointSolutionStream.open(afterCheckpointingSolutionFileName, std::ios::in | std::ios::binary);
2011 if( checkpointSolutionStream )
2015 if( sol->read(paraComm, checkpointSolutionStream) )
2020 if( tryToSetIncumbentSolution(dynamic_cast<BbParaSolution *>(solution->clone(paraComm)),
true) )
2022 std::cout <<
"***** After checkpoint solution is RIGHT! ****************" << std::endl;
2031 if( tryToSetIncumbentSolution(dynamic_cast<BbParaSolution *>(solution->clone(paraComm)),
true) )
2033 std::cout <<
"***** After checkpoint solution is RIGHT! ****************" << std::endl;
2042 checkpointSolutionStream.close();
2058 ScipParaInitiator::generateRacingRampUpParameterSets(
2069 for(
int n = 1; n < nParamSets + 1 ; n++ )
2071 std::ostringstream oss;
2074 << std::setfill(
'0') << std::setw(5)
2078 SCIP_CALL_ABORT( SCIPresetParams(scip) );
2079 if( SCIPreadParams(scip, oss.str().c_str()) != SCIP_OKAY )
2081 std::cout <<
"Cannot read racing parameter file = " << oss.str().c_str() << std::endl;
2085 racingScipDiffParamSet = scipParaComm->createScipDiffParamSet(scip);
2086 racingRampUpParamSets[n-1] = scipParaComm->createScipParaRacingRampUpParamSet(
2093 racingScipDiffParamSet
2095 SCIP_CALL_ABORT( SCIPresetParams(scip) );
2100 if( racingSettingsName )
2102 SCIP_CALL_ABORT( SCIPresetParams(scip) );
2103 SCIP_CALL_ABORT( SCIPreadParams(scip, racingSettingsName) );
2116 #if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) ) 2129 #if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) ) 2135 if( racingSettingsName )
2137 racingScipDiffParamSet = scipParaComm->createScipDiffParamSet(scip);
2139 racingRampUpParamSets[n] = scipParaComm->createScipParaRacingRampUpParamSet(
2146 racingScipDiffParamSet
2151 if( n >= nParamSets )
return;
2154 if( racingSettingsName )
2156 SCIP_CALL_ABORT( SCIPresetParams(scip) );
2163 ScipParaInitiator::getStatus(
2166 SCIP_SOL* sol = SCIPgetBestSol(scip);
2169 return std::string(
"solution found exist");
2173 return std::string(
"no solution");
2179 ScipParaInitiator::printSolverVersion(
2183 #ifndef SCIP_THREADSAFE_MESSAGEHDLRS 2184 SCIPprintVersion( NULL );
2186 SCIPprintVersion( scip, NULL );
2189 SCIPprintExternalCodes(scip, NULL);
2194 ScipParaInitiator::accumulateInitialStat(
2212 ScipParaInitiator::setInitialStatOnDiffSubproblem(
2232 ScipParaInitiator::setFinalSolverStatus(
2241 ScipParaInitiator::setNumberOfNodesSolved(
2250 ScipParaInitiator::setDualBound(
2254 if( bound > finalDualBound )
2256 finalDualBound = bound;
2262 ScipParaInitiator::outputFinalSolverStatistics(
2274 *os <<
"SCIP Status : ";
2277 switch ( finalState )
2280 *os <<
"initial nodes were generated" << std::endl;
2286 *os <<
"solving was interrupted [hard time limit reached]" << std::endl;
2289 *os <<
"solving was interrupted [memory limit reached]" << std::endl;
2292 *os <<
"solving was interrupted [given gap reached]" << std::endl;
2295 *os <<
"solving was interrupted" << std::endl;
2298 if( SCIPgetNSols(scip) > 0 )
2300 *os <<
"problem is solved" << std::endl;
2304 *os <<
"problem is solved [infeasible]" << std::endl;
2308 *os <<
"requested subproblems are solved" << std::endl;
2314 *os <<
"Total Time : " << time << std::endl;
2315 *os <<
" solving : " << time << std::endl;
2316 *os <<
" presolving : " << SCIPgetPresolvingTime(scip) <<
" (included in solving)" << std::endl;
2317 *os <<
"B&B Tree :" << std::endl;
2318 *os <<
" nodes (total) : " << nSolved << std::endl;
2319 *os <<
"Solution :" << std::endl;
2320 *os <<
" Solutions found : " << SCIPgetNSols(scip) << std::endl;
2321 SCIP_Real primalbound = SCIPinfinity(scip);
2327 if( SCIPgetNSols(scip) != 0 )
2329 primalbound = SCIPgetPrimalbound(scip);
2333 if( solution && solution->getNVars() > 0 )
2335 primalbound = solution->getObjectiveFunctionValue();
2342 primalbound = objlimit;
2346 *os <<
" Primal Bound : ";
2347 if( SCIPisInfinity(scip,
REALABS(primalbound) ) )
2349 *os <<
" -" << std::endl;
2353 (*os).setf(std::ios::showpos);
2354 *os << std::scientific << std::showpoint << std::setprecision(14) << primalbound << std::endl;
2355 (*os).unsetf(std::ios::showpos);
2358 finalDualBound = instance->convertToExternalValue(finalDualBound);
2359 SCIP_Real finalGap = 0.0;
2360 if( SCIPisEQ(scip, primalbound, finalDualBound) )
2362 else if( SCIPisZero(scip, finalDualBound)
2363 || SCIPisZero(scip, primalbound)
2364 || SCIPisInfinity(scip,
REALABS(primalbound))
2365 || SCIPisInfinity(scip,
REALABS(finalDualBound))
2366 || primalbound * finalDualBound < 0.0 )
2367 finalGap = SCIPinfinity(scip);
2369 finalGap =
REALABS((primalbound - finalDualBound)/MIN(
REALABS(finalDualBound),
REALABS(primalbound)));
2371 #if SCIP_VERSION > 302 || ( SCIP_VERSION == 302 && SCIP_SUBVERSION == 1 ) 2372 *os <<
" Dual Bound : ";
2374 *os <<
"Dual Bound : ";
2376 if( SCIPisInfinity(scip,
REALABS(finalDualBound) ) )
2377 *os <<
" -" << std::endl;
2380 (*os).setf(std::ios::showpos);
2381 *os << std::scientific << std::showpoint << std::setprecision(14)
2382 << finalDualBound << std::endl;
2383 (*os).unsetf(std::ios::showpos);
2386 if( SCIPgetNSols(scip) == 0 )
2388 *os <<
" -" << std::endl;
2390 else if( SCIPisInfinity(scip, finalGap ) )
2391 *os <<
" infinite" << std::endl;
2394 *os << std::fixed << std::setprecision(5) << 100.0 * finalGap <<
" %" << std::endl;
2396 if( finalGap > SCIPepsilon(scip) && !SCIPisInfinity(scip,
REALABS(primalbound) ) )
2398 *os << std::scientific <<
"* Warning: final gap: " << finalGap <<
" is greater than SCIPepsilon: " << SCIPepsilon(scip) << std::endl;
2402 ( finalState ==
ProblemWasSolved && ( SCIPgetNSols(scip) == 0 || ( SCIPgetNSols(scip) != 0 ) ) ) );
2406 userPlugins->writeUserSolution(scip, paraComm->getSize()-1, finalDualBound);
2411 ScipParaInitiator::outputProblemInfo(
2412 int *nNonLinearConsHdlrs
2415 std::cout <<
"Original Problem :" << std::endl;
2416 std::cout <<
" Problem name : " << SCIPgetProbName(scip) << std::endl;
2417 std::cout <<
" Variables : " << SCIPgetNOrigVars(scip)
2418 <<
" (" << SCIPgetNOrigBinVars(scip) <<
" binary, " 2419 << SCIPgetNOrigIntVars(scip) <<
" integer, " 2420 << SCIPgetNOrigImplVars(scip) <<
" implicit integer, " 2421 << SCIPgetNOrigContVars(scip) <<
" continuous)" << std::endl;
2422 std::cout <<
" Constraints : " << SCIPgetNOrigConss(scip) << std::endl;
2423 std::cout <<
" Objective sense : " << (SCIPgetObjsense(scip) == SCIP_OBJSENSE_MINIMIZE ?
"minimize" :
"maximize") << std::endl;
2424 std::cout <<
"Presolved Problem :" << std::endl;
2425 std::cout <<
" Variables : " << SCIPgetNVars(scip)
2426 <<
" (" << SCIPgetNBinVars(scip) <<
" binary, " 2427 << SCIPgetNIntVars(scip) <<
" integer, " 2428 << SCIPgetNImplVars(scip) <<
" implicit integer, " 2429 << SCIPgetNContVars(scip) <<
" continuous)" << std::endl;
2430 std::cout <<
" Constraints : " << SCIPgetNConss(scip) << std::endl;
2432 std::cout <<
"Constraints : Number" << std::endl;
2433 for(
int i = 0; i < SCIPgetNConshdlrs(scip); ++i )
2435 SCIP_CONSHDLR* conshdlr;
2436 int startnactiveconss;
2437 int maxnactiveconss;
2438 conshdlr = SCIPgetConshdlrs(scip)[i];
2439 startnactiveconss = SCIPconshdlrGetStartNActiveConss(conshdlr);
2440 maxnactiveconss = SCIPconshdlrGetMaxNActiveConss(conshdlr);
2441 if( startnactiveconss > 0 )
2443 std::cout <<
" " << std::setw(17) << std::left << SCIPconshdlrGetName(conshdlr) <<
": " 2444 << startnactiveconss << ( maxnactiveconss > startnactiveconss ?
'+' :
' ') << std::endl;
2445 if ( std::string(SCIPconshdlrGetName(conshdlr)) != std::string(
"linear") )
2447 *nNonLinearConsHdlrs += startnactiveconss;
2454 ScipParaInitiator::onlyLinearConsHandler(
2457 for(
int i = 0; i < SCIPgetNConss(scip); ++i )
2459 SCIP_CONS** conss = SCIPgetConss(scip);
2460 SCIP_CONSHDLR* conshdlr = SCIPconsGetHdlr(conss[i]);
2461 if( std::string(SCIPconshdlrGetName(conshdlr)) != std::string(
"linear") )
2480 ScipParaInitiator::readUgsIncumbentSolution(
2481 UGS::UgsParaCommMpi *ugsComm,
2485 UGS::UgsUpdateIncumbent *updateIncumbent =
new UGS::UgsUpdateIncumbent();
2486 updateIncumbent->receive(ugsComm->getMyComm(), source);
2488 if( ( instance->getOrigObjSense() == SCIP_OBJSENSE_MINIMIZE && (convertToExternalValue(solution->getObjectiveFunctionValue()) - updateIncumbent->getObjective() ) >
MINEPSILON ) ||
2489 ( instance->getOrigObjSense() == SCIP_OBJSENSE_MAXIMIZE && ( updateIncumbent->getObjective() - convertToExternalValue(solution->getObjectiveFunctionValue()) ) >
MINEPSILON ) )
2493 std::ostringstream s;
2494 s << ugsComm->getSolverName(updateIncumbent->getUpdatedSolverId()) <<
"-" << updateIncumbent->getSeqNumber() <<
".sol";
2496 SCIP_CALL_ABORT( SCIPcreateOrigSol(scip, &origSol, NULL) );
2497 SCIP_Bool partial = FALSE;
2498 SCIP_Bool error = FALSE;
2499 SCIP_CALL_ABORT( SCIPreadSolFile(scip, s.str().c_str(), origSol, FALSE, &partial, &error ) );
2505 if( solution )
delete solution;
2506 if( (!partial) && (!error) )
2508 SCIP_Bool stored = FALSE;
2509 SCIP_CALL_ABORT( SCIPtrySol(scip, origSol, FALSE, TRUE, TRUE, TRUE, FALSE, &stored) );
2515 SCIP_SOL *sol = SCIPgetBestSol(scip);
2516 int nVars = SCIPgetNVars(scip);
2517 SCIP_VAR **vars = SCIPgetVars(scip);
2518 SCIP_Real *vals =
new SCIP_Real[nVars];
2519 SCIP_CALL_ABORT( SCIPgetSolVals(scip, sol, nVars, vars, vals) );
2520 solution = scipParaComm->createScipParaSolution(
2522 SCIPgetSolTransObj(scip, sol),
2531 solution = scipParaComm->createScipParaSolution(
2533 convertToInternalValue(updateIncumbent->getObjective()),
2542 solution = scipParaComm->createScipParaSolution(
2544 convertToInternalValue(updateIncumbent->getObjective()),
2551 SCIP_CALL_ABORT( SCIPfreeSol(scip, &origSol) );
2553 delete updateIncumbent;
2560 delete updateIncumbent;
2567 ScipParaInitiator::writeUgsIncumbentSolution(
2568 UGS::UgsParaCommMpi *ugsComm
2573 std::ostringstream s;
2574 s << ugsComm->getMySolverName() <<
"-" << seqNumber <<
".sol";
2575 FILE *fp = fopen(s.str().c_str(),
"w");
2578 fprintf (stderr,
"Cannot open solution file to write. File name = %s\n", s.str().c_str());
2582 SCIP_SOL* sol = SCIPgetBestSol(scip);
2587 SCIP_CALL_ABORT( SCIPprintSol(scip, sol, fp, TRUE) );
2591 UGS::UgsUpdateIncumbent *uui =
new UGS::UgsUpdateIncumbent(ugsComm->getMySolverId(), seqNumber, convertToExternalValue(solution->getObjectiveFunctionValue()) );
2592 uui->send(ugsComm->getMyComm(),0);
initial nodes were generated
#define SCIP_PRESOLVIG_MEMORY_FACTOR
ParaInstance extenstion for SCIP solver.
static const int LogSolvingStatusFilePath
void accumulateOn(SCIP *scip)
void setObjectiveFuntionValue(SCIP_Real val)
int getOrigProbIndex(int index)
double getObjectiveFunctionValue()
static const int TryNBranchingOrderInRacing
static const int RacingParamsDirPath
static const int NMaxRacingBaseParameters
static const int RacingRampUpTerminationCriteria
static const int SolverSettingsExceptRootNode
static const int TryNVariablegOrderInRacing
void setValue(int i, SCIP_Real val)
int indexAmongSolvers(int index)
void getSolValuesForOriginalProblem(ScipParaSolution *sol, SCIP_Real *vals)
requested subproblem was solved
#define PARA_COMM_CALL(paracommcall)
SCIP * getParaInstanceScip()
static const int UseRootNodeCuts
static const int ParaDOUBLE
static const int SolverSettingsAtRacing
FinalSolverState
Final status of computation.
void setUserPlugins(ParaInitiator *initiator)
#define SCIP_MEMORY_COPY_FACTOR
static const int NoUpperBoundTransferInRacing
hard time limit is reached
#define THROW_LOGICAL_ERROR1(msg1)
static const int SolutionFilePath
given gap is reached for the computation
long long virtualMemUsedAtLc
Class for the difference between instance and subproblem.
static const int CheckFeasibilityInLC
memory limit is reached in a solver
static const int MaxNRacingParamSetSeed
void addInitialBranchVarStats(int minDepth, int maxDepth, SCIP *scip)
static const int InstanceTransferMethod
computing was interrupted
static const int DistributeBestPrimalSolution
static const int OutputPresolvedInstance
SCIP message handler for ParaSCIP and FiberSCIP.
static const int MemoryLimit
bool isOriginalIndeciesMap()
static const int StopRacingNumberOfNodesLeft
#define SCIP_FIXED_MEMORY_FACTOR
static const int StopRacingTimeLimit
class for initial statistics collecting after racing
static const int RampUpPhaseProcess
static const int CommunicateTighterBoundsInRacing
static const int TimeLimit
double memoryLimitOfSolverSCIP
ParaInitiator extension for SCIP solver.
class ParaRacingRampUpParamSet (parameter set for racing ramp-up)
static const int SolverSettingsForInitialPresolving
static const int NoPreprocessingInLC
ParaInitialStat extension for SCIP solver.
static const int SolverSettingsAtRootNode
#define DEF_SCIP_PARA_COMM(scip_para_comm, comm)
#define THROW_LOGICAL_ERROR3(msg1, msg2, msg3)