dec_consclass.cpp
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 "dec_consclass.h"
37 #include "cons_decomp.h"
38 #include "class_seeed.h"
39 #include "class_seeedpool.h"
40 #include "class_consclassifier.h"
41 #include "gcg.h"
42 #include "scip/cons_setppc.h"
43 #include "scip/scip.h"
44 #include "scip_misc.h"
45 #include "scip/clock.h"
46 
47 #include <sstream>
48 
49 #include <iostream>
50 #include <algorithm>
51 
52 /* constraint handler properties */
53 #define DEC_DETECTORNAME "consclass"
54 #define DEC_DESC "detector consclass"
55 #define DEC_FREQCALLROUND 1
56 #define DEC_MAXCALLROUND 0
57 #define DEC_MINCALLROUND 0
58 #define DEC_FREQCALLROUNDORIGINAL 1
59 #define DEC_MAXCALLROUNDORIGINAL INT_MAX
60 #define DEC_MINCALLROUNDORIGINAL 0
61 #define DEC_PRIORITY 0
62 #define DEC_DECCHAR 'c'
63 #define DEC_ENABLED TRUE
64 #define DEC_ENABLEDORIGINAL FALSE
65 #define DEC_ENABLEDFINISHING FALSE
66 #define DEC_ENABLEDPOSTPROCESSING FALSE
67 #define DEC_SKIP FALSE
68 #define DEC_USEFULRECALL FALSE
69 #define DEC_LEGACYMODE FALSE
71 #define DEFAULT_MAXIMUMNCLASSES 5
72 #define AGGRESSIVE_MAXIMUMNCLASSES 9
73 #define FAST_MAXIMUMNCLASSES 3
74 
75 #define SET_MULTIPLEFORSIZETRANSF 12500
76 
77 /*
78  * Data structures
79  */
80 
84 struct DEC_DetectorData
85 {
86 };
87 
88 /*
89  * Local methods
90  */
91 
92 /* put your local methods here, and declare them static */
93 
94 /*
95  * detector callback methods
96  */
97 
99 #define freeConsclass NULL
100 
102 #if 0
103 static
105 { /*lint --e{715}*/
106 
107  SCIPerrorMessage("Exit function of detector <%s> not implemented!\n", DEC_DETECTORNAME);
108  SCIPABORT();
109 
110  return SCIP_OKAY;
111 }
112 #else
113 #define exitConsclass NULL
114 #endif
115 
117 #if 0
118 static
120 { /*lint --e{715}*/
121 
122  SCIPerrorMessage("Init function of detector <%s> not implemented!\n", DEC_DETECTORNAME);
123  SCIPABORT();
124 
125  return SCIP_OKAY;
126 }
127 #else
128 #define initConsclass NULL
129 #endif
130 
132 //static DEC_DECL_DETECTSTRUCTURE(detectConsclass)
133 //{ /*lint --e{715}*/
134 // *result = SCIP_DIDNOTFIND;
135 //
136 // SCIPerrorMessage("Detection function of detector <%s> not implemented!\n", DEC_DETECTORNAME)
137 //; SCIPABORT(); /*lint --e{527}*/
138 //
139 // return SCIP_OKAY;
140 //}
141 
142 #define detectConsclass NULL
143 
144 #define finishSeeedConsclass NULL
145 
146 static DEC_DECL_PROPAGATESEEED(propagateSeeedConsclass)
147 {
148  *result = SCIP_DIDNOTFIND;
149  char decinfo[SCIP_MAXSTRLEN];
150 
151  SCIP_CLOCK* temporaryClock;
152 
153  if ( seeedPropagationData->seeedToPropagate->getNOpenconss() != seeedPropagationData->seeedpool->getNConss() )
154  {
155  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " abort dec_consclass cause there are %d many open vars of %d total vars and %d many open conss of %d total conss \n ", seeedPropagationData->seeedToPropagate->getNOpenvars(), seeedPropagationData->seeedpool->getNVars(), seeedPropagationData->seeedToPropagate->getNOpenconss() ,seeedPropagationData->seeedpool->getNConss() );
156  *result = SCIP_SUCCESS;
157  return SCIP_OKAY;
158  }
159 
160  SCIP_CALL_ABORT( SCIPcreateClock(scip, &temporaryClock) );
161  SCIP_CALL_ABORT( SCIPstartClock(scip, temporaryClock) );
162 
163  std::vector<gcg::Seeed*> foundseeeds(0);
164 
165  gcg::Seeed* seeedOrig;
166  gcg::Seeed* seeed;
167 
168  int maximumnclasses;
169 
170  if( seeedPropagationData->seeedpool->getNConss() + seeedPropagationData->seeedpool->getNVars() >= 50000 )
171  SCIPgetIntParam(scip, "detection/maxnclassesperclassifierforlargeprobs", &maximumnclasses);
172  else
173  SCIPgetIntParam(scip, "detection/maxnclassesperclassifier", &maximumnclasses);
174 
175  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " in dec_consclass: there are %d different constraint classes \n ", seeedPropagationData->seeedpool->getNConsClassifiers() );
176 
177 
178  for( int classifierIndex = 0; classifierIndex < seeedPropagationData->seeedpool->getNConsClassifiers(); ++classifierIndex )
179  {
180  gcg::ConsClassifier* classifier = seeedPropagationData->seeedpool->getConsClassifier( classifierIndex );
181  std::vector<int> consclassindices_master = std::vector<int>(0);
182 
183  if ( classifier->getNClasses() > maximumnclasses )
184  {
185  std::cout << " the current consclass distribution includes " << classifier->getNClasses() << " classes but only " << maximumnclasses << " are allowed for propagateSeeed() of cons class detector" << std::endl;
186  continue;
187  }
188 
189  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " the current constraint classifier \"%s\" consists of %d different classes \n ", classifier->getName(), classifier->getNClasses() );
190 
191  seeedOrig = seeedPropagationData->seeedToPropagate;
192 
193  for( int i = 0; i < classifier->getNClasses(); ++ i )
194  {
195  if ( classifier->getClassDecompInfo( i ) == gcg::ONLY_MASTER )
196  consclassindices_master.push_back( i );
197  }
198 
199  std::vector< std::vector<int> > subsetsOfConsclasses = classifier->getAllSubsets( true, false, false );
200 
201  for( size_t subset = 0; subset < subsetsOfConsclasses.size(); ++subset )
202  {
203  if( subsetsOfConsclasses[subset].size() == 0 && consclassindices_master.size() == 0 )
204  continue;
205 
206  seeed = new gcg::Seeed(seeedOrig);
207 
209  for( int i = 0; i < seeed->getNOpenconss(); ++i )
210  {
211  bool foundCons = false;
212  for( size_t consclassId = 0; consclassId < subsetsOfConsclasses[subset].size(); ++consclassId )
213  {
214  if( classifier->getClassOfCons( seeed->getOpenconss()[i] ) == subsetsOfConsclasses[subset][consclassId] )
215  {
216  seeed->bookAsMasterCons(seeed->getOpenconss()[i]);
217  foundCons = true;
218  break;
219  }
220  }
222  if ( !foundCons )
223  {
224  for( size_t consclassId = 0; consclassId < consclassindices_master.size(); ++consclassId )
225  {
226  if( classifier->getClassOfCons( seeed->getOpenconss()[i] ) == consclassindices_master[consclassId] )
227  {
228  seeed->bookAsMasterCons(seeed->getOpenconss()[i]);
229  break;
230  }
231  }
232  }
233  }
234 
236  std::stringstream decdesc;
237  decdesc << "consclass" << "\\_" << classifier->getName() << ": \\\\ ";
238  std::vector<int> curmasterclasses( consclassindices_master );
239  for ( size_t consclassId = 0; consclassId < subsetsOfConsclasses[subset].size(); ++consclassId )
240  {
241  if ( consclassId > 0 )
242  {
243  decdesc << "-";
244  }
245  decdesc << classifier->getClassName( subsetsOfConsclasses[subset][consclassId] );
246 
247  if( std::find( consclassindices_master.begin(), consclassindices_master.end(),
248  subsetsOfConsclasses[subset][consclassId] ) == consclassindices_master.end() )
249  {
250  curmasterclasses.push_back( subsetsOfConsclasses[subset][consclassId] );
251  }
252  }
253  for ( size_t consclassId = 0; consclassId < consclassindices_master.size(); ++consclassId )
254  {
255  if ( consclassId > 0 || subsetsOfConsclasses[subset].size() > 0)
256  {
257  decdesc << "-";
258  }
259  decdesc << classifier->getClassName( consclassindices_master[consclassId] );
260  }
261 
262  seeed->flushBooked();
263  (void) SCIPsnprintf(decinfo, SCIP_MAXSTRLEN, decdesc.str().c_str());
264  seeed->addDetectorChainInfo(decinfo);
265  seeed->setConsClassifierStatistics( seeed->getNDetectors(), classifier, curmasterclasses );
266 
267  foundseeeds.push_back(seeed);
268  }
269  }
270 
271  SCIP_CALL_ABORT( SCIPstopClock(scip, temporaryClock ) );
272 
273  SCIP_CALL( SCIPallocMemoryArray(scip, &(seeedPropagationData->newSeeeds), foundseeeds.size() ) );
274  seeedPropagationData->nNewSeeeds = foundseeeds.size();
275 
276  SCIPinfoMessage(scip, NULL, "dec_consclass found %d new seeeds \n", seeedPropagationData->nNewSeeeds );
277 
278  for( int s = 0; s < seeedPropagationData->nNewSeeeds; ++s )
279  {
280  seeedPropagationData->newSeeeds[s] = foundseeeds[s];
281  seeedPropagationData->newSeeeds[s]->addClockTime(SCIPclockGetTime(temporaryClock ) );
282  }
283 
284  SCIP_CALL_ABORT(SCIPfreeClock(scip, &temporaryClock) );
285 
286  *result = SCIP_SUCCESS;
287 
288  return SCIP_OKAY;
289 }
290 
291 static
292 DEC_DECL_PROPAGATEFROMTOOLBOX(propagateFromToolboxConsclass)
293 {
294  *result = SCIP_DIDNOTFIND;
295  char decinfo[SCIP_MAXSTRLEN];
296  gcg::ConsClassifier** classifiers;
297  int nclassifiers;
298  SCIP_Bool newclass, newclassifier;
299  gcg::ConsClassifier* selectedclassifier;
300  std::vector<int> selectedclasses;
301  int i, j;
302  char stri[SCIP_MAXSTRLEN];
303  SCIP_Bool finished;
304 
305  char* command;
306  int commandlen;
307  SCIP_Bool endoffile;
308 
309  if( seeedPropagationData->seeedToPropagate->getNOpenconss() != seeedPropagationData->seeedpool->getNConss() )
310  {
311  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, "Aborting dec_consclass because there are %d open vars of %d total vars and %d open conss of %d total conss \n ", seeedPropagationData->seeedToPropagate->getNOpenvars(), seeedPropagationData->seeedpool->getNVars(), seeedPropagationData->seeedToPropagate->getNOpenconss() ,seeedPropagationData->seeedpool->getNConss() );
312  return SCIP_ERROR;
313  }
314  if( seeedPropagationData->seeedpool->getNConsClassifiers() == 0 )
315  {
316  SCIPinfoMessage(scip, NULL, "No ConsClassifiers listed for propagation, starting classification.\n");
317  seeedPropagationData->seeedpool->calcClassifierAndNBlockCandidates(scip);
318  if( seeedPropagationData->seeedpool->getNConsClassifiers() == 0 )
319  {
320  SCIPinfoMessage(scip, NULL, "No ConsClassifiers found after calculation, aborting!.\n");
321  return SCIP_ERROR;
322  }
323  }
324  std::vector<gcg::Seeed*> foundseeeds(0);
325 
326  gcg::Seeed* seeedOrig;
327  gcg::Seeed* seeed;
328 
329  int maximumnclasses;
330 
331  if( seeedPropagationData->seeedpool->getNConss() + seeedPropagationData->seeedpool->getNVars() >= 50000 )
332  SCIPgetIntParam(scip, "detection/maxnclassesperclassifierforlargeprobs", &maximumnclasses);
333  else
334  SCIPgetIntParam(scip, "detection/maxnclassesperclassifier", &maximumnclasses);
335 
336  SCIP_CALL( SCIPallocMemoryArray(scip, &classifiers, seeedPropagationData->seeedpool->getNConsClassifiers()) );
337 
338  SCIPinfoMessage(scip, NULL, "\n%d consclassifiers available for propagation.\n", seeedPropagationData->seeedpool->getNConsClassifiers() );
339  nclassifiers = 0;
340  for( int classifierIndex = 0; classifierIndex < seeedPropagationData->seeedpool->getNConsClassifiers(); ++classifierIndex )
341  {
342  gcg::ConsClassifier* classifier = seeedPropagationData->seeedpool->getConsClassifier( classifierIndex );
343  if( classifier->getNClasses() > maximumnclasses )
344  {
345  std::cout << " the current consclass distribution includes " << classifier->getNClasses() << " classes but only " << maximumnclasses << " are allowed for propagateSeeed() of cons class detector" << std::endl;
346  continue;
347  }
348  newclassifier = TRUE;
349  for( i = 0; i < nclassifiers; ++i )
350  {
351  if( classifiers[i] == classifier )
352  {
353  newclassifier = FALSE;
354  }
355  }
356 
357  if( newclassifier )
358  {
359  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, "The constraint classifier \"%s\" consists of %d different classes.\n", classifier->getName(), classifier->getNClasses() );
360  classifiers[nclassifiers] = classifier;
361  ++nclassifiers;
362  }
363  }
364 
365  selectedclassifier = classifiers[0]; //default case to omit warnings
366  /* user selects a consclassifier */
367  finished = FALSE;
368  while( !finished )
369  {
370  SCIPinfoMessage(scip, NULL, "Available consclassifiers:\n");
371  for( i = 0; i < nclassifiers; ++i )
372  {
373  SCIPinfoMessage(scip, NULL, "%d) ", i+1); //+1 as we want the list to start with 1)
374  SCIPinfoMessage(scip, NULL, "%s\n", classifiers[i]->getName() );
375  }
376 
377  commandlen = 0;
378  while( commandlen == 0 )
379  {
380  SCIP_CALL( SCIPdialoghdlrGetWord(dialoghdlr, dialog, "Type in the name or number of the consclassifier that you want to use (seperated by spaces) or \"done\", (use \"quit\" to exit detector): \nGCG/toolbox> ", &command, &endoffile) );
381  commandlen = strlen(command);
382  }
383 
384  if( !strncmp( command, "done", commandlen) == 0 && !strncmp( command, "quit", commandlen) == 0 )
385  {
386  for( i = 0; i < nclassifiers; ++i )
387  {
388  sprintf(stri, "%d", i+1); //used for matching numberings in the list, off-by-one since classifiers array starts with index 0 and our list with 1)
389  if( strncmp( command, classifiers[i]->getName(), commandlen) == 0 || strncmp( command, stri, commandlen ) == 0 )
390  {
391  selectedclassifier = classifiers[i];
392  finished = TRUE;
393  continue;
394  }
395  }
396  }
397  else if( strncmp( command, "done", commandlen) == 0 )
398  {
399  finished = TRUE;
400  continue;
401  }
402  else if( strncmp( command, "quit", commandlen) == 0 )
403  {
404  SCIPfreeMemoryArray(scip, &classifiers);
405  *result = SCIP_DIDNOTFIND;
406  return SCIP_OKAY;
407  }
408  }
409 
410  std::vector<int> consclassindices = std::vector<int>(0);
411  for( i = 0; i < selectedclassifier->getNClasses(); ++i )
412  {
413  consclassindices.push_back(i);
414  }
415 
416  SCIPinfoMessage(scip, NULL, "You will now be asked to enter a selection of classes iteratively. If you have finished your selection, enter \"done\".\n");
417  finished = FALSE;
418  while( !finished )
419  {
420  std::vector<int> nConssOfClasses = selectedclassifier->getNConssOfClasses();
421  SCIPinfoMessage(scip, NULL, "The following classes are available for the selected consclassifier \"%s\":\n",selectedclassifier->getName());
422  for( i = 0; i < static_cast<int>(consclassindices.size()); ++i )
423  {
424  SCIPinfoMessage(scip, NULL, "%d) ", i+1); //+1 as we want the list to start with 1)
425  SCIPinfoMessage(scip, NULL, "%s || NConss: %d || %s\n", selectedclassifier->getClassName(consclassindices[i]),nConssOfClasses[i], selectedclassifier->getClassDescription(consclassindices[i]));
426  }
427 
428  commandlen = 0;
429  while( commandlen == 0 )
430  {
431  SCIP_CALL( SCIPdialoghdlrGetWord(dialoghdlr, dialog, "Type in the name(s) or number(s) of classes (seperated by spaces) or \"done\", (use \"quit\" to exit detector): \nGCG/toolbox> ", &command, &endoffile) );
432  commandlen = strlen(command);
433  }
434 
435  if( !strncmp( command, "done", commandlen) == 0 && !strncmp( command, "quit", commandlen) == 0 )
436  {
437  for( i = 0; i < static_cast<int>(consclassindices.size()); ++i )
438  {
439  newclass = TRUE;
440  sprintf(stri, "%d", i+1); //used for matching numberings in the list, off-by-one since classifiers array starts with index 0 and our list with 1)
441  if( strncmp( command, selectedclassifier->getClassNameOfCons(consclassindices[i]), commandlen) == 0 || strncmp( command, stri, commandlen ) == 0 )
442  {
443  /* check that we do not select the same classifier multiple times*/
444  for( j = 0; j < static_cast<int>(selectedclasses.size()); ++j )
445  {
446  if( selectedclasses[j] == consclassindices[i] )
447  {
448  newclass = FALSE;
449  }
450  }
451  if( newclass )
452  {
453  selectedclasses.push_back(consclassindices[i]);
454 
455  SCIPinfoMessage(scip, NULL, "\nCurrently selected classifiers: ");
456  for( j = 0; j < static_cast<int>(selectedclasses.size()); ++j )
457  {
458  SCIPinfoMessage(scip, NULL, "\"%s\" ", selectedclassifier->getClassNameOfCons(selectedclasses[j]));
459  }
460  SCIPinfoMessage(scip, NULL, "\n\n");
461 
462  if( selectedclasses.size() >= consclassindices.size() )
463  {
464  finished = TRUE;
465  break;
466  }
467  }
468  else
469  {
470  SCIPinfoMessage(scip, NULL, "\n+++Class \"%s\" is already selected!+++\n\n", selectedclassifier->getClassNameOfCons(consclassindices[i]));
471  }
472  }
473  }
474  }
475  else if( strncmp( command, "done", commandlen) == 0 )
476  {
477  finished = TRUE;
478  continue;
479  }
480  else if( strncmp( command, "quit", commandlen) == 0 )
481  {
482  SCIPfreeMemoryArray(scip, &classifiers);
483  *result = SCIP_DIDNOTFIND;
484  return SCIP_OKAY;
485  }
486  }
487 
488  std::vector<int> consclassindices_master = std::vector<int>(0);
489 
490  seeedOrig = seeedPropagationData->seeedToPropagate;
491 
492  for( i = 0; i < selectedclassifier->getNClasses(); ++ i )
493  {
494  if ( selectedclassifier->getClassDecompInfo(i) == gcg::ONLY_MASTER )
495  consclassindices_master.push_back(i);
496  }
497 
498  if( selectedclasses.size() == 0 && consclassindices_master.size() == 0 )
499  {
500  *result = SCIP_DIDNOTFIND;
501  SCIPfreeMemoryArray(scip, &classifiers);
502  return SCIP_OKAY;
503  }
504 
505  seeed = new gcg::Seeed(seeedOrig);
506 
508  for( i = 0; i < seeed->getNOpenconss(); ++i )
509  {
510  bool foundCons = false;
511  for( size_t consclassId = 0; consclassId < selectedclasses.size(); ++consclassId )
512  {
513  if( selectedclassifier->getClassOfCons( seeed->getOpenconss()[i] ) == selectedclasses[consclassId] )
514  {
515  seeed->bookAsMasterCons(seeed->getOpenconss()[i]);
516  foundCons = true;
517  break;
518  }
519  }
521  if( !foundCons )
522  {
523  for( size_t consclassId = 0; consclassId < consclassindices_master.size(); ++consclassId )
524  {
525  if( selectedclassifier->getClassOfCons( seeed->getOpenconss()[i] ) == consclassindices_master[consclassId] )
526  {
527  seeed->bookAsMasterCons(seeed->getOpenconss()[i]);
528  break;
529  }
530  }
531  }
532  }
533 
535  std::stringstream decdesc;
536  decdesc << "consclass" << "\\_" << selectedclassifier->getName() << ": \\\\ ";
537  std::vector<int> curmasterclasses( consclassindices_master );
538  for( size_t consclassId = 0; consclassId < selectedclasses.size(); ++consclassId )
539  {
540  if( consclassId > 0 )
541  {
542  decdesc << "-";
543  }
544  decdesc << selectedclassifier->getClassName( selectedclasses[consclassId] );
545 
546  if( std::find( consclassindices_master.begin(), consclassindices_master.end(),
547  selectedclasses[consclassId] ) == consclassindices_master.end() )
548  {
549  curmasterclasses.push_back( selectedclasses[consclassId] );
550  }
551  }
552  for( size_t consclassId = 0; consclassId < consclassindices_master.size(); ++consclassId )
553  {
554  if( consclassId > 0 || selectedclasses.size() > 0)
555  {
556  decdesc << "-";
557  }
558  decdesc << selectedclassifier->getClassName( consclassindices_master[consclassId] );
559  }
560 
561  seeed->flushBooked();
562  (void) SCIPsnprintf(decinfo, SCIP_MAXSTRLEN, decdesc.str().c_str());
563  seeed->addDetectorChainInfo(decinfo);
564  seeed->setDetectorPropagated(detector);
565  seeed->setConsClassifierStatistics( seeed->getNDetectors(), selectedclassifier, curmasterclasses );
566 
567  foundseeeds.push_back(seeed);
568 
569 
570  //@TODO: This alloc is already done in cons_decomp:SCIPconshdlrDecompToolboxActOnSeeed(..).
571  //This is contrary to the behaviour of other detectors such as hrcg, hrg and hr but not connectedbase
572  SCIP_CALL( SCIPallocMemoryArray(scip, &(seeedPropagationData->newSeeeds), foundseeeds.size() ) );
573  seeedPropagationData->nNewSeeeds = foundseeeds.size();
574 
575  for( int s = 0; s < seeedPropagationData->nNewSeeeds; ++s )
576  {
577  seeedPropagationData->newSeeeds[s] = foundseeeds[s];
578  }
579 
580  *result = SCIP_SUCCESS;
581  SCIPfreeMemoryArray(scip, &classifiers);
582  return SCIP_OKAY;
583 }
584 
585 #define finishFromToolboxConsclass NULL
586 
587 #define detectorPostprocessSeeedConsclass NULL
588 
589 static
590 DEC_DECL_SETPARAMAGGRESSIVE(setParamAggressiveConsclass)
591 {
592  char setstr[SCIP_MAXSTRLEN];
593  SCIP_Real modifier;
594 
595  int newval;
596  const char* name = DECdetectorGetName(detector);
597 
598  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
599  SCIP_CALL( SCIPsetBoolParam(scip, setstr, TRUE) );
600 
601  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/origenabled", name);
602  SCIP_CALL( SCIPsetBoolParam(scip, setstr, TRUE) );
603 
604  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
605  SCIP_CALL( SCIPsetBoolParam(scip, setstr, FALSE ) );
606 
607  if( SCIPgetStage(scip) < SCIP_STAGE_PROBLEM )
608  {
609  return SCIP_OKAY;
610  }
611 
612  modifier = ((SCIP_Real)SCIPgetNConss(scip) + (SCIP_Real)SCIPgetNVars(scip) ) / SET_MULTIPLEFORSIZETRANSF;
613  modifier = log(modifier) / log(2.);
614 
615  if (!SCIPisFeasPositive(scip, modifier) )
616  modifier = -1.;
617 
618  modifier = SCIPfloor(scip, modifier);
619 
620  newval = MAX( 6, AGGRESSIVE_MAXIMUMNCLASSES - modifier );
621  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxnclasses", name);
622 
623  SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
624  SCIPinfoMessage(scip, NULL, "\n%s = %d\n", setstr, newval);
625 
626 
627  return SCIP_OKAY;
628 
629 }
630 
631 
632 static
633 DEC_DECL_SETPARAMDEFAULT(setParamDefaultConsclass)
634 {
635  char setstr[SCIP_MAXSTRLEN];
636  SCIP_Real modifier;
637 
638  int newval;
639  const char* name = DECdetectorGetName(detector);
640 
641  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
642  SCIP_CALL( SCIPsetBoolParam(scip, setstr, TRUE) );
643 
644  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/origenabled", name);
645  SCIP_CALL( SCIPsetBoolParam(scip, setstr, TRUE ) );
646 
647  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
648  SCIP_CALL( SCIPsetBoolParam(scip, setstr, FALSE ) );
649 
650  if( SCIPgetStage(scip) < SCIP_STAGE_PROBLEM )
651  {
652  return SCIP_OKAY;
653  }
654 
655 
656  modifier = ( (SCIP_Real)SCIPgetNConss(scip) + (SCIP_Real)SCIPgetNVars(scip) ) / SET_MULTIPLEFORSIZETRANSF;
657  modifier = log(modifier) / log(2);
658 
659  if (!SCIPisFeasPositive(scip, modifier) )
660  modifier = -1.;
661 
662  modifier = SCIPfloor(scip, modifier);
663 
664  newval = MAX( 6, DEFAULT_MAXIMUMNCLASSES - modifier );
665  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxnclasses", name);
666 
667  SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
668  SCIPinfoMessage(scip, NULL, "\n%s = %d\n", setstr, newval);
669 
670  return SCIP_OKAY;
671 
672 }
673 
674 static
675 DEC_DECL_SETPARAMFAST(setParamFastConsclass)
676 {
677  char setstr[SCIP_MAXSTRLEN];
678  SCIP_Real modifier;
679  int newval;
680 
681  const char* name = DECdetectorGetName(detector);
682 
683  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
684  SCIP_CALL( SCIPsetBoolParam(scip, setstr, TRUE) );
685 
686  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/origenabled", name);
687  SCIP_CALL( SCIPsetBoolParam(scip, setstr, FALSE) );
688 
689  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
690  SCIP_CALL( SCIPsetBoolParam(scip, setstr, FALSE ) );
691 
692  if( SCIPgetStage(scip) < SCIP_STAGE_PROBLEM )
693  {
694  return SCIP_OKAY;
695  }
696 
697 
698  modifier = ( (SCIP_Real)SCIPgetNConss(scip) + (SCIP_Real)SCIPgetNVars(scip) ) / SET_MULTIPLEFORSIZETRANSF;
699 
700  modifier = log(modifier) / log(2);
701 
702  if (!SCIPisFeasPositive(scip, modifier) )
703  modifier = -1.;
704 
705  modifier = SCIPfloor(scip, modifier);
706 
707  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxnclasses", name);
708 
709  newval = MAX( 6, FAST_MAXIMUMNCLASSES - modifier );
710 
711  SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
712  SCIPinfoMessage(scip, NULL, "\n%s = %d\n", setstr, newval);
713 
714  return SCIP_OKAY;
715 
716 }
717 
718 
719 
720 /*
721  * detector specific interface methods
722  */
723 
726 )
727 {
728  DEC_DETECTORDATA* detectordata;
729  char setstr[SCIP_MAXSTRLEN];
730 
732  detectordata = NULL;
733 
734  SCIP_CALL(
737  freeConsclass, initConsclass, exitConsclass, propagateSeeedConsclass, propagateFromToolboxConsclass, finishFromToolboxConsclass, finishSeeedConsclass, detectorPostprocessSeeedConsclass, setParamAggressiveConsclass, setParamDefaultConsclass, setParamFastConsclass));
738 
741  const char* name = DEC_DETECTORNAME;
742  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxnclasses", name);
743  SCIP_CALL( SCIPaddIntParam(scip, setstr, "maximum number of classes ", NULL, FALSE, DEFAULT_MAXIMUMNCLASSES, 1, INT_MAX, NULL, NULL ) );
744 
745  return SCIP_OKAY;
746 }
#define DEC_ENABLEDPOSTPROCESSING
#define DEC_MAXCALLROUNDORIGINAL
#define DEC_DECL_INITDETECTOR(x)
Definition: type_detector.h:70
#define finishFromToolboxConsclass
const int * getOpenconss()
returns array containing constraints not assigned yet
#define DEC_ENABLED
#define DEC_DESC
int getClassOfCons(int consindex)
#define SET_MULTIPLEFORSIZETRANSF
static DEC_DECL_SETPARAMDEFAULT(setParamDefaultConsclass)
GCG interface methods.
#define freeConsclass
void setConsClassifierStatistics(int detectorchainindex, ConsClassifier *classifier, std::vector< int > consclassesmaster)
registers statistics for a used consclassifier
#define DEFAULT_MAXIMUMNCLASSES
const char * getClassName(int classindex)
static DEC_DECL_PROPAGATEFROMTOOLBOX(propagateFromToolboxConsclass)
class for classifying constraints
#define DEC_PRIORITY
const char * getClassNameOfCons(int consindex)
#define DEC_ENABLEDFINISHING
std::vector< int > getNConssOfClasses()
#define finishSeeedConsclass
#define DEC_DETECTORNAME
#define AGGRESSIVE_MAXIMUMNCLASSES
SCIP_RETCODE flushBooked()
assigns all booked constraints and variables and deletes them from list of open cons and open vars ...
SCIP_RETCODE SCIPincludeDetectorConsclass(SCIP *scip)
#define exitConsclass
#define DEC_MINCALLROUND
CONS_DECOMPINFO getClassDecompInfo(int classindex)
#define DEC_FREQCALLROUND
various SCIP helper methods
class to manage partial decompositions (aka seeed), each seeed corresponds to one seeedpool which con...
Definition: class_seeed.h:71
consclass detector
SCIP_RETCODE setDetectorPropagated(DEC_DETECTOR *detector)
sets seeed to be propagated by a detector
#define DEC_USEFULRECALL
void addDetectorChainInfo(const char *decinfo)
adds a detectorchain information string to the corresponding vector (that carries information for eac...
static DEC_DECL_PROPAGATESEEED(propagateSeeedConsclass)
#define DEC_SKIP
std::vector< std::vector< int > > getAllSubsets(bool both, bool only_master, bool only_pricing)
const char * getClassDescription(int classindex)
#define FAST_MAXIMUMNCLASSES
#define DEC_DECCHAR
#define DEC_FREQCALLROUNDORIGINAL
#define DEC_ENABLEDORIGINAL
SCIP_RETCODE DECincludeDetector(SCIP *scip, const char *name, const char decchar, const char *description, int freqCallRound, int maxCallRound, int minCallRound, int freqCallRoundOriginal, int maxCallRoundOriginal, int minCallRoundOriginal, int priority, SCIP_Bool enabled, SCIP_Bool enabledOriginal, SCIP_Bool enabledFinishing, SCIP_Bool enabledPostprocessing, SCIP_Bool skip, SCIP_Bool usefulRecall, SCIP_Bool legacymode, DEC_DETECTORDATA *detectordata, DEC_DECL_DETECTSTRUCTURE((*detectStructure)), DEC_DECL_FREEDETECTOR((*freeDetector)), DEC_DECL_INITDETECTOR((*initDetector)), DEC_DECL_EXITDETECTOR((*exitDetector)), DEC_DECL_PROPAGATESEEED((*propagateSeeedDetector)), DEC_DECL_PROPAGATEFROMTOOLBOX((*propagateFromToolboxDetector)), DEC_DECL_FINISHFROMTOOLBOX((*finishFromToolboxDetector)), DEC_DECL_FINISHSEEED((*finishSeeedDetector)), DEC_DECL_POSTPROCESSSEEED((*postprocessSeeedDetector)), DEC_DECL_SETPARAMAGGRESSIVE((*setParamAggressiveDetector)), DEC_DECL_SETPARAMDEFAULT((*setParamDefaultDetector)),)
includes one detector
#define DEC_MAXCALLROUND
#define initConsclass
#define DEC_LEGACYMODE
#define DEC_DECL_EXITDETECTOR(x)
Definition: type_detector.h:80
#define DEC_MINCALLROUNDORIGINAL
static DEC_DECL_SETPARAMAGGRESSIVE(setParamAggressiveConsclass)
int getNDetectors()
returns the number of detectors the seeed is propagated by
struct gcg::subset subset
static DEC_DECL_SETPARAMFAST(setParamFastConsclass)
int getNOpenconss()
returns size of vector containing constraints not assigned yet
#define detectorPostprocessSeeedConsclass
class with functions for seeed pool where a seeed is a (potentially incomplete) description of a deco...
SCIP_RETCODE bookAsMasterCons(int consToMaster)
books a constraint to be added to the master constraints (by calling flushBooked all bookings are in ...
const char * DECdetectorGetName(DEC_DETECTOR *detector)
returns the name of the provided detector
SCIP_RESULT result
Definition: dec_dbscan.cpp:88
constraint handler for structure detection
#define detectConsclass