Skip to content

Commit 9abb1f8

Browse files
committed
Merge remote-tracking branch 'origin/v10-minor'
2 parents dc2229b + 754173d commit 9abb1f8

File tree

8 files changed

+172
-97
lines changed

8 files changed

+172
-97
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ Fixed bugs
473473
- recompute activity bounds before checking infeasibility and redundancy in linear constraint presolving
474474
- skip integer variables with fractional value in reference solution when finding additional variable fixings in ALNS heuristic
475475
- fix call of SCIPaddExprsViolScoreNonlinear() with constant expressions (no variables)
476+
- fixed bug with concurrent solve w.r.t. variable indices that led to segmentation faults and fix termination test
476477
- adjust further bounds before checking feasibility in SCIPvarAddVlb() and SCIPvarAddVub() to detect integrality cutoff
477478
- fixed issue in cons_linking.c where the last fixed binary variable was not set after the binary variables are created.
478479
- fixed issue in cons_linking.c where the number of binary variable is 1, but the constraint is added during solving.

src/scip/concsolver_scip.c

Lines changed: 118 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ SCIP_RETCODE disableConflictingDualReductions(
215215
return SCIP_OKAY;
216216

217217
SCIP_CALL( SCIPsetBoolParam(scip, "misc/allowstrongdualreds", FALSE) );
218+
218219
return SCIP_OKAY;
219220
}
220221

@@ -224,7 +225,7 @@ SCIP_RETCODE setChildSelRule(
224225
SCIP_CONCSOLVER* concsolver /**< the concurrent solver */
225226
)
226227
{
227-
SCIP_CONCSOLVERDATA* data;
228+
SCIP_CONCSOLVERDATA* data;
228229
static const char childsel[] = { 'h', 'i', 'p', 'r', 'l', 'd', 'u' };
229230

230231
assert(concsolver != NULL);
@@ -237,7 +238,7 @@ SCIP_RETCODE setChildSelRule(
237238
return SCIP_OKAY;
238239
}
239240

240-
/** initialize the concurrent SCIP solver, i.e. setup the copy of the problem and the
241+
/** initialize the concurrent SCIP solver, i.e., setup the copy of the problem and the
241242
* mapping of the variables */
242243
static
243244
SCIP_RETCODE initConcsolver(
@@ -275,8 +276,8 @@ SCIP_RETCODE initConcsolver(
275276
SCIP_CALL( SCIPcreate(&data->solverscip) );
276277
SCIPsetMessagehdlrQuiet(data->solverscip, SCIPmessagehdlrIsQuiet(SCIPgetMessagehdlr(scip)));
277278
SCIP_CALL( SCIPhashmapCreate(&varmapfw, SCIPblkmem(data->solverscip), data->nvars) );
278-
SCIP_CALL( SCIPcopy(scip, data->solverscip, varmapfw, NULL, SCIPconcsolverGetName(concsolver), TRUE, FALSE, FALSE,
279-
FALSE, &valid) );
279+
SCIP_CALL( SCIPcopyConsCompression(scip, data->solverscip, varmapfw, NULL, SCIPconcsolverGetName(concsolver),
280+
NULL, NULL, 0, TRUE, FALSE, FALSE, FALSE, &valid) );
280281
assert(valid);
281282

282283
/* allocate memory for the arrays to store the variable mapping */
@@ -287,27 +288,59 @@ SCIP_RETCODE initConcsolver(
287288
for( i = 0; i < data->nvars; i++ )
288289
{
289290
SCIP_VAR* var;
291+
int idx;
292+
290293
var = (SCIP_VAR*) SCIPhashmapGetImage(varmapfw, vars[i]);
291294
assert(var != NULL);
292-
varperm[SCIPvarGetIndex(var)] = i;
295+
idx = SCIPvarGetIndex(var);
296+
assert(0 <= idx && idx < data->nvars);
297+
298+
/* Note that because some aggregations or fixed variables cannot be resolved by some constraint handlers (in
299+
* particular cons_orbitope_pp), the copied problem may contain more variables than the original problem has
300+
* active variables. These variables will be ignored in the following, since they depend on the other `active'
301+
* varibles. See concurrent.c:SCIPgetConcurrentVaridx(). */
302+
varperm[idx] = i;
293303
data->vars[i] = var;
294304
}
295305

306+
/* transfer solutions from original problem to concurent instances */
296307
if( SCIPgetNSols(scip) != 0 )
297308
{
298309
SCIP_Bool stored;
299310
SCIP_Real* solvals;
300311
SCIP_SOL* sol = SCIPgetBestSol(scip);
301312
SCIP_SOL* solversol;
313+
int norigvars;
302314

303315
SCIP_CALL( SCIPallocBufferArray(data->solverscip, &solvals, data->nvars) );
304316

305317
SCIP_CALL( SCIPgetSolVals(scip, sol, data->nvars, vars, solvals) );
306318
SCIP_CALL( SCIPcreateSol(data->solverscip, &solversol, NULL) );
307319
SCIP_CALL( SCIPsetSolVals(data->solverscip, solversol, data->nvars, data->vars, solvals) );
308-
309320
SCIPfreeBufferArray(data->solverscip, &solvals);
310321

322+
/* handle fixed variables */
323+
norigvars = SCIPgetNOrigVars(data->solverscip);
324+
if( norigvars > data->nvars )
325+
{
326+
SCIP_VAR** origvars;
327+
int v;
328+
329+
origvars = SCIPgetOrigVars(data->solverscip);
330+
for( v = 0; v < norigvars; ++v )
331+
{
332+
SCIP_VAR* var;
333+
var = origvars[v];
334+
if( SCIPisEQ(data->solverscip, SCIPvarGetLbGlobal(var), SCIPvarGetUbGlobal(var)) )
335+
{
336+
if( ! SCIPisZero(data->solverscip, SCIPvarGetLbGlobal(var)) )
337+
{
338+
SCIP_CALL( SCIPsetSolVal(data->solverscip, solversol, var, SCIPvarGetLbGlobal(var)) );
339+
}
340+
}
341+
}
342+
}
343+
311344
SCIP_CALL( SCIPaddSolFree(data->solverscip, &solversol, &stored) );
312345

313346
assert(stored);
@@ -319,7 +352,7 @@ SCIP_RETCODE initConcsolver(
319352
* also fails on check/instances/Symmetry/partorb_1-FullIns_3.cip
320353
* TODO: test if this leads to any problems
321354
*/
322-
SCIP_CALL( SCIPcreateConcurrent(data->solverscip, concsolver, varperm) );
355+
SCIP_CALL( SCIPcreateConcurrent(data->solverscip, concsolver, varperm, data->nvars) );
323356
SCIPfreeBufferArray(data->solverscip, &varperm);
324357

325358
/* free the hashmap */
@@ -404,7 +437,7 @@ SCIP_DECL_CONCSOLVERCREATEINST(concsolverScipCreateInstance)
404437
{
405438
/* print message about missing setting files only in verblevel full */
406439
SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, "skipping non existent parameter file <%s> for concurrent solver <%s>\n",
407-
filename, SCIPconcsolverGetName(concsolver));
440+
filename, SCIPconcsolverGetName(concsolver));
408441
}
409442

410443
/* include eventhandler for synchronization */
@@ -495,55 +528,56 @@ static
495528
SCIP_DECL_CONCSOLVERCOPYSOLVINGDATA(concsolverGetSolvingData)
496529
{
497530
SCIP_CONCSOLVERDATA* data;
498-
SCIP_VAR** vars;
499-
int nvars;
500531
int nsols;
501-
SCIP_SOL** sols;
502-
SCIP_Real* solvals;
503-
SCIP_HEUR* heur;
504-
int i;
505532

533+
assert(scip != NULL);
506534
assert(concsolver != NULL);
507535

508536
data = SCIPconcsolverGetData(concsolver);
509537
assert(data != NULL);
510538
assert(data->solverscip != NULL);
511539

512-
assert(scip != NULL);
513-
vars = SCIPgetVars(scip);
514-
nvars = SCIPgetNVars(scip);
515-
516540
nsols = SCIPgetNSols(data->solverscip);
517-
sols = SCIPgetSols(data->solverscip);
541+
if( nsols > 0 )
542+
{
543+
SCIP_VAR** vars;
544+
SCIP_SOL** sols;
545+
SCIP_Real* solvals;
546+
int nvars;
547+
int i;
518548

519-
assert(nvars == data->nvars);
549+
vars = SCIPgetVars(scip);
550+
nvars = SCIPgetNVars(scip);
551+
assert(nvars == data->nvars);
520552

521-
/* allocate buffer array used for translating the solution to the given SCIP */
522-
SCIP_CALL( SCIPallocBufferArray(scip, &solvals, nvars) );
553+
sols = SCIPgetSols(data->solverscip);
523554

524-
/* add the solutions to the given SCIP */
525-
for( i = 0; i < nsols; ++i )
526-
{
527-
SCIP_SOL* sol;
528-
SCIP_Bool stored;
529-
SCIP_CALL( SCIPgetSolVals(data->solverscip, sols[i], nvars, data->vars, solvals) );
555+
/* allocate buffer array used for translating the solution to the given SCIP */
556+
SCIP_CALL( SCIPallocBufferArray(scip, &solvals, nvars) );
530557

531-
heur = SCIPsolGetHeur(sols[i]);
558+
/* add the solutions to the given SCIP */
559+
for( i = 0; i < nsols; ++i )
560+
{
561+
SCIP_SOL* sol;
562+
SCIP_HEUR* heur;
563+
SCIP_Bool stored;
532564

533-
if( heur != NULL )
534-
heur = SCIPfindHeur(scip, SCIPheurGetName(heur));
565+
SCIP_CALL( SCIPgetSolVals(data->solverscip, sols[i], nvars, data->vars, solvals) );
535566

536-
SCIP_CALL( SCIPcreateSol(scip, &sol, heur) );
537-
SCIP_CALL( SCIPsetSolVals(scip, sol, nvars, vars, solvals) );
567+
heur = SCIPsolGetHeur(sols[i]);
568+
if( heur != NULL )
569+
heur = SCIPfindHeur(scip, SCIPheurGetName(heur));
538570

539-
SCIP_CALL( SCIPcopySolStats(sols[i], sol) );
571+
SCIP_CALL( SCIPcreateSol(scip, &sol, heur) );
572+
SCIP_CALL( SCIPsetSolVals(scip, sol, nvars, vars, solvals) );
573+
SCIP_CALL( SCIPcopySolStats(sols[i], sol) );
574+
SCIP_CALL( SCIPaddSolFree(scip, &sol, &stored) );
575+
}
540576

541-
SCIP_CALL( SCIPaddSolFree(scip, &sol, &stored) );
577+
/* free the buffer array */
578+
SCIPfreeBufferArray(scip, &solvals);
542579
}
543580

544-
/* free the buffer array */
545-
SCIPfreeBufferArray(scip, &solvals);
546-
547581
/* copy solving statistics and status from the solver SCIP to the given SCIP */
548582
SCIP_CALL( SCIPcopyConcurrentSolvingStats(data->solverscip, scip) );
549583

@@ -662,7 +696,9 @@ SCIP_DECL_CONCSOLVERSYNCWRITE(concsolverScipSyncWrite)
662696
boundstore = SCIPgetConcurrentGlobalBoundChanges(data->solverscip);
663697

664698
if( boundstore != NULL )
699+
{
665700
SCIP_CALL( SCIPsyncdataAddBoundChanges(syncstore, syncdata, boundstore) );
701+
}
666702

667703
SCIPsyncdataAddMemTotal(syncdata, SCIPgetMemTotal(data->solverscip));
668704

@@ -694,6 +730,9 @@ SCIP_DECL_CONCSOLVERSYNCREAD(concsolverScipSyncRead)
694730
for( i = 0; i < nsols; ++i )
695731
{
696732
SCIP_SOL* newsol;
733+
SCIP_VAR** origvars;
734+
int norigvars;
735+
int v;
697736

698737
/* do not add own solutions */
699738
if( concsolverids[i] == concsolverid )
@@ -704,6 +743,26 @@ SCIP_DECL_CONCSOLVERSYNCREAD(concsolverScipSyncRead)
704743
SCIP_CALL( SCIPcreateOrigSol(data->solverscip, &newsol, NULL) );
705744

706745
SCIP_CALL( SCIPsetSolVals(data->solverscip, newsol, data->nvars, data->vars, solvals[i]) );
746+
747+
/* treat possible fixed original variables */
748+
norigvars = SCIPgetNOrigVars(data->solverscip);
749+
if( norigvars > data->nvars )
750+
{
751+
origvars = SCIPgetOrigVars(data->solverscip);
752+
for( v = 0; v < norigvars; ++v )
753+
{
754+
SCIP_VAR* var;
755+
var = origvars[v];
756+
if( SCIPisEQ(data->solverscip, SCIPvarGetLbGlobal(var), SCIPvarGetUbGlobal(var)) )
757+
{
758+
if( ! SCIPisZero(data->solverscip, SCIPvarGetLbGlobal(var)) )
759+
{
760+
SCIP_CALL( SCIPsetSolVal(data->solverscip, newsol, var, SCIPvarGetLbGlobal(var)) );
761+
}
762+
}
763+
}
764+
}
765+
707766
SCIPdebugMessage("adding solution in concurrent solver %s\n", SCIPconcsolverGetName(concsolver));
708767
SCIP_CALL( SCIPaddConcurrentSol(data->solverscip, newsol) );
709768
}
@@ -716,11 +775,14 @@ SCIP_DECL_CONCSOLVERSYNCREAD(concsolverScipSyncRead)
716775

717776
for( i = 0; i < nbndchgs; ++i )
718777
{
719-
SCIP_VAR* var;
778+
SCIP_VAR* var;
720779
SCIP_BOUNDTYPE boundtype;
721780
SCIP_Real newbound;
781+
int idx;
722782

723-
var = data->vars[SCIPboundstoreGetChgVaridx(boundstore, i)];
783+
idx = SCIPboundstoreGetChgVaridx(boundstore, i);
784+
assert(0 <= idx && idx < data->nvars);
785+
var = data->vars[idx];
724786
boundtype = SCIPboundstoreGetChgType(boundstore, i);
725787
newbound = SCIPboundstoreGetChgVal(boundstore, i);
726788

@@ -768,57 +830,57 @@ SCIP_RETCODE SCIPincludeConcurrentScipSolvers(
768830
SCIP_CALL( SCIPallocMemory(scip, &data) );
769831
data->loademphasis = FALSE;
770832
SCIP_CALL( SCIPincludeConcsolverType(scip, "scip", 1.0, concsolverScipCreateInstance, concsolverScipDestroyInstance, concsolverScipInitSeeds,
771-
concsolverScipExec, concsolverGetSolvingData, concsolverScipStop, concsolverScipSyncWrite,
772-
concsolverScipSyncRead, concsolverTypeScipFreeData, data) );
833+
concsolverScipExec, concsolverGetSolvingData, concsolverScipStop, concsolverScipSyncWrite,
834+
concsolverScipSyncRead, concsolverTypeScipFreeData, data) );
773835

774836
SCIP_CALL( SCIPallocMemory(scip, &data) );
775837
data->loademphasis = TRUE;
776838
data->emphasis = SCIP_PARAMEMPHASIS_DEFAULT;
777839
SCIP_CALL( SCIPincludeConcsolverType(scip, "scip-default", 0.0, concsolverScipCreateInstance, concsolverScipDestroyInstance, concsolverScipInitSeeds,
778-
concsolverScipExec, concsolverGetSolvingData, concsolverScipStop, concsolverScipSyncWrite,
779-
concsolverScipSyncRead, concsolverTypeScipFreeData, data) );
840+
concsolverScipExec, concsolverGetSolvingData, concsolverScipStop, concsolverScipSyncWrite,
841+
concsolverScipSyncRead, concsolverTypeScipFreeData, data) );
780842

781843
SCIP_CALL( SCIPallocMemory(scip, &data) );
782844
data->loademphasis = TRUE;
783845
data->emphasis = SCIP_PARAMEMPHASIS_CPSOLVER;
784846
SCIP_CALL( SCIPincludeConcsolverType(scip, "scip-cpsolver", 0.0, concsolverScipCreateInstance, concsolverScipDestroyInstance, concsolverScipInitSeeds,
785-
concsolverScipExec, concsolverGetSolvingData, concsolverScipStop, concsolverScipSyncWrite,
786-
concsolverScipSyncRead, concsolverTypeScipFreeData, data) );
847+
concsolverScipExec, concsolverGetSolvingData, concsolverScipStop, concsolverScipSyncWrite,
848+
concsolverScipSyncRead, concsolverTypeScipFreeData, data) );
787849

788850
SCIP_CALL( SCIPallocMemory(scip, &data) );
789851
data->loademphasis = TRUE;
790852
data->emphasis = SCIP_PARAMEMPHASIS_EASYCIP;
791853
SCIP_CALL( SCIPincludeConcsolverType(scip, "scip-easycip", 0.0, concsolverScipCreateInstance, concsolverScipDestroyInstance, concsolverScipInitSeeds,
792-
concsolverScipExec, concsolverGetSolvingData, concsolverScipStop, concsolverScipSyncWrite,
793-
concsolverScipSyncRead, concsolverTypeScipFreeData, data) );
854+
concsolverScipExec, concsolverGetSolvingData, concsolverScipStop, concsolverScipSyncWrite,
855+
concsolverScipSyncRead, concsolverTypeScipFreeData, data) );
794856

795857
SCIP_CALL( SCIPallocMemory(scip, &data) );
796858
data->loademphasis = TRUE;
797859
data->emphasis = SCIP_PARAMEMPHASIS_FEASIBILITY;
798860
SCIP_CALL( SCIPincludeConcsolverType(scip, "scip-feas", 0.0, concsolverScipCreateInstance, concsolverScipDestroyInstance, concsolverScipInitSeeds,
799-
concsolverScipExec, concsolverGetSolvingData, concsolverScipStop, concsolverScipSyncWrite,
800-
concsolverScipSyncRead, concsolverTypeScipFreeData, data) );
861+
concsolverScipExec, concsolverGetSolvingData, concsolverScipStop, concsolverScipSyncWrite,
862+
concsolverScipSyncRead, concsolverTypeScipFreeData, data) );
801863

802864
SCIP_CALL( SCIPallocMemory(scip, &data) );
803865
data->loademphasis = TRUE;
804866
data->emphasis = SCIP_PARAMEMPHASIS_HARDLP;
805867
SCIP_CALL( SCIPincludeConcsolverType(scip, "scip-hardlp", 0.0, concsolverScipCreateInstance, concsolverScipDestroyInstance, concsolverScipInitSeeds,
806-
concsolverScipExec, concsolverGetSolvingData, concsolverScipStop, concsolverScipSyncWrite,
807-
concsolverScipSyncRead, concsolverTypeScipFreeData, data) );
868+
concsolverScipExec, concsolverGetSolvingData, concsolverScipStop, concsolverScipSyncWrite,
869+
concsolverScipSyncRead, concsolverTypeScipFreeData, data) );
808870

809871
SCIP_CALL( SCIPallocMemory(scip, &data) );
810872
data->loademphasis = TRUE;
811873
data->emphasis = SCIP_PARAMEMPHASIS_OPTIMALITY;
812874
SCIP_CALL( SCIPincludeConcsolverType(scip, "scip-opti", 0.0, concsolverScipCreateInstance, concsolverScipDestroyInstance, concsolverScipInitSeeds,
813-
concsolverScipExec, concsolverGetSolvingData, concsolverScipStop, concsolverScipSyncWrite,
814-
concsolverScipSyncRead, concsolverTypeScipFreeData, data) );
875+
concsolverScipExec, concsolverGetSolvingData, concsolverScipStop, concsolverScipSyncWrite,
876+
concsolverScipSyncRead, concsolverTypeScipFreeData, data) );
815877

816878
SCIP_CALL( SCIPallocMemory(scip, &data) );
817879
data->loademphasis = TRUE;
818880
data->emphasis = SCIP_PARAMEMPHASIS_COUNTER;
819881
SCIP_CALL( SCIPincludeConcsolverType(scip, "scip-counter", 0.0, concsolverScipCreateInstance, concsolverScipDestroyInstance, concsolverScipInitSeeds,
820-
concsolverScipExec, concsolverGetSolvingData, concsolverScipStop, concsolverScipSyncWrite,
821-
concsolverScipSyncRead, concsolverTypeScipFreeData, data) );
882+
concsolverScipExec, concsolverGetSolvingData, concsolverScipStop, concsolverScipSyncWrite,
883+
concsolverScipSyncRead, concsolverTypeScipFreeData, data) );
822884

823885
return SCIP_OKAY;
824886
}

0 commit comments

Comments
 (0)