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 >= 163
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, TRUE, FALSE, &success) );
71#elif SCIP_APIVERSION >= 131
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, TRUE, FALSE, &success) );
74#elif SCIP_APIVERSION >= 101
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, TRUE, FALSE, &success) );
77#elif SCIP_APIVERSION >= 100
78 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, *targetscip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
79 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) );
87 SCIP_CALL_ABORT( SCIPcopyParamSettings(
scip, *targetscip) );
90 SCIP_HASHMAP* varmap = 0;
91 if( SCIPgetNVars(
scip) > 0 )
93 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(*targetscip), SCIPgetNVars(
scip)) );
95 SCIP_HASHMAP* conssmap = 0;
96 if( SCIPgetNConss(
scip) > 0 )
98 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(*targetscip), SCIPgetNConss(
scip)) );
104 (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN,
"%s", SCIPgetProbName(
scip));
107 SCIP_CALL_ABORT( SCIPcopyProb(
scip, *targetscip, varmap, conssmap, TRUE, probname) );
110 if( SCIPgetNVars(
scip) > 0 )
112#if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) )
113 SCIP_CALL_ABORT( SCIPcopyVars(
scip, *targetscip, varmap, conssmap, TRUE) );
115 SCIP_CALL_ABORT( SCIPcopyVars(
scip, *targetscip, varmap, conssmap, NULL, NULL, 0, TRUE) );
118 if( SCIPgetNConss(
scip) > 0 )
120 SCIP_CALL_ABORT( SCIPcopyConss(
scip, *targetscip, varmap, conssmap, TRUE, FALSE, &success) );
123#if SCIP_APIVERSION > 39
129 SCIP_CALL_ABORT( SCIPcopyBenders(
scip, *targetscip, NULL, TRUE, &valid) );
135 if( SCIPgetNConss(
scip) > 0 )
137 SCIPhashmapFree(&conssmap);
139 if( SCIPgetNVars(
scip) > 0 )
141 SCIPhashmapFree(&varmap);
143 std::cerr <<
"Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
148 if( SCIPgetNConss(
scip) > 0 )
150 SCIPhashmapFree(&conssmap);
152 if( SCIPgetNVars(
scip) > 0 )
154 SCIPhashmapFree(&varmap);
170 if( commTh->getRank() == root )
172 for(
int i = 0; i < commTh->getSize(); i++ )
177 SCIP_CALL_ABORT( SCIPcreate(&newScip) );
194 if( commTh->getRank() == root )
198 SCIP_Bool success = TRUE;
201 SCIP_CALL_ABORT( SCIPcreate(&tempScip) );
204#if SCIP_APIVERSION >= 163
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, TRUE, TRUE, FALSE, &success) );
207#elif SCIP_APIVERSION >= 131
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, TRUE, TRUE, FALSE, &success) );
210#elif 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) );
213#elif SCIP_APIVERSION >= 100
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) );
216#elif SCIP_APIVERSION >= 17
217 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, tempScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
218 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
220 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, tempScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
221 TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
223 SCIP_CALL_ABORT( SCIPcopyParamSettings(
scip, tempScip) );
226 SCIP_HASHMAP* varmap = 0;
227 if( SCIPgetNVars(
scip) > 0 )
229 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(tempScip), SCIPgetNVars(
scip)) );
231 SCIP_HASHMAP* conssmap = 0;
232 if( SCIPgetNConss(
scip) > 0 )
234 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(tempScip), SCIPgetNConss(
scip)) );
237 SCIP_CALL_ABORT( SCIPcopyProb(
scip, tempScip, varmap, conssmap, TRUE,
"") );
241 if( SCIPgetNVars(
scip) > 0 )
243#if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) )
244 SCIP_CALL_ABORT( SCIPcopyVars(
scip, tempScip, varmap, conssmap, TRUE) );
246 SCIP_CALL_ABORT( SCIPcopyVars(
scip, tempScip, varmap, conssmap, NULL, NULL, 0, TRUE) );
249 if( SCIPgetNConss(
scip) > 0 )
251 SCIP_CALL_ABORT( SCIPcopyConss(
scip, tempScip, varmap, conssmap, TRUE, FALSE, &success) );
254#if SCIP_APIVERSION > 39
260 SCIP_CALL_ABORT( SCIPcopyBenders(
scip, tempScip, NULL, TRUE, &valid) );
267 if( SCIPgetNConss(
scip) > 0 )
269 SCIPhashmapFree(&conssmap);
271 if( SCIPgetNVars(
scip) > 0 )
273 SCIPhashmapFree(&varmap);
276 std::cerr <<
"Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
282 int n = SCIPgetNVars(tempScip);
286 if( SCIPgetNConss(
scip) > 0 )
288 SCIPhashmapFree(&conssmap);
290 if( SCIPgetNVars(
scip) > 0 )
292 SCIPhashmapFree(&varmap);
295 SCIPinfoMessage(
scip, NULL,
"** ParaScipInstance copy does not increase the number of variables. **\n");
300 SCIPinfoMessage(
scip, NULL,
"** ParaScipInstance copy increased the number of variables. **\n");
303 if( SCIPgetNConss(
scip) > 0 )
305 SCIPhashmapFree(&conssmap);
307 if( SCIPgetNVars(
scip) > 0 )
309 SCIPhashmapFree(&varmap);
351 for(
int i = 0; i < commTh->getSize(); i++ )
360 std::unique_lock<std::mutex> lk(
cv_m);
361 cv.wait(lk, [commTh]{
return nInitSolvers >= (commTh->getSize()-1); });
365 for(
int i = 0; i < commTh->getSize(); i++ )
387 SCIP_CALL_ABORT( SCIPcreate(&
scip) );
388 char probname[SCIP_MAXSTRLEN];
390 assert(received != NULL);
391 assert(
scip != NULL);
392 SCIP_Bool success = TRUE;
395#if SCIP_APIVERSION >= 163
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, TRUE, TRUE, TRUE, FALSE, &success) );
398#elif SCIP_APIVERSION >= 131
399 SCIP_CALL_ABORT( SCIPcopyPlugins(received,
scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
400 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
401#elif SCIP_APIVERSION >= 101
402 SCIP_CALL_ABORT( SCIPcopyPlugins(received,
scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
403 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
404#elif SCIP_APIVERSION >= 100
405 SCIP_CALL_ABORT( SCIPcopyPlugins(received,
scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
406 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
407#elif SCIP_APIVERSION >= 17
408 SCIP_CALL_ABORT( SCIPcopyPlugins(received,
scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
409 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
411 SCIP_CALL_ABORT( SCIPcopyPlugins(received,
scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
412 TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
417 SCIPerrorMessage(
"Error in SCIPcopyPlugins\n");
420 SCIP_CALL_ABORT( SCIPcopyParamSettings(received,
scip) );
429 SCIP_HASHMAP* varmap = 0;
430 if( SCIPgetNVars(received) > 0 )
432 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(
scip), SCIPgetNVars(received)) );
434 SCIP_HASHMAP* conssmap = 0;
435 if( SCIPgetNConss(received) > 0 )
437 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(
scip), SCIPgetNConss(received)) );
443 (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN,
"%s", SCIPgetProbName(received));
446 SCIP_CALL_ABORT( SCIPcopyProb(received,
scip, varmap, conssmap, TRUE, probname) );
450 if( SCIPgetNVars(received) > 0 )
452#if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) )
453 SCIP_CALL_ABORT( SCIPcopyVars(received,
scip, varmap, conssmap, TRUE) );
455 SCIP_CALL_ABORT( SCIPcopyVars(received,
scip, varmap, conssmap, NULL, NULL, 0, TRUE) );
458 if( SCIPgetNConss(received) > 0 )
460 SCIP_CALL_ABORT( SCIPcopyConss(received,
scip, varmap, conssmap, TRUE, FALSE, &success) );
463#if SCIP_APIVERSION > 39
469 SCIP_CALL_ABORT( SCIPcopyBenders(received,
scip, NULL, TRUE, &valid) );
475 std::lock_guard<std::mutex> lk(
cv_m);
481 if( SCIPgetNConss(received) > 0 )
483 SCIPhashmapFree(&conssmap);
485 if( SCIPgetNVars(received) > 0 )
487 SCIPhashmapFree(&varmap);
489 std::cerr <<
"Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
493 nVars = SCIPgetNVars(received);
495 int n = SCIPgetNVars(
scip);
500 assert(
nVars <= n );
510 for(
int i = 0; i < SCIPgetNTotalVars(
scip); i++ )
517 SCIP_VAR **srcVars = SCIPgetVars(received);
519 assert(SCIPgetNTotalVars(
scip) >= SCIPgetNVars(received));
525 for(
int i = 0; i < SCIPgetNVars(received); i++ )
527 SCIP_VAR* copyvar = (SCIP_VAR*)SCIPhashmapGetImage(varmap, (
void*)srcVars[i]);
561 if( SCIPgetNConss(received) > 0 )
563 SCIPhashmapFree(&conssmap);
565 if( SCIPgetNVars(received) > 0 )
567 SCIPhashmapFree(&varmap);
600 bool noPreprocessingInLC,
601 bool usetRootNodeCuts,
604 char *settingsNameLC,
622 if( method == 0 && SCIPgetStage(inScip) == SCIP_STAGE_INIT )
624 if( SCIPgetStage(
scip) == SCIP_STAGE_PROBLEM)
626 SCIP_CALL_ABORT( SCIPtransformProb(
scip));
628 if(
scip == inScip )
return;
633 SCIPinfoMessage(
scip, NULL,
"* If you use check mechanism, you should check the following codes. *\n");
634 SCIP_Bool success = TRUE;
635 char probname[SCIP_MAXSTRLEN];
637#if SCIP_APIVERSION >= 163
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, TRUE, TRUE, TRUE, TRUE, &success) );
640#elif SCIP_APIVERSION >= 131
641 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
642 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, &success) );
643#elif SCIP_APIVERSION >= 101
644 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
645 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, &success) );
646#elif SCIP_APIVERSION >= 100
647 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
648 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, &success) );
649#elif SCIP_APIVERSION >= 17
650 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
651 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, &success) );
653 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
654 TRUE, TRUE, TRUE, TRUE, TRUE, &success) );
656 SCIP_CALL_ABORT( SCIPcopyParamSettings(
scip, inScip) );
659 SCIP_HASHMAP* varmap = 0;
660 if( SCIPgetNVars(
scip) > 0 )
662 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(inScip), SCIPgetNVars(
scip)) );
664 SCIP_HASHMAP* conssmap = 0;
665 if( SCIPgetNConss(
scip) > 0 )
667 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(inScip), SCIPgetNConss(
scip)) );
672 (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN,
"%s_%s", SCIPgetProbName(
scip),
"solver_created");
673 SCIP_CALL_ABORT( SCIPcreateProb(inScip, probname, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );
675 SCIP_CALL_ABORT( SCIPcopyProb(
scip, inScip, varmap, conssmap, TRUE, probname) );
678 if( SCIPgetNVars(
scip) > 0 )
680#if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) )
681 SCIP_CALL_ABORT( SCIPcopyVars(
scip, inScip, varmap, conssmap, TRUE) );
683 SCIP_CALL_ABORT( SCIPcopyVars(
scip, inScip, varmap, conssmap, NULL, NULL, 0, TRUE) );
686 if( SCIPgetNConss(
scip) > 0 )
688 SCIP_CALL_ABORT( SCIPcopyConss(
scip, inScip, varmap, conssmap, TRUE, FALSE, &success) );
691#if SCIP_APIVERSION > 39
697 SCIP_CALL_ABORT( SCIPcopyBenders(
scip, inScip, NULL, TRUE, &valid) );
703 if( SCIPgetNConss(
scip) > 0 )
705 SCIPhashmapFree(&conssmap);
707 if( SCIPgetNVars(
scip) > 0 )
709 SCIPhashmapFree(&varmap);
711 std::cerr <<
"Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
716 if( SCIPgetNConss(
scip) > 0 )
718 SCIPhashmapFree(&conssmap);
720 if( SCIPgetNVars(
scip) > 0 )
722 SCIPhashmapFree(&varmap);
727 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.