Scippy

GCG

Branch-and-Price & Column Generation for Everyone

clsvar_objvaluesigns.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-2021 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 
28 /**@file clsvar_objvaluesigns.cpp
29  * @ingroup CLASSIFIERS
30  * @brief classifies variables according to their objective function value signs
31  */
32 
33 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
34 
35 #include "clsvar_objvaluesigns.h"
36 #include "cons_decomp.h"
37 #include "cons_decomp.hpp"
38 #include <vector>
39 #include <stdio.h>
40 #include <sstream>
41 
42 #include "class_detprobdata.h"
43 
44 #include "class_varpartition.h"
45 #include "scip_misc.h"
46 
47 /* classifier properties */
48 #define DEC_CLASSIFIERNAME "objectivevaluesigns" /**< name of classifier */
49 #define DEC_DESC "objective function value signs" /**< short description of classification*/
50 #define DEC_PRIORITY 0
51 
52 #define DEC_ENABLED TRUE
53 
54 
55 /*
56  * Data structures
57  */
58 
59 /** classifier handler data */
60 struct DEC_ClassifierData
61 {
62 };
63 
64 
65 /*
66  * Local methods
67  */
68 
69 /* put your local methods here, and declare them static */
70 
71 
72 /*
73  * classifier callback methods
74  */
75 
76 /** destructor of classifier to free user data (called when GCG is exiting) */
77 #define classifierFree NULL
78 
79 static
80 DEC_DECL_VARCLASSIFY(classifierClassify)
81 {
82  gcg::DETPROBDATA* detprobdata;
83  if( transformed )
84  {
85  detprobdata = GCGconshdlrDecompGetDetprobdataPresolved(scip);
86  }
87  else
88  {
89  detprobdata = GCGconshdlrDecompGetDetprobdataOrig(scip);
90  }
91 
92  // CLASSIFICATION
93  gcg::VarPartition* classifier= new gcg::VarPartition(scip, "varobjvalsigns", 3, detprobdata->getNVars() ); /* new VarPartition */
94  SCIP_Real curobjval;
95 
96  /* set up class information */
97  classifier->setClassName( 0, "zero" );
98  classifier->setClassDescription( 0, "This class contains all variables with objective function value zero." );
99  classifier->setClassDecompInfo( 0, gcg::MASTER );
100  classifier->setClassName( 1, "positive" );
101  classifier->setClassDescription( 1, "This class contains all variables with positive objective function value." );
102  classifier->setClassDecompInfo( 1, gcg::ALL );
103  classifier->setClassName( 2, "negative" );
104  classifier->setClassDescription( 2, "This class contains all variables with negative objective function value." );
105  classifier->setClassDecompInfo( 2, gcg::ALL );
106 
107  /* assign vars */
108  for( int v = 0; v < detprobdata->getNVars(); ++v )
109  {
110  assert( detprobdata->getVar(v) != NULL );
111  curobjval = SCIPvarGetObj(detprobdata->getVar(v));
112 
113  if( SCIPisZero(scip, curobjval) )
114  {
115  classifier->assignVarToClass(v, 0);
116  }
117  else if ( SCIPisPositive(scip, curobjval) )
118  {
119  classifier->assignVarToClass(v, 1);
120  }
121  else
122  {
123  classifier->assignVarToClass(v, 2);
124  }
125  }
126 
127  /* remove a class if there is no variable with the respective sign */
128  classifier->removeEmptyClasses();
129 
130  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, " Varclassifier \"%s\" yields a classification with %d different variable classes\n", classifier->getName(), classifier->getNClasses()) ;
131 
132 
133  detprobdata->addVarPartition(classifier);
134  return SCIP_OKAY;
135 }
136 
137 /*
138  * classifier specific interface methods
139  */
140 
142  SCIP* scip /**< SCIP data structure */
143 )
144 {
145  DEC_CLASSIFIERDATA* classifierdata = NULL;
146 
147  SCIP_CALL( DECincludeVarClassifier(scip, DEC_CLASSIFIERNAME, DEC_DESC, DEC_PRIORITY, DEC_ENABLED, classifierdata, classifierFree, classifierClassify) );
148 
149  return SCIP_OKAY;
150 }
void setClassDescription(int classindex, const char *desc)
SCIP_RETCODE SCIPincludeVarClassifierObjValueSigns(SCIP *scip)
#define DEC_CLASSIFIERNAME
class representing a partition of a set of variables
static DEC_DECL_VARCLASSIFY(classifierClassify)
constraint handler for structure detection
DETPROBDATA * GCGconshdlrDecompGetDetprobdataOrig(SCIP *scip)
help method to access detprobdata for unpresolved problem
SCIP_RETCODE DECincludeVarClassifier(SCIP *scip, const char *name, const char *description, int priority, SCIP_Bool enabled, DEC_CLASSIFIERDATA *classifierdata, DEC_DECL_FREEVARCLASSIFIER((*freeClassifier)),)
various SCIP helper methods
int getNVars()
return the number of variables considered in the detprobdata
#define DEC_DESC
void setClassName(int classindex, const char *name)
void assignVarToClass(int varindex, int classindex)
C++ interface of cons_decomp.
void addVarPartition(VarPartition *partition)
adds a variable partition if it is no duplicate of an existing variable partition
void setClassDecompInfo(int classindex, VAR_DECOMPINFO decompInfo)
DETPROBDATA * GCGconshdlrDecompGetDetprobdataPresolved(SCIP *scip)
help method to access detprobdata for transformed problem
#define classifierFree
classifies variables according to their objective function value signs
SCIP_VAR * getVar(int varIndex)
returns SCIP variable related to a variable index
class storing partialdecs and the problem matrix
#define DEC_ENABLED
#define DEC_PRIORITY