SCIP

    Solving Constraint Integer Programs

    heur_optcumulative.c
    Go to the documentation of this file.
    1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    2/* */
    3/* This file is part of the program and library */
    4/* SCIP --- Solving Constraint Integer Programs */
    5/* */
    6/* Copyright (c) 2002-2026 Zuse Institute Berlin (ZIB) */
    7/* */
    8/* Licensed under the Apache License, Version 2.0 (the "License"); */
    9/* you may not use this file except in compliance with the License. */
    10/* You may obtain a copy of the License at */
    11/* */
    12/* http://www.apache.org/licenses/LICENSE-2.0 */
    13/* */
    14/* Unless required by applicable law or agreed to in writing, software */
    15/* distributed under the License is distributed on an "AS IS" BASIS, */
    16/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
    17/* See the License for the specific language governing permissions and */
    18/* limitations under the License. */
    19/* */
    20/* You should have received a copy of the Apache-2.0 license */
    21/* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
    22/* */
    23/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    24
    25/**@file heur_optcumulative.c
    26 * @ingroup PRIMALHEURISTICS
    27 * @brief heuristic for cumulative scheduling with optional activities
    28 * @author Stefan Heinz
    29 */
    30
    31/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    32
    34#include "heur_optcumulative.h"
    35
    36
    37#define HEUR_NAME "optcumulative"
    38#define HEUR_DESC "problem specific heuristic of cumulative scheduling problems with optional jobs"
    39#define HEUR_DISPCHAR 'q'
    40#define HEUR_PRIORITY -1106000
    41#define HEUR_FREQ -1
    42#define HEUR_FREQOFS 0
    43#define HEUR_MAXDEPTH -1
    44#define HEUR_TIMING SCIP_HEURTIMING_BEFORENODE
    45#define HEUR_USESSUBSCIP TRUE /**< does the heuristic use a secondary SCIP instance? */
    46
    47#define DEFAULT_MAXNODES 1000LL /**< maximum number of nodes to regard in the subproblem */
    48#define DEFAULT_MAXPROPROUNDS -1 /**< maximum number of propagation rounds during probing */
    49
    50/*
    51 * Data structures
    52 */
    53
    55{
    59 unsigned int* keys;
    60 int* nones;
    63};
    65
    66
    67/** primal heuristic data */
    68struct SCIP_HeurData
    69{
    70 SCIP_VAR*** binvars; /**< machnine job matrix (choice variables) */
    71 SCIP_VAR*** vars; /**< machnine job matrix (start time variables) */
    72 int** durations; /**< machnine job duration matrix */
    73 int** demands; /**< machnine job demands matrix */
    74 int* machines; /**< number of jobs for each machines */
    75 int* capacities; /**< machine capacities */
    76 int nmachines; /**< number of machines */
    77 int njobs; /**< number of njobs */
    78
    79 SCIP_Longint maxnodes; /**< maximum number of nodes to regard in the subproblem */
    80 int maxproprounds; /**< maximum number of propagation rounds during probing */
    81 SCIP_Bool initialized; /**< are the candidate list initialized? */
    82
    83 SCIP_ASSIGNMENT** machineassignments;
    84};
    85
    86/*
    87 * Local methods
    88 */
    89
    90/** reset heuristic data structure */
    91static
    93 SCIP* scip, /**< original SCIP data structure */
    94 SCIP_HEURDATA* heurdata /**< structure containing heurdata */
    95 )
    96{
    97 heurdata->vars = NULL;
    98 heurdata->binvars = NULL;
    99 heurdata->durations = NULL;
    100 heurdata->demands = NULL;
    101 heurdata->machines = NULL;
    102 heurdata->capacities = NULL;
    103 heurdata->machineassignments = NULL;
    104 heurdata->nmachines = 0;
    105 heurdata->njobs = 0;
    106
    107 heurdata->initialized = FALSE;
    108}
    109
    110/** apply variable bound fixing during probing */
    111static
    113 SCIP* scip, /**< original SCIP data structure */
    114 SCIP_HEURDATA* heurdata, /**< structure containing heurdata */
    115 SCIP_Bool* infeasible /**< pointer to store whether problem is infeasible */
    116 )
    117{
    118 SCIP_VAR*** binvars;
    119 int* machines;
    120 int* possitions;
    121 int nmachines;
    122 int j;
    123 int m;
    124
    125 binvars = heurdata->binvars;
    126 nmachines = heurdata->nmachines;
    127 machines = heurdata->machines;
    128
    129 SCIP_CALL( SCIPallocBufferArray(scip, &possitions, nmachines) );
    130 BMSclearMemoryArray(possitions, nmachines);
    131
    132 while( !(*infeasible) )
    133 {
    134 SCIP_VAR* var;
    135 SCIP_Real objval;
    136 int bestmachine;
    137
    138 bestmachine = -1;
    139 objval = SCIPinfinity(scip);
    140
    141 /* search over all machines and find the next cheapest job to assign */
    142 for( m = 0; m < nmachines; ++m )
    143 {
    144 int currentpos;
    145
    146 currentpos = possitions[m];
    147
    148 /* find next unfixed variable for the current machine */
    149 for( j = currentpos; j < machines[m]; ++j )
    150 {
    151 if( SCIPvarGetLbLocal(binvars[m][j]) + 0.5 < SCIPvarGetUbLocal(binvars[m][j]) )
    152 break;
    153
    154 possitions[m]++;
    155 }
    156
    157 currentpos = possitions[m];
    158
    159 /* check if we have a variable left on that machine */
    160 if( currentpos < machines[m] )
    161 {
    162 assert(binvars[m][currentpos] != NULL);
    163
    164 /* check if the objective coefficient is better than the best known one */
    165 if( SCIPvarGetObj(binvars[m][currentpos]) < objval )
    166 {
    167 objval = SCIPvarGetObj(binvars[m][currentpos]);
    168 bestmachine = m;
    169 }
    170 }
    171 }
    172
    173 /* check if unsigned variable was left */
    174 if( bestmachine == -1 )
    175 break;
    176
    177 assert(bestmachine < nmachines);
    178 assert(possitions[bestmachine] < machines[bestmachine]);
    179
    180 var = binvars[bestmachine][possitions[bestmachine]];
    181 assert(var != NULL);
    182 assert(SCIPvarGetLbLocal(var) + 0.5 < SCIPvarGetUbLocal(var));
    183
    184 possitions[bestmachine]++;
    185
    187
    188 SCIP_CALL( SCIPfixVarProbing(scip, var, 1.0) );
    189
    190 SCIPdebugMessage("variable <%s> objective coefficient <%g> fixed to 1.0 (%d pseudo cands)\n",
    192
    193 /* check if problem is already infeasible */
    194 SCIP_CALL( SCIPpropagateProbing(scip, heurdata->maxproprounds, infeasible, NULL) );
    195
    196 if( *infeasible )
    197 {
    198 /* backtrack */
    200
    201 /* after backtracking the variable might be already fixed to zero */
    202 if( SCIPvarGetUbLocal(var) > 0.5 )
    203 {
    204 SCIP_CALL( SCIPfixVarProbing(scip, var, 0.0) );
    205 }
    206
    207 SCIP_CALL( SCIPpropagateProbing(scip, heurdata->maxproprounds, infeasible, NULL) );
    208 }
    209 }
    210
    211 SCIPfreeBufferArray(scip, &possitions);
    212
    213 SCIPdebugMessage("probing ended with %sfeasible problem\n", (*infeasible) ? "in" : "");
    214
    215 return SCIP_OKAY;
    216}
    217
    218/** initialize the solution by assign the lower bound of the variable as solution value */
    219static
    221 SCIP* scip, /**< SCIP data structure */
    222 SCIP_SOL* sol /**< solution to be initialize */
    223 )
    224{
    225 SCIP_VAR** vars;
    226 int nvars;
    227 int v;
    228
    229 nvars = SCIPgetNOrigVars(scip);
    230 vars = SCIPgetOrigVars(scip);
    231
    232 for( v = 0; v < nvars; ++v )
    233 {
    234 SCIP_CALL( SCIPsetSolVal(scip, sol, vars[v], SCIPvarGetLbLocal(vars[v])) );
    235 }
    236
    237 return SCIP_OKAY;
    238}
    239
    240/** main procedure of the optcumulative heuristic */
    241static
    243 SCIP* scip, /**< SCIP data structure */
    244 SCIP_HEUR* heur, /**< heuristic */
    245 SCIP_HEURDATA* heurdata, /**< heuristic data structure */
    246 SCIP_RESULT* result /**< pointer to store the result */
    247 )
    248{
    249 SCIP_Real lowerbound;
    250 SCIP_Real upperbound;
    251 SCIP_Real pseudoobj;
    252 SCIP_Bool infeasible;
    253
    254 assert(heur != NULL);
    255 assert(heurdata != NULL);
    256
    257 /* initialize default values */
    258 infeasible = FALSE;
    259
    260 *result = SCIP_DIDNOTFIND;
    261
    262 /* start probing */
    264
    265 /* apply the variable fixings */
    266 SCIP_CALL( applyOptcumulativeFixings(scip, heurdata, &infeasible) );
    267
    268 lowerbound = SCIPgetLowerbound(scip);
    269 upperbound = SCIPgetUpperbound(scip);
    270 pseudoobj = SCIPgetPseudoObjval(scip);
    271
    272 /* if a solution has been found --> fix all other variables by subscip if necessary */
    273 if( !infeasible && pseudoobj >= lowerbound && pseudoobj < upperbound )
    274 {
    275 SCIP_ASSIGNMENT* machineassignment;
    276 int pos;
    277
    278 SCIP_SOL* sol;
    279 SCIP_VAR** vars;
    280 SCIP_Real* lbs;
    281 SCIP_Real* ubs;
    282 int* durations;
    283 int* demands;
    284 SCIP_Bool unbounded;
    285 int njobs;
    286 int nvars;
    287 int j;
    288 int m;
    289
    290 /* create temporary solution */
    291 SCIP_CALL( SCIPcreateOrigSol(scip, &sol, heur) );
    292
    293 /* initialize the solution with the lower bound of all variables */
    295
    296 njobs = heurdata->njobs;
    297
    298 /* allocate memory for collecting the information for the single machines */
    299 SCIP_CALL( SCIPallocBufferArray(scip, &vars, njobs) );
    300 SCIP_CALL( SCIPallocBufferArray(scip, &durations, njobs) );
    301 SCIP_CALL( SCIPallocBufferArray(scip, &demands, njobs) );
    302 SCIP_CALL( SCIPallocBufferArray(scip, &lbs, njobs) );
    303 SCIP_CALL( SCIPallocBufferArray(scip, &ubs, njobs) );
    304
    305 nvars = -1;
    306
    307 for( m = 0; m < heurdata->nmachines && !infeasible; ++m )
    308 {
    309 unsigned int key;
    310 int a;
    311
    312 machineassignment = heurdata->machineassignments[m];
    313
    314 pos = machineassignment->nassignments;
    315
    316 /* realloc memory if not enough space left */
    317 if( machineassignment->nassignments == machineassignment->sassignments)
    318 {
    319 int oldsize;
    320 int newsize;
    321
    322 oldsize = machineassignment->sassignments;
    323 newsize = SCIPcalcMemGrowSize(scip, pos + 1);
    324
    325 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &(machineassignment->vars), oldsize, newsize) );
    326 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &(machineassignment->solvals), oldsize, newsize) );
    327 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &(machineassignment->feasibles), oldsize, newsize) );
    328 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &(machineassignment->keys), oldsize, newsize) );
    329 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &(machineassignment->nones), oldsize, newsize) );
    330
    331 machineassignment->sassignments = newsize;
    332 }
    333 assert(machineassignment->sassignments > pos);
    334
    335 assert(njobs >= heurdata->machines[m]);
    336 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &machineassignment->vars[pos], heurdata->machines[m]) ); /*lint !e866*/
    337 BMSclearMemoryArray(machineassignment->vars[pos], heurdata->machines[m]); /*lint !e866*/
    338 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &machineassignment->solvals[pos], heurdata->machines[m]) ); /*lint !e866*/
    339 machineassignment->nassignments++;
    340 nvars = 0;
    341 key = 0;
    342
    343 /* collect the jobs which are assign to that machine */
    344 for( j = 0; j < heurdata->machines[m]; ++j )
    345 {
    346 SCIP_VAR* binvar;
    347
    348 binvar = heurdata->binvars[m][j];
    349 assert(binvar != NULL);
    350
    351 /* check if job is assign to that machine */
    352 if( SCIPvarGetLbLocal(binvar) > 0.5 )
    353 {
    354 vars[nvars] = heurdata->vars[m][j];
    355 durations[nvars] = heurdata->durations[m][j];
    356 demands[nvars] = heurdata->demands[m][j];
    357 nvars++;
    358
    359 machineassignment->vars[pos][j] = TRUE;
    360 key |= (1 << (j % 32)); /*lint !e701*/
    361
    362 SCIP_CALL( SCIPsetSolVal(scip, sol, binvar, 1.0) );
    363 }
    364 }
    365 machineassignment->nones[pos] = nvars;
    366 machineassignment->keys[pos] = key;
    367
    368 /* if none of the variables is assigned to that machine we skip it */
    369 if( nvars == 0 )
    370 {
    371 SCIPfreeBlockMemoryArray(scip, &machineassignment->vars[pos], heurdata->machines[m]); /*lint !e866*/
    372 SCIPfreeBlockMemoryArray(scip, &machineassignment->solvals[pos], heurdata->machines[m]); /*lint !e866*/
    373 machineassignment->nassignments--;
    374 continue;
    375 }
    376
    377 /* check whether we already have try a subset of this variable combination */
    378 for( a = pos - 1; a >= 0; --a )
    379 {
    380 /* infeasible check */
    381 if( !machineassignment->feasibles[a]
    382 && nvars > machineassignment->nones[a] && ((~key & machineassignment->keys[a]) == 0) )
    383 {
    384 /* if we compare to an infeasible assignment, that assignment can be smaller or equal since a smaller
    385 * infeasible assignment induces a infeasibility for all assignments which include that assignment
    386 */
    387
    388 /* do the expensive pairwise comparison */
    389 for( j = heurdata->machines[m] - 1; j >= 0; --j )
    390 {
    391 /* at least the same variables in the old combination have to be assigned to 1 */
    392 if( machineassignment->vars[pos][j] < machineassignment->vars[a][j] )
    393 break;
    394 }
    395 /* we already tried this combination */
    396 if( j == -1 )
    397 break;
    398 }
    399 /* feasible check */
    400 else if( machineassignment->feasibles[a] &&
    401 nvars < machineassignment->nones[a] && ((key & ~(machineassignment->keys[a])) == 0) )
    402 {
    403 /* if we compare to a feasible assignment, that assignment can be larger or equal since a larger feasible
    404 * assignment induces a feasibility for all assignments which is subset of that assignment
    405 */
    406
    407 /* do the expensive pairwise comparison */
    408 for( j = heurdata->machines[m] - 1; j >= 0; --j )
    409 {
    410 if( machineassignment->vars[pos][j] > machineassignment->vars[a][j] )
    411 break;
    412 }
    413 /* we already tried this combination */
    414 if( j == -1 )
    415 break;
    416 }
    417 else if( nvars == machineassignment->nones[a] && ((~key & machineassignment->keys[a]) == 0) )
    418 {
    419 /* do the expensive pairwise comparison */
    420 for( j = heurdata->machines[m] - 1; j >= 0; --j )
    421 {
    422 if( machineassignment->vars[pos][j] != machineassignment->vars[a][j] )
    423 break;
    424 }
    425 /* we already tried this combination */
    426 if( j == -1 )
    427 break;
    428 }
    429 }
    430
    431 if( a >= 0 )
    432 {
    433 SCIPdebugMessage("We already tried %s this combination, it was %s\n",
    434 machineassignment->nones[pos] > machineassignment->nones[a] ? "a subset of" : (machineassignment->nones[pos] > machineassignment->nones[a] ? "a superset of" : ""),
    435 machineassignment->feasibles[a] ? "feasible" : "infeasible");
    436
    437 /* delete unnecessary data */
    438 SCIPfreeBlockMemoryArray(scip, &machineassignment->vars[pos], heurdata->machines[m]); /*lint !e866*/
    439 SCIPfreeBlockMemoryArray(scip, &machineassignment->solvals[pos], heurdata->machines[m]); /*lint !e866*/
    440 machineassignment->nassignments--;
    441
    442 infeasible = !machineassignment->feasibles[a];
    443
    444 if( infeasible )
    445 break;
    446
    447 for( j = 0; j < heurdata->machines[m]; ++j )
    448 {
    449 if( machineassignment->vars[a][j] && SCIPvarGetLbLocal(heurdata->binvars[m][j]) > 0.5 )
    450 {
    451 SCIP_CALL( SCIPsetSolVal(scip, sol, heurdata->vars[m][j], machineassignment->solvals[a][j]) );
    452 }
    453 }
    454 }
    455 else
    456 {
    457 SCIP_Real* objvals;
    458 SCIP_Real timelimit;
    459 SCIP_Real memorylimit;
    460 SCIP_Bool solved;
    461 SCIP_Bool error;
    462 int v;
    463
    464 SCIPdebugMessage("check machine %d (variables %d)\n", m, nvars);
    465
    466 SCIP_CALL( SCIPallocBufferArray(scip, &objvals, nvars) );
    467
    468 for( v = 0; v < nvars; ++v )
    469 {
    470 SCIP_VAR* var;
    471
    472 var = vars[v];
    473 assert(var != NULL);
    474
    475 lbs[v] = SCIPvarGetLbLocal(var);
    476 ubs[v] = SCIPvarGetUbLocal(var);
    477 objvals[v] = SCIPvarGetObj(var);
    478 }
    479
    480 /* check whether there is enough time and memory left */
    481 SCIP_CALL( SCIPgetRealParam(scip, "limits/time", &timelimit) );
    482 if( !SCIPisInfinity(scip, timelimit) )
    483 timelimit -= SCIPgetSolvingTime(scip);
    484 SCIP_CALL( SCIPgetRealParam(scip, "limits/memory", &memorylimit) );
    485
    486 /* substract the memory already used by the main SCIP and the estimated memory usage of external software */
    487 if( !SCIPisInfinity(scip, memorylimit) )
    488 {
    489 memorylimit -= SCIPgetMemUsed(scip)/1048576.0;
    490 memorylimit -= SCIPgetMemExternEstim(scip)/1048576.0;
    491 }
    492
    493 /* solve the cumulative condition separately */
    494 SCIP_CALL( SCIPsolveCumulative(scip, nvars, lbs, ubs, objvals, durations, demands, heurdata->capacities[m], 0, INT_MAX,
    495 timelimit, memorylimit, heurdata->maxnodes, &solved, &infeasible, &unbounded, &error) );
    496 assert(!unbounded);
    497 assert(!error);
    498
    499 SCIPfreeBufferArray(scip, &objvals);
    500
    501 machineassignment->feasibles[pos] = !infeasible;
    502
    503 if( infeasible )
    504 {
    505 SCIPdebugMessage("infeasible :-(\n");
    506 break;
    507 }
    508
    509 for( j = 0, v = 0; j < heurdata->machines[m]; ++j )
    510 {
    511 if( machineassignment->vars[pos][j] && SCIPvarGetLbLocal(heurdata->binvars[m][j]) > 0.5 )
    512 {
    513 SCIP_CALL( SCIPsetSolVal(scip, sol, heurdata->vars[m][j], lbs[v]) );
    514 machineassignment->solvals[pos][j] = lbs[v];
    515 v++;
    516 }
    517 }
    518 }
    519 }
    520
    523 SCIPfreeBufferArray(scip, &demands);
    524 SCIPfreeBufferArray(scip, &durations);
    526
    527 /* try and free solution */
    528 if( !infeasible )
    529 {
    530 SCIP_Bool stored;
    531
    532 SCIPdebugMessage("************ try solution <%g>\n", SCIPgetSolOrigObj(scip, sol));
    533
    534 SCIP_CALL( SCIPtrySolFree(scip, &sol, FALSE, FALSE, FALSE, FALSE, TRUE, &stored) );
    535
    536 if( stored )
    537 *result = SCIP_FOUNDSOL;
    538 }
    539 }
    540
    541 /* exit probing mode */
    543
    544 return SCIP_OKAY;
    545}
    546
    547/*
    548 * Callback methods of primal heuristic
    549 */
    550
    551/** copy method for primal heuristic plugins (called when SCIP copies plugins) */
    552static
    553SCIP_DECL_HEURCOPY(heurCopyOptcumulative)
    554{ /*lint --e{715}*/
    555 assert(scip != NULL);
    556 assert(heur != NULL);
    557
    559
    560 /* call inclusion method of heuristic */
    562
    563 return SCIP_OKAY;
    564}
    565
    566/** destructor of primal heuristic to free user data (called when SCIP is exiting) */
    567static
    568SCIP_DECL_HEURFREE(heurFreeOptcumulative)
    569{ /*lint --e{715}*/
    570 SCIP_HEURDATA* heurdata;
    571 int m;
    572
    573 /* free heuristic data */
    574 heurdata = SCIPheurGetData(heur);
    575 assert(heurdata != NULL);
    576
    577 /* release all variables */
    578 for( m = heurdata->nmachines - 1; m >= 0; --m )
    579 {
    580 int a;
    581
    582 for( a = 0; a < heurdata->machineassignments[m]->nassignments; ++a )
    583 {
    584 SCIPfreeBlockMemoryArray(scip, &(heurdata->machineassignments[m]->vars[a]), heurdata->machines[m]); /*lint !e866*/
    585 SCIPfreeBlockMemoryArray(scip, &(heurdata->machineassignments[m]->solvals[a]), heurdata->machines[m]); /*lint !e866*/
    586 }
    587
    588 SCIPfreeBlockMemoryArray(scip, &(heurdata->machineassignments[m]->nones), heurdata->machineassignments[m]->sassignments);
    589 SCIPfreeBlockMemoryArray(scip, &(heurdata->machineassignments[m]->keys), heurdata->machineassignments[m]->sassignments);
    590 SCIPfreeBlockMemoryArray(scip, &(heurdata->machineassignments[m]->feasibles), heurdata->machineassignments[m]->sassignments);
    591 SCIPfreeBlockMemoryArray(scip, &(heurdata->machineassignments[m]->solvals), heurdata->machineassignments[m]->sassignments);
    592 SCIPfreeBlockMemoryArray(scip, &(heurdata->machineassignments[m]->vars), heurdata->machineassignments[m]->sassignments);
    593 SCIPfreeBlockMemory(scip, &heurdata->machineassignments[m]); /*lint !e866*/
    594
    595 SCIPfreeBlockMemoryArray(scip, &heurdata->vars[m], heurdata->machines[m]);
    596 SCIPfreeBlockMemoryArray(scip, &heurdata->binvars[m], heurdata->machines[m]);
    597 SCIPfreeBlockMemoryArray(scip, &heurdata->durations[m], heurdata->machines[m]);
    598 SCIPfreeBlockMemoryArray(scip, &heurdata->demands[m], heurdata->machines[m]);
    599 }
    600
    601 /* free arrays */
    602 SCIPfreeBlockMemoryArrayNull(scip, &heurdata->machineassignments, heurdata->nmachines);
    603 SCIPfreeBlockMemoryArrayNull(scip, &heurdata->demands, heurdata->nmachines);
    604 SCIPfreeBlockMemoryArrayNull(scip, &heurdata->durations, heurdata->nmachines);
    605 SCIPfreeBlockMemoryArrayNull(scip, &heurdata->binvars, heurdata->nmachines);
    606 SCIPfreeBlockMemoryArrayNull(scip, &heurdata->vars, heurdata->nmachines);
    607
    608 SCIPfreeBlockMemoryArrayNull(scip, &heurdata->capacities, heurdata->nmachines);
    609 SCIPfreeBlockMemoryArrayNull(scip, &heurdata->machines, heurdata->nmachines);
    610
    611 SCIPfreeBlockMemory(scip, &heurdata);
    612 SCIPheurSetData(heur, NULL);
    613
    614 return SCIP_OKAY;
    615}
    616
    617/** initialization method of primal heuristic (called after problem was transformed) */
    618#define heurInitOptcumulative NULL
    619
    620/** deinitialization method of primal heuristic (called before transformed problem is freed) */
    621#define heurExitOptcumulative NULL
    622
    623/** solving process initialization method of primal heuristic (called when branch and bound process is about to begin) */
    624#define heurInitsolOptcumulative NULL
    625
    626/** solving process deinitialization method of primal heuristic (called before branch and bound process data is freed) */
    627#define heurExitsolOptcumulative NULL
    628
    629/** execution method of primal heuristic */
    630static
    631SCIP_DECL_HEUREXEC(heurExecOptcumulative)
    632{ /*lint --e{715}*/
    633 SCIP_HEURDATA* heurdata;
    634
    635 assert( heur != NULL );
    636 assert( scip != NULL );
    637 assert( result != NULL );
    638
    639 *result = SCIP_DIDNOTRUN;
    640
    642 return SCIP_OKAY;
    643
    644 heurdata = SCIPheurGetData(heur);
    645 assert(heurdata != NULL);
    646
    647 if( !heurdata->initialized )
    648 return SCIP_OKAY;
    649
    650 if( SCIPisStopped(scip) )
    651 return SCIP_OKAY;
    652
    653 SCIPdebugMessage("apply optcumulative heuristic at node %"SCIP_LONGINT_FORMAT"\n",
    655
    656 *result = SCIP_DIDNOTFIND;
    657
    658 /* try variable lower and upper bounds which respect to objective coefficients */
    659 SCIP_CALL( applyOptcumulative(scip, heur, heurdata, result) );
    660
    661 return SCIP_OKAY;
    662}
    663
    664/*
    665 * primal heuristic specific interface methods
    666 */
    667
    668/** creates the optcumulative primal heuristic and includes it in SCIP */
    670 SCIP* scip /**< SCIP data structure */
    671 )
    672{
    673 SCIP_HEURDATA* heurdata;
    674
    675 /* create optcumulative primal heuristic data */
    676 SCIP_CALL( SCIPallocBlockMemory(scip, &heurdata) );
    677 heurdataReset(scip, heurdata);
    678
    679 /* include primal heuristic */
    682 heurCopyOptcumulative,
    683 heurFreeOptcumulative, heurInitOptcumulative, heurExitOptcumulative,
    685 heurdata) );
    686
    687 /* add variable bounds primal heuristic parameters */
    688 SCIP_CALL( SCIPaddLongintParam(scip, "heuristics/"HEUR_NAME"/maxnodes",
    689 "maximum number of nodes to regard in the subproblem",
    690 &heurdata->maxnodes, TRUE,DEFAULT_MAXNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
    691 SCIP_CALL( SCIPaddIntParam(scip, "heuristics/"HEUR_NAME"/maxproprounds",
    692 "maximum number of propagation rounds during probing (-1 infinity)",
    693 &heurdata->maxproprounds, TRUE, DEFAULT_MAXPROPROUNDS, -1, INT_MAX/4, NULL, NULL) );
    694
    695 return SCIP_OKAY;
    696}
    697
    698/** initialize the heuristics data structure */
    700 SCIP* scip, /**< original SCIP data structure */
    701 int nmachines, /**< number of machines */
    702 int njobs, /**< number of njobs */
    703 int* machines, /**< number of jobs for each machines */
    704 SCIP_VAR*** binvars, /**< machnine job matrix (choice variables) */
    705 SCIP_VAR*** vars, /**< machnine job matrix (start time variables) */
    706 int** durations, /**< machnine job duration matrix */
    707 int** demands, /**< machnine job demands matrix */
    708 int* capacities /**< machine capacities */
    709 )
    710{
    711 SCIP_HEUR* heur;
    712 SCIP_HEURDATA* heurdata;
    713 int m;
    714
    715 heur = SCIPfindHeur(scip, HEUR_NAME);
    716
    717 if( heur == NULL )
    718 {
    719 SCIPerrorMessage("optcumulative heuristic not found\n");
    720 return SCIP_PLUGINNOTFOUND;
    721 }
    722
    723 heurdata = SCIPheurGetData(heur);
    724 assert(heurdata != NULL);
    725
    726 /* copy the problem data */
    727 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &heurdata->vars, nmachines) );
    728 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &heurdata->binvars, nmachines) );
    729 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &heurdata->durations, nmachines) );
    730 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &heurdata->demands, nmachines) );
    731 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &heurdata->machineassignments, nmachines) );
    732
    733 for( m = 0; m < nmachines; ++m )
    734 {
    735 SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &heurdata->vars[m], vars[m], machines[m]) ); /*lint !e866*/
    736 SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &heurdata->binvars[m], binvars[m], machines[m]) ); /*lint !e866*/
    737 SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &heurdata->durations[m], durations[m], machines[m]) ); /*lint !e866*/
    738 SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &heurdata->demands[m], demands[m], machines[m]) ); /*lint !e866*/
    739
    740 /* sort variable w.r.t. their objective coefficient */
    741 SCIPsortPtrPtrIntInt((void**)heurdata->binvars[m], (void**)heurdata->vars[m],
    742 heurdata->durations[m], heurdata->demands[m], SCIPvarCompObj, machines[m]);
    743
    744 SCIP_CALL( SCIPallocBlockMemory(scip, &heurdata->machineassignments[m]) ); /*lint !e866*/
    745 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(heurdata->machineassignments[m]->vars), njobs) );
    746 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(heurdata->machineassignments[m]->solvals), njobs) );
    747 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(heurdata->machineassignments[m]->feasibles), njobs) );
    748 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(heurdata->machineassignments[m]->keys), njobs) );
    749 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(heurdata->machineassignments[m]->nones), njobs) );
    750 heurdata->machineassignments[m]->nassignments = 0;
    751 heurdata->machineassignments[m]->sassignments = njobs;
    752 }
    753
    754 SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &heurdata->machines, machines, nmachines) );
    755 SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &heurdata->capacities, capacities, nmachines) );
    756
    757 heurdata->nmachines = nmachines;
    758 heurdata->njobs = njobs;
    759 heurdata->initialized = TRUE;
    760
    761 return SCIP_OKAY;
    762}
    SCIP_VAR * a
    Definition: circlepacking.c:66
    constraint handler for cumulative constraints
    #define NULL
    Definition: def.h:257
    #define SCIP_Longint
    Definition: def.h:150
    #define SCIP_Bool
    Definition: def.h:100
    #define SCIP_STRINGEQ(name, reference, retcode)
    Definition: def.h:454
    #define SCIP_Real
    Definition: def.h:165
    #define TRUE
    Definition: def.h:102
    #define FALSE
    Definition: def.h:103
    #define SCIP_LONGINT_FORMAT
    Definition: def.h:157
    #define SCIP_LONGINT_MAX
    Definition: def.h:151
    #define SCIP_CALL(x)
    Definition: def.h:364
    SCIP_RETCODE SCIPsolveCumulative(SCIP *scip, int njobs, SCIP_Real *ests, SCIP_Real *lsts, SCIP_Real *objvals, int *durations, int *demands, int capacity, int hmin, int hmax, SCIP_Real timelimit, SCIP_Real memorylimit, SCIP_Longint maxnodes, SCIP_Bool *solved, SCIP_Bool *infeasible, SCIP_Bool *unbounded, SCIP_Bool *error)
    SCIP_Bool SCIPisStopped(SCIP *scip)
    Definition: scip_general.c:767
    SCIP_VAR ** SCIPgetOrigVars(SCIP *scip)
    Definition: scip_prob.c:2811
    int SCIPgetNOrigVars(SCIP *scip)
    Definition: scip_prob.c:2838
    SCIP_RETCODE SCIPaddLongintParam(SCIP *scip, const char *name, const char *desc, SCIP_Longint *valueptr, SCIP_Bool isadvanced, SCIP_Longint defaultvalue, SCIP_Longint minvalue, SCIP_Longint maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
    Definition: scip_param.c:111
    SCIP_RETCODE SCIPaddIntParam(SCIP *scip, const char *name, const char *desc, int *valueptr, SCIP_Bool isadvanced, int defaultvalue, int minvalue, int maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
    Definition: scip_param.c:83
    SCIP_RETCODE SCIPgetRealParam(SCIP *scip, const char *name, SCIP_Real *value)
    Definition: scip_param.c:307
    int SCIPgetNPseudoBranchCands(SCIP *scip)
    Definition: scip_branch.c:766
    SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
    Definition: heur.c:1368
    SCIP_RETCODE SCIPincludeHeur(SCIP *scip, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, SCIP_HEURTIMING timingmask, SCIP_Bool usessubscip, SCIP_DECL_HEURCOPY((*heurcopy)), SCIP_DECL_HEURFREE((*heurfree)), SCIP_DECL_HEURINIT((*heurinit)), SCIP_DECL_HEUREXIT((*heurexit)), SCIP_DECL_HEURINITSOL((*heurinitsol)), SCIP_DECL_HEUREXITSOL((*heurexitsol)), SCIP_DECL_HEUREXEC((*heurexec)), SCIP_HEURDATA *heurdata)
    Definition: scip_heur.c:67
    SCIP_HEUR * SCIPfindHeur(SCIP *scip, const char *name)
    Definition: scip_heur.c:263
    const char * SCIPheurGetName(SCIP_HEUR *heur)
    Definition: heur.c:1467
    void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
    Definition: heur.c:1378
    SCIP_Real SCIPgetPseudoObjval(SCIP *scip)
    Definition: scip_lp.c:339
    SCIP_Longint SCIPgetMemExternEstim(SCIP *scip)
    Definition: scip_mem.c:126
    #define SCIPfreeBlockMemoryArray(scip, ptr, num)
    Definition: scip_mem.h:110
    SCIP_Longint SCIPgetMemUsed(SCIP *scip)
    Definition: scip_mem.c:100
    int SCIPcalcMemGrowSize(SCIP *scip, int num)
    Definition: scip_mem.c:139
    #define SCIPallocBufferArray(scip, ptr, num)
    Definition: scip_mem.h:124
    #define SCIPfreeBufferArray(scip, ptr)
    Definition: scip_mem.h:136
    #define SCIPallocBlockMemoryArray(scip, ptr, num)
    Definition: scip_mem.h:93
    #define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
    Definition: scip_mem.h:99
    #define SCIPfreeBlockMemory(scip, ptr)
    Definition: scip_mem.h:108
    #define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
    Definition: scip_mem.h:111
    #define SCIPallocBlockMemory(scip, ptr)
    Definition: scip_mem.h:89
    #define SCIPduplicateBlockMemoryArray(scip, ptr, source, num)
    Definition: scip_mem.h:105
    SCIP_Longint SCIPnodeGetNumber(SCIP_NODE *node)
    Definition: tree.c:8513
    int SCIPgetProbingDepth(SCIP *scip)
    Definition: scip_probing.c:199
    SCIP_RETCODE SCIPpropagateProbing(SCIP *scip, int maxproprounds, SCIP_Bool *cutoff, SCIP_Longint *ndomredsfound)
    Definition: scip_probing.c:581
    SCIP_RETCODE SCIPbacktrackProbing(SCIP *scip, int probingdepth)
    Definition: scip_probing.c:226
    SCIP_RETCODE SCIPstartProbing(SCIP *scip)
    Definition: scip_probing.c:120
    SCIP_RETCODE SCIPnewProbingNode(SCIP *scip)
    Definition: scip_probing.c:166
    SCIP_RETCODE SCIPfixVarProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval)
    Definition: scip_probing.c:419
    SCIP_RETCODE SCIPendProbing(SCIP *scip)
    Definition: scip_probing.c:261
    SCIP_RETCODE SCIPcreateOrigSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
    Definition: scip_sol.c:829
    SCIP_RETCODE SCIPtrySolFree(SCIP *scip, SCIP_SOL **sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
    Definition: scip_sol.c:4114
    SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
    Definition: scip_sol.c:1890
    SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
    Definition: scip_sol.c:1569
    SCIP_Real SCIPgetUpperbound(SCIP *scip)
    SCIP_Real SCIPgetLowerbound(SCIP *scip)
    SCIP_Real SCIPgetSolvingTime(SCIP *scip)
    Definition: scip_timing.c:378
    SCIP_Real SCIPinfinity(SCIP *scip)
    SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
    SCIP_NODE * SCIPgetCurrentNode(SCIP *scip)
    Definition: scip_tree.c:91
    SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
    Definition: var.c:24300
    SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
    Definition: var.c:23932
    const char * SCIPvarGetName(SCIP_VAR *var)
    Definition: var.c:23299
    SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
    Definition: var.c:24266
    void SCIPsortPtrPtrIntInt(void **ptrarray1, void **ptrarray2, int *intarray1, int *intarray2, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), int len)
    #define heurInitsolOptcumulative
    static SCIP_DECL_HEUREXEC(heurExecOptcumulative)
    static SCIP_RETCODE initializeSol(SCIP *scip, SCIP_SOL *sol)
    #define DEFAULT_MAXNODES
    SCIP_RETCODE SCIPinitHeurOptcumulative(SCIP *scip, int nmachines, int njobs, int *machines, SCIP_VAR ***binvars, SCIP_VAR ***vars, int **durations, int **demands, int *capacities)
    #define HEUR_TIMING
    #define HEUR_FREQOFS
    #define HEUR_DESC
    static SCIP_RETCODE applyOptcumulativeFixings(SCIP *scip, SCIP_HEURDATA *heurdata, SCIP_Bool *infeasible)
    static SCIP_RETCODE applyOptcumulative(SCIP *scip, SCIP_HEUR *heur, SCIP_HEURDATA *heurdata, SCIP_RESULT *result)
    #define HEUR_DISPCHAR
    #define HEUR_MAXDEPTH
    #define HEUR_PRIORITY
    static void heurdataReset(SCIP *scip, SCIP_HEURDATA *heurdata)
    #define HEUR_NAME
    #define heurExitOptcumulative
    #define heurExitsolOptcumulative
    SCIP_RETCODE SCIPincludeHeurOptcumulative(SCIP *scip)
    #define HEUR_FREQ
    #define HEUR_USESSUBSCIP
    #define DEFAULT_MAXPROPROUNDS
    #define heurInitOptcumulative
    static SCIP_DECL_HEURCOPY(heurCopyOptcumulative)
    static SCIP_DECL_HEURFREE(heurFreeOptcumulative)
    heuristic for cumulative scheduling with optional activities
    #define BMSclearMemoryArray(ptr, num)
    Definition: memory.h:130
    #define SCIPerrorMessage
    Definition: pub_message.h:64
    #define SCIPdebugMessage
    Definition: pub_message.h:96
    SCIP_Real ** solvals
    SCIP_Bool * feasibles
    unsigned int * keys
    struct SCIP_HeurData SCIP_HEURDATA
    Definition: type_heur.h:77
    @ SCIP_DIDNOTRUN
    Definition: type_result.h:42
    @ SCIP_DIDNOTFIND
    Definition: type_result.h:44
    @ SCIP_FOUNDSOL
    Definition: type_result.h:56
    enum SCIP_Result SCIP_RESULT
    Definition: type_result.h:61
    @ SCIP_PLUGINNOTFOUND
    Definition: type_retcode.h:54
    @ SCIP_OKAY
    Definition: type_retcode.h:42
    @ SCIP_INVALIDCALL
    Definition: type_retcode.h:51
    enum SCIP_Retcode SCIP_RETCODE
    Definition: type_retcode.h:63