misc.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program */
4 /* GCG --- Generic Column Generation */
5 /* a Dantzig-Wolfe decomposition based extension */
6 /* of the branch-cut-and-price framework */
7 /* SCIP --- Solving Constraint Integer Programs */
8 /* */
9 /* Copyright (C) 2010-2018 Operations Research, RWTH Aachen University */
10 /* Zuse Institute Berlin (ZIB) */
11 /* */
12 /* This program is free software; you can redistribute it and/or */
13 /* modify it under the terms of the GNU Lesser General Public License */
14 /* as published by the Free Software Foundation; either version 3 */
15 /* of the License, or (at your option) any later version. */
16 /* */
17 /* This program is distributed in the hope that it will be useful, */
18 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
19 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
20 /* GNU Lesser General Public License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with this program; if not, write to the Free Software */
24 /* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.*/
25 /* */
26 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
27 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 #include "gcg.h"
37 #include "relax_gcg.h"
38 #include "pricer_gcg.h"
39 #include "benders_gcg.h"
40 #include "pub_gcgvar.h"
41 #include "cons_decomp.h"
42 #include "gcgsort.h"
43 #include <string.h>
44 #include <unistd.h>
45 
48 static
50  SCIP_VAR* mastervar,
51  SCIP_VAR* origvar
52  )
53 {
54  int i;
55  SCIP_VAR** origvars;
56  SCIP_Real* origvals;
57  int norigvars;
58 
59  assert(mastervar != NULL);
60  assert(origvar != NULL);
61 
62  origvars = GCGmasterVarGetOrigvars(mastervar);
63  norigvars = GCGmasterVarGetNOrigvars(mastervar);
64  origvals = GCGmasterVarGetOrigvals(mastervar);
65 
66  for( i = 0; i < norigvars; ++i )
67  {
68  if( origvars[i] == origvar )
69  {
70  return origvals[i];
71  }
72  }
73 
74  return 0.0;
75 }
76 
78 static
79 GCG_DECL_SORTPTRCOMP(mastervarcomp)
80 {
81  SCIP* origprob = (SCIP *) userdata; /* TODO: continue here */
82  SCIP_VAR* mastervar1;
83  SCIP_VAR* mastervar2;
84  SCIP_VAR** origvars;
85  int norigvars;
86  int i;
87 
88  mastervar1 = elem1;
89  mastervar2 = elem2;
90 
91  assert(mastervar1 != NULL);
92  assert(mastervar2 != NULL);
93 
94  if( GCGvarGetBlock(mastervar1) < 0 )
95  {
96  SCIPdebugMessage("linkingvar or directy transferred var\n");
97  }
98  if( GCGvarGetBlock(mastervar2) < 0 )
99  {
100  SCIPdebugMessage("linkingvar or directy transferred var\n");
101  }
102 
103  /* TODO: get all original variables (need scip...maybe from pricer via function and scip_ */
104  origvars = SCIPgetVars(origprob);
105  norigvars = SCIPgetNVars(origprob);
106 
107  for( i = 0; i < norigvars; ++i )
108  {
109  if( SCIPvarGetType(origvars[i]) > SCIP_VARTYPE_INTEGER )
110  continue;
111 
112  if( SCIPisFeasGT(origprob, getGeneratorEntry(mastervar1, origvars[i]), getGeneratorEntry(mastervar2, origvars[i])) )
113  return -1;
114  if( SCIPisFeasLT(origprob, getGeneratorEntry(mastervar1, origvars[i]), getGeneratorEntry(mastervar2, origvars[i])) )
115  return 1;
116  }
117 
118  return 0;
119 }
120 
125  SCIP* scip,
126  SCIP_SOL* mastersol,
127  SCIP_SOL** origsol
128  )
129 {
130  SCIP* masterprob;
131  int npricingprobs;
132  int* blocknrs;
133  SCIP_Real* blockvalue;
134  SCIP_Real increaseval;
135  SCIP_VAR** mastervars;
136  SCIP_VAR** mastervarsall;
137  SCIP_Real* mastervals;
138  int nmastervarsall;
139  int nmastervars;
140  SCIP_VAR** vars;
141  int nvars;
142  SCIP_Real feastol;
143  SCIP_Bool discretization;
144  int i;
145  int j;
146 
147  assert(scip != NULL);
148  assert(origsol != NULL);
149 
150  masterprob = GCGgetMasterprob(scip);
151  npricingprobs = GCGgetNPricingprobs(scip);
152 
153  assert( !SCIPisInfinity(scip, SCIPgetSolOrigObj(masterprob, mastersol)) );
154 
156  {
157  SCIP_SOL* relaxsol;
158 
159  relaxsol = GCGgetBendersRelaxationSol(scip);
160 
161  SCIP_CALL( SCIPcreateSolCopy(scip, origsol, relaxsol) );
162  SCIP_CALL( SCIPunlinkSol(scip, *origsol) );
163 
164  return SCIP_OKAY;
165  }
166 
167  SCIP_CALL( SCIPcreateSol(scip, origsol, GCGrelaxGetProbingheur(scip)) );
168 
169  if( GCGgetDecompositionMode(scip) != DEC_DECMODE_ORIGINAL && !GCGmasterIsSolValid(masterprob, mastersol) )
170  return SCIP_OKAY;
171 
172  SCIP_CALL( SCIPallocBufferArray(scip, &blockvalue, npricingprobs) );
173  SCIP_CALL( SCIPallocBufferArray(scip, &blocknrs, npricingprobs) );
174 
175  SCIP_CALL( SCIPgetBoolParam(scip, "relaxing/gcg/discretization", &discretization) );
176 
177  if( discretization && (SCIPgetNContVars(scip) > 0) )
178  {
179  SCIP_VAR** fixedvars;
180  SCIP_Real* fixedvals;
181  int nfixedvars;
182 
183  /* get variables of the master problem and their solution values */
184  SCIP_CALL( SCIPgetVarsData(masterprob, &mastervarsall, &nmastervarsall, NULL, NULL, NULL, NULL) );
185 
186  /* getting the fixed variables */
187  fixedvars = SCIPgetFixedVars(masterprob);
188  nfixedvars = SCIPgetNFixedVars(masterprob);
189 
190  assert(mastervarsall != NULL);
191  assert(nmastervarsall >= 0);
192 
193  SCIP_CALL( SCIPallocBufferArray(scip, &mastervars, nmastervarsall + nfixedvars) );
194 
195  SCIP_CALL( SCIPallocBufferArray(scip, &mastervals, nmastervarsall + nfixedvars) );
196  SCIP_CALL( SCIPallocBufferArray(scip, &fixedvals, nfixedvars) );
197 
198  SCIP_CALL( SCIPgetSolVals(masterprob, mastersol, nmastervarsall, mastervarsall, mastervals) );
199  SCIP_CALL( SCIPgetSolVals(masterprob, mastersol, nfixedvars, fixedvars, fixedvals) );
200 
201  nmastervars = 0;
202 
203  for( i = 0; i < nmastervarsall; ++i )
204  {
205  SCIP_Real solval;
206 
207  assert( i >= nmastervars );
208  solval = mastervals[i];
209 
210  if( !SCIPisZero(scip, solval) )
211  {
212  mastervars[nmastervars] = mastervarsall[i];
213  mastervals[nmastervars] = solval;
214 
215  ++nmastervars;
216  }
217  }
218 
219  /* adding the fixed variables to the mastervars array */
220  for( i = 0; i < nfixedvars; i++ )
221  {
222  SCIP_Real solval;
223 
224  solval = fixedvals[i];
225 
226  if( !SCIPisZero(scip, solval) )
227  {
228  mastervars[nmastervars] = fixedvars[i];
229  mastervals[nmastervars] = solval;
230 
231  ++nmastervars;
232  }
233  }
234 
235  SCIPfreeBufferArray(scip, &fixedvals);
236 
237  /* sort mastervariables lexicographically */
238  GCGsortPtrPtr((void**)mastervars, (void**) mastervals, mastervarcomp, scip, nmastervars );
239  }
240  else
241  {
242  SCIP_VAR** fixedvars;
243  SCIP_Real* fixedvals;
244  int nfixedvars;
245 
246  /* get variables of the master problem and their solution values */
247  SCIP_CALL( SCIPgetVarsData(masterprob, &mastervarsall, &nmastervarsall, NULL, NULL, NULL, NULL) );
248 
249  /* getting the fixed variables */
250  fixedvars = SCIPgetFixedVars(masterprob);
251  nfixedvars = SCIPgetNFixedVars(masterprob);
252 
253  assert(mastervarsall != NULL);
254  assert(nmastervarsall >= 0);
255 
256  SCIP_CALL( SCIPallocBufferArray(scip, &mastervars, nmastervarsall + nfixedvars) );
257  SCIP_CALL( SCIPallocBufferArray(scip, &mastervals, nmastervarsall + nfixedvars) );
258  SCIP_CALL( SCIPallocBufferArray(scip, &fixedvals, nfixedvars) );
259 
260  SCIP_CALL( SCIPgetSolVals(masterprob, mastersol, nmastervarsall, mastervarsall, mastervals) );
261  SCIP_CALL( SCIPgetSolVals(masterprob, mastersol, nfixedvars, fixedvars, fixedvals) );
262 
263  nmastervars = 0;
264 
265  for( i = 0; i < nmastervarsall; ++i )
266  {
267  SCIP_Real solval;
268 
269  assert( i >= nmastervars );
270  solval = mastervals[i];
271 
272  if( !SCIPisZero(scip, solval) )
273  {
274  mastervars[nmastervars] = mastervarsall[i];
275  mastervals[nmastervars] = solval;
276 
277  ++nmastervars;
278  }
279  }
280 
281  /* adding the fixed variables to the mastervars array */
282  for( i = 0; i < nfixedvars; i++ )
283  {
284  SCIP_Real solval;
285 
286  solval = fixedvals[i];
287 
288  if( !SCIPisZero(scip, solval) )
289  {
290  mastervars[nmastervars] = fixedvars[i];
291  mastervals[nmastervars] = solval;
292 
293  ++nmastervars;
294  }
295  }
296 
297  SCIPfreeBufferArray(scip, &fixedvals);
298  }
299 
300  /* initialize the block values for the pricing problems */
301  for( i = 0; i < npricingprobs; i++ )
302  {
303  blockvalue[i] = 0.0;
304  blocknrs[i] = 0;
305  }
306 
307  /* loop over all given master variables */
308  for( i = 0; i < nmastervars; i++ )
309  {
310  SCIP_VAR** origvars;
311  int norigvars;
312  SCIP_Real* origvals;
313  SCIP_Bool isray;
314  int blocknr;
315 
316  if( SCIPisZero(masterprob, mastervals[i]) )
317  continue;
318 
319  origvars = GCGmasterVarGetOrigvars(mastervars[i]);
320  norigvars = GCGmasterVarGetNOrigvars(mastervars[i]);
321  origvals = GCGmasterVarGetOrigvals(mastervars[i]);
322  blocknr = GCGvarGetBlock(mastervars[i]);
323  isray = GCGmasterVarIsRay(mastervars[i]);
324 
325  assert(GCGvarIsMaster(mastervars[i]));
326 
328  assert(!SCIPisInfinity(scip, mastervals[i]));
329 
330  /* first of all, handle variables representing rays */
331  if( isray )
332  {
333  assert(blocknr >= 0);
334  /* we also want to take into account variables representing rays, that have a small value (between normal and feas eps),
335  * so we do no feas comparison here */
336  if( SCIPisPositive(masterprob, mastervals[i]) )
337  {
338  /* loop over all original variables contained in the current master variable */
339  for( j = 0; j < norigvars; j++ )
340  {
341  if( SCIPisZero(scip, origvals[j]) )
342  continue;
343 
344  assert(!SCIPisZero(scip, origvals[j]));
345 
346  /* the original variable is a linking variable: just transfer the solution value of the direct copy (this is done later) */
347  if( GCGoriginalVarIsLinking(origvars[j]) )
348  continue;
349 
350  SCIPdebugMessage("Increasing value of %s by %f because of %s\n", SCIPvarGetName(origvars[j]), origvals[j] * mastervals[i], SCIPvarGetName(mastervars[i]));
351  /* increase the corresponding value */
352  SCIP_CALL( SCIPincSolVal(scip, *origsol, origvars[j], origvals[j] * mastervals[i]) );
353  }
354  }
355  mastervals[i] = 0.0;
356  continue;
357  }
358 
359  /* variable was directly transferred to the master problem (only in linking conss or linking variable) */
362  if( blocknr == -1 )
363  {
364  assert(norigvars == 1);
365  assert(origvals[0] == 1.0);
366 
367  /* increase the corresponding value */
368  SCIPdebugMessage("Increasing value of %s by %f because of %s\n", SCIPvarGetName(origvars[0]), origvals[0] * mastervals[i], SCIPvarGetName(mastervars[i]));
369  SCIP_CALL( SCIPincSolVal(scip, *origsol, origvars[0], origvals[0] * mastervals[i]) );
370  mastervals[i] = 0.0;
371  continue;
372  }
373  if( blocknr == -2 )
374  {
375  assert(norigvars == 0);
376 
377  mastervals[i] = 0.0;
378  continue;
379  }
380 
381  /* handle the variables with value >= 1 to get integral values in original solution */
382  while( SCIPisFeasGE(masterprob, mastervals[i], 1.0) )
383  {
384  assert(blocknr >= 0);
385  /* loop over all original variables contained in the current master variable */
386  for( j = 0; j < norigvars; j++ )
387  {
388  SCIP_VAR* pricingvar;
389  int norigpricingvars;
390  SCIP_VAR** origpricingvars;
391  if( SCIPisZero(scip, origvals[j]) )
392  continue;
393  assert(!SCIPisZero(scip, origvals[j]));
394 
395  /* the original variable is a linking variable: just transfer the solution value of the direct copy (this is done above) */
396  if( GCGoriginalVarIsLinking(origvars[j]) )
397  continue;
398 
399  pricingvar = GCGoriginalVarGetPricingVar(origvars[j]);
400  assert(GCGvarIsPricing(pricingvar));
401 
402  norigpricingvars = GCGpricingVarGetNOrigvars(pricingvar);
403  origpricingvars = GCGpricingVarGetOrigvars(pricingvar);
404 
405  /* just in case a variable has a value higher than the number of blocks, it represents */
406  if( norigpricingvars <= blocknrs[blocknr] )
407  {
408  SCIPdebugMessage("Increasing value of %s by %f because of %s\n", SCIPvarGetName(origpricingvars[norigpricingvars-1]), mastervals[i] * origvals[j], SCIPvarGetName(mastervars[i]));
409  /* increase the corresponding value */
410  SCIP_CALL( SCIPincSolVal(scip, *origsol, origpricingvars[norigpricingvars-1], mastervals[i] * origvals[j]) );
411  mastervals[i] = 1.0;
412  }
413  /* this should be default */
414  else
415  {
416  SCIPdebugMessage("Increasing value of %s by %f because of %s\n", SCIPvarGetName(origpricingvars[blocknrs[blocknr]]), origvals[j], SCIPvarGetName(mastervars[i]) );
417  /* increase the corresponding value */
418  SCIP_CALL( SCIPincSolVal(scip, *origsol, origpricingvars[blocknrs[blocknr]], origvals[j]) );
419  }
420  }
421  mastervals[i] = mastervals[i] - 1.0;
422  blocknrs[blocknr]++;
423  }
424  assert(!SCIPisFeasNegative(masterprob, mastervals[i]));
425  }
426 
427  /* TODO: Change order of mastervars */
428 
429  /* loop over all given master variables */
430  for( i = 0; i < nmastervars; i++ )
431  {
432  SCIP_VAR** origvars;
433  int norigvars;
434  SCIP_Real* origvals;
435  int blocknr;
436 
437  origvars = GCGmasterVarGetOrigvars(mastervars[i]);
438  norigvars = GCGmasterVarGetNOrigvars(mastervars[i]);
439  origvals = GCGmasterVarGetOrigvals(mastervars[i]);
440  blocknr = GCGvarGetBlock(mastervars[i]);
441 
442  if( SCIPisFeasZero(masterprob, mastervals[i]) )
443  {
444  continue;
445  }
446  assert(SCIPisFeasGE(masterprob, mastervals[i], 0.0) && SCIPisFeasLT(masterprob, mastervals[i], 1.0));
447 
448  while( SCIPisFeasPositive(masterprob, mastervals[i]) )
449  {
450  assert(blocknr >= 0);
451  assert(GCGvarIsMaster(mastervars[i]));
452  assert(!GCGmasterVarIsRay(mastervars[i]));
453 
454  increaseval = MIN(mastervals[i], 1.0 - blockvalue[blocknr]);
455  /* loop over all original variables contained in the current master variable */
456  for( j = 0; j < norigvars; j++ )
457  {
458  SCIP_VAR* pricingvar;
459  int norigpricingvars;
460  SCIP_VAR** origpricingvars;
461 
462  if( SCIPisZero(scip, origvals[j]) )
463  continue;
464 
465  /* the original variable is a linking variable: just transfer the solution value of the direct copy (this is done above) */
466  if( GCGoriginalVarIsLinking(origvars[j]) )
467  continue;
468 
469  pricingvar = GCGoriginalVarGetPricingVar(origvars[j]);
470  assert(GCGvarIsPricing(pricingvar));
471 
472  norigpricingvars = GCGpricingVarGetNOrigvars(pricingvar);
473  origpricingvars = GCGpricingVarGetOrigvars(pricingvar);
474 
475  if( norigpricingvars <= blocknrs[blocknr] )
476  {
477  increaseval = mastervals[i];
478 
479  SCIPdebugMessage("Increasing value of %s by %f because of %s\n", SCIPvarGetName(origpricingvars[norigpricingvars-1]), origvals[j] * increaseval, SCIPvarGetName(mastervars[i]) );
480  /* increase the corresponding value */
481  SCIP_CALL( SCIPincSolVal(scip, *origsol, origpricingvars[norigpricingvars-1], origvals[j] * increaseval) );
482  }
483  else
484  {
485  /* increase the corresponding value */
486  SCIPdebugMessage("Increasing value of %s by %f because of %s\n", SCIPvarGetName(origpricingvars[blocknrs[blocknr]]), origvals[j] * increaseval, SCIPvarGetName(mastervars[i]) );
487  SCIP_CALL( SCIPincSolVal(scip, *origsol, origpricingvars[blocknrs[blocknr]], origvals[j] * increaseval) );
488  }
489  }
490 
491  mastervals[i] = mastervals[i] - increaseval;
492  if( SCIPisFeasZero(masterprob, mastervals[i]) )
493  {
494  mastervals[i] = 0.0;
495  }
496  blockvalue[blocknr] += increaseval;
497 
498  /* if the value assigned to the block is equal to 1, this block is full and we take the next block */
499  if( SCIPisFeasGE(masterprob, blockvalue[blocknr], 1.0) )
500  {
501  blockvalue[blocknr] = 0.0;
502  blocknrs[blocknr]++;
503  }
504  }
505  }
506 
507  SCIPfreeBufferArray(scip, &mastervals);
508  SCIPfreeBufferArray(scip, &mastervars);
509 
510  SCIPfreeBufferArray(scip, &blocknrs);
511  SCIPfreeBufferArray(scip, &blockvalue);
512 
513  /* if the solution violates one of its bounds by more than feastol
514  * and less than 10*feastol, round it and print a warning
515  */
516  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
517  SCIP_CALL( SCIPgetRealParam(scip, "numerics/feastol", &feastol) );
518 
519  for( i = 0; i < nvars; ++i )
520  {
521  SCIP_Real solval;
522  SCIP_Real lb;
523  SCIP_Real ub;
524 
525  solval = SCIPgetSolVal(scip, *origsol, vars[i]);
526  lb = SCIPvarGetLbLocal(vars[i]);
527  ub = SCIPvarGetUbLocal(vars[i]);
528 
529  if( SCIPisFeasGT(scip, solval, ub) && EPSEQ(solval, ub, 10 * feastol) )
530  {
531  SCIP_CALL( SCIPsetSolVal(scip, *origsol, vars[i], ub) );
532  SCIPwarningMessage(scip, "Variable %s rounded from %g to %g in relaxation solution\n",
533  SCIPvarGetName(vars[i]), solval, ub);
534  }
535  else if( SCIPisFeasLT(scip, solval, lb) && EPSEQ(solval, lb, 10 * feastol) )
536  {
537  SCIP_CALL( SCIPsetSolVal(scip, *origsol, vars[i], lb) );
538  SCIPwarningMessage(scip, "Variable %s rounded from %g to %g in relaxation solution\n",
539  SCIPvarGetName(vars[i]), solval, lb);
540  }
541  }
542 
543  return SCIP_OKAY;
544 }
545 
546 
549  SCIP* scip,
550  SCIP_VAR** origvars,
551  SCIP_Real* origvals,
552  int norigvars,
553  SCIP_VAR** mastervars,
554  SCIP_Real* mastervals,
555  int nmastervars
556  )
557 {
558  int i;
559  int j;
560  int k;
561 
562  assert(scip != NULL);
563  assert(origvars != NULL);
564  assert(origvals != NULL);
565  assert(mastervars != NULL);
566  assert(mastervals != NULL);
567  assert(nmastervars >= 0);
568 
569  /* set all values to 0 initially */
570  for( i = 0; i < nmastervars; i++ )
571  mastervals[i] = 0.0;
572 
573  /* iterate over all original variables */
574  for( i = 0; i < norigvars; i++ )
575  {
576  SCIP_VAR** varmastervars;
577  SCIP_Real* varmastervals;
578  int blocknr;
579 
580  assert(GCGvarIsOriginal(origvars[i]));
581  varmastervars = GCGoriginalVarGetMastervars(origvars[i]);
582  varmastervals = GCGoriginalVarGetMastervals(origvars[i]);
583  blocknr = GCGvarGetBlock(origvars[i]);
584 
585  /* variable belongs to no block (or is a linking variable), so it was transferred directly to the master problem,
586  * hence, we transfer the value directly to the corresponding master variabe
587  */
588  if( blocknr < 0 )
589  {
590  assert(blocknr == -1 || blocknr == -2);
591  assert(SCIPvarIsOriginal(varmastervars[0]));
592  assert(SCIPvarGetTransVar(varmastervars[0]) != NULL);
593 
594  for( k = 0; k < nmastervars; k++ )
595  {
596  if( mastervars[k] == SCIPvarGetTransVar(varmastervars[0]) )
597  {
598  mastervals[k] += (varmastervals[0] * origvals[i]);
599  break;
600  }
601  }
602  assert(k < nmastervars);
603  }
604  /* variable belongs to exactly one block, so we have to look at all master variables and increase their values
605  * if they contain the original variable
606  */
607  else
608  {
609  SCIP_VAR* pricingvar;
610  SCIP_VAR* origvar;
611  SCIP_VAR** curmastervars;
612  SCIP_Real* curmastervals;
613  int ncurmastervars;
614 
615  pricingvar = GCGoriginalVarGetPricingVar(origvars[i]);
616  assert(GCGvarIsPricing(pricingvar));
617 
618  origvar = GCGpricingVarGetOriginalVar(pricingvar);
619  assert(GCGvarIsOriginal(origvar));
620  curmastervars = GCGoriginalVarGetMastervars(origvar);
621  curmastervals = GCGoriginalVarGetMastervals(origvar);
622  ncurmastervars = GCGoriginalVarGetNMastervars(origvar);
623 
624  for( j = 0; j < ncurmastervars; j++ )
625  {
626  assert(SCIPvarIsTransformed(curmastervars[j]));
627  for( k = 0; k < nmastervars; k++ )
628  if( mastervars[k] == curmastervars[j] )
629  {
630  mastervals[k] += (curmastervals[j] * origvals[i]);
631  break;
632  }
633  assert(k < nmastervars);
634  }
635  }
636 
637  }
638 }
639 
641 SCIP_Bool GCGisOriginal(
642  SCIP* scip
643  )
644 {
645  assert(scip != NULL);
646  return SCIPfindRelax(scip, "gcg") != NULL;
647 }
648 
650 SCIP_Bool GCGisMaster(
651  SCIP* scip
652  )
653 {
654  assert(scip != NULL);
655  return SCIPfindPricer(scip, "gcg") != NULL;
656 }
657 
659 SCIP_RETCODE GCGprintStatistics(
660  SCIP* scip,
661  FILE* file
662 )
663 {
664  assert(scip != NULL);
665 
666  SCIPmessageFPrintInfo(SCIPgetMessagehdlr(GCGgetMasterprob(scip)), file, "\nMaster Program statistics:\n");
667  SCIP_CALL( SCIPprintStatistics(GCGgetMasterprob(scip), file) );
669  && SCIPgetStage(GCGgetMasterprob(scip)) > SCIP_STAGE_PRESOLVED )
670  {
672  }
673 
675  {
676  SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "\nOriginal Program statistics:\n");
677  SCIP_CALL( SCIPprintStatistics(scip, file) );
678  }
679  else
680  {
683  SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "\nOriginal Program Solution statistics:\n");
684  SCIPprintSolutionStatistics(scip, file);
685  }
686  SCIPmessageFPrintInfo(SCIPgetMessagehdlr(GCGgetMasterprob(scip)), file, "\n");
688  && SCIPgetStage(scip) >= SCIP_STAGE_SOLVING )
689  {
690  SCIP_CALL( GCGmasterPrintSimplexIters(GCGgetMasterprob(scip), file) );
691  SCIPmessageFPrintInfo(SCIPgetMessagehdlr(GCGgetMasterprob(scip)), file, "\n");
692  }
694  {
695  SCIP_CALL( GCGprintDetectorStatistics(scip, file) );
696  }
697  if( SCIPgetStage(scip) >= SCIP_STAGE_PRESOLVING && GCGgetNPricingprobs(scip) > 0 )
698  {
699  SCIPmessageFPrintInfo(SCIPgetMessagehdlr(GCGgetMasterprob(scip)), file, "\n");
700  SCIP_CALL( GCGprintDecompStatistics(scip, file) );
701  }
702  return SCIP_OKAY;
703 }
704 
705 SCIP_RETCODE GCGprintInstanceName(
706  SCIP* scip,
707  FILE* file
708 )
709 {
710  SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "filename: %s \n", GCGgetFilename(scip) );
711  return SCIP_OKAY;
712 }
713 
714 
716  SCIP* scip,
717  SCIP_DIALOGHDLR* dialoghdlr
718  )
719 {
720  FILE* file;
721 
722  char* filepath;
723  char completefilepath[SCIP_MAXSTRLEN];
724 
725  SCIPgetStringParam(scip, "write/miplib2017featurefilepath", &filepath);
726 
727  (void) SCIPsnprintf(completefilepath, SCIP_MAXSTRLEN, "%s%s", filepath, ".csv");
728 
729 
730  file = fopen(completefilepath, "w");
731  if( file == NULL )
732  {
733  SCIPdialogMessage(scip, NULL, "error creating file <%s>\n", completefilepath);
734  SCIPprintSysError(completefilepath);
735  SCIPdialoghdlrClearBuffer(dialoghdlr);
736 
737  return SCIP_OKAY;
738  }
739 
740  SCIP_CALL( GCGprintMiplibBaseInformationHeader(scip, file) );
741 
742 
743  SCIP_CALL( GCGprintMiplibBaseInformation(scip, file) );
744 
745  SCIP_CALL( GCGprintMiplibConnectedInformation(scip, file) );
746 
747  SCIP_CALL( GCGprintMiplibDecompInformation(scip, file) );
748 
749  SCIPmessageFPrintInfo(SCIPgetMessagehdlr(GCGgetMasterprob(scip)), file, "\n, " );
750 
751 
752  fclose(file);
753 
754  return SCIP_OKAY;
755 }
756 
757 
758 
759 
762  SCIP* scip,
763  FILE* file
764 )
765 {
766  assert(scip != NULL);
767 
768  if( !GCGdetectionTookPlace(scip) )
769  {
770  SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "\nDetection did not take place so far\n");
771  return SCIP_OKAY;
772  }
773 
774  SCIPmessageFPrintInfo(SCIPgetMessagehdlr(scip), file, "\nStart writing complete detection information:\n");
775 
776  SCIP_CALL( GCGprintInstanceName(scip, file) );
777 
778 
779 
781 
782  GCGprintCompleteDetectionTime(scip, file);
783 
784  GCGprintClassifierInformation(scip, file);
785 
786  GCGprintDecompInformation(scip, file);
787 
788 // GCGprintMiplibStructureInformation(scip, file);
789 
790  return SCIP_OKAY;
791 }
792 
793 
794 
797  SCIP_CONS* cons
798  )
799 {
800  SCIP_CONSHDLR* conshdlr;
801  assert(cons != NULL);
802  conshdlr = SCIPconsGetHdlr(cons);
803  if( strcmp("origbranch", SCIPconshdlrGetName(conshdlr)) == 0 )
804  return TRUE;
805  else if( strcmp("masterbranch", SCIPconshdlrGetName(conshdlr)) == 0 )
806  return TRUE;
807 
808  return FALSE;
809 }
SCIP_Bool GCGisMaster(SCIP *scip)
Definition: misc.c:650
SCIP_Bool GCGvarIsOriginal(SCIP_VAR *var)
Definition: gcgvar.c:162
SCIP_Bool GCGdetectionTookPlace(SCIP *scip)
GCG interface methods.
SCIP_Bool GCGmasterVarIsRay(SCIP_VAR *var)
Definition: gcgvar.c:816
SCIP_RETCODE GCGprintDetectorStatistics(SCIP *scip, FILE *file)
SCIP_Bool GCGisOriginal(SCIP *scip)
Definition: misc.c:641
SCIP_RETCODE GCGprintCompleteDetectionTime(SCIP *givenscip, FILE *file)
void GCGtransformOrigvalsToMastervals(SCIP *scip, SCIP_VAR **origvars, SCIP_Real *origvals, int norigvars, SCIP_VAR **mastervars, SCIP_Real *mastervals, int nmastervars)
Definition: misc.c:548
SCIP_RETCODE GCGprintDecompStatistics(SCIP *scip, FILE *file)
Definition: decomp.c:3751
SCIP_RETCODE GCGprintMiplibBaseInformationHeader(SCIP *scip, FILE *file)
SCIP_Bool GCGmasterIsSolValid(SCIP *scip, SCIP_SOL *mastersol)
SCIP * GCGgetMasterprob(SCIP *scip)
Definition: relax_gcg.c:3838
SCIP_RETCODE GCGprintStatistics(SCIP *scip, FILE *file)
Definition: misc.c:659
SCIP_RETCODE GCGprintMiplibDecompInformation(SCIP *scip, FILE *file)
EXTERN void GCGsortPtrPtr(void **ptrarray1, void **ptrarray2, GCG_DECL_SORTPTRCOMP((*ptrcomp)), void *userdata, int len)
SCIP_Bool GCGvarIsMaster(SCIP_VAR *var)
Definition: gcgvar.c:148
SCIP_RETCODE GCGprintInstanceName(SCIP *scip, FILE *file)
Definition: misc.c:705
sorting functions, adapted from SCIP&#39;s sorttpl to include userdata
static SCIP_Real getGeneratorEntry(SCIP_VAR *mastervar, SCIP_VAR *origvar)
Definition: misc.c:49
int GCGgetNPricingprobs(SCIP *scip)
Definition: relax_gcg.c:3897
SCIP_RETCODE GCGprintMiplibStructureInformation(SCIP *scip, SCIP_DIALOGHDLR *dialoghdlr)
Definition: misc.c:715
SCIP_Bool GCGisConsGCGCons(SCIP_CONS *cons)
Definition: misc.c:796
SCIP_RETCODE GCGprintClassifierInformation(SCIP *scip, FILE *file)
SCIP_RETCODE GCGprintMiplibBaseInformation(SCIP *scip, FILE *file)
SCIP_VAR ** GCGpricingVarGetOrigvars(SCIP_VAR *var)
Definition: gcgvar.c:920
SCIP_RETCODE GCGtransformMastersolToOrigsol(SCIP *scip, SCIP_SOL *mastersol, SCIP_SOL **origsol)
Definition: misc.c:124
GCG relaxator.
SCIP_Bool GCGoriginalVarIsLinking(SCIP_VAR *var)
Definition: gcgvar.c:176
GCG variable pricer.
SCIP_Real * GCGmasterVarGetOrigvals(SCIP_VAR *var)
Definition: gcgvar.c:888
int GCGvarGetBlock(SCIP_VAR *var)
Definition: gcgvar.c:936
GCG Benders&#39; decomposition.
SCIP_SOL * GCGgetBendersRelaxationSol(SCIP *scip)
Definition: relax_gcg.c:5052
SCIP_VAR * GCGpricingVarGetOriginalVar(SCIP_VAR *var)
Definition: gcgvar.c:489
SCIP_RETCODE GCGmasterPrintSimplexIters(SCIP *scip, FILE *file)
SCIP_Bool GCGvarIsPricing(SCIP_VAR *var)
Definition: gcgvar.c:133
SCIP_RETCODE GCGprintBlockcandidateInformation(SCIP *scip, FILE *file)
public methods for GCG variables
static GCG_DECL_SORTPTRCOMP(mastervarcomp)
Definition: misc.c:79
int GCGpricingVarGetNOrigvars(SCIP_VAR *var)
Definition: gcgvar.c:904
DEC_DECMODE GCGgetDecompositionMode(SCIP *scip)
Definition: relax_gcg.c:5075
SCIP_RETCODE GCGprintCompleteDetectionStatistics(SCIP *scip, FILE *file)
Definition: misc.c:761
int GCGmasterVarGetNOrigvars(SCIP_VAR *var)
Definition: gcgvar.c:846
SCIP_RETCODE GCGprintDecompInformation(SCIP *scip, FILE *file)
SCIP_RETCODE GCGprintMiplibConnectedInformation(SCIP *scip, FILE *file)
int GCGoriginalVarGetNMastervars(SCIP_VAR *var)
Definition: gcgvar.c:545
SCIP_VAR ** GCGmasterVarGetOrigvars(SCIP_VAR *var)
Definition: gcgvar.c:866
SCIP_VAR ** GCGoriginalVarGetMastervars(SCIP_VAR *var)
Definition: gcgvar.c:561
const char * GCGgetFilename(SCIP *scip)
Definition: relax_gcg.c:4850
constraint handler for structure detection
void GCGpricerPrintPricingStatistics(SCIP *scip, FILE *file)
SCIP_Real * GCGoriginalVarGetMastervals(SCIP_VAR *var)
Definition: gcgvar.c:577
SCIP_VAR * GCGoriginalVarGetPricingVar(SCIP_VAR *var)
Definition: gcgvar.c:206
SCIP_HEUR * GCGrelaxGetProbingheur(SCIP *scip)
Definition: relax_gcg.c:4219