36#include <condition_variable>
40#include "scip/scipdefplugins.h"
52static std::condition_variable
cv;
57ScipParaInstance::copyScipEnvironment(
61 char probname[SCIP_MAXSTRLEN];
64 assert(*targetscip != NULL);
65 SCIP_Bool success = TRUE;
68#if SCIP_APIVERSION >= 131
69 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, *targetscip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
70 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
71#elif SCIP_APIVERSION >= 101
72 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, *targetscip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
73 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
74#elif SCIP_APIVERSION >= 100
75 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, *targetscip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
76 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
77#elif SCIP_APIVERSION >= 17
78 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, *targetscip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
79 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
81 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, *targetscip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
82 TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
84 SCIP_CALL_ABORT( SCIPcopyParamSettings(
scip, *targetscip) );
87 SCIP_HASHMAP* varmap = 0;
88 if( SCIPgetNVars(
scip) > 0 )
90 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(*targetscip), SCIPgetNVars(
scip)) );
92 SCIP_HASHMAP* conssmap = 0;
93 if( SCIPgetNConss(
scip) > 0 )
95 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(*targetscip), SCIPgetNConss(
scip)) );
101 (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN,
"%s", SCIPgetProbName(
scip));
104 SCIP_CALL_ABORT( SCIPcopyProb(
scip, *targetscip, varmap, conssmap, TRUE, probname) );
107 if( SCIPgetNVars(
scip) > 0 )
109#if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) )
110 SCIP_CALL_ABORT( SCIPcopyVars(
scip, *targetscip, varmap, conssmap, TRUE) );
112 SCIP_CALL_ABORT( SCIPcopyVars(
scip, *targetscip, varmap, conssmap, NULL, NULL, 0, TRUE) );
115 if( SCIPgetNConss(
scip) > 0 )
117 SCIP_CALL_ABORT( SCIPcopyConss(
scip, *targetscip, varmap, conssmap, TRUE, FALSE, &success) );
120#if SCIP_APIVERSION > 39
126 SCIP_CALL_ABORT( SCIPcopyBenders(
scip, *targetscip, NULL, TRUE, &valid) );
132 if( SCIPgetNConss(
scip) > 0 )
134 SCIPhashmapFree(&conssmap);
136 if( SCIPgetNVars(
scip) > 0 )
138 SCIPhashmapFree(&varmap);
140 std::cerr <<
"Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
145 if( SCIPgetNConss(
scip) > 0 )
147 SCIPhashmapFree(&conssmap);
149 if( SCIPgetNVars(
scip) > 0 )
151 SCIPhashmapFree(&varmap);
167 if( commTh->getRank() == root )
169 for(
int i = 0; i < commTh->getSize(); i++ )
174 SCIP_CALL_ABORT( SCIPcreate(&newScip) );
191 if( commTh->getRank() == root )
195 SCIP_Bool success = TRUE;
198 SCIP_CALL_ABORT( SCIPcreate(&tempScip) );
201#if SCIP_APIVERSION >= 131
202 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, tempScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
203 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
204#elif SCIP_APIVERSION >= 101
205 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, tempScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
206 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
207#elif SCIP_APIVERSION >= 100
208 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, tempScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
209 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
210#elif SCIP_APIVERSION >= 17
211 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, tempScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
212 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
214 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, tempScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
215 TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
217 SCIP_CALL_ABORT( SCIPcopyParamSettings(
scip, tempScip) );
220 SCIP_HASHMAP* varmap = 0;
221 if( SCIPgetNVars(
scip) > 0 )
223 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(tempScip), SCIPgetNVars(
scip)) );
225 SCIP_HASHMAP* conssmap = 0;
226 if( SCIPgetNConss(
scip) > 0 )
228 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(tempScip), SCIPgetNConss(
scip)) );
231 SCIP_CALL_ABORT( SCIPcopyProb(
scip, tempScip, varmap, conssmap, TRUE,
"") );
235 if( SCIPgetNVars(
scip) > 0 )
237#if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) )
238 SCIP_CALL_ABORT( SCIPcopyVars(
scip, tempScip, varmap, conssmap, TRUE) );
240 SCIP_CALL_ABORT( SCIPcopyVars(
scip, tempScip, varmap, conssmap, NULL, NULL, 0, TRUE) );
243 if( SCIPgetNConss(
scip) > 0 )
245 SCIP_CALL_ABORT( SCIPcopyConss(
scip, tempScip, varmap, conssmap, TRUE, FALSE, &success) );
248#if SCIP_APIVERSION > 39
254 SCIP_CALL_ABORT( SCIPcopyBenders(
scip, tempScip, NULL, TRUE, &valid) );
261 if( SCIPgetNConss(
scip) > 0 )
263 SCIPhashmapFree(&conssmap);
265 if( SCIPgetNVars(
scip) > 0 )
267 SCIPhashmapFree(&varmap);
270 std::cerr <<
"Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
276 int n = SCIPgetNVars(tempScip);
280 if( SCIPgetNConss(
scip) > 0 )
282 SCIPhashmapFree(&conssmap);
284 if( SCIPgetNVars(
scip) > 0 )
286 SCIPhashmapFree(&varmap);
289 SCIPinfoMessage(
scip, NULL,
"** ParaScipInstance copy does not increase the number of variables. **\n");
294 SCIPinfoMessage(
scip, NULL,
"** ParaScipInstance copy increased the number of variables. **\n");
297 if( SCIPgetNConss(
scip) > 0 )
299 SCIPhashmapFree(&conssmap);
301 if( SCIPgetNVars(
scip) > 0 )
303 SCIPhashmapFree(&varmap);
345 for(
int i = 0; i < commTh->getSize(); i++ )
354 std::unique_lock<std::mutex> lk(
cv_m);
355 cv.wait(lk, [commTh]{
return nInitSolvers >= (commTh->getSize()-1); });
359 for(
int i = 0; i < commTh->getSize(); i++ )
381 SCIP_CALL_ABORT( SCIPcreate(&
scip) );
382 char probname[SCIP_MAXSTRLEN];
384 assert(received != NULL);
385 assert(
scip != NULL);
386 SCIP_Bool success = TRUE;
389#if SCIP_APIVERSION >= 131
390 SCIP_CALL_ABORT( SCIPcopyPlugins(received,
scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
391 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
392#elif SCIP_APIVERSION >= 101
393 SCIP_CALL_ABORT( SCIPcopyPlugins(received,
scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
394 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
395#elif SCIP_APIVERSION >= 100
396 SCIP_CALL_ABORT( SCIPcopyPlugins(received,
scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
397 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
398#elif SCIP_APIVERSION >= 17
399 SCIP_CALL_ABORT( SCIPcopyPlugins(received,
scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
400 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
402 SCIP_CALL_ABORT( SCIPcopyPlugins(received,
scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
403 TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
408 SCIPerrorMessage(
"Error in SCIPcopyPlugins\n");
411 SCIP_CALL_ABORT( SCIPcopyParamSettings(received,
scip) );
420 SCIP_HASHMAP* varmap = 0;
421 if( SCIPgetNVars(received) > 0 )
423 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(
scip), SCIPgetNVars(received)) );
425 SCIP_HASHMAP* conssmap = 0;
426 if( SCIPgetNConss(received) > 0 )
428 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(
scip), SCIPgetNConss(received)) );
434 (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN,
"%s", SCIPgetProbName(received));
437 SCIP_CALL_ABORT( SCIPcopyProb(received,
scip, varmap, conssmap, TRUE, probname) );
441 if( SCIPgetNVars(received) > 0 )
443#if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) )
444 SCIP_CALL_ABORT( SCIPcopyVars(received,
scip, varmap, conssmap, TRUE) );
446 SCIP_CALL_ABORT( SCIPcopyVars(received,
scip, varmap, conssmap, NULL, NULL, 0, TRUE) );
449 if( SCIPgetNConss(received) > 0 )
451 SCIP_CALL_ABORT( SCIPcopyConss(received,
scip, varmap, conssmap, TRUE, FALSE, &success) );
454#if SCIP_APIVERSION > 39
460 SCIP_CALL_ABORT( SCIPcopyBenders(received,
scip, NULL, TRUE, &valid) );
466 std::lock_guard<std::mutex> lk(
cv_m);
472 if( SCIPgetNConss(received) > 0 )
474 SCIPhashmapFree(&conssmap);
476 if( SCIPgetNVars(received) > 0 )
478 SCIPhashmapFree(&varmap);
480 std::cerr <<
"Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
484 nVars = SCIPgetNVars(received);
486 int n = SCIPgetNVars(
scip);
491 assert(
nVars <= n );
501 for(
int i = 0; i < SCIPgetNTotalVars(
scip); i++ )
508 SCIP_VAR **srcVars = SCIPgetVars(received);
510 assert(SCIPgetNTotalVars(
scip) >= SCIPgetNVars(received));
516 for(
int i = 0; i < SCIPgetNVars(received); i++ )
518 SCIP_VAR* copyvar = (SCIP_VAR*)SCIPhashmapGetImage(varmap, (
void*)srcVars[i]);
552 if( SCIPgetNConss(received) > 0 )
554 SCIPhashmapFree(&conssmap);
556 if( SCIPgetNVars(received) > 0 )
558 SCIPhashmapFree(&varmap);
591 bool noPreprocessingInLC,
592 bool usetRootNodeCuts,
595 char *settingsNameLC,
613 if( method == 0 && SCIPgetStage(inScip) == SCIP_STAGE_INIT )
615 if( SCIPgetStage(
scip) == SCIP_STAGE_PROBLEM)
617 SCIP_CALL_ABORT( SCIPtransformProb(
scip));
619 if(
scip == inScip )
return;
624 SCIPinfoMessage(
scip, NULL,
"* If you use check mechanism, you should check the following codes. *\n");
625 SCIP_Bool success = TRUE;
626 char probname[SCIP_MAXSTRLEN];
628#if SCIP_APIVERSION >= 131
629 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
630 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, &success) );
631#elif SCIP_APIVERSION >= 101
632 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
633 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, &success) );
634#elif SCIP_APIVERSION >= 100
635 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
636 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, &success) );
637#elif SCIP_APIVERSION >= 17
638 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
639 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, &success) );
641 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
642 TRUE, TRUE, TRUE, TRUE, TRUE, &success) );
644 SCIP_CALL_ABORT( SCIPcopyParamSettings(
scip, inScip) );
647 SCIP_HASHMAP* varmap = 0;
648 if( SCIPgetNVars(
scip) > 0 )
650 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(inScip), SCIPgetNVars(
scip)) );
652 SCIP_HASHMAP* conssmap = 0;
653 if( SCIPgetNConss(
scip) > 0 )
655 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(inScip), SCIPgetNConss(
scip)) );
660 (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN,
"%s_%s", SCIPgetProbName(
scip),
"solver_created");
661 SCIP_CALL_ABORT( SCIPcreateProb(inScip, probname, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );
663 SCIP_CALL_ABORT( SCIPcopyProb(
scip, inScip, varmap, conssmap, TRUE, probname) );
666 if( SCIPgetNVars(
scip) > 0 )
668#if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) )
669 SCIP_CALL_ABORT( SCIPcopyVars(
scip, inScip, varmap, conssmap, TRUE) );
671 SCIP_CALL_ABORT( SCIPcopyVars(
scip, inScip, varmap, conssmap, NULL, NULL, 0, TRUE) );
674 if( SCIPgetNConss(
scip) > 0 )
676 SCIP_CALL_ABORT( SCIPcopyConss(
scip, inScip, varmap, conssmap, TRUE, FALSE, &success) );
679#if SCIP_APIVERSION > 39
685 SCIP_CALL_ABORT( SCIPcopyBenders(
scip, inScip, NULL, TRUE, &valid) );
691 if( SCIPgetNConss(
scip) > 0 )
693 SCIPhashmapFree(&conssmap);
695 if( SCIPgetNVars(
scip) > 0 )
697 SCIPhashmapFree(&varmap);
699 std::cerr <<
"Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
704 if( SCIPgetNConss(
scip) > 0 )
706 SCIPhashmapFree(&conssmap);
708 if( SCIPgetNVars(
scip) > 0 )
710 SCIPhashmapFree(&varmap);
715 SCIPinfoMessage(
scip, NULL,
"You should use instance transfer method 0 or 1!\n");
Base class of communicator for UG Framework.
int bcast(UG::ParaComm *comm, int rank, int method)
int * mapToSolverLocalIndecies
bool copyIncreasedVariables
int * mapToOriginalIndecies
void createProblem(SCIP *scip, int method, bool noPreprocessingInLC, bool usetRootNodeCuts, ScipDiffParamSet *scipDiffParamSetRoot, ScipDiffParamSet *scipDiffParamSet, char *settingsNameLC, char *isolname)
void copyScipEnvironment(SCIP **scip)
Base class of communicator object.
static ScipParaCommTh * comm
static const int ParaInstanceType
static const int ParaBYTE
static const int TagParaInstance
#define DEF_PARA_COMM(para_comm, comm)
#define PARA_COMM_CALL(paracommcall)
static std::condition_variable cv
static const char * PRESOLVED_INSTANCE
ScipParaInstance extension for threads communication.