Scippy

GCG

Branch-and-Price & Column Generation for Everyone

graphalgorithms.h
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and library */
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-2026 Operations Research, RWTH Aachen University */
10/* Zuse Institute Berlin (ZIB) */
11/* */
12/* Licensed under the Apache License, Version 2.0 (the "License"); */
13/* you may not use this file except in compliance with the License. */
14/* You may obtain a copy of the License at */
15/* */
16/* http://www.apache.org/licenses/LICENSE-2.0 */
17/* */
18/* Unless required by applicable law or agreed to in writing, software */
19/* distributed under the License is distributed on an "AS IS" BASIS, */
20/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
21/* See the License for the specific language governing permissions and */
22/* limitations under the License. */
23/* */
24/* You should have received a copy of the Apache-2.0 license */
25/* along with GCG; see the file LICENSE. If not visit gcg.or.rwth-aachen.de.*/
26/* */
27/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
28
29/**@file graphalgorithms.h
30 * @brief several metrics for graphs
31 * @author Martin Bergner
32 */
33
34/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35
36#ifndef GRAPHALGORITHMS_H_
37#define GRAPHALGORITHMS_H_
38
39#include "graph/hypergraph.h"
40#include "graph/graph.h"
41#include "graph/graph_gcg.h"
42
43namespace gcg {
44
45// A structure to represent a subset for union-find
46typedef struct subset
47{
48 int parent;
49 int rank;
51
52
53template<class T>
55
56public:
57 /** compute weighted sum of external degrees */
59 Hypergraph<T>& graph /**< the hypergraph */
60 );
61
62 /** compute minimum hyperedge cut */
64 Hypergraph<T>& graph /**< the hypergraph */
65 );
66
67 /** compute k-1 metric */
69 Hypergraph<T>& graph /**< the hypergraph */
70 );
71
72 /** run DBSCAN on the distance graph */
73 static std::vector<int> dbscan(
74 Graph<GraphGCG>& graph, /**< the graph with weighted edges */
75 double eps, /**< radius in which we search for the neighbors */
76 int minPts = 4 /**< minimum number of neighbors needed to define a core point (can be fixed to 4 as stated in the paper) */
77 );
78
79
80 /** run MST on the distance graph */
81 static std::vector<int> mst(
82 Graph<GraphGCG>& graph, /**< the graph with weighted edges */
83 double cutoff, /**< threshold below which we cut the edges */
84 int minPts = 4 /**< minimum number of points needed in a cluster */
85 );
86
87
88 /** run MCL on the similarity graph */
89 static std::vector<int> mcl(
90 Graph<GraphGCG>& graph, /**< the graph with weighted edges */
91 int& stoppedAfter, /**< number of iterations after which the clustering terminated */
92 double inflatefac, /**< inflate factor */
93 int maxiters = 25, /**< max number of iterations, set to 25 per default */
94 int expandfac = 2 /**< expand factor, should be always set to 2 */
95 );
96
97
98
99
100//private:
101
102 /** help function for DBSCAN */
103 static void expandCluster(
104 Graph<T>& graph,
105 std::vector<bool>& visited,
106 std::vector<bool>& is_core,
107 std::vector<int>& labels,
108 int point,
109 std::vector<int>& NeighborPts,
110 int curr_cluster,
111 double eps,
112 int minPts
113 );
114
115 static double cutoff;
116
117 // Returns true if the weight of the edge is bigger than the this->cutoff
118 static bool cutoffif(
119 EdgeGCG &a
120 );
121
122 // Compare two edges according to their weights.
123 // Used in sort() for sorting an array of edges
124 static int weightComp(
125 const void* a,
126 const void* b
127 );
128
129 // A utility function to find set of an element i
130 // (uses path compression technique)
131 static int mstfind(
132 std::vector<subset>& subsets,
133 int i
134 );
135
136 // A function that does union of two sets of x and y
137 // (uses union by rank)
138 static void mstunion(
139 std::vector<subset>& subsets,
140 int x,
141 int y
142 );
143
144};
145
146} /* namespace gcg */
147
148
149
150#endif /* GRAPHALGORITHMS_H_ */
static SCIP_Real computeMincut(Hypergraph< T > &graph)
static std::vector< int > mst(Graph< GraphGCG > &graph, double cutoff, int minPts=4)
static bool cutoffif(EdgeGCG &a)
static int weightComp(const void *a, const void *b)
static std::vector< int > mcl(Graph< GraphGCG > &graph, int &stoppedAfter, double inflatefac, int maxiters=25, int expandfac=2)
static SCIP_Real computekMetric(Hypergraph< T > &graph)
static SCIP_Real computeSoed(Hypergraph< T > &graph)
static void mstunion(std::vector< subset > &subsets, int x, int y)
static int mstfind(std::vector< subset > &subsets, int i)
static std::vector< int > dbscan(Graph< GraphGCG > &graph, double eps, int minPts=4)
static void expandCluster(Graph< T > &graph, std::vector< bool > &visited, std::vector< bool > &is_core, std::vector< int > &labels, int point, std::vector< int > &NeighborPts, int curr_cluster, double eps, int minPts)
#define SCIP_Real
miscellaneous graph methods for structure detection
Implementation of the graph which supports both node and edge weights.
miscellaneous hypergraph methods for structure detection
struct gcg::subset subset
real eps