Scippy

GCG

Branch-and-Price & Column Generation for Everyone

class_indexpartition.h
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 class_indexpartition.h
29  * @brief generalization of ConsPartition and VarPartition
30  * @author Julius Hense
31  *
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 #ifndef GCG_CLASS_INDEXPARTITION_H__
37 #define GCG_CLASS_INDEXPARTITION_H__
38 
39 #include "objscip/objscip.h"
40 #include <vector>
41 #include <string>
42 
43 namespace gcg
44 {
45 
47 {
48 
49 protected:
50  SCIP* scip; /**< scip data structure */
51 
52 private:
53  std::string name; /**< name of the partition */
54  int nClasses; /**< number of classes the partition provides */
55  int nIndices; /**< number of indices */
56  std::vector<int> indicesToClasses; /**< index i is assigned to class indicesToClasses[i] (-1 if not assigned)*/
57  std::vector<std::string> classNames; /**< name of class k is classNames[k] */
58  std::vector<std::string> classDescriptions; /**< information text describing class k is classDescriptions[k] */
59  std::vector<int> classDecompInfo; /**< decomposition information of class k is classDecompInfo[k] */
60 
61 
62 protected:
63 
64  /** constructor */
66  SCIP* scip, /**< scip data structure */
67  const char* name, /**< name of partition (will be copied) */
68  int nClasses, /**< initial number of classes */
69  int nIndices /**< number of indices to be classified */
70  );
71 
72  /** copy constructor */
74  const IndexPartition* toCopy /**< IndexPartition to be copied */
75  );
76 
77 
78  /** destructor */
79  virtual ~IndexPartition();
80 
81  /** creates a new class, returns index of the class */
82  int addClass(
83  const char* name, /**< name of the class (will be copied) */
84  const char* desc /**< description of the class (will be copied) */
85  );
86 
87  /** assigns an index to a class */
88  void assignIndexToClass(
89  int index, /**< index to be assigned */
90  int classindex /**< index of the class */
91  );
92 
93  /** returns a vector containing all possible subsets of the given classindices */
94  std::vector<std::vector<int>> getAllSubsets(
95  std::vector<int>& classindices /**< classindices to be considered */
96  );
97 
98  /** returns the decomposition info of the a class */
100  int classindex /**< index of the class */
101  );
102 
103  /** returns the name of the class an index is assigned to */
104  const char* getClassNameOfIndex(
105  int index
106  );
107 
108  /** returns the index of the class an index is assigned to */
109  int getClassOfIndex(
110  int index
111  );
112 
113  /** returns vector containing the assigned class of each index */
114  std::vector<int>& getIndicesToClasses(
115  );
116 
117  /** returns the number of indices */
118  int getNIndices(
119  );
120 
121  /** returns a vector with the numbers of indices that are assigned to the classes */
122  std::vector<int> getNIndicesOfClasses(
123  );
124 
125  /** returns whether an index is already assigned to a class */
126  bool isIndexClassified(
127  int index
128  );
129 
130  /** sets the decomposition info of the a class */
131  void setClassDecompInfo(
132  int classindex, /**< index of the class */
133  int decompInfo /**< decomposition info */
134  );
135 
136 
137 public:
138 
139  /** returns true if the other partition has an equivalent index structure,
140  * meaning that the partition of the set of constraints is the same ignoring the concrete classindices, classnames, etc. */
141  bool isDuplicateOf(
142  IndexPartition* otherPartition /**< other partition to be checked */
143  );
144 
145  /** returns the information text of a class */
146  const char* getClassDescription(
147  int classindex /**< index of class */
148  );
149 
150  /** returns the name of a class */
151  const char* getClassName(
152  int classindex /**< index of class */
153  );
154 
155  /** returns the name of the partition */
156  const char* getName(
157  );
158 
159 
160  /** returns the number of classes the partition provides */
161  int getNClasses(
162  );
163 
164  /** returns a class index mapping for creating a new partition
165  * the enlarged class is always the class with index 0
166  * returns empty vector if the current number of classes is lower than an upper bound
167  * or greater than 2*(upper bound) */
168  std::vector<int> reduceClasses(
169  int maxNumberOfClasses /**< upper bound */
170  );
171 
172  /** removes all classes which do not have any assigned index (classindices may change)
173  * returns number of removed classes */
174  int removeEmptyClasses(
175  );
176 
177  /** sets the information text of a class */
178  void setClassDescription(
179  int classindex, /**< index of class */
180  const char* desc /**< description of class (will be copied) */
181  );
182 
183  /** sets the name of a class */
184  void setClassName(
185  int classindex, /**< index of class */
186  const char* name /**< name of class (will be copied) */
187  );
188 
189 };
190 
191 
192 } /* namespace gcg */
193 #endif /* SRC_CLASS_INDEXPARTITION_H_ */
void setClassDescription(int classindex, const char *desc)
int addClass(const char *name, const char *desc)
std::vector< int > & getIndicesToClasses()
void setClassDecompInfo(int classindex, int decompInfo)
const char * getClassName(int classindex)
std::vector< std::vector< int > > getAllSubsets(std::vector< int > &classindices)
void setClassName(int classindex, const char *name)
IndexPartition(SCIP *scip, const char *name, int nClasses, int nIndices)
bool isIndexClassified(int index)
std::vector< int > getNIndicesOfClasses()
const char * getClassNameOfIndex(int index)
std::vector< int > reduceClasses(int maxNumberOfClasses)
bool isDuplicateOf(IndexPartition *otherPartition)
void assignIndexToClass(int index, int classindex)
int getClassDecompInfo(int classindex)
const char * getClassDescription(int classindex)