Scippy

GCG

Branch-and-Price & Column Generation for Everyone

rowgraph_weighted.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 rowgraph_weighted.h
29  * @brief A row graph where each row is a node and rows are adjacent if they share a variable.
30  * The edges are weighted according to specified similarity measure.
31  * @author Igor Pesic
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 #ifndef GCG_ROWGRAPH_WEIGHTED_H_
37 #define GCG_ROWGRAPH_WEIGHTED_H_
38 
39 #include "graph.h"
40 #include "rowgraph.h"
41 
42 namespace gcg {
43 
45 {
46  JOHNSON = 1,
48  JACCARD = 5,
49  COSINE = 6,
50  SIMPSON = 9,
51 };
53 
55 {
56  SIM = 0,
57  DIST = 1
58 };
59 typedef enum WeightType WEIGHT_TYPE;
60 
61 
62 template <class T>
64 {
65 private:
66  int n_blocks;
67  int non_cl;
68 
69  /** removes the colliding rows from the clusters (should be used just after clustering)
70  * Method: Assign labels to columns and remove conss where column label doesn't match the conss label.
71  */
72  virtual SCIP_RETCODE postProcess(std::vector<int>& labels, bool enabled);
73 
74  virtual SCIP_RETCODE postProcessForPartialGraph(gcg::DETPROBDATA* detprobdata, gcg::PARTIALDECOMP* partialdec, std::vector<int>& labels, bool enabled);
75 
76  /** removes the colliding rows from the clusters (should be used just after clustering)
77  * Method: solve the stable set problem with greedy heuristic
78  * NOTE: this function is obsolete because the new version of postProcess has the same results, and is faster
79  */
80  virtual SCIP_RETCODE postProcessStableSet(std::vector<int>& labels, bool enabled);
81 
82  virtual SCIP_RETCODE postProcessStableSetForPartialGraph(gcg::DETPROBDATA* detprobdata, gcg::PARTIALDECOMP* partialdec, std::vector<int>& labels, bool enabled);
83 
84 public:
86  SCIP* scip, /**< SCIP data structure */
87  Weights w /**< weights for the given graph */
88  );
89  virtual ~RowGraphWeighted();
90 
91  // we need this to avoid the warning of hidding the parent function
93 
94  virtual SCIP_RETCODE createFromMatrix(
95  SCIP_CONS** conss, /**< constraints for which graph should be created */
96  SCIP_VAR** vars, /**< variables for which graph should be created */
97  int nconss_, /**< number of constraints */
98  int nvars_, /**< number of variables */
99  DISTANCE_MEASURE dist, /**< Here we define the distance measure between two rows */
100  WEIGHT_TYPE w_type /**< Depending on the algorithm we can build distance or similarity graph */
101  );
102 
103  // we need this to avoid the warning of hidding the parent function
105 
106  /** creates a graph with open constraints and open variables of the partialdec */
107  virtual SCIP_RETCODE createFromPartialMatrix(
108  DETPROBDATA* detprobdata, /**< detection process information and data */
109  PARTIALDECOMP* partialdec, /**< partial decomposition to use for matrix */
110  DISTANCE_MEASURE dist, /**< Here we define the distance measure between two rows */
111  WEIGHT_TYPE w_type /**< Depending on the algorithm we can build distance or similarity graph */
112  );
113 
114  static double calculateSimilarity(
115  int a, /**< number of common variables in two rows */
116  int b, /**< number of variables that appear only in the 2nd row */
117  int c, /**< number of variables that appear only in the 1st row */
118  DISTANCE_MEASURE dist, /**< Here we define the distance measure between two rows */
119  WEIGHT_TYPE w_type, /**< Depending on the algorithm we can build distance or similarity graph */
120  bool itself /**< true if we calculate similarity between the row itself */
121  );
122 
123  /** return a partition of the nodes with the help of DBSCAN */
124  virtual SCIP_RETCODE computePartitionDBSCAN(double eps, bool postprocenable);
125 
126  /** return a partition of the nodes with the help of DBSCAN */
127  virtual SCIP_RETCODE computePartitionDBSCANForPartialGraph(gcg::DETPROBDATA* detprobdata, gcg::PARTIALDECOMP* partialdec, double eps, bool postprocenable);
128 
129  /** return a partition of the nodes with the help of MST */
130  virtual SCIP_RETCODE computePartitionMST(double eps, bool postprocenable);
131 
132  /** return a partition of the nodes with the help of MST */
133  virtual SCIP_RETCODE computePartitionMSTForPartialGraph(gcg::DETPROBDATA* detprobdata, gcg::PARTIALDECOMP* partialdec, double eps, bool postprocenable);
134 
135  /** return a partition of the nodes with the help of MST */
136  virtual SCIP_RETCODE computePartitionMCL(int& stoppedAfter, double inflatefactor, bool postprocenable);
137 
138  /** return a partition of the nodes with the help of MST */
139  virtual SCIP_RETCODE computePartitionMCLForPartialGraph(gcg::DETPROBDATA* detprobdata, gcg::PARTIALDECOMP* partialdec, int& stoppedAfter, double inflatefactor, bool postprocenable);
140 
141  /** return the number of clusters after post-processing */
142  virtual SCIP_RETCODE getNBlocks(int& _n_blocks);
143 
144  virtual SCIP_RETCODE nonClustered(int& _non_cl);
145 
146  virtual double getEdgeWeightPercentile(double q);
147 
148 
149 };
150 
151 } /* namespace gcg */
152 #endif /* GCG_ROWGRAPH_WEIGHTED_H_ */
virtual SCIP_RETCODE createFromMatrix(SCIP_CONS **conss, SCIP_VAR **vars, int nconss_, int nvars_, DISTANCE_MEASURE dist, WEIGHT_TYPE w_type)
A row graph where each row is a node and rows are adjacent if they share a variable.
virtual SCIP_RETCODE getNBlocks(int &_n_blocks)
virtual SCIP_RETCODE nonClustered(int &_non_cl)
RowGraphWeighted(SCIP *scip, Weights w)
virtual SCIP_RETCODE computePartitionDBSCANForPartialGraph(gcg::DETPROBDATA *detprobdata, gcg::PARTIALDECOMP *partialdec, double eps, bool postprocenable)
virtual SCIP_RETCODE computePartitionMCL(int &stoppedAfter, double inflatefactor, bool postprocenable)
enum DistanceMeasure DISTANCE_MEASURE
@ INTERSECTION
virtual SCIP_RETCODE computePartitionMCLForPartialGraph(gcg::DETPROBDATA *detprobdata, gcg::PARTIALDECOMP *partialdec, int &stoppedAfter, double inflatefactor, bool postprocenable)
virtual SCIP_RETCODE computePartitionMSTForPartialGraph(gcg::DETPROBDATA *detprobdata, gcg::PARTIALDECOMP *partialdec, double eps, bool postprocenable)
virtual SCIP_RETCODE createFromPartialMatrix(DETPROBDATA *detprobdata, PARTIALDECOMP *partialdec, DISTANCE_MEASURE dist, WEIGHT_TYPE w_type)
enum WeightType WEIGHT_TYPE
virtual SCIP_RETCODE computePartitionMST(double eps, bool postprocenable)
class to manage partial decompositions
miscellaneous graph methods for structure detection
virtual double getEdgeWeightPercentile(double q)
virtual SCIP_RETCODE computePartitionDBSCAN(double eps, bool postprocenable)
static double calculateSimilarity(int a, int b, int c, DISTANCE_MEASURE dist, WEIGHT_TYPE w_type, bool itself)