Scippy

SCIP

Solving Constraint Integer Programs

heur_repair.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-2019 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file heur_repair.c
17  * @brief repair primal heuristic
18  * @author Gregor Hendel
19  * @author Thomas Nagel
20  *
21  */
22 
23 /* This heuristic takes an infeasible solution and tries to repair it.
24  * This can happen by variable fixing as long as the sum of all potential possible shiftings
25  * is higher than alpha*slack or slack variables with a strong penalty on the objective function.
26  * This heuristic cannot run if variable fixing and slack variables are turned off.
27  */
28 
29 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
30 
31 #include "blockmemshell/memory.h"
32 #include "scip/cons_linear.h"
33 #include "scip/cons_varbound.h"
34 #include "scip/heur_repair.h"
35 #include "scip/pub_heur.h"
36 #include "scip/pub_lp.h"
37 #include "scip/pub_message.h"
38 #include "scip/pub_misc.h"
39 #include "scip/pub_misc_sort.h"
40 #include "scip/pub_var.h"
41 #include "scip/scip_branch.h"
42 #include "scip/scip_cons.h"
43 #include "scip/scip_copy.h"
44 #include "scip/scip_general.h"
45 #include "scip/scip_heur.h"
46 #include "scip/scip_lp.h"
47 #include "scip/scip_mem.h"
48 #include "scip/scip_message.h"
49 #include "scip/scip_numerics.h"
50 #include "scip/scip_param.h"
51 #include "scip/scip_prob.h"
52 #include "scip/scip_sol.h"
53 #include "scip/scip_solve.h"
54 #include "scip/scip_solvingstats.h"
55 #include "scip/scip_timing.h"
56 #include "scip/scip_tree.h"
57 #include "scip/scip_var.h"
58 #include "scip/scipdefplugins.h"
59 #include <string.h>
60 
61 #define HEUR_NAME "repair"
62 #define HEUR_DESC "tries to repair a primal infeasible solution"
63 #define HEUR_DISPCHAR '!'
64 #define HEUR_PRIORITY 0
65 #define HEUR_FREQ -1
66 #define HEUR_FREQOFS 0
67 #define HEUR_MAXDEPTH -1
68 #define HEUR_TIMING SCIP_HEURTIMING_AFTERNODE
69 #define HEUR_USESSUBSCIP TRUE /**< does the heuristic use a secondary SCIP instance? */
70 #define DEFAULT_MINFIXINGRATE 0.3 /* minimum percentage of integer variables that have to be fixed */
71 
72 #define DEFAULT_NODESOFS 500 /* number of nodes added to the contingent of the total nodes */
73 #define DEFAULT_MAXNODES 5000 /* maximum number of nodes to regard in the subproblem */
74 #define DEFAULT_MINNODES 50 /* minimum number of nodes to regard in the subproblem */
75 #define DEFAULT_NODESQUOT 0.1 /* subproblem nodes in relation to nodes of the original problem */
76 
77 #define DEFAULT_FILENAME "-" /**< file name of a solution to be used as infeasible starting point */
78 #define DEFAULT_ROUNDIT TRUE /**< if it is TRUE : fractional variables which are not fractional in the given
79  * solution are rounded, if it is FALSE : solving process of this heuristic
80  * is stopped
81  */
82 #define DEFAULT_USEOBJFACTOR FALSE /**< should a scaled objective function for original variables be used in repair
83  * subproblem?
84  */
85 #define DEFAULT_USEVARFIX TRUE /**< should variable fixings be used in repair subproblem? */
86 #define DEFAULT_USESLACKVARS FALSE /**< should slack variables be used in repair subproblem? */
87 #define DEFAULT_ALPHA 2.0 /**< how many times the potential should be bigger than the slack? */
88 
89 /*
90  * Data structures
91  */
92 
93 
94 /** primal heuristic data */
95 struct SCIP_HeurData
96 {
97  SCIP_SOL* infsol; /**< infeasible solution to start with */
98  char* filename; /**< file name of a solution to be used as infeasible starting point */
99  SCIP_Longint usednodes; /**< number of already used nodes by repair */
100  SCIP_Longint subnodes; /**< number of nodes which were necessary to solve the sub-SCIP */
101  SCIP_Longint subiters; /**< contains total number of iterations used in primal and dual simplex
102  * and barrier algorithm to solve the sub-SCIP
103  */
104  SCIP_Real relvarfixed; /**< relative number of fixed variables */
105  SCIP_Real alpha; /**< how many times the potential should be bigger than the slack? */
106  SCIP_Real nodesquot; /**< subproblem nodes in relation to nodes of the original problem */
107  SCIP_Real minfixingrate; /**< minimum percentage of integer variables that have to be fixed */
108 #ifdef SCIP_STATISTIC
109  SCIP_Real relviolatedvars; /**< relative number of violated variables */
110  SCIP_Real subpresoltime; /**< time for presolving the sub-SCIP */
111  SCIP_Real relviolatedcons; /**< relative number of violated cons */
112  SCIP_Real originalsolval; /**< value of the solution find by repair, in the original Problem*/
113  SCIP_Real improvedoldsol; /**< value of the given solution after being improved by SCIP */
114  int nviolatedvars; /**< number of violated variables in the given solution */
115  int norigvars; /**< number of all variables in the given problem */
116  int nviolatedcons; /**< number of violated cons in the given solution */
117  int norcons; /**< number of all cons in the given problem */
118 #endif
119  int nvarfixed; /**< number of all variables fixed in the sub problem */
120  int runs; /**< number of branch and bound runs performed to solve the sub-SCIP */
121  int nodesofs; /**< number of nodes added to the contingent of the total nodes */
122  int maxnodes; /**< maximum number of nodes to regard in the subproblem */
123  int minnodes; /**< minimum number of nodes to regard in the subproblem */
124  SCIP_Bool roundit; /**< if it is TRUE : fractional variables which are not fractional in the
125  * given solution are rounded, if it is FALSE : solving process of this
126  * heuristic is stopped.
127  */
128  SCIP_Bool useobjfactor; /**< should a scaled objective function for original variables be used in
129  * repair subproblem?
130  */
131  SCIP_Bool usevarfix; /**< should variable fixings be used in repair subproblem? */
132  SCIP_Bool useslackvars; /**< should slack variables be used in repair subproblem? */
133 };
134 
135 
136 /*
137  * Local methods
138  */
139 
140 /** computes a factor, so that (factor) * (original objective upper bound) <= 1.*/
141 static
143  SCIP* scip, /**< SCIP data structure */
144  SCIP* subscip, /**< SCIP data structure */
145  SCIP_Real* factor, /**< SCIP_Real to save the factor for the old objective function*/
146  SCIP_Bool* success /**< SCIP_Bool: Is the factor real?*/
147  )
148 {
149  SCIP_VAR** vars;
150  SCIP_Real lprelaxobj;
151  SCIP_Real upperbound;
152  SCIP_Real objoffset;
153  int nvars;
154  int i;
155 
156  *success = TRUE;
157  *factor = 0.0;
158  upperbound = 0.0;
159 
160  lprelaxobj = SCIPgetLowerbound(scip);
161 
162  if( SCIPisInfinity(scip, -lprelaxobj) )
163  {
164  return SCIP_OKAY;
165  }
166 
167  if( !SCIPisInfinity(scip, SCIPgetUpperbound(scip)) )
168  {
169  upperbound = SCIPgetUpperbound(scip);
170  }
171  else
172  {
173  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
174 
175  /* tries to find an upper bound for the original objective function, by compute the worst objective value of the
176  * LP-relaxation, which holds all variable bounds
177  */
178  for (i = 0; i < nvars; ++i)
179  {
180  upperbound = SCIPvarGetObj(vars[i]);
181  if( SCIPisInfinity(scip, upperbound) || SCIPisInfinity(scip, -upperbound) )
182  {
183  /* TODO fancy diving function to find a solution for the max problem */
184  *factor = 1 / SCIPinfinity(scip);
185  return SCIP_OKAY;
186  }
187  else if( SCIPisZero(scip, upperbound) )
188  {
189  continue;
190  }
191  else if( SCIPisGT(scip, 0.0, upperbound) )
192  {
193  *factor += upperbound * SCIPvarGetLbGlobal(vars[i]);
194  }
195  else
196  {
197  *factor += upperbound * SCIPvarGetUbGlobal(vars[i]);
198  }
199  }
200  }
201 
202  /* Ending-sequence */
203  *factor = upperbound - lprelaxobj;
204  if( !SCIPisZero(scip, *factor) )
205  {
206  *factor = 1.0 / *factor;
207  }
208 
209  /* set an offset which guarantees positive objective values */
210  objoffset = -lprelaxobj * (*factor);
211  SCIP_CALL( SCIPaddOrigObjoffset(subscip, -objoffset) );
212 
213  return SCIP_OKAY;
214 }
215 
216 /** returns the contributed potential for a variable */
217 static
219  SCIP* scip, /**< SCIP data structure */
220  SCIP_SOL* sol, /**< infeasible solution */
221  SCIP_VAR* var, /**< variable, which potential should be returned */
222  SCIP_Real coefficient, /**< variables coefficient in corresponding row */
223  int sgn /**< sign of the slack */
224  )
225 {
226  SCIP_Real potential;
227 
228  assert(NULL != scip);
229  assert(NULL != var);
230 
231  if( 0 > sgn * coefficient )
232  {
233  if( SCIPisInfinity(scip, -SCIPvarGetLbGlobal(var)) )
234  {
235  potential = SCIPinfinity(scip);
236  }
237  else
238  {
239  potential = coefficient * (SCIPgetSolVal(scip, sol, var) - SCIPvarGetLbGlobal(var));
240  }
241  }
242  else
243  {
244  if( SCIPisInfinity(scip, SCIPvarGetUbGlobal(var)) )
245  {
246  potential = -SCIPinfinity(scip);
247  }
248  else
249  {
250  potential = coefficient * (SCIPgetSolVal(scip, sol, var) - SCIPvarGetUbGlobal(var));
251  }
252  }
253 
254  if( SCIPisZero(scip, potential) )
255  {
256  potential = 0.0;
257  }
258  return potential;
259 }
260 
261 /** finds out if a variable can be fixed with respect to the potentials of all rows, if it is possible, the potentials
262  * of rows are adapted and TRUE is returned.
263  */
264 static
266  SCIP* scip, /**< SCIP data structure */
267  SCIP* subscip, /**< sub-SCIP data structure */
268  SCIP_SOL* sol, /**< solution data structure */
269  SCIP_Real* potential, /**< array with all potential values */
270  SCIP_Real* slack, /**< array with all slack values */
271  SCIP_VAR* var, /**< variable to be fixed? */
272  SCIP_VAR* subvar, /**< representative variable for var in the sub-SCIP */
273  int* inftycounter, /**< counters how many variables have an infinity potential in a row */
274  SCIP_HEURDATA* heurdata, /**< repairs heuristic data */
275  SCIP_Bool* infeasible, /**< pointer to store whether the fixing is infeasible */
276  SCIP_Bool* fixed /**< pointer to store whether the fixing was performed (variable was unfixed) */
277  )
278 {
279  SCIP_ROW** rows;
280  SCIP_COL* col;
281  SCIP_Real* vals;
282  SCIP_Real alpha;
283  SCIP_Real solval;
284  int nrows;
285  int i;
286  int sgn;
287  int rowindex;
288 
289  assert(NULL != scip);
290  assert(NULL != potential);
291  assert(NULL != slack);
292  assert(NULL != var);
293  assert(NULL != inftycounter);
294  assert(NULL != heurdata);
295 
296  alpha = heurdata->alpha;
297  *infeasible = TRUE;
298  *fixed = FALSE;
299 
300  solval = SCIPgetSolVal(scip, sol, var);
301 
302  if( SCIPisFeasLT(scip, solval, SCIPvarGetLbGlobal(var)) )
303  {
304  return SCIP_OKAY;
305  }
306  if( SCIPisFeasGT(scip, solval, SCIPvarGetUbGlobal(var)) )
307  {
308  return SCIP_OKAY;
309  }
310 
311  col = SCIPvarGetCol(var);
312  rows = SCIPcolGetRows(col);
313  nrows = SCIPcolGetNLPNonz(col);
314  vals = SCIPcolGetVals(col);
315 
316  if( NULL == rows )
317  {
318  SCIP_CALL( SCIPfixVar(subscip, subvar, solval,
319  infeasible, fixed) );
320  assert(!*infeasible && *fixed);
321  heurdata->nvarfixed++;
322  SCIPdebugMsg(scip,"Variable %s is fixed to %g\n",SCIPvarGetName(var), solval);
323  return SCIP_OKAY;
324  }
325  assert(NULL != rows);
326 
327  /* iterate over rows, where the variable coefficient is nonzero */
328  for( i = 0; i < nrows; ++i )
329  {
330  SCIP_Real contribution;
331  rowindex = SCIProwGetLPPos(rows[i]);
332  assert(rowindex >= 0);
333 
334  sgn = 1;
335 
336  if( SCIPisFeasZero(scip, slack[rowindex]) )
337  {
338  continue;
339  }
340  else if( SCIPisFeasGT(scip, 0.0 , slack[rowindex]) )
341  {
342  sgn = -1;
343  }
344 
345  contribution = getPotentialContributed(scip, sol, var, vals[i], sgn);
346 
347  if( !SCIPisInfinity(scip, REALABS(contribution)) )
348  {
349  potential[rowindex] -= contribution;
350  }
351  else
352  {
353  inftycounter[rowindex]--;
354  }
355 
356  assert(0 <= inftycounter[rowindex]);
357  if( 0 == inftycounter[rowindex] && REALABS(potential[rowindex]) < alpha * REALABS(slack[rowindex]) )
358  {
359  /* revert the changes before */
360  int j = i;
361  for( ; j >= 0; --j )
362  {
363  sgn = 1;
364  if( 0 == slack[rowindex] )
365  {
366  continue;
367  }
368  rowindex = SCIProwGetLPPos(rows[j]);
369  if( 0 > slack[rowindex])
370  {
371  sgn = -1;
372  }
373  contribution = getPotentialContributed(scip, sol, var, vals[j], sgn);
374  if( !SCIPisInfinity(scip, REALABS(contribution)) )
375  {
376  potential[rowindex] += contribution;
377  }
378  else
379  {
380  inftycounter[rowindex]++;
381  }
382  }
383  return SCIP_OKAY;
384  }
385  }
386 
387  SCIP_CALL( SCIPfixVar(subscip, subvar, solval, infeasible, fixed) );
388  assert(!*infeasible && *fixed);
389  heurdata->nvarfixed++;
390  SCIPdebugMsg(scip,"Variable %s is fixed to %g\n",SCIPvarGetName(var),
391  SCIPgetSolVal(scip, sol, var));
392 
393  return SCIP_OKAY;
394 }
395 
396 /** checks if all integral variables in the given solution are integral. */
397 static
399  SCIP* scip, /**< SCIP data structure */
400  SCIP_SOL* sol, /**< solution pointer to the to be checked solution */
401  SCIP_Bool roundit, /**< round fractional solution values of integer variables */
402  SCIP_Bool* success /**< pointer to store if all integral variables are integral or could
403  * be rounded
404  */
405  )
406 {
407  SCIP_VAR** vars;
408  int nvars;
409  int nfracvars;
410  int nbinvars;
411  int nintvars;
412  int i;
413 
414  assert(NULL != success);
415  assert(NULL != sol);
416 
417  *success = TRUE;
418 
419  /* get variable data */
420  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, &nbinvars, &nintvars, NULL, NULL) );
421 
422  /* check if the candidates are fractional and round them if necessary */
423  nfracvars = nbinvars + nintvars;
424  for( i = 0; i < nfracvars; ++i)
425  {
426  SCIP_Real value = SCIPgetSolVal(scip, sol, vars[i]);
427 
428  if( SCIPisInfinity(scip, REALABS(value)) )
429  {
430  *success = FALSE;
431  SCIPdebugMsg(scip, "Variable with infinite solution value");
432 
433  return SCIP_OKAY;
434  }
435  if( !SCIPisFeasIntegral(scip, value) )
436  {
437  if( roundit )
438  {
439  SCIP_Real roundedvalue;
440 
442  {
443  roundedvalue = SCIPceil(scip, value - 1.0);
444  }
445  else
446  {
447  roundedvalue = SCIPfloor(scip, value + 1.0);
448  }
449 
450  SCIP_CALL( SCIPsetSolVal(scip, sol, vars[i], roundedvalue) );
451  }
452  else
453  {
454  *success = FALSE;
455  SCIPdebugMsg(scip, "Repair: All variables are integral.\n");
456  return SCIP_OKAY;
457  }
458  }
459  }
460 
461  /* ensure that no other variables have infinite LP solution values */
462  for( ; i < nvars; ++i )
463  {
464  if( SCIPisInfinity(scip, REALABS(SCIPgetSolVal(scip, sol, vars[i]))) )
465  {
466  *success = FALSE;
467  SCIPdebugMsg(scip, "Variable with infinite solution value");
468 
469  return SCIP_OKAY;
470  }
471  }
472 
473  SCIPdebugMsg(scip, "All variables rounded.\n");
474  return SCIP_OKAY;
475 }
476 
477 /** creates a new solution for the original problem by copying the solution of the subproblem */
478 static
480  SCIP* scip, /**< original SCIP data structure */
481  SCIP* subscip, /**< SCIP structure of the subproblem */
482  SCIP_VAR** subvars, /**< the variables of the subproblem */
483  SCIP_HEUR* heur, /**< Repair heuristic structure */
484  SCIP_SOL* subsol, /**< solution of the subproblem */
485  SCIP_Bool* success /**< used to store whether new solution was found or not */
486  )
487 {
488  SCIP_VAR** vars; /* the original problem's variables */
489  int nvars; /* the original problem's number of variables */
490  SCIP_Real* subsolvals; /* solution values of the subproblem */
491  SCIP_SOL* newsol; /* solution to be created for the original problem */
492 
493  assert(scip != NULL);
494  assert(subscip != NULL);
495  assert(subvars != NULL);
496  assert(subsol != NULL);
497 
498  /* get variables' data */
499  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
500 
501  /* sub-SCIP may have more variables than the number of active (transformed) variables in the main SCIP
502  * since constraint copying may have required the copy of variables that are fixed in the main SCIP
503  */
504  assert(nvars <= SCIPgetNOrigVars(subscip));
505 
506  SCIP_CALL( SCIPallocBufferArray(scip, &subsolvals, nvars) );
507 
508  /* copy the solution */
509  SCIP_CALL( SCIPgetSolVals(subscip, subsol, nvars, subvars, subsolvals) );
510 
511  /* create new solution for the original problem */
512  SCIP_CALL( SCIPcreateSol(scip, &newsol, heur) );
513  SCIP_CALL( SCIPsetSolVals(scip, newsol, nvars, vars, subsolvals) );
514  /* try to add new solution to SCIP and free it immediately */
515  SCIP_CALL( SCIPtrySolFree(scip, &newsol, FALSE, FALSE, TRUE, TRUE, TRUE, success) );
516 
517 #ifdef SCIP_STATISTICS
518  {
519  SCIP_HEURDATA* heurdata;
520  heurdata = SCIPheurGetData(heur);
521 
522  if( *success )
523  {
524  heurdata->originalsolval = SCIPgetSolOrigObj(scip, newsol);
525  }
526  }
527 #endif
528 
529  SCIPfreeBufferArray(scip, &subsolvals);
530 
531  return SCIP_OKAY;
532 }
533 
534 /** tries to fix variables as an approach to repair a solution. */
535 static
537  SCIP* scip, /**< SCIP data structure of the problem */
538  SCIP_HEUR* heur, /**< pointer to this heuristic instance */
539  SCIP_RESULT* result, /**< pointer to return the result status */
540  SCIP_Longint nnodes /**< nodelimit for sub-SCIP */
541  )
542 {
543  SCIP* subscip = NULL;
544  SCIP_VAR** vars = NULL;
545  SCIP_VAR** subvars = NULL;
546  SCIP_ROW** rows;
547  SCIP_CONS** subcons = NULL;
548  int* nviolatedrows = NULL;
549  int* permutation = NULL;
550  int* inftycounter = NULL;
551  SCIP_SOL* sol;
552  SCIP_SOL* subsol = NULL;
553  SCIP_HEURDATA* heurdata;
554  SCIP_Real* potential = NULL;
555  SCIP_Real* slacks = NULL;
556  SCIP_RETCODE retcode = SCIP_OKAY;
557  SCIP_Real timelimit;
558  SCIP_Real memorylimit;
559  SCIP_Real factor;
560  char probname[SCIP_MAXSTRLEN];
561  int i;
562  int nbinvars;
563  int nintvars;
564  int nvars;
565  int nrows;
566  int ndiscvars;
567  int nfixeddiscvars;
568  SCIP_Bool success;
569 
570  heurdata = SCIPheurGetData(heur);
571  sol = heurdata->infsol;
572 
573  /* initializes the sub-SCIP */
574  SCIP_CALL( SCIPcreate(&subscip) );
576  SCIP_CALL( SCIPcopyParamSettings(scip, subscip) );
577 
578  /* use inference branching */
579  if( SCIPfindBranchrule(subscip, "inference") != NULL && !SCIPisParamFixed(subscip, "branching/inference/priority") )
580  {
581  SCIP_CALL( SCIPsetIntParam(subscip, "branching/inference/priority", INT_MAX/4) );
582  }
583 
584  /* get name of the original problem and add the string "_repairsub" */
585  (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN, "%s_repairsub", SCIPgetProbName(scip));
586 
587  SCIP_CALL( SCIPcreateProb(subscip, probname, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );
588 
589  /* a trivial feasible solution can be constructed if violations are modeled with slack variables */
590  if( heurdata->useslackvars )
591  {
592  SCIP_CALL( SCIPcreateSol(subscip, &subsol, heur) );
593  }
594 
595  /* gets all original variables */
596  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, &nbinvars, &nintvars, NULL, NULL) );
597  SCIP_CALL( SCIPallocBufferArray(scip, &subvars, nvars) );
598  SCIP_CALL( SCIPallocBufferArray(scip, &nviolatedrows, nvars) );
599  SCIP_CALL( SCIPallocBufferArray(scip, &permutation, nvars) );
600 
601  SCIPdebugMsg(scip,"\n\n Calling objective factor calculation \n\n");
602  if( heurdata->useobjfactor )
603  {
604  SCIP_CALL( getObjectiveFactor(scip, subscip, &factor, &success) );
605  }
606  else
607  {
608  factor = 0.0;
609  }
610 
611  /* adds all original variables */
612  ndiscvars = 0;
613  for( i = 0; i < nvars; ++i )
614  {
615  SCIP_CONS* cons;
616  SCIP_Real lb;
617  SCIP_Real ub;
618  SCIP_Real lborig;
619  SCIP_Real uborig;
620  SCIP_Real varslack;
621  SCIP_Real objval;
622  SCIP_Real value;
623  SCIP_VARTYPE vartype;
624  char varname[SCIP_MAXSTRLEN];
625  char slackvarname[SCIP_MAXSTRLEN];
626  char consvarname[SCIP_MAXSTRLEN];
627 
628 #ifdef SCIP_STATISTIC
629  heurdata->norigvars++;
630 #endif
631 
632  varslack = 0.0;
633  lborig = SCIPvarGetLbGlobal(vars[i]);
634  uborig = SCIPvarGetUbGlobal(vars[i]);
635  value = SCIPgetSolVal(scip, sol, vars[i]);
636  vartype = SCIPvarGetType(vars[i]);
637 
638  nviolatedrows[i] = 0;
639 
640  /* if the value of x is lower than the variables lower bound, sets the slack to a correcting value */
641  if( heurdata->useslackvars && SCIPisFeasLT(scip, value, lborig) )
642  {
643  lb = value;
644  varslack = lborig - value;
645  }
646  else
647  {
648  lb = lborig;
649  }
650 
651  /* if the value of x is bigger than the variables upper bound, sets the slack to a correcting value */
652  if( heurdata->useslackvars && SCIPisFeasGT(scip, value, uborig) )
653  {
654  ub = value;
655  varslack = uborig - value;
656  }
657  else
658  {
659  ub = uborig;
660  }
661 
662  if( heurdata->useobjfactor )
663  {
664  objval = SCIPvarGetObj(vars[i])*factor;
665 
666  if( SCIPisZero(scip, objval) )
667  {
668  objval = 0.0;
669  }
670  }
671  else
672  {
673  objval = SCIPvarGetObj(vars[i]);
674  }
675 
676  /* if a binary variable is out of bound, generalize it to an integer variable */
677  if( !SCIPisFeasZero(scip, varslack) && SCIP_VARTYPE_BINARY == vartype )
678  {
679  vartype = SCIP_VARTYPE_INTEGER;
680  }
681 
682  (void) SCIPsnprintf(varname, SCIP_MAXSTRLEN, "sub_%s", SCIPvarGetName(vars[i]));
683 
684  /* Adds the sub representing variable to the sub-SCIP. */
685  SCIP_CALL( SCIPcreateVarBasic(subscip, &subvars[i], varname, lb, ub, objval, vartype) );
686  SCIP_CALL( SCIPaddVar(subscip, subvars[i]) );
687 
688  /* a trivial feasible solution can be constructed if violations are modeled with slack variables */
689  if( heurdata->useslackvars )
690  {
691  SCIP_CALL( SCIPsetSolVal(subscip, subsol, subvars[i], value) );
692  }
693 
694  /* if necessary adds a constraint to represent the original bounds of x.*/
695  if( !SCIPisFeasEQ(scip, varslack, 0.0) )
696  {
697  SCIP_VAR* newvar;
698  (void) SCIPsnprintf(slackvarname, SCIP_MAXSTRLEN, "artificialslack_%s", SCIPvarGetName(vars[i]));
699  (void) SCIPsnprintf(consvarname, SCIP_MAXSTRLEN, "boundcons_%s", SCIPvarGetName(vars[i]));
700 
701  /* initialize and add an artificial slack variable */
702  if( heurdata->useobjfactor )
703  {
704  SCIP_CALL( SCIPcreateVarBasic(subscip, &newvar, slackvarname, 0.0, 1.0, 1.0, SCIP_VARTYPE_CONTINUOUS));
705  }
706  else
707  {
708  SCIP_CALL( SCIPcreateVarBasic(subscip, &newvar, slackvarname, 0.0, 1.0, 1.0, SCIP_VARTYPE_BINARY));
709  }
710  SCIP_CALL( SCIPaddVar(subscip, newvar) );
711 
712  /* set the value of the slack variable to 1 to punish the use of it.
713  * note that a trivial feasible solution can be only constructed if violations are modeled with slack variables
714  */
715  if( heurdata->useslackvars )
716  {
717  SCIP_CALL( SCIPsetSolVal(subscip, subsol, newvar, 1.0) );
718  }
719 
720  /* adds a linear constraint to represent the old bounds */
721  SCIP_CALL( SCIPcreateConsBasicVarbound(subscip, &cons, consvarname, subvars[i], newvar, varslack, lb, ub) );
722  SCIP_CALL( SCIPaddCons(subscip, cons) );
723  SCIP_CALL( SCIPreleaseVar(subscip, &newvar) );
724  SCIP_CALL( SCIPreleaseCons(subscip, &cons) );
725 
726  /* increases the counter for violated vars */
727 #ifdef SCIP_STATISTIC
728  heurdata->nviolatedvars++;
729 #endif
730  }
731 
732 #ifdef SCIP_STATISTIC
733  if( SCIPisFeasLT(scip, value, lb) || SCIPisFeasGT(scip, value, ub) )
734  {
735  heurdata->nviolatedvars++;
736  }
737 #endif
738  if( SCIP_VARTYPE_BINARY == vartype || SCIP_VARTYPE_INTEGER == vartype )
739  {
740  ndiscvars++;
741  }
742  }
743 
744  /* check solution for feasibility regarding the LP rows (SCIPgetRowSolActivity()) */
745  rows = SCIPgetLPRows(scip);
746  nrows = SCIPgetNLPRows(scip);
747 
748  SCIP_CALL( SCIPallocBufferArray(scip, &potential, nrows) );
749  SCIP_CALL( SCIPallocBufferArray(scip, &slacks, nrows) );
750  SCIP_CALL( SCIPallocBufferArray(scip, &subcons, nrows) );
751  SCIP_CALL( SCIPallocBufferArray(scip, &inftycounter, nrows) );
752 
753  /* Adds all original constraints and computes potentials and slacks */
754  for (i = 0; i < nrows; ++i)
755  {
756  SCIP_COL** cols;
757  SCIP_VAR** consvars;
758  SCIP_Real* vals;
759  SCIP_Real constant;
760  SCIP_Real lhs;
761  SCIP_Real rhs;
762  SCIP_Real rowsolact;
763  int nnonz;
764  int j;
765 
766 #ifdef SCIP_STATISTIC
767  heurdata->norcons++;
768 #endif
769 
770  /* gets the values to check the constraint */
771  constant = SCIProwGetConstant(rows[i]);
772  lhs = SCIPisInfinity(scip, -SCIProwGetLhs(rows[i])) ? SCIProwGetLhs(rows[i]) : SCIProwGetLhs(rows[i]) - constant;
773  rhs = SCIPisInfinity(scip, SCIProwGetRhs(rows[i])) ? SCIProwGetRhs(rows[i]) : SCIProwGetRhs(rows[i]) - constant;
774  rowsolact = SCIPgetRowSolActivity(scip, rows[i], sol) - constant;
775  vals = SCIProwGetVals(rows[i]);
776  potential[i] = 0.0;
777  inftycounter[i] = 0;
778 
779  assert(SCIPisFeasLE(scip, lhs, rhs));
780 
781  nnonz = SCIProwGetNNonz(rows[i]);
782  cols = SCIProwGetCols(rows[i]);
783  SCIP_CALL( SCIPallocBufferArray(subscip, &consvars, nnonz) );
784 
785  /* sets the slack if its necessary */
786  if( SCIPisFeasLT(scip, rowsolact, lhs) )
787  {
788  slacks[i] = lhs - rowsolact;
789 #ifdef SCIP_STATISTIC
790  heurdata->nviolatedcons++;
791 #endif
792  }
793  else if( SCIPisFeasGT(scip, rowsolact, rhs) )
794  {
795  slacks[i] = rhs - rowsolact;
796 #ifdef SCIP_STATISTIC
797  heurdata->nviolatedcons++;
798 #endif
799  }
800  else
801  {
802  slacks[i] = 0.0;
803  }
804 
805  /* translate all variables from the original SCIP to the sub-SCIP with sub-SCIP variables. */
806  for( j = 0; j < nnonz; ++j )
807  {
808  SCIP_Real contribution;
809  int pos;
810  int sgn = 1;
811 
812  /* negative slack represents a right hand side violation */
813  if( SCIPisFeasGT(scip, 0.0, slacks[i]) )
814  {
815  assert(!SCIPisInfinity(scip, rhs));
816  sgn = -1;
817  }
818  #ifndef NDEBUG
819  else
820  assert(!SCIPisInfinity(scip, lhs));
821  #endif
822 
823  pos = SCIPvarGetProbindex(SCIPcolGetVar(cols[j]));
824  consvars[j] = subvars[pos];
825  assert(pos >= 0);
826 
827  /* compute potentials */
828  contribution = getPotentialContributed(scip, sol, vars[pos], vals[j], sgn);
829  if( !SCIPisInfinity(scip, REALABS(contribution)) )
830  {
831  potential[i] += contribution;
832  }
833  else
834  {
835  inftycounter[i]++;
836  }
837 
838  if( !SCIPisZero(scip, slacks[i]) )
839  {
840  nviolatedrows[pos]++;
841  }
842  }
843 
844  /* create a new linear constraint, representing the old one */
845  SCIP_CALL( SCIPcreateConsBasicLinear(subscip, &subcons[i], SCIProwGetName(rows[i]),
846  nnonz, consvars, vals, lhs, rhs) );
847 
848  if( heurdata->useslackvars )
849  {
850  SCIP_VAR* newvar;
851  char varname[SCIP_MAXSTRLEN];
852 
853  /*if necessary adds a new artificial slack variable*/
854  if( !SCIPisFeasEQ(subscip, slacks[i], 0.0) )
855  {
856  (void) SCIPsnprintf(varname, SCIP_MAXSTRLEN, "artificialslack_%s", SCIProwGetName(rows[i]));
857  SCIP_CALL( SCIPcreateVarBasic(subscip, &newvar, varname, 0.0, 1.0, 1.0, SCIP_VARTYPE_CONTINUOUS) );
858  SCIP_CALL( SCIPaddVar(subscip, newvar) );
859 
860  /* a trivial feasible solution can be constructed if violations are modeled with slack variables */
861  SCIP_CALL( SCIPsetSolVal(subscip, subsol, newvar, 1.0) );
862  SCIP_CALL( SCIPaddCoefLinear(subscip, subcons[i], newvar, slacks[i]) );
863  SCIP_CALL( SCIPreleaseVar(subscip, &newvar) );
864  }
865  }
866 
867  /*Adds the Constraint and release it.*/
868  SCIP_CALL( SCIPaddCons(subscip, subcons[i]) );
869  SCIP_CALL( SCIPreleaseCons(subscip, &subcons[i]) );
870  SCIPfreeBufferArray(subscip, &consvars);
871  }
872 
873  if( heurdata->usevarfix )
874  {
875  /* get the greedy order */
876  for( i = 0; i < nvars; ++i )
877  {
878  permutation[i] = i;
879  }
880  SCIPsortIntInt(nviolatedrows, permutation, nvars);
881 
882  /* loops over variables and greedily fix variables, but preserve the cover property that enough slack is given to
883  * violated rows
884  */
885  nfixeddiscvars = 0;
886  heurdata->nvarfixed = 0;
887  for( i = 0; i < nvars; ++i )
888  {
889  SCIP_Bool infeasible = FALSE;
890  SCIP_Bool fixed = TRUE;
891 
892  SCIP_CALL( tryFixVar(scip, subscip, sol, potential, slacks, vars[permutation[i]], subvars[permutation[i]], inftycounter, heurdata, &infeasible, &fixed) );
893 
894  if( fixed && (SCIP_VARTYPE_BINARY == SCIPvarGetType(subvars[permutation[i]])
895  || SCIP_VARTYPE_INTEGER == SCIPvarGetType(subvars[permutation[i]])) )
896  {
897  nfixeddiscvars++;
898  }
899  }
900  SCIPdebugMsg(scip,"fixings finished\n\n");
901  if( heurdata->minfixingrate > ((SCIP_Real)nfixeddiscvars/MAX((SCIP_Real)ndiscvars,1.0)) )
902  {
903  goto TERMINATE;
904  }
905  }
906 
907  /* a trivial feasible solution can be constructed if violations are modeled with slack variables */
908  if( heurdata->useslackvars )
909  {
910  SCIP_CALL( SCIPaddSolFree(subscip, &subsol, &success) );
911 
912  if( !success )
913  {
914  SCIPdebugMsg(scip, "Initial repair solution was not accepted.\n");
915  }
916  }
917 
918 #ifdef SCIP_STATISTIC
919  if( heurdata->useslackvars )
920  heurdata->improvedoldsol = SCIPgetSolOrigObj(subscip, subsol);
921 #endif
922 
923  /* check whether there is enough time and memory left */
924  SCIP_CALL( SCIPgetRealParam(scip, "limits/time", &timelimit) );
925  if( !SCIPisInfinity(scip, timelimit) )
926  timelimit -= SCIPgetSolvingTime(scip);
927  SCIP_CALL( SCIPgetRealParam(scip, "limits/memory", &memorylimit) );
928 
929  /* subtract the memory already used by the main SCIP and the estimated memory usage of external software */
930  if( !SCIPisInfinity(scip, memorylimit) )
931  {
932  memorylimit -= SCIPgetMemUsed(scip) / 1048576.0;
933  memorylimit -= SCIPgetMemExternEstim(scip) / 1048576.0;
934  }
935 
936  /* abort if no time is left or not enough memory to create a copy of SCIP, including external memory usage */
937  if( timelimit <= 0.0 || memorylimit <= 2.0 * SCIPgetMemExternEstim(scip) / 1048576.0 )
938  goto TERMINATE;
939 
940  /* set limits for the subproblem */
941  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/nodes", nnodes) );
942  SCIP_CALL( SCIPsetRealParam(subscip, "limits/time", timelimit) );
943  SCIP_CALL( SCIPsetRealParam(subscip, "limits/memory", memorylimit) );
944  SCIP_CALL( SCIPsetObjlimit(subscip,1.0) );
945 
946  /* forbid recursive call of heuristics and separators solving sub-SCIPs */
947  SCIP_CALL( SCIPsetSubscipsOff(subscip, TRUE) );
948 
949  /* disable output to console */
950  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", (int)SCIP_VERBLEVEL_NONE) );
951 
952 #ifdef SCIP_DEBUG
953  /* for debugging Repair, enable MIP output */
954  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", (int)SCIP_VERBLEVEL_FULL) );
955  SCIP_CALL( SCIPsetIntParam(subscip, "display/freq", -1) );
956 #endif
957 
958  /* solve the subproblem */
959  retcode = SCIPsolve(subscip);
960 
961  /* errors in sub-SCIPs should not kill the overall solving process. Hence, we print a warning message. Only
962  * in debug mode, SCIP will stop
963  */
964  if( retcode != SCIP_OKAY )
965  {
966  SCIPwarningMessage(scip, "Error while solving subproblem in REPAIR heuristic; sub-SCIP terminated with code <%d>\n", retcode);
967  SCIPABORT(); /*lint --e{527}*/
968  goto TERMINATE;
969  }
970 
971  success = FALSE;
972 
973  /* if a solution is found, save its value and create a new solution instance for the original SCIP */
974  if( SCIPgetBestSol(subscip) != NULL )
975  {
976 #ifdef SCIP_STATISTIC
977  heurdata->improvedoldsol = SCIPgetSolOrigObj(subscip, SCIPgetBestSol(subscip));
978 #endif
979  /* print solving statistics of subproblem if we are in SCIP's debug mode */
981 
982  assert(SCIPgetNSols(subscip) > 0);
983  SCIP_CALL( createNewSol(scip, subscip, subvars, heur, SCIPgetBestSol(subscip), &success) );
984 
985  if( success )
986  {
987  *result = SCIP_FOUNDSOL;
988  }
989  }
990  else
991  {
992  SCIPdebugMsg(scip,"No solution found!\n");
993  }
994 
995  if( SCIPgetStage(subscip) >= SCIP_STAGE_SOLVED )
996  {
997  heurdata->subiters = SCIPgetNLPIterations(subscip);
998  heurdata->subnodes = SCIPgetNTotalNodes(subscip);
999 #ifdef SCIP_STATISTIC
1000  heurdata->subpresoltime = SCIPgetPresolvingTime(subscip);
1001 #endif
1002  heurdata->runs = SCIPgetNRuns(subscip);
1003  }
1004 
1005  /* terminates the solving process */
1006 TERMINATE:
1007  if( NULL != sol )
1008  {
1009  SCIP_CALL( SCIPfreeSol(scip, &sol) );
1010  }
1011  SCIPfreeBufferArrayNull(scip, &nviolatedrows);
1012  for( i = 0; i < nvars; ++i )
1013  {
1014  SCIP_CALL( SCIPreleaseVar(subscip, &subvars[i]) );
1015  }
1016  SCIPfreeBufferArrayNull(scip, &inftycounter);
1017  SCIPfreeBufferArrayNull(scip, &subcons);
1018  SCIPfreeBufferArrayNull(scip, &slacks);
1019  SCIPfreeBufferArrayNull(scip, &potential);
1020  SCIPfreeBufferArrayNull(scip, &permutation);
1021  SCIPfreeBufferArrayNull(scip, &subvars);
1022 
1023  if( NULL != subsol )
1024  {
1025  SCIP_CALL( SCIPfreeSol(subscip, &subsol) );
1026  }
1027 
1028  SCIP_CALL( SCIPfree(&subscip) );
1029 
1030  SCIPdebugMsg(scip, "repair finished\n");
1031  return SCIP_OKAY;
1032 }
1033 
1034 
1035 /*
1036  * Callback methods of primal heuristic
1037  */
1038 
1039 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
1040 static
1041 SCIP_DECL_HEURFREE(heurFreeRepair)
1042 { /*lint --e{715}*/
1043  SCIP_HEURDATA* heurdata;
1044 
1045  heurdata = SCIPheurGetData(heur);
1047  assert(heurdata != NULL);
1048  SCIPfreeMemory(scip, &heurdata);
1049 
1050  SCIPheurSetData(heur, NULL);
1051 
1052  return SCIP_OKAY;
1053 }
1054 
1055 
1056 /** initialization method of primal heuristic (called after problem was transformed) */
1057 static
1058 SCIP_DECL_HEURINIT(heurInitRepair)
1059 { /*lint --e{715}*/
1060  SCIP_HEURDATA* heurdata;
1061 
1062  heurdata = SCIPheurGetData(heur);
1064  heurdata->subiters = -1;
1065  heurdata->subnodes = -1;
1066  heurdata->runs = 0;
1067 
1068  heurdata->nvarfixed = 0;
1069  heurdata->relvarfixed = -1;
1070 
1071 #ifdef SCIP_STATISTIC
1072  heurdata->subpresoltime = 0;
1073 
1074  heurdata->nviolatedvars = 0;
1075  heurdata->norigvars = 0;
1076  heurdata->relviolatedvars = 0;
1077  heurdata->nviolatedcons = 0;
1078  heurdata->norcons = 0;
1079  heurdata->relviolatedcons = 0;
1080 
1081  heurdata->originalsolval = SCIP_INVALID;
1082 
1083  heurdata->improvedoldsol = SCIP_UNKNOWN;
1084 #endif
1085 
1086  heurdata->usednodes = 0;
1087 
1088  return SCIP_OKAY;
1089 }
1090 
1091 
1092 /** deinitialization method of primal heuristic (called before transformed problem is freed) */
1093 static
1094 SCIP_DECL_HEUREXIT(heurExitRepair)
1095 { /*lint --e{715}*/
1096 #ifdef SCIP_STATISTIC
1097  SCIP_HEURDATA* heurdata;
1098  SCIP_Real time;
1099  SCIP_Real relvars;
1100  SCIP_Real relcons;
1101  SCIP_Real relfixed;
1102  char solval[SCIP_MAXSTRLEN];
1103  int violateds;
1104  int ninvars;
1105  int ninvcons;
1106  int nvars;
1107  int ncons;
1108  int iterations;
1109  int nodes;
1110  int runs;
1111 
1112  heurdata = SCIPheurGetData(heur);
1113  violateds = heurdata->nviolatedvars+heurdata->nviolatedcons;
1114  ninvars = heurdata->nviolatedvars;
1115  ninvcons = heurdata->nviolatedcons;
1116  nvars = heurdata->norigvars;
1117  ncons = heurdata->norcons;
1118  iterations = heurdata->subiters;
1119  nodes = heurdata->subnodes;
1120  time = heurdata->subpresoltime;
1121  runs = heurdata->runs;
1122 
1123  if( SCIP_INVALID == heurdata->originalsolval )
1124  {
1125  (void) SCIPsnprintf(solval, SCIP_MAXSTRLEN ,"--");
1126  }
1127  else
1128  {
1129  (void) SCIPsnprintf(solval, SCIP_MAXSTRLEN, "%15.9g", heurdata->originalsolval);
1130  }
1131 
1132  heurdata->relviolatedvars = MAX((SCIP_Real)heurdata->norigvars, 1.0);
1133  heurdata->relviolatedvars = heurdata->nviolatedvars/heurdata->relviolatedvars;
1134  heurdata->relviolatedcons = MAX((SCIP_Real)heurdata->norcons, 1.0);
1135  heurdata->relviolatedcons = heurdata->nviolatedcons/heurdata->relviolatedcons;
1136 
1137  heurdata->relvarfixed = MAX((SCIP_Real)heurdata->norigvars, 1.0);
1138  heurdata->relvarfixed = heurdata->nvarfixed/heurdata->relvarfixed;
1139  relvars = heurdata->relviolatedvars;
1140  relcons = heurdata->relviolatedcons;
1141  relfixed = heurdata->relvarfixed;
1142 
1143  /* prints all statistic data for a user*/
1144  SCIPstatistic(
1145  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, "<repair> \n total violations : %10d\n", violateds);
1146  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " violated variables : %10d\n", ninvars);
1147  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " total variables : %10d\n", nvars)
1148  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " relative violated variables : %10.2f%%\n", 100 * relvars);
1149  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " violated constraints : %10d\n", ninvcons);
1150  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " total constraints : %10d\n", ncons);
1151  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " relative violated constraints: %10.2f%%\n", 100* relcons);
1152  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " fixed variables : %10d\n", heurdata->nvarfixed);
1153  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " relative fixed variables : %10.2f%%\n\n", 100* relfixed);
1154  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " iterations : %10d\n", iterations);
1155  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " nodes : %10d\n", nodes);
1156  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " number of runs : %10d\n", runs);
1157  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " presolve time : %10.2f\n", time);
1158  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, "</repair>\n\n");
1159  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " value of best solution : %10g\n", solval);
1160  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " improved orig. solval : %10g\n", heurdata->improvedoldsol);
1162  )
1163 
1164 #endif
1165  return SCIP_OKAY;
1166 }
1167 
1168 /** execution method of primal heuristic. Repair needs an incorrect solution, in which all variables are in their bound. */
1169 static
1170 SCIP_DECL_HEUREXEC(heurExecRepair)
1171 { /*lint --e{715}*/
1172  SCIP_HEURDATA* heurdata;
1173  SCIP_RETCODE retcode;
1174  SCIP_Bool success;
1175  SCIP_Bool error;
1177 
1178  heurdata = SCIPheurGetData(heur);
1179  SCIPdebugMsg(scip, "%s\n", heurdata->filename);
1180 
1181  /* checks the result pointer */
1182  assert(result != NULL);
1183  *result = SCIP_DIDNOTRUN;
1184 
1185  /* if repair already ran or neither variable fixing nor slack variables are enabled, stop */
1186  if( 0 < SCIPheurGetNCalls(heur) || !(heurdata->usevarfix || heurdata->useslackvars) )
1187  return SCIP_OKAY;
1188 
1189  /* do not run if the neither the LP is constructed nor a user given solution exists */
1190  if( SCIPgetLPSolstat(scip) != SCIP_LPSOLSTAT_OPTIMAL && strcmp(heurdata->filename, DEFAULT_FILENAME) == 0 )
1191  return SCIP_OKAY;
1192 
1193  /* calculate the maximal number of branching nodes until heuristic is aborted */
1194  nnodes = (SCIP_Longint)(heurdata->nodesquot * SCIPgetNNodes(scip));
1195 
1196  /* reward REPAIR if it succeeded often */
1197  nnodes = (SCIP_Longint)(nnodes * 3.0 * (SCIPheurGetNBestSolsFound(heur)+1.0)/(SCIPheurGetNCalls(heur) + 1.0));
1198  nnodes -= (SCIP_Longint)(100.0 * SCIPheurGetNCalls(heur)); /* count the setup costs for the sub-MIP as 100 nodes */
1199  nnodes += heurdata->nodesofs;
1200 
1201  /* determine the node limit for the current process */
1202  nnodes -= heurdata->usednodes;
1203  nnodes = MIN(nnodes, heurdata->maxnodes);
1204 
1205  /* check whether we have enough nodes left to call subproblem solving */
1206  if( nnodes < heurdata->minnodes )
1207  return SCIP_OKAY;
1208 
1209  if( !SCIPhasCurrentNodeLP(scip) )
1210  return SCIP_OKAY;
1211 
1212  if( !SCIPisLPConstructed(scip) )
1213  {
1214  SCIP_Bool cutoff;
1215 
1216  SCIP_CALL( SCIPconstructLP(scip, &cutoff) );
1217 
1218  /* manually cut off the node if the LP construction detected infeasibility (heuristics cannot return such a result) */
1219  if( cutoff )
1220  {
1222  return SCIP_OKAY;
1223  }
1224  }
1225 
1226  /* create original solution */
1227  SCIP_CALL( SCIPcreateOrigSol(scip, &(heurdata->infsol), heur) );
1228 
1229  /* use read method to enter solution from a file */
1230  if( strcmp(heurdata->filename, DEFAULT_FILENAME) == 0 )
1231  {
1232  retcode = SCIPlinkLPSol(scip, heurdata->infsol);
1233  }
1234  else
1235  {
1236  error = FALSE;
1237  retcode = SCIPreadSolFile(scip, heurdata->filename, heurdata->infsol, FALSE, NULL, &error);
1238  }
1239 
1240  if( SCIP_NOFILE == retcode )
1241  {
1242  assert(strcmp(heurdata->filename, DEFAULT_FILENAME) != 0);
1243  SCIPwarningMessage(scip, "cannot open file <%s> for reading\n", heurdata->filename);
1244 
1245  SCIP_CALL( SCIPfreeSol(scip, &(heurdata->infsol)) );
1246  return SCIP_OKAY;
1247  }
1248  else if( retcode != SCIP_OKAY )
1249  {
1250  SCIPwarningMessage(scip, "cannot run repair, unknown return status <%d>\n", retcode);
1251  SCIP_CALL( SCIPfreeSol(scip, &(heurdata->infsol)) );
1252  return SCIP_OKAY;
1253  }
1254  SCIPdebugMsg(scip, "Repair: Solution file read.\n");
1255 
1256  /* checks the integrality of all discrete variable */
1257  SCIP_CALL( checkCands(scip, heurdata->infsol, heurdata->roundit, &success) );
1258  if( !success )
1259  {
1260  SCIPdebugMsg(scip,"Given solution is not integral, repair terminates.\n");
1261  SCIP_CALL( SCIPfreeSol(scip, &(heurdata->infsol)) );
1262  return SCIP_OKAY;
1263  }
1264 
1265  *result = SCIP_DIDNOTFIND;
1266 
1267  SCIP_CALL( SCIPtrySol(scip, heurdata->infsol, FALSE, FALSE, TRUE, TRUE, TRUE, &success) );
1268 
1269  /* the solution is not feasible for the original problem; we will try to repair it */
1270  if( !success )
1271  {
1272  assert(NULL != heurdata->infsol);
1273  assert(heurdata->usevarfix || heurdata->useslackvars);
1274  SCIP_CALL( applyRepair(scip, heur, result, nnodes) );
1275  }
1276  else
1277  {
1278  SCIP_CALL( SCIPfreeSol(scip, &(heurdata->infsol)) );
1279  }
1280 
1281  return SCIP_OKAY;
1282 }
1283 
1284 /* primal heuristic specific interface methods */
1285 
1286 /** creates the repair primal heuristic and includes it in SCIP */
1288  SCIP* scip /**< SCIP data structure */
1289  )
1290 {
1291  SCIP_HEURDATA* heurdata;
1292  SCIP_HEUR* heur;
1293 
1294  /* create repair primal heuristic data */
1295  heurdata = NULL;
1296 
1297  SCIP_CALL( SCIPallocMemory(scip ,&heurdata) );
1298 
1299  heur = NULL;
1300 
1301  /* include primal heuristic */
1302  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
1304  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecRepair, heurdata) );
1305 
1306  assert(heur != NULL);
1307  assert(heurdata != NULL);
1308 
1309  /* set non fundamental callbacks via setter functions */
1310  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeRepair) );
1311  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitRepair) );
1312  SCIP_CALL( SCIPsetHeurExit(scip, heur, heurExitRepair) );
1313 
1314  /* add repair primal heuristic parameters */
1315 
1316  heurdata->filename = NULL;
1317  /* add string parameter for filename containing a solution */
1318  SCIP_CALL( SCIPaddStringParam(scip, "heuristics/" HEUR_NAME "/filename",
1319  "file name of a solution to be used as infeasible starting point, [-] if not available",
1320  &heurdata->filename, FALSE, DEFAULT_FILENAME, NULL, NULL) );
1321 
1322  /* add bool parameter for decision how to deal with unfractional cands */
1323  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/roundit",
1324  "True : fractional variables which are not fractional in the given solution are rounded, "
1325  "FALSE : solving process of this heuristic is stopped. ",
1326  &heurdata->roundit, FALSE, DEFAULT_ROUNDIT, NULL, NULL));
1327 
1328  /* add bool parameter for decision how the objective function should be */
1329  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/useobjfactor",
1330  "should a scaled objective function for original variables be used in repair subproblem?",
1331  &heurdata->useobjfactor, FALSE, DEFAULT_USEOBJFACTOR, NULL, NULL));
1332 
1333  /* add bool parameter for decision if variable fixings should be used */
1334  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/usevarfix",
1335  "should variable fixings be used in repair subproblem?",
1336  &heurdata->usevarfix, FALSE, DEFAULT_USEVARFIX, NULL, NULL));
1337 
1338  /* add bool parameter for decision how the objective function should be */
1339  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/useslackvars",
1340  "should slack variables be used in repair subproblem?",
1341  &heurdata->useslackvars, FALSE, DEFAULT_USESLACKVARS, NULL, NULL));
1342 
1343  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/alpha", "factor for the potential of var fixings",
1344  &heurdata->alpha, TRUE, DEFAULT_ALPHA, 0.0, 100.00, NULL, NULL) );
1345 
1346  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/nodesofs",
1347  "number of nodes added to the contingent of the total nodes",
1348  &heurdata->nodesofs, FALSE, DEFAULT_NODESOFS, 0, INT_MAX, NULL, NULL) );
1349 
1350  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/maxnodes",
1351  "maximum number of nodes to regard in the subproblem",
1352  &heurdata->maxnodes, TRUE, DEFAULT_MAXNODES, 0, INT_MAX, NULL, NULL) );
1353 
1354  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/minnodes",
1355  "minimum number of nodes required to start the subproblem",
1356  &heurdata->minnodes, TRUE, DEFAULT_MINNODES, 0, INT_MAX, NULL, NULL) );
1357 
1358  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/nodesquot",
1359  "contingent of sub problem nodes in relation to the number of nodes of the original problem",
1360  &heurdata->nodesquot, FALSE, DEFAULT_NODESQUOT, 0.0, 1.0, NULL, NULL) );
1361 
1362  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/minfixingrate",
1363  "minimum percentage of integer variables that have to be fixed",
1364  &heurdata->minfixingrate, FALSE, DEFAULT_MINFIXINGRATE, 0.0, 1.0, NULL, NULL) );
1365 
1366  return SCIP_OKAY;
1367 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
SCIP_RETCODE SCIPcreateOrigSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:556
SCIP_Longint SCIPheurGetNCalls(SCIP_HEUR *heur)
Definition: heur.c:1380
static SCIP_DECL_HEUREXIT(heurExitRepair)
Definition: heur_repair.c:1099
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip_sol.c:976
#define NULL
Definition: def.h:253
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
Definition: scip_sol.c:1212
public methods for SCIP parameter handling
#define HEUR_DISPCHAR
Definition: heur_repair.c:63
static SCIP_RETCODE createNewSol(SCIP *scip, SCIP *subscip, SCIP_VAR **subvars, SCIP_HEUR *heur, SCIP_SOL *subsol, SCIP_Bool *success)
Definition: heur_repair.c:484
int SCIPgetNLPRows(SCIP *scip)
Definition: scip_lp.c:561
Constraint handler for variable bound constraints .
static void message(unsigned int type, const CURF *curf, const char *msg,...)
Definition: grphload.c:317
SCIP_EXPORT int SCIPvarGetNLocksUpType(SCIP_VAR *var, SCIP_LOCKTYPE locktype)
Definition: var.c:3241
public methods for memory management
static SCIP_Real getPotentialContributed(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real coefficient, int sgn)
Definition: heur_repair.c:223
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1165
#define SCIP_MAXSTRLEN
Definition: def.h:274
SCIP_Real * SCIPcolGetVals(SCIP_COL *col)
Definition: lp.c:16845
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:122
int SCIProwGetNNonz(SCIP_ROW *row)
Definition: lp.c:16887
#define DEFAULT_USEOBJFACTOR
Definition: heur_repair.c:85
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1352
public solving methods
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
public methods for timing
static SCIP_DECL_HEURINIT(heurInitRepair)
Definition: heur_repair.c:1063
SCIP_RETCODE SCIPcreateVarBasic(SCIP *scip, SCIP_VAR **var, const char *name, SCIP_Real lb, SCIP_Real ub, SCIP_Real obj, SCIP_VARTYPE vartype)
Definition: scip_var.c:184
SCIP_Real SCIProwGetConstant(SCIP_ROW *row)
Definition: lp.c:16932
SCIP_NODE * SCIPgetCurrentNode(SCIP *scip)
Definition: scip_tree.c:80
SCIP_Real SCIPgetSolvingTime(SCIP *scip)
Definition: scip_timing.c:359
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
Definition: scip_message.c:215
#define FALSE
Definition: def.h:73
SCIP_ROW ** SCIPcolGetRows(SCIP_COL *col)
Definition: lp.c:16835
SCIP_RETCODE SCIPreadSolFile(SCIP *scip, const char *filename, SCIP_SOL *sol, SCIP_Bool xml, SCIP_Bool *partial, SCIP_Bool *error)
Definition: scip_sol.c:2884
SCIP_EXPORT SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17200
SCIP_RETCODE SCIPincludeHeurRepair(SCIP *scip)
Definition: heur_repair.c:1292
SCIP_Real SCIPgetPresolvingTime(SCIP *scip)
Definition: scip_timing.c:423
SCIP_RETCODE SCIPcreateConsBasicLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs)
SCIP_EXPORT SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:16903
#define TRUE
Definition: def.h:72
#define SCIPdebug(x)
Definition: pub_message.h:74
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_RETCODE SCIPlinkLPSol(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1017
SCIP_Bool SCIPisLPConstructed(SCIP *scip)
Definition: scip_lp.c:91
SCIP_RETCODE SCIPcutoffNode(SCIP *scip, SCIP_NODE *node)
Definition: scip_tree.c:423
SCIP_RETCODE SCIPsolve(SCIP *scip)
Definition: scip_solve.c:2535
static SCIP_RETCODE applyRepair(SCIP *scip, SCIP_HEUR *heur, SCIP_RESULT *result, SCIP_Longint nnodes)
Definition: heur_repair.c:541
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:51
public methods for problem variables
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:47
SCIP_Real SCIPceil(SCIP *scip, SCIP_Real val)
SCIP_Longint SCIPgetMemUsed(SCIP *scip)
Definition: scip_mem.c:90
SCIP_RETCODE SCIPsetSubscipsOff(SCIP *scip, SCIP_Bool quiet)
Definition: scip_param.c:891
int SCIProwGetLPPos(SCIP_ROW *row)
Definition: lp.c:17155
SCIP_Real SCIPgetUpperbound(SCIP *scip)
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:123
public methods for SCIP variables
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
Definition: scip_heur.c:184
SCIP_RETCODE SCIPtrySol(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:3124
#define SCIPdebugMsg
Definition: scip_message.h:69
static SCIP_RETCODE checkCands(SCIP *scip, SCIP_SOL *sol, SCIP_Bool roundit, SCIP_Bool *success)
Definition: heur_repair.c:403
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
Definition: scip_lp.c:158
SCIP_Longint SCIPheurGetNBestSolsFound(SCIP_HEUR *heur)
Definition: heur.c:1400
SCIP_Bool SCIPhasCurrentNodeLP(SCIP *scip)
Definition: scip_lp.c:73
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_ROW ** SCIPgetLPRows(SCIP *scip)
Definition: scip_lp.c:540
public methods for numerical tolerances
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:319
SCIP_RETCODE SCIPsetObjlimit(SCIP *scip, SCIP_Real objlimit)
Definition: scip_prob.c:1421
public methods for querying solving statistics
int SCIPgetNSols(SCIP *scip)
Definition: scip_sol.c:2205
SCIP_RETCODE SCIPsetRealParam(SCIP *scip, const char *name, SCIP_Real value)
Definition: scip_param.c:612
SCIP_RETCODE SCIPincludeHeurBasic(SCIP *scip, SCIP_HEUR **heur, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, SCIP_HEURTIMING timingmask, SCIP_Bool usessubscip, SCIP_DECL_HEUREXEC((*heurexec)), SCIP_HEURDATA *heurdata)
Definition: scip_heur.c:107
public methods for the branch-and-bound tree
SCIP_RETCODE SCIPaddOrigObjoffset(SCIP *scip, SCIP_Real addval)
Definition: scip_prob.c:1289
#define DEFAULT_MINFIXINGRATE
Definition: heur_repair.c:70
SCIP_Longint SCIPgetNNodes(SCIP *scip)
SCIP_RETCODE SCIPcreate(SCIP **scip)
Definition: scip_general.c:282
SCIP_RETCODE SCIPcopyParamSettings(SCIP *sourcescip, SCIP *targetscip)
Definition: scip_copy.c:2248
SCIP_EXPORT const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:16738
#define HEUR_TIMING
Definition: heur_repair.c:68
SCIP_COL ** SCIProwGetCols(SCIP_ROW *row)
Definition: lp.c:16912
SCIP_Longint SCIPgetNTotalNodes(SCIP *scip)
SCIP_BRANCHRULE * SCIPfindBranchrule(SCIP *scip, const char *name)
Definition: scip_branch.c:286
#define DEFAULT_USEVARFIX
Definition: heur_repair.c:90
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define SCIPfreeBufferArrayNull(scip, ptr)
Definition: scip_mem.h:124
SCIP_Real * SCIProwGetVals(SCIP_ROW *row)
Definition: lp.c:16922
#define DEFAULT_MAXNODES
Definition: heur_repair.c:73
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
int SCIPcolGetNLPNonz(SCIP_COL *col)
Definition: lp.c:16824
#define DEFAULT_USESLACKVARS
Definition: heur_repair.c:91
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:1175
#define REALABS(x)
Definition: def.h:188
public methods for problem copies
#define HEUR_DESC
Definition: heur_repair.c:62
#define DEFAULT_ALPHA
Definition: heur_repair.c:92
#define SCIP_CALL(x)
Definition: def.h:365
SCIP_RETCODE SCIPaddStringParam(SCIP *scip, const char *name, const char *desc, char **valueptr, SCIP_Bool isadvanced, const char *defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:184
int SCIPgetNOrigVars(SCIP *scip)
Definition: scip_prob.c:2427
#define HEUR_FREQ
Definition: heur_repair.c:65
repair primal heuristic
public methods for primal heuristic plugins and divesets
public methods for constraint handler plugins and constraints
SCIP_RETCODE SCIPgetRealParam(SCIP *scip, const char *name, SCIP_Real *value)
Definition: scip_param.c:297
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
SCIP_EXPORT SCIP_COL * SCIPvarGetCol(SCIP_VAR *var)
Definition: var.c:17066
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:111
#define SCIP_UNKNOWN
Definition: def.h:185
SCIP_Real SCIPinfinity(SCIP *scip)
public data structures and miscellaneous methods
SCIP_RETCODE SCIPsetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
Definition: scip_sol.c:1254
#define DEFAULT_NODESQUOT
Definition: heur_repair.c:75
#define SCIP_Bool
Definition: def.h:70
SCIP_RETCODE SCIPincludeDefaultPlugins(SCIP *scip)
SCIP_RETCODE SCIPaddSolFree(SCIP *scip, SCIP_SOL **sol, SCIP_Bool *stored)
Definition: scip_sol.c:3014
SCIP_RETCODE SCIPconstructLP(SCIP *scip, SCIP_Bool *cutoff)
Definition: scip_lp.c:114
const char * SCIPgetProbName(SCIP *scip)
Definition: scip_prob.c:1066
SCIP_EXPORT void SCIPsortIntInt(int *intarray1, int *intarray2, int len)
SCIP_RETCODE SCIPsetHeurExit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXIT((*heurexit)))
Definition: scip_heur.c:200
SCIP_EXPORT SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17362
SCIP_Bool SCIPisParamFixed(SCIP *scip, const char *name)
Definition: scip_param.c:209
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
Definition: lp.c:16966
#define MIN(x, y)
Definition: def.h:223
public methods for LP management
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
#define HEUR_PRIORITY
Definition: heur_repair.c:64
SCIP_RETCODE SCIPfixVar(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval, SCIP_Bool *infeasible, SCIP_Bool *fixed)
Definition: scip_var.c:8180
SCIP_RETCODE SCIPcreateProb(SCIP *scip, const char *name, SCIP_DECL_PROBDELORIG((*probdelorig)), SCIP_DECL_PROBTRANS((*probtrans)), SCIP_DECL_PROBDELTRANS((*probdeltrans)), SCIP_DECL_PROBINITSOL((*probinitsol)), SCIP_DECL_PROBEXITSOL((*probexitsol)), SCIP_DECL_PROBCOPY((*probcopy)), SCIP_PROBDATA *probdata)
Definition: scip_prob.c:105
SCIP_RETCODE SCIPcreateConsBasicVarbound(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR *var, SCIP_VAR *vbdvar, SCIP_Real vbdcoef, SCIP_Real lhs, SCIP_Real rhs)
Constraint handler for linear constraints in their most general form, .
SCIP_RETCODE SCIPaddVar(SCIP *scip, SCIP_VAR *var)
Definition: scip_prob.c:1667
static SCIP_DECL_HEURFREE(heurFreeRepair)
Definition: heur_repair.c:1046
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:129
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
Definition: lp.c:16736
public methods for the LP relaxation, rows and columns
#define DEFAULT_MINNODES
Definition: heur_repair.c:74
SCIP_EXPORT int SCIPvarGetNLocksDownType(SCIP_VAR *var, SCIP_LOCKTYPE locktype)
Definition: var.c:3184
#define SCIPfreeMemory(scip, ptr)
Definition: scip_mem.h:67
SCIP_Real SCIPfloor(SCIP *scip, SCIP_Real val)
SCIP_RETCODE SCIPsetLongintParam(SCIP *scip, const char *name, SCIP_Longint value)
Definition: scip_param.c:554
methods for sorting joint arrays of various types
SCIP_RETCODE SCIPgetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
Definition: scip_sol.c:1389
#define DEFAULT_NODESOFS
Definition: heur_repair.c:72
public methods for branching rule plugins and branching
#define HEUR_MAXDEPTH
Definition: heur_repair.c:67
#define HEUR_FREQOFS
Definition: heur_repair.c:66
general public methods
#define MAX(x, y)
Definition: def.h:222
SCIP_Bool SCIPisFeasGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Longint SCIPgetNLPIterations(SCIP *scip)
#define DEFAULT_ROUNDIT
Definition: heur_repair.c:78
public methods for solutions
SCIP_Real SCIPgetLowerbound(SCIP *scip)
SCIP_EXPORT SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17352
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
static SCIP_RETCODE getObjectiveFactor(SCIP *scip, SCIP *subscip, SCIP_Real *factor, SCIP_Bool *success)
Definition: heur_repair.c:147
public methods for message output
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip_prob.c:1861
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10263
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:73
#define HEUR_USESSUBSCIP
Definition: heur_repair.c:69
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
Definition: scip_var.c:1251
#define SCIPstatistic(x)
Definition: pub_message.h:101
#define SCIP_Real
Definition: def.h:164
const char * SCIProwGetName(SCIP_ROW *row)
Definition: lp.c:17025
public methods for message handling
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define SCIP_INVALID
Definition: def.h:184
#define HEUR_NAME
Definition: heur_repair.c:61
#define DEFAULT_FILENAME
Definition: heur_repair.c:77
#define SCIP_Longint
Definition: def.h:149
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip_heur.c:168
#define SCIPallocMemory(scip, ptr)
Definition: scip_mem.h:51
SCIP_EXPORT int SCIPvarGetProbindex(SCIP_VAR *var)
Definition: var.c:17045
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_prob.c:2765
enum SCIP_Vartype SCIP_VARTYPE
Definition: type_var.h:60
static SCIP_DECL_HEUREXEC(heurExecRepair)
Definition: heur_repair.c:1175
#define nnodes
Definition: gastrans.c:65
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
Definition: lp.c:16976
public methods for primal heuristics
SCIP_RETCODE SCIPfree(SCIP **scip)
Definition: scip_general.c:314
SCIP_Longint SCIPgetMemExternEstim(SCIP *scip)
Definition: scip_mem.c:116
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip_cons.c:1109
SCIP_STAGE SCIPgetStage(SCIP *scip)
Definition: scip_general.c:355
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:3218
#define SCIPABORT()
Definition: def.h:337
public methods for global and local (sub)problems
default SCIP plugins
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition: scip_sol.c:2304
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
Definition: scip_param.c:496
SCIP_Real SCIPgetRowSolActivity(SCIP *scip, SCIP_ROW *row, SCIP_SOL *sol)
Definition: scip_lp.c:1982
int SCIPgetNRuns(SCIP *scip)
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1435
static SCIP_RETCODE tryFixVar(SCIP *scip, SCIP *subscip, SCIP_SOL *sol, SCIP_Real *potential, SCIP_Real *slack, SCIP_VAR *var, SCIP_VAR *subvar, int *inftycounter, SCIP_HEURDATA *heurdata, SCIP_Bool *infeasible, SCIP_Bool *fixed)
Definition: heur_repair.c:270
memory allocation routines