39 #include "scip/scipdefplugins.h" 52 ScipParaInstance::copyScipEnvironment(
56 char probname[SCIP_MAXSTRLEN];
59 assert(*targetscip != NULL);
60 SCIP_Bool success = TRUE;
63 #if SCIP_VERSION == 211 && SCIP_SUBVERSION == 0 64 SCIP_CALL_ABORT( SCIPcopyPlugins(scip, *targetscip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
65 TRUE, TRUE, TRUE, TRUE, &success) );
67 #if SCIP_APIVERSION >= 100 68 #if SCIP_APIVERSION >= 101 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, FALSE, &success) );
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, FALSE, &success) );
75 #elif SCIP_APIVERSION >= 17 76 SCIP_CALL_ABORT( SCIPcopyPlugins(scip, *targetscip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
77 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
79 SCIP_CALL_ABORT( SCIPcopyPlugins(scip, *targetscip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
80 TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
83 SCIP_CALL_ABORT( SCIPcopyParamSettings(scip, *targetscip) );
86 SCIP_HASHMAP* varmap = 0;
87 if( SCIPgetNVars(scip) > 0 )
89 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(*targetscip), SCIPgetNVars(scip)) );
91 SCIP_HASHMAP* conssmap = 0;
92 if( SCIPgetNConss(scip) > 0 )
94 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(*targetscip), SCIPgetNConss(scip)) );
100 (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN,
"%s", SCIPgetProbName(scip));
103 SCIP_CALL_ABORT( SCIPcopyProb(scip, *targetscip, varmap, conssmap, TRUE, probname) );
106 if( SCIPgetNVars(scip) > 0 )
108 #if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) ) 109 SCIP_CALL_ABORT( SCIPcopyVars(scip, *targetscip, varmap, conssmap, TRUE) );
111 SCIP_CALL_ABORT( SCIPcopyVars(scip, *targetscip, varmap, conssmap, NULL, NULL, 0, TRUE) );
114 if( SCIPgetNConss(scip) > 0 )
116 SCIP_CALL_ABORT( SCIPcopyConss(scip, *targetscip, varmap, conssmap, TRUE, FALSE, &success) );
119 #if SCIP_APIVERSION > 39 125 SCIP_CALL_ABORT( SCIPcopyBenders(scip, *targetscip, NULL, TRUE, &valid) );
131 if( SCIPgetNConss(scip) > 0 )
133 SCIPhashmapFree(&conssmap);
135 if( SCIPgetNVars(scip) > 0 )
137 SCIPhashmapFree(&varmap);
139 std::cerr <<
"Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
144 if( SCIPgetNConss(scip) > 0 )
146 SCIPhashmapFree(&conssmap);
148 if( SCIPgetNVars(scip) > 0 )
150 SCIPhashmapFree(&varmap);
156 ScipParaInstanceTh::bcast(
164 #if 0 // sender side creation 166 if( commTh->getRank() == root )
168 for(
int i = 0; i < commTh->getSize(); i++ )
173 SCIP_CALL_ABORT( SCIPcreate(&newScip) );
174 copyScipEnvironment(&newScip);
185 commTh->uTypeReceive((
void **)&scip,
ParaInstanceType, root, TagParaInstance)
189 #else // receiver side creation 190 if( commTh->getRank() == root )
194 SCIP_Bool success = TRUE;
197 SCIP_CALL_ABORT( SCIPcreate(&tempScip) );
200 #if SCIP_VERSION == 211 && SCIP_SUBVERSION == 0 201 SCIP_CALL_ABORT( SCIPcopyPlugins(scip, tempScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
202 TRUE, TRUE, TRUE, TRUE, &success) );
204 #if SCIP_APIVERSION >= 100 205 #if SCIP_APIVERSION >= 101 206 SCIP_CALL_ABORT( SCIPcopyPlugins(scip, tempScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
207 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
209 SCIP_CALL_ABORT( SCIPcopyPlugins(scip, tempScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
210 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
212 #elif SCIP_APIVERSION >= 17 213 SCIP_CALL_ABORT( SCIPcopyPlugins(scip, tempScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
214 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
216 SCIP_CALL_ABORT( SCIPcopyPlugins(scip, tempScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
217 TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
220 SCIP_CALL_ABORT( SCIPcopyParamSettings(scip, tempScip) );
223 SCIP_HASHMAP* varmap = 0;
224 if( SCIPgetNVars(scip) > 0 )
226 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(tempScip), SCIPgetNVars(scip)) );
228 SCIP_HASHMAP* conssmap = 0;
229 if( SCIPgetNConss(scip) > 0 )
231 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(tempScip), SCIPgetNConss(scip)) );
234 SCIP_CALL_ABORT( SCIPcopyProb(scip, tempScip, varmap, conssmap, TRUE,
"") );
238 if( SCIPgetNVars(scip) > 0 )
240 #if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) ) 241 SCIP_CALL_ABORT( SCIPcopyVars(scip, tempScip, varmap, conssmap, TRUE) );
243 SCIP_CALL_ABORT( SCIPcopyVars(scip, tempScip, varmap, conssmap, NULL, NULL, 0, TRUE) );
246 if( SCIPgetNConss(scip) > 0 )
248 SCIP_CALL_ABORT( SCIPcopyConss(scip, tempScip, varmap, conssmap, TRUE, FALSE, &success) );
251 #if SCIP_APIVERSION > 39 257 SCIP_CALL_ABORT( SCIPcopyBenders(scip, tempScip, NULL, TRUE, &valid) );
264 if( SCIPgetNConss(scip) > 0 )
266 SCIPhashmapFree(&conssmap);
268 if( SCIPgetNVars(scip) > 0 )
270 SCIPhashmapFree(&varmap);
273 std::cerr <<
"Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
277 nVars = SCIPgetNVars(scip);
278 varIndexRange = nVars;
279 int n = SCIPgetNVars(tempScip);
283 if( SCIPgetNConss(scip) > 0 )
285 SCIPhashmapFree(&conssmap);
287 if( SCIPgetNVars(scip) > 0 )
289 SCIPhashmapFree(&varmap);
292 std::cout <<
"** ParaScipInstance copy does not increase the number of variables. **" << std::endl;
297 std::cout <<
"** ParaScipInstance copy increased the number of variables. **" << std::endl;
298 varIndexRange = SCIPgetNTotalVars(tempScip);
299 copyIncreasedVariables =
true;
335 for(
int i = 0; i < commTh->getSize(); i++ )
347 for(
int i = 0; i < commTh->getSize(); i++ )
352 commTh->send(NULL, 0,
ParaBYTE, i, TagParaInstance)
365 commTh->uTypeReceive((
void **)&received,
ParaInstanceType, root, TagParaInstance)
369 SCIP_CALL_ABORT( SCIPcreate(&scip) );
370 char probname[SCIP_MAXSTRLEN];
372 assert(received != NULL);
373 assert(scip != NULL);
374 SCIP_Bool success = TRUE;
377 #if SCIP_VERSION == 211 && SCIP_SUBVERSION == 0 378 SCIP_CALL_ABORT( SCIPcopyPlugins(received, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
379 TRUE, TRUE, TRUE, TRUE, &success) );
381 #if SCIP_APIVERSION >= 100 382 #if SCIP_APIVERSION >= 101 383 SCIP_CALL_ABORT( SCIPcopyPlugins(received, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
384 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
386 SCIP_CALL_ABORT( SCIPcopyPlugins(received, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
387 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
389 #elif SCIP_APIVERSION >= 17 390 SCIP_CALL_ABORT( SCIPcopyPlugins(received, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
391 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
393 SCIP_CALL_ABORT( SCIPcopyPlugins(received, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
394 TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
400 std::cout <<
"Error in SCIPcopyPlugins" << std::endl;
403 SCIP_CALL_ABORT( SCIPcopyParamSettings(received, scip) );
407 SCIP_HASHMAP* varmap = 0;
408 if( SCIPgetNVars(received) > 0 )
410 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(scip), SCIPgetNVars(received)) );
412 SCIP_HASHMAP* conssmap = 0;
413 if( SCIPgetNConss(received) > 0 )
415 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(scip), SCIPgetNConss(received)) );
421 (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN,
"%s", SCIPgetProbName(received));
424 SCIP_CALL_ABORT( SCIPcopyProb(received, scip, varmap, conssmap, TRUE, probname) );
428 if( SCIPgetNVars(received) > 0 )
430 #if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) ) 431 SCIP_CALL_ABORT( SCIPcopyVars(received, scip, varmap, conssmap, TRUE) );
433 SCIP_CALL_ABORT( SCIPcopyVars(received, scip, varmap, conssmap, NULL, NULL, 0, TRUE) );
436 if( SCIPgetNConss(received) > 0 )
438 SCIP_CALL_ABORT( SCIPcopyConss(received, scip, varmap, conssmap, TRUE, FALSE, &success) );
441 #if SCIP_APIVERSION > 39 447 SCIP_CALL_ABORT( SCIPcopyBenders(received, scip, NULL, TRUE, &valid) );
454 if( SCIPgetNConss(received) > 0 )
456 SCIPhashmapFree(&conssmap);
458 if( SCIPgetNVars(received) > 0 )
460 SCIPhashmapFree(&varmap);
462 std::cerr <<
"Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
466 nVars = SCIPgetNVars(received);
467 varIndexRange = nVars;
468 int n = SCIPgetNVars(scip);
473 assert( nVars <= n );
476 copyIncreasedVariables =
true;
481 mapToOriginalIndecies =
new int[SCIPgetNTotalVars(scip)];
482 mapToSolverLocalIndecies =
new int[SCIPgetNTotalVars(scip)];
483 for(
int i = 0; i < SCIPgetNTotalVars(scip); i++ )
486 mapToOriginalIndecies[i] = -1;
487 mapToSolverLocalIndecies[i] = -1;
490 SCIP_VAR **srcVars = SCIPgetVars(received);
492 assert(SCIPgetNTotalVars(scip) >= SCIPgetNVars(received));
498 for(
int i = 0; i < SCIPgetNVars(received); i++ )
500 SCIP_VAR* copyvar = (SCIP_VAR*)SCIPhashmapGetImage(varmap, (
void*)srcVars[i]);
511 mapToOriginalIndecies[SCIPvarGetIndex(copyvar)] = i;
512 mapToSolverLocalIndecies[i] = SCIPvarGetIndex(copyvar);
534 if( SCIPgetNConss(received) > 0 )
536 SCIPhashmapFree(&conssmap);
538 if( SCIPgetNVars(received) > 0 )
540 SCIPhashmapFree(&varmap);
546 commTh->receive( NULL, 0,
ParaBYTE, root, TagParaInstance )
557 ScipParaInstanceTh::ScipParaInstanceTh(
573 bool noPreprocessingInLC,
574 bool usetRootNodeCuts,
577 char *settingsNameLC,
595 if( method == 0 && SCIPgetStage(inScip) == SCIP_STAGE_INIT )
597 if( SCIPgetStage(
scip) == SCIP_STAGE_PROBLEM)
599 SCIP_CALL_ABORT( SCIPtransformProb(
scip));
601 if(
scip == inScip )
return;
606 std::cout <<
"* If you use check mechanism, you should check the following codes. *" << std::endl;
607 SCIP_Bool success = TRUE;
608 char probname[SCIP_MAXSTRLEN];
610 #if SCIP_VERSION == 211 && SCIP_SUBVERSION == 0 611 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
612 TRUE, TRUE, TRUE, TRUE, &success) );
614 #if SCIP_APIVERSION >= 100 615 #if SCIP_APIVERSION >= 101 616 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
617 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
619 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
620 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
622 #elif SCIP_APIVERSION >= 17 623 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
624 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
626 SCIP_CALL_ABORT( SCIPcopyPlugins(
scip, inScip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
627 TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
630 SCIP_CALL_ABORT( SCIPcopyParamSettings(
scip, inScip) );
633 SCIP_HASHMAP* varmap = 0;
634 if( SCIPgetNVars(
scip) > 0 )
636 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(inScip), SCIPgetNVars(
scip)) );
638 SCIP_HASHMAP* conssmap = 0;
639 if( SCIPgetNConss(
scip) > 0 )
641 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(inScip), SCIPgetNConss(
scip)) );
646 (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN,
"%s_%s", SCIPgetProbName(
scip),
"solver_created");
647 SCIP_CALL_ABORT( SCIPcreateProb(inScip, probname, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );
649 SCIP_CALL_ABORT( SCIPcopyProb(
scip, inScip, varmap, conssmap, TRUE, probname) );
652 if( SCIPgetNVars(
scip) > 0 )
654 #if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) ) 655 SCIP_CALL_ABORT( SCIPcopyVars(
scip, inScip, varmap, conssmap, TRUE) );
657 SCIP_CALL_ABORT( SCIPcopyVars(
scip, inScip, varmap, conssmap, NULL, NULL, 0, TRUE) );
660 if( SCIPgetNConss(
scip) > 0 )
662 SCIP_CALL_ABORT( SCIPcopyConss(
scip, inScip, varmap, conssmap, TRUE, FALSE, &success) );
665 #if SCIP_APIVERSION > 39 671 SCIP_CALL_ABORT( SCIPcopyBenders(
scip, inScip, NULL, TRUE, &valid) );
677 if( SCIPgetNConss(
scip) > 0 )
679 SCIPhashmapFree(&conssmap);
681 if( SCIPgetNVars(
scip) > 0 )
683 SCIPhashmapFree(&varmap);
685 std::cerr <<
"Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
690 if( SCIPgetNConss(
scip) > 0 )
692 SCIPhashmapFree(&conssmap);
694 if( SCIPgetNVars(
scip) > 0 )
696 SCIPhashmapFree(&varmap);
701 std::cout <<
"You should use instance transfer method 0 or 1!" << std::endl;
static ScipParaCommTh * comm
static const int ParaInstanceType
void createProblem(SCIP *scip, int method, bool noPreprocessingInLC, bool usetRootNodeCuts, ScipDiffParamSet *scipDiffParamSetRoot, ScipDiffParamSet *scipDiffParamSet, char *settingsNameLC, char *isolname)
#define PARA_COMM_CALL(paracommcall)
#define DEF_PARA_COMM(para_comm, comm)
static const int ParaBYTE
static const char * PRESOLVED_INSTANCE
ScipParaInstance extension for threads communication.
Base class of communicator object.