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_VERSION == 211 && SCIP_SUBVERSION == 0
69 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, *targetscip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
70 TRUE, TRUE, TRUE, TRUE, &success) );
72 #if SCIP_APIVERSION >= 100
73 #if SCIP_APIVERSION >= 101
74 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, *targetscip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
75 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
77 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, *targetscip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
78 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
80 #elif SCIP_APIVERSION >= 17
81 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, *targetscip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
82 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
84 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, *targetscip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
85 TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
88 SCIP_CALL_ABORT( SCIPcopyParamSettings(
scip, *targetscip) );
91 SCIP_HASHMAP* varmap = 0;
92 if( SCIPgetNVars(
scip) > 0 )
94 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(*targetscip), SCIPgetNVars(
scip)) );
96 SCIP_HASHMAP* conssmap = 0;
97 if( SCIPgetNConss(
scip) > 0 )
99 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(*targetscip), SCIPgetNConss(
scip)) );
105 (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN,
"%s", SCIPgetProbName(
scip));
108 SCIP_CALL_ABORT( SCIPcopyProb(
scip, *targetscip, varmap, conssmap, TRUE, probname) );
111 if( SCIPgetNVars(
scip) > 0 )
113#if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) )
114 SCIP_CALL_ABORT( SCIPcopyVars(
scip, *targetscip, varmap, conssmap, TRUE) );
116 SCIP_CALL_ABORT( SCIPcopyVars(
scip, *targetscip, varmap, conssmap, NULL, NULL, 0, TRUE) );
119 if( SCIPgetNConss(
scip) > 0 )
121 SCIP_CALL_ABORT( SCIPcopyConss(
scip, *targetscip, varmap, conssmap, TRUE, FALSE, &success) );
124#if SCIP_APIVERSION > 39
130 SCIP_CALL_ABORT( SCIPcopyBenders(
scip, *targetscip, NULL, TRUE, &valid) );
136 if( SCIPgetNConss(
scip) > 0 )
138 SCIPhashmapFree(&conssmap);
140 if( SCIPgetNVars(
scip) > 0 )
142 SCIPhashmapFree(&varmap);
144 std::cerr <<
"Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
149 if( SCIPgetNConss(
scip) > 0 )
151 SCIPhashmapFree(&conssmap);
153 if( SCIPgetNVars(
scip) > 0 )
155 SCIPhashmapFree(&varmap);
171 if( commTh->getRank() == root )
173 for(
int i = 0; i < commTh->getSize(); i++ )
178 SCIP_CALL_ABORT( SCIPcreate(&newScip) );
195 if( commTh->getRank() == root )
199 SCIP_Bool success = TRUE;
202 SCIP_CALL_ABORT( SCIPcreate(&tempScip) );
205#if SCIP_VERSION == 211 && SCIP_SUBVERSION == 0
206 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, tempScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
207 TRUE, TRUE, TRUE, TRUE, &success) );
209 #if SCIP_APIVERSION >= 100
210 #if SCIP_APIVERSION >= 101
211 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, tempScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
212 TRUE, TRUE, 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, TRUE, TRUE, FALSE, &success) );
217 #elif SCIP_APIVERSION >= 17
218 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, tempScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
219 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
221 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, tempScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
222 TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
225 SCIP_CALL_ABORT( SCIPcopyParamSettings(
scip, tempScip) );
228 SCIP_HASHMAP* varmap = 0;
229 if( SCIPgetNVars(
scip) > 0 )
231 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(tempScip), SCIPgetNVars(
scip)) );
233 SCIP_HASHMAP* conssmap = 0;
234 if( SCIPgetNConss(
scip) > 0 )
236 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(tempScip), SCIPgetNConss(
scip)) );
239 SCIP_CALL_ABORT( SCIPcopyProb(
scip, tempScip, varmap, conssmap, TRUE,
"") );
243 if( SCIPgetNVars(
scip) > 0 )
245#if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) )
246 SCIP_CALL_ABORT( SCIPcopyVars(
scip, tempScip, varmap, conssmap, TRUE) );
248 SCIP_CALL_ABORT( SCIPcopyVars(
scip, tempScip, varmap, conssmap, NULL, NULL, 0, TRUE) );
251 if( SCIPgetNConss(
scip) > 0 )
253 SCIP_CALL_ABORT( SCIPcopyConss(
scip, tempScip, varmap, conssmap, TRUE, FALSE, &success) );
256#if SCIP_APIVERSION > 39
262 SCIP_CALL_ABORT( SCIPcopyBenders(
scip, tempScip, NULL, TRUE, &valid) );
269 if( SCIPgetNConss(
scip) > 0 )
271 SCIPhashmapFree(&conssmap);
273 if( SCIPgetNVars(
scip) > 0 )
275 SCIPhashmapFree(&varmap);
278 std::cerr <<
"Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
284 int n = SCIPgetNVars(tempScip);
288 if( SCIPgetNConss(
scip) > 0 )
290 SCIPhashmapFree(&conssmap);
292 if( SCIPgetNVars(
scip) > 0 )
294 SCIPhashmapFree(&varmap);
297 std::cout <<
"** ParaScipInstance copy does not increase the number of variables. **" << std::endl;
302 std::cout <<
"** ParaScipInstance copy increased the number of variables. **" << std::endl;
344 for(
int i = 0; i < commTh->getSize(); i++ )
353 std::unique_lock<std::mutex> lk(
cv_m);
354 cv.wait(lk, [commTh]{
return nInitSolvers >= (commTh->getSize()-1); });
358 for(
int i = 0; i < commTh->getSize(); i++ )
380 SCIP_CALL_ABORT( SCIPcreate(&
scip) );
381 char probname[SCIP_MAXSTRLEN];
383 assert(received != NULL);
384 assert(
scip != NULL);
385 SCIP_Bool success = TRUE;
388#if SCIP_VERSION == 211 && SCIP_SUBVERSION == 0
389 SCIP_CALL_ABORT( SCIPcopyPlugins(received,
scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
390 TRUE, TRUE, TRUE, TRUE, &success) );
392 #if SCIP_APIVERSION >= 100
393 #if SCIP_APIVERSION >= 101
394 SCIP_CALL_ABORT( SCIPcopyPlugins(received,
scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
395 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
397 SCIP_CALL_ABORT( SCIPcopyPlugins(received,
scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
398 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
400 #elif SCIP_APIVERSION >= 17
401 SCIP_CALL_ABORT( SCIPcopyPlugins(received,
scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
402 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
404 SCIP_CALL_ABORT( SCIPcopyPlugins(received,
scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
405 TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
411 std::cout <<
"Error in SCIPcopyPlugins" << std::endl;
414 SCIP_CALL_ABORT( SCIPcopyParamSettings(received,
scip) );
423 SCIP_HASHMAP* varmap = 0;
424 if( SCIPgetNVars(received) > 0 )
426 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(
scip), SCIPgetNVars(received)) );
428 SCIP_HASHMAP* conssmap = 0;
429 if( SCIPgetNConss(received) > 0 )
431 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(
scip), SCIPgetNConss(received)) );
437 (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN,
"%s", SCIPgetProbName(received));
440 SCIP_CALL_ABORT( SCIPcopyProb(received,
scip, varmap, conssmap, TRUE, probname) );
444 if( SCIPgetNVars(received) > 0 )
446#if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) )
447 SCIP_CALL_ABORT( SCIPcopyVars(received,
scip, varmap, conssmap, TRUE) );
449 SCIP_CALL_ABORT( SCIPcopyVars(received,
scip, varmap, conssmap, NULL, NULL, 0, TRUE) );
452 if( SCIPgetNConss(received) > 0 )
454 SCIP_CALL_ABORT( SCIPcopyConss(received,
scip, varmap, conssmap, TRUE, FALSE, &success) );
457#if SCIP_APIVERSION > 39
463 SCIP_CALL_ABORT( SCIPcopyBenders(received,
scip, NULL, TRUE, &valid) );
469 std::lock_guard<std::mutex> lk(
cv_m);
475 if( SCIPgetNConss(received) > 0 )
477 SCIPhashmapFree(&conssmap);
479 if( SCIPgetNVars(received) > 0 )
481 SCIPhashmapFree(&varmap);
483 std::cerr <<
"Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
487 nVars = SCIPgetNVars(received);
489 int n = SCIPgetNVars(
scip);
494 assert(
nVars <= n );
504 for(
int i = 0; i < SCIPgetNTotalVars(
scip); i++ )
511 SCIP_VAR **srcVars = SCIPgetVars(received);
513 assert(SCIPgetNTotalVars(
scip) >= SCIPgetNVars(received));
519 for(
int i = 0; i < SCIPgetNVars(received); i++ )
521 SCIP_VAR* copyvar = (SCIP_VAR*)SCIPhashmapGetImage(varmap, (
void*)srcVars[i]);
555 if( SCIPgetNConss(received) > 0 )
557 SCIPhashmapFree(&conssmap);
559 if( SCIPgetNVars(received) > 0 )
561 SCIPhashmapFree(&varmap);
594 bool noPreprocessingInLC,
595 bool usetRootNodeCuts,
598 char *settingsNameLC,
616 if( method == 0 && SCIPgetStage(inScip) == SCIP_STAGE_INIT )
618 if( SCIPgetStage(
scip) == SCIP_STAGE_PROBLEM)
620 SCIP_CALL_ABORT( SCIPtransformProb(
scip));
622 if(
scip == inScip )
return;
627 std::cout <<
"* If you use check mechanism, you should check the following codes. *" << std::endl;
628 SCIP_Bool success = TRUE;
629 char probname[SCIP_MAXSTRLEN];
631#if SCIP_VERSION == 211 && SCIP_SUBVERSION == 0
632 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
633 TRUE, TRUE, TRUE, TRUE, &success) );
635 #if SCIP_APIVERSION >= 100
636 #if SCIP_APIVERSION >= 101
637 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
638 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
640 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
641 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
643 #elif SCIP_APIVERSION >= 17
644 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
645 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
647 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
648 TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
651 SCIP_CALL_ABORT( SCIPcopyParamSettings(
scip, inScip) );
654 SCIP_HASHMAP* varmap = 0;
655 if( SCIPgetNVars(
scip) > 0 )
657 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(inScip), SCIPgetNVars(
scip)) );
659 SCIP_HASHMAP* conssmap = 0;
660 if( SCIPgetNConss(
scip) > 0 )
662 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(inScip), SCIPgetNConss(
scip)) );
667 (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN,
"%s_%s", SCIPgetProbName(
scip),
"solver_created");
668 SCIP_CALL_ABORT( SCIPcreateProb(inScip, probname, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );
670 SCIP_CALL_ABORT( SCIPcopyProb(
scip, inScip, varmap, conssmap, TRUE, probname) );
673 if( SCIPgetNVars(
scip) > 0 )
675#if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) )
676 SCIP_CALL_ABORT( SCIPcopyVars(
scip, inScip, varmap, conssmap, TRUE) );
678 SCIP_CALL_ABORT( SCIPcopyVars(
scip, inScip, varmap, conssmap, NULL, NULL, 0, TRUE) );
681 if( SCIPgetNConss(
scip) > 0 )
683 SCIP_CALL_ABORT( SCIPcopyConss(
scip, inScip, varmap, conssmap, TRUE, FALSE, &success) );
686#if SCIP_APIVERSION > 39
692 SCIP_CALL_ABORT( SCIPcopyBenders(
scip, inScip, NULL, TRUE, &valid) );
698 if( SCIPgetNConss(
scip) > 0 )
700 SCIPhashmapFree(&conssmap);
702 if( SCIPgetNVars(
scip) > 0 )
704 SCIPhashmapFree(&varmap);
706 std::cerr <<
"Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
711 if( SCIPgetNConss(
scip) > 0 )
713 SCIPhashmapFree(&conssmap);
715 if( SCIPgetNVars(
scip) > 0 )
717 SCIPhashmapFree(&varmap);
722 std::cout <<
"You should use instance transfer method 0 or 1!" << std::endl;
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.