dec_varclass.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_varclass.h"
37 #include "cons_decomp.h"
38 #include "class_seeed.h"
39 #include "class_seeedpool.h"
40 #include "class_varclassifier.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 "varclass"
54 #define DEC_DESC "detector varclass"
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 'v'
63 #define DEC_ENABLED TRUE
64 #define DEC_ENABLEDORIGINAL TRUE
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 8
72 #define AGGRESSIVE_MAXIMUMNCLASSES 10
73 #define FAST_MAXIMUMNCLASSES 6
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 freeVarclass 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 exitVarclass 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 initVarclass NULL
129 #endif
130 
132 //static DEC_DECL_DETECTSTRUCTURE(detectVarclass)
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 detectVarclass NULL
143 
144 #define finishSeeedVarclass NULL
145 
146 static DEC_DECL_PROPAGATESEEED(propagateSeeedVarclass)
147 {
148  *result = SCIP_DIDNOTFIND;
149  char decinfo[SCIP_MAXSTRLEN];
150 
151  SCIP_CLOCK* temporaryClock;
152 
153  if (seeedPropagationData->seeedToPropagate->getNOpenconss() != seeedPropagationData->seeedpool->getNConss() || seeedPropagationData->seeedToPropagate->getNOpenvars() != seeedPropagationData->seeedpool->getNVars() )
154  {
155  *result = SCIP_SUCCESS;
156  return SCIP_OKAY;
157  }
158 
159  SCIP_CALL_ABORT( SCIPcreateClock(scip, &temporaryClock) );
160  SCIP_CALL_ABORT( SCIPstartClock(scip, temporaryClock) );
161 
162  std::vector<gcg::Seeed*> foundseeeds(0);
163 
164  gcg::Seeed* seeedOrig;
165  gcg::Seeed* seeed;
166 
167  int maximumnclasses;
168 
169  if( seeedPropagationData->seeedpool->getNConss() + seeedPropagationData->seeedpool->getNVars() >= 50000 )
170  SCIPgetIntParam(scip, "detection/maxnclassesperclassifierforlargeprobs", &maximumnclasses);
171  else
172  SCIPgetIntParam(scip, "detection/maxnclassesperclassifier", &maximumnclasses);
173 
174  for( int classifierIndex = 0; classifierIndex < seeedPropagationData->seeedpool->getNVarClassifiers(); ++classifierIndex )
175  {
176  gcg::VarClassifier* classifier = seeedPropagationData->seeedpool->getVarClassifier( classifierIndex );
177  std::vector<int> varclassindices_master = std::vector<int>(0);
178  std::vector<int> varclassindices_linking = std::vector<int>(0);
179 
180  if ( classifier->getNClasses() > maximumnclasses )
181  {
182  std::cout << " the current varclass distribution includes " << classifier->getNClasses() << " classes but only " << maximumnclasses << " are allowed for propagateSeeed() of var class detector" << std::endl;
183  continue;
184  }
185 
186  seeedOrig = seeedPropagationData->seeedToPropagate;
187 
188  for( int i = 0; i < classifier->getNClasses(); ++ i )
189  {
190  switch( classifier->getClassDecompInfo( i ) )
191  {
192  case gcg::ALL:
193  break;
194  case gcg::LINKING:
195  varclassindices_linking.push_back( i );
196  break;
197  case gcg::MASTER:
198  varclassindices_master.push_back( i );
199  break;
200  case gcg::BLOCK:
201  break;
202  }
203  }
204 
205  std::vector< std::vector<int> > subsetsOfVarclasses = classifier->getAllSubsets( true, false, false, false );
206 
207  for( size_t subset = 0; subset < subsetsOfVarclasses.size(); ++subset )
208  {
209  if( subsetsOfVarclasses[subset].size() == 0 && varclassindices_master.size() == 0 && varclassindices_linking.size() == 0 )
210  continue;
211 
212  seeed = new gcg::Seeed(seeedOrig);
213 
215  for( int i = 0; i < seeed->getNOpenvars(); ++i )
216  {
217  bool foundVar = false;
218  for( size_t varclassId = 0; varclassId < subsetsOfVarclasses[subset].size(); ++varclassId )
219  {
220  if( classifier->getClassOfVar( seeed->getOpenvars()[i] ) == subsetsOfVarclasses[subset][varclassId] )
221  {
222  seeed->bookAsLinkingVar(seeed->getOpenvars()[i]);
223  foundVar = true;
224  break;
225  }
226  }
228  if ( !foundVar )
229  {
230  for( size_t varclassId = 0; varclassId < varclassindices_linking.size(); ++varclassId )
231  {
232  if( classifier->getClassOfVar( seeed->getOpenvars()[i] ) == varclassindices_linking[varclassId] )
233  {
234  seeed->bookAsLinkingVar(seeed->getOpenvars()[i]);
235  foundVar = true;
236  break;
237  }
238  }
239  }
241  if ( !foundVar )
242  {
243  for( size_t varclassId = 0; varclassId < varclassindices_master.size(); ++varclassId )
244  {
245  if( classifier->getClassOfVar( seeed->getOpenvars()[i] ) == varclassindices_master[varclassId] )
246  {
247  seeed->bookAsMasterVar(seeed->getOpenvars()[i]);
248  break;
249  }
250  }
251  }
252  }
253 
255  std::stringstream decdesc;
256  decdesc << "varclass" << "\\_" << classifier->getName() << ": \\\\ ";
257  std::vector<int> curlinkingclasses( varclassindices_linking );
258  for ( size_t varclassId = 0; varclassId < subsetsOfVarclasses[subset].size(); ++varclassId )
259  {
260  if ( varclassId > 0 )
261  {
262  decdesc << "-";
263  }
264  decdesc << classifier->getClassName( subsetsOfVarclasses[subset][varclassId] );
265 
266  if( std::find( varclassindices_linking.begin(), varclassindices_linking.end(),
267  subsetsOfVarclasses[subset][varclassId] ) == varclassindices_linking.end() )
268  {
269  curlinkingclasses.push_back( subsetsOfVarclasses[subset][varclassId] );
270  }
271  }
272  for ( size_t varclassId = 0; varclassId < varclassindices_linking.size(); ++varclassId )
273  {
274  if ( varclassId > 0 || subsetsOfVarclasses[subset].size() > 0)
275  {
276  decdesc << "-";
277  }
278  decdesc << classifier->getClassName( varclassindices_linking[varclassId] );
279  }
280 
281  seeed->flushBooked();
282  (void) SCIPsnprintf(decinfo, SCIP_MAXSTRLEN, decdesc.str().c_str());
283  seeed->addDetectorChainInfo(decinfo);
284  seeed->setVarClassifierStatistics( seeed->getNDetectors(), classifier, curlinkingclasses,
285  varclassindices_master );
286 
287  foundseeeds.push_back(seeed);
288  }
289  }
290 
291  SCIP_CALL_ABORT( SCIPstopClock(scip, temporaryClock ) );
292 
293  SCIP_CALL( SCIPallocMemoryArray(scip, &(seeedPropagationData->newSeeeds), foundseeeds.size() ) );
294  seeedPropagationData->nNewSeeeds = foundseeeds.size();
295 
296  for( int s = 0; s < seeedPropagationData->nNewSeeeds; ++s )
297  {
298  seeedPropagationData->newSeeeds[s] = foundseeeds[s];
299  seeedPropagationData->newSeeeds[s]->addClockTime(SCIPclockGetTime(temporaryClock ) );
300  }
301 
302  SCIP_CALL_ABORT(SCIPfreeClock(scip, &temporaryClock) );
303 
304  *result = SCIP_SUCCESS;
305 
306  return SCIP_OKAY;
307 }
308 
309 static
310 DEC_DECL_PROPAGATEFROMTOOLBOX(propagateFromToolboxVarclass)
311 {
312  *result = SCIP_DIDNOTFIND;
313  char decinfo[SCIP_MAXSTRLEN];
314  gcg::VarClassifier** classifiers;
315  int nclassifiers;
316  SCIP_Bool newclass, newclassifier;
317  gcg::VarClassifier* selectedclassifier;
318  std::vector<int> selectedclasses;
319  int i, j;
320  char stri[SCIP_MAXSTRLEN];
321  SCIP_Bool finished;
322 
323  char* command;
324  int commandlen;
325  SCIP_Bool endoffile;
326 
327  if (seeedPropagationData->seeedToPropagate->getNOpenconss() != seeedPropagationData->seeedpool->getNConss() || seeedPropagationData->seeedToPropagate->getNOpenvars() != seeedPropagationData->seeedpool->getNVars() )
328  {
329  *result = SCIP_SUCCESS;
330  return SCIP_OKAY;
331  }
332 
333  if( seeedPropagationData->seeedpool->getNVarClassifiers() == 0 )
334  {
335  SCIPinfoMessage(scip, NULL, "No VarClassifiers listed for propagation, starting classification.\n");
336  seeedPropagationData->seeedpool->calcClassifierAndNBlockCandidates(scip);
337  if( seeedPropagationData->seeedpool->getNVarClassifiers() == 0 )
338  {
339  SCIPinfoMessage(scip, NULL, "No VarClassifiers found after calculation, aborting!.\n");
340  return SCIP_ERROR;
341  }
342  }
343 
344  std::vector<gcg::Seeed*> foundseeeds(0);
345 
346  gcg::Seeed* seeedOrig;
347  gcg::Seeed* seeed;
348 
349  int maximumnclasses;
350 
351  if( seeedPropagationData->seeedpool->getNConss() + seeedPropagationData->seeedpool->getNVars() >= 50000 )
352  SCIPgetIntParam(scip, "detection/maxnclassesperclassifierforlargeprobs", &maximumnclasses);
353  else
354  SCIPgetIntParam(scip, "detection/maxnclassesperclassifier", &maximumnclasses);
355 
356  SCIP_CALL( SCIPallocMemoryArray(scip, &classifiers, seeedPropagationData->seeedpool->getNVarClassifiers()) );
357 
358  if( seeedPropagationData->seeedpool->getNVarClassifiers() == 0 )
359  {
360  SCIPinfoMessage(scip, NULL, "No varclassifiers available for propagation, aborting!\n");
361  *result = SCIP_DIDNOTFIND;
362  return SCIP_OKAY;
363  }
364 
365  SCIPinfoMessage(scip, NULL, "\n%d varclassifiers available for propagation.\n", seeedPropagationData->seeedpool->getNVarClassifiers() );
366 
367  nclassifiers = 0;
368  for( int classifierIndex = 0; classifierIndex < seeedPropagationData->seeedpool->getNVarClassifiers(); ++classifierIndex )
369  {
370  gcg::VarClassifier* classifier = seeedPropagationData->seeedpool->getVarClassifier( classifierIndex );
371  if( classifier->getNClasses() > maximumnclasses )
372  {
373  std::cout << " the current varclass distribution includes " << classifier->getNClasses() << " classes but only " << maximumnclasses << " are allowed for propagateSeeed() of cons class detector" << std::endl;
374  continue;
375  }
376  newclassifier = TRUE;
377  for( i = 0; i < nclassifiers; ++i )
378  {
379  if( classifiers[i] == classifier )
380  {
381  newclassifier = FALSE;
382  }
383  }
384 
385  if( newclassifier )
386  {
387  classifiers[nclassifiers] = classifier;
388  ++nclassifiers;
389  }
390  }
391 
392  selectedclassifier = classifiers[0]; //default case to omit warnings
393  /* user selects a consclassifier */
394  finished = FALSE;
395  while( !finished )
396  {
397  SCIPinfoMessage(scip, NULL, "Available consclassifiers:\n");
398  for( i = 0; i < nclassifiers; ++i )
399  {
400  SCIPinfoMessage(scip, NULL, "%d) ", i+1); //+1 as we want the list to start with 1)
401  SCIPinfoMessage(scip, NULL, "%s\n", classifiers[i]->getName() );
402  }
403 
404  commandlen = 0;
405  while( commandlen == 0 )
406  {
407  SCIP_CALL( SCIPdialoghdlrGetWord(dialoghdlr, dialog, "Type in the name or number of the varclassifier that you want to use (seperated by spaces) or \"done\", (use \"quit\" to exit detector): \nGCG/toolbox> ", &command, &endoffile) );
408  commandlen = strlen(command);
409  }
410 
411  if( !strncmp( command, "done", commandlen) == 0 && !strncmp( command, "quit", commandlen) == 0 )
412  {
413  for( i = 0; i < nclassifiers; ++i )
414  {
415  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)
416  if( strncmp( command, classifiers[i]->getName(), commandlen) == 0 || strncmp( command, stri, commandlen ) == 0 )
417  {
418  selectedclassifier = classifiers[i];
419  finished = TRUE;
420  continue;
421  }
422  }
423  }
424  else if( strncmp( command, "done", commandlen) == 0 )
425  {
426  finished = TRUE;
427  continue;
428  }
429  else if( strncmp( command, "quit", commandlen) == 0 )
430  {
431  SCIPfreeMemoryArray(scip, &classifiers);
432  *result = SCIP_DIDNOTFIND;
433  return SCIP_OKAY;
434  }
435  }
436 
437  std::vector<int> varclassindices = std::vector<int>(0);
438  for( i = 0; i < selectedclassifier->getNClasses(); ++i )
439  {
440  varclassindices.push_back(i);
441  }
442 
443  SCIPinfoMessage(scip, NULL, "You will now be asked to enter a selection of classes iteratively. If you have finished your selection, enter \"done\".\n");
444  finished = FALSE;
445  while( !finished )
446  {
447  std::vector<int> nVarsOfClasses = selectedclassifier->getNVarsOfClasses();
448  SCIPinfoMessage(scip, NULL, "The following classes are available for the selected varclassifier \"%s\":\n",selectedclassifier->getName());
449  for( i = 0; i < static_cast<int>(varclassindices.size()); ++i )
450  {
451  SCIPinfoMessage(scip, NULL, "%d) ", i+1); //+1 as we want the list to start with 1)
452  SCIPinfoMessage(scip, NULL, "%s || NConss: %d || %s\n", selectedclassifier->getClassName(varclassindices[i]), nVarsOfClasses[i], selectedclassifier->getClassDescription(varclassindices[i]));
453  }
454 
455  commandlen = 0;
456  while( commandlen == 0 )
457  {
458  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) );
459  commandlen = strlen(command);
460  }
461 
462  if( !strncmp( command, "done", commandlen) == 0 && !strncmp( command, "quit", commandlen) == 0 )
463  {
464  for( i = 0; i < static_cast<int>(varclassindices.size()); ++i )
465  {
466  newclass = TRUE;
467  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)
468  if( strncmp( command, selectedclassifier->getClassNameOfVar(varclassindices[i]), commandlen) == 0 || strncmp( command, stri, commandlen ) == 0 )
469  {
470  /* check that we do not select the same classifier multiple times*/
471  for( j = 0; j < static_cast<int>(selectedclasses.size()); ++j )
472  {
473  if( selectedclasses[j] == varclassindices[i] )
474  {
475  newclass = FALSE;
476  }
477  }
478  if( newclass )
479  {
480  selectedclasses.push_back(varclassindices[i]);
481 
482  SCIPinfoMessage(scip, NULL, "\nCurrently selected classifiers: ");
483  for( j = 0; j < static_cast<int>(selectedclasses.size()); ++j )
484  {
485  SCIPinfoMessage(scip, NULL, "\"%s\" ", selectedclassifier->getClassNameOfVar(selectedclasses[j]));
486  }
487  SCIPinfoMessage(scip, NULL, "\n\n");
488 
489  if( selectedclasses.size() >= varclassindices.size() )
490  {
491  finished = TRUE;
492  break;
493  }
494  }
495  else
496  {
497  SCIPinfoMessage(scip, NULL, "\n+++Class \"%s\" is already selected!+++\n\n", selectedclassifier->getClassNameOfVar(varclassindices[i]));
498  }
499  }
500  }
501  }
502  else if( strncmp( command, "done", commandlen) == 0 )
503  {
504  finished = TRUE;
505  continue;
506  }
507  else if( strncmp( command, "quit", commandlen) == 0 )
508  {
509  SCIPfreeMemoryArray(scip, &classifiers);
510  *result = SCIP_DIDNOTFIND;
511  return SCIP_OKAY;
512  }
513  }
514 
515  std::vector<int> varclassindices_master = std::vector<int>(0);
516  std::vector<int> varclassindices_linking = std::vector<int>(0);
517 
518  seeedOrig = seeedPropagationData->seeedToPropagate;
519 
520  for( i = 0; i < selectedclassifier->getNClasses(); ++ i )
521  {
522  switch( selectedclassifier->getClassDecompInfo( i ) )
523  {
524  case gcg::ALL:
525  break;
526  case gcg::LINKING:
527  varclassindices_linking.push_back( i );
528  break;
529  case gcg::MASTER:
530  varclassindices_master.push_back( i );
531  break;
532  case gcg::BLOCK:
533  break;
534  }
535  }
536 
537  if( selectedclasses.size() == 0 && varclassindices_master.size() == 0 && varclassindices_linking.size() == 0 )
538  {
539  *result = SCIP_DIDNOTFIND;
540  SCIPfreeMemoryArray(scip, &classifiers);
541  return SCIP_OKAY;
542  }
543 
544  seeed = new gcg::Seeed(seeedOrig);
545 
547  for( i = 0; i < seeed->getNOpenvars(); ++i )
548  {
549  bool foundVar = false;
550  for( size_t varclassId = 0; varclassId < selectedclasses.size(); ++varclassId )
551  {
552  if( selectedclassifier->getClassOfVar( seeed->getOpenvars()[i] ) == selectedclasses[varclassId] )
553  {
554  seeed->bookAsLinkingVar(seeed->getOpenvars()[i]);
555  foundVar = true;
556  break;
557  }
558  }
560  if ( !foundVar )
561  {
562  for( size_t varclassId = 0; varclassId < varclassindices_linking.size(); ++varclassId )
563  {
564  if( selectedclassifier->getClassOfVar( seeed->getOpenvars()[i] ) == varclassindices_linking[varclassId] )
565  {
566  seeed->bookAsLinkingVar(seeed->getOpenvars()[i]);
567  foundVar = true;
568  break;
569  }
570  }
571  }
573  if ( !foundVar )
574  {
575  for( size_t varclassId = 0; varclassId < varclassindices_master.size(); ++varclassId )
576  {
577  if( selectedclassifier->getClassOfVar( seeed->getOpenvars()[i] ) == varclassindices_master[varclassId] )
578  {
579  seeed->bookAsMasterVar(seeed->getOpenvars()[i]);
580  break;
581  }
582  }
583  }
584  }
585 
587  std::stringstream decdesc;
588  decdesc << "varclass" << "\\_" << selectedclassifier->getName() << ": \\\\ ";
589  std::vector<int> curlinkingclasses( varclassindices_linking );
590  for ( size_t varclassId = 0; varclassId < selectedclasses.size(); ++varclassId )
591  {
592  if ( varclassId > 0 )
593  {
594  decdesc << "-";
595  }
596  decdesc << selectedclassifier->getClassName( selectedclasses[varclassId] );
597 
598  if( std::find( varclassindices_linking.begin(), varclassindices_linking.end(),
599  selectedclasses[varclassId] ) == varclassindices_linking.end() )
600  {
601  curlinkingclasses.push_back( selectedclasses[varclassId] );
602  }
603  }
604  for ( size_t varclassId = 0; varclassId < varclassindices_linking.size(); ++varclassId )
605  {
606  if ( varclassId > 0 || selectedclasses.size() > 0)
607  {
608  decdesc << "-";
609  }
610  decdesc << selectedclassifier->getClassName( varclassindices_linking[varclassId] );
611  }
612 
613  seeed->flushBooked();
614  (void) SCIPsnprintf(decinfo, SCIP_MAXSTRLEN, decdesc.str().c_str());
615  seeed->addDetectorChainInfo(decinfo);
616  seeed->setDetectorPropagated(detector);
617  seeed->setVarClassifierStatistics( seeed->getNDetectors(), selectedclassifier, curlinkingclasses,
618  varclassindices_master );
619 
620  foundseeeds.push_back(seeed);
621 
622 
623 
624  //@TODO: This alloc is already done in cons_decomp:SCIPconshdlrDecompToolboxActOnSeeed(..).
625  //This is contrary to the behaviour of other detectors such as hrcg, hrg and hr but not connectedbase
626  SCIP_CALL( SCIPallocMemoryArray(scip, &(seeedPropagationData->newSeeeds), foundseeeds.size() ) );
627  seeedPropagationData->nNewSeeeds = foundseeeds.size();
628 
629  for( int s = 0; s < seeedPropagationData->nNewSeeeds; ++s )
630  {
631  seeedPropagationData->newSeeeds[s] = foundseeeds[s];
632  }
633 
634  *result = SCIP_SUCCESS;
635  SCIPfreeMemoryArray(scip, &classifiers);
636  return SCIP_OKAY;
637 }
638 
639 #define finishFromToolboxVarclass NULL
640 
641 #define detectorPostprocessSeeedVarclass NULL
642 
643 static
644 DEC_DECL_SETPARAMAGGRESSIVE(setParamAggressiveVarclass)
645 {
646  char setstr[SCIP_MAXSTRLEN];
647  SCIP_Real modifier;
648 
649  int newval;
650  const char* name = DECdetectorGetName(detector);
651 
652  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
653  SCIP_CALL( SCIPsetBoolParam(scip, setstr, TRUE) );
654 
655  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/origenabled", name);
656  SCIP_CALL( SCIPsetBoolParam(scip, setstr, TRUE) );
657 
658  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
659  SCIP_CALL( SCIPsetBoolParam(scip, setstr, FALSE ) );
660 
661  if( SCIPgetStage(scip) < SCIP_STAGE_PROBLEM )
662  return SCIP_OKAY;
663 
664  modifier = ((SCIP_Real)SCIPgetNConss(scip) + (SCIP_Real)SCIPgetNVars(scip) ) / SET_MULTIPLEFORSIZETRANSF;
665  modifier = log(modifier) / log(2.);
666 
667  if (!SCIPisFeasPositive(scip, modifier) )
668  modifier = -1.;
669 
670  modifier = SCIPfloor(scip, modifier);
671 
672  newval = MAX( 2, AGGRESSIVE_MAXIMUMNCLASSES - modifier );
673  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxnclasses", name);
674 
675  SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
676  SCIPinfoMessage(scip, NULL, "\n%s = %d\n", setstr, newval);
677 
678 
679  return SCIP_OKAY;
680 
681 }
682 
683 
684 static
685 DEC_DECL_SETPARAMDEFAULT(setParamDefaultVarclass)
686 {
687  char setstr[SCIP_MAXSTRLEN];
688  SCIP_Real modifier;
689 
690  int newval;
691  const char* name = DECdetectorGetName(detector);
692 
693  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
694  SCIP_CALL( SCIPsetBoolParam(scip, setstr, DEC_ENABLED) );
695 
696  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/origenabled", name);
697  SCIP_CALL( SCIPsetBoolParam(scip, setstr, DEC_ENABLEDORIGINAL ) );
698 
699  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
700  SCIP_CALL( SCIPsetBoolParam(scip, setstr, DEC_ENABLEDFINISHING ) );
701 
702  if( SCIPgetStage(scip) < SCIP_STAGE_PROBLEM )
703  return SCIP_OKAY;
704 
705  modifier = ( (SCIP_Real)SCIPgetNConss(scip) + (SCIP_Real)SCIPgetNVars(scip) ) / SET_MULTIPLEFORSIZETRANSF;
706  modifier = log(modifier) / log(2);
707 
708  if (!SCIPisFeasPositive(scip, modifier) )
709  modifier = -1.;
710 
711  modifier = SCIPfloor(scip, modifier);
712 
713  newval = MAX( 2, DEFAULT_MAXIMUMNCLASSES - modifier );
714  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxnclasses", name);
715 
716  SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
717  SCIPinfoMessage(scip, NULL, "\n%s = %d\n", setstr, newval);
718 
719  return SCIP_OKAY;
720 
721 }
722 
723 static
724 DEC_DECL_SETPARAMFAST(setParamFastVarclass)
725 {
726  char setstr[SCIP_MAXSTRLEN];
727  SCIP_Real modifier;
728  int newval;
729 
730  const char* name = DECdetectorGetName(detector);
731 
732  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/enabled", name);
733  SCIP_CALL( SCIPsetBoolParam(scip, setstr, FALSE) );
734 
735  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/origenabled", name);
736  SCIP_CALL( SCIPsetBoolParam(scip, setstr, FALSE) );
737 
738  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/finishingenabled", name);
739  SCIP_CALL( SCIPsetBoolParam(scip, setstr, FALSE ) );
740 
741  if( SCIPgetStage(scip) < SCIP_STAGE_PROBLEM )
742  return SCIP_OKAY;
743 
744  modifier = ( (SCIP_Real)SCIPgetNConss(scip) + (SCIP_Real)SCIPgetNVars(scip) ) / SET_MULTIPLEFORSIZETRANSF;
745 
746  modifier = log(modifier) / log(2);
747 
748  if (!SCIPisFeasPositive(scip, modifier) )
749  modifier = -1.;
750 
751  modifier = SCIPfloor(scip, modifier);
752 
753  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxnclasses", name);
754 
755  newval = MAX( 2, FAST_MAXIMUMNCLASSES - modifier );
756 
757  SCIP_CALL( SCIPsetIntParam(scip, setstr, newval ) );
758  SCIPinfoMessage(scip, NULL, "\n%s = %d\n", setstr, newval);
759 
760  return SCIP_OKAY;
761 
762 }
763 
764 
765 
766 /*
767  * detector specific interface methods
768  */
769 
772 )
773 {
774  DEC_DETECTORDATA* detectordata;
775  char setstr[SCIP_MAXSTRLEN];
776 
778  detectordata = NULL;
779 
780  SCIP_CALL(
783  freeVarclass, initVarclass, exitVarclass, propagateSeeedVarclass, propagateFromToolboxVarclass, finishFromToolboxVarclass, finishSeeedVarclass, detectorPostprocessSeeedVarclass, setParamAggressiveVarclass, setParamDefaultVarclass, setParamFastVarclass));
784 
787  const char* name = DEC_DETECTORNAME;
788  (void) SCIPsnprintf(setstr, SCIP_MAXSTRLEN, "detection/detectors/%s/maxnclasses", name);
789  SCIP_CALL( SCIPaddIntParam(scip, setstr, "maximum number of classes ", NULL, FALSE, DEFAULT_MAXIMUMNCLASSES, 1, INT_MAX, NULL, NULL ) );
790 
791  return SCIP_OKAY;
792 }
static DEC_DECL_PROPAGATEFROMTOOLBOX(propagateFromToolboxVarclass)
std::vector< int > getNVarsOfClasses()
const char * getClassNameOfVar(int varindex)
#define DEC_DECL_INITDETECTOR(x)
Definition: type_detector.h:70
#define AGGRESSIVE_MAXIMUMNCLASSES
#define DEC_DESC
varclass detector
GCG interface methods.
#define DEC_MAXCALLROUNDORIGINAL
const char * getClassName(int classindex)
#define DEC_ENABLEDPOSTPROCESSING
#define DEC_ENABLEDORIGINAL
#define DEC_DECCHAR
#define DEC_PRIORITY
int getNOpenvars()
returns size of vector containing variables not assigned yet
static DEC_DECL_SETPARAMFAST(setParamFastVarclass)
#define DEC_MINCALLROUNDORIGINAL
#define DEC_FREQCALLROUNDORIGINAL
SCIP_RETCODE flushBooked()
assigns all booked constraints and variables and deletes them from list of open cons and open vars ...
int getClassOfVar(int varindex)
std::vector< std::vector< int > > getAllSubsets(bool all, bool linking, bool master, bool block)
#define DEC_USEFULRECALL
#define exitVarclass
various SCIP helper methods
class to manage partial decompositions (aka seeed), each seeed corresponds to one seeedpool which con...
Definition: class_seeed.h:71
#define DEC_FREQCALLROUND
#define DEC_LEGACYMODE
#define FAST_MAXIMUMNCLASSES
SCIP_RETCODE setDetectorPropagated(DEC_DETECTOR *detector)
sets seeed to be propagated by a detector
void addDetectorChainInfo(const char *decinfo)
adds a detectorchain information string to the corresponding vector (that carries information for eac...
VAR_DECOMPINFO getClassDecompInfo(int classindex)
#define detectorPostprocessSeeedVarclass
const char * getClassDescription(int classindex)
#define initVarclass
static DEC_DECL_SETPARAMDEFAULT(setParamDefaultVarclass)
#define DEFAULT_MAXIMUMNCLASSES
#define SET_MULTIPLEFORSIZETRANSF
#define DEC_ENABLED
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
SCIP_RETCODE SCIPincludeDetectorVarclass(SCIP *scip)
#define DEC_ENABLEDFINISHING
class for classifying variables
#define initConsclass
#define DEC_MAXCALLROUND
const int * getOpenvars()
returns array containing variables not assigned yet
#define DEC_SKIP
#define DEC_DECL_EXITDETECTOR(x)
Definition: type_detector.h:80
int getNDetectors()
returns the number of detectors the seeed is propagated by
#define finishFromToolboxVarclass
struct gcg::subset subset
class with functions for seeed pool where a seeed is a (potentially incomplete) description of a deco...
const char * DECdetectorGetName(DEC_DETECTOR *detector)
returns the name of the provided detector
#define detectVarclass
SCIP_RESULT result
Definition: dec_dbscan.cpp:88
#define DEC_MINCALLROUND
void setVarClassifierStatistics(int detectorchainindex, VarClassifier *classifier, std::vector< int > varclasseslinking, std::vector< int > varclassesmaster)
registers statistics for a used varclassifier
constraint handler for structure detection
static DEC_DECL_SETPARAMAGGRESSIVE(setParamAggressiveVarclass)
#define DEC_DETECTORNAME
#define finishSeeedVarclass
SCIP_RETCODE bookAsLinkingVar(int varToLinking)
books a variable to be added to the linking variables (by calling flushBooked all bookings are in fac...
#define freeVarclass
SCIP_RETCODE bookAsMasterVar(int varToMaster)
books a variable to be added to the master variables (by calling flushBooked all bookings are in fact...
static DEC_DECL_PROPAGATESEEED(propagateSeeedVarclass)