Scippy

GCG

Branch-and-Price & Column Generation for Everyone

graph_gcg.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 graph_gcg.h
30 * @brief Implementation of the graph which supports both node and edge weights.
31 * @author Igor Pesic
32 */
33
34/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35
36#ifndef GCG_GRAPH_GCG_H_
37#define GCG_GRAPH_GCG_H_
38
39#include <map>
40#include "graph/bridge.h"
41
42#ifdef WITH_GSL
43 #include <gsl/gsl_spmatrix.h>
44 #include <gsl/gsl_spblas.h>
45#endif
46
47namespace gcg {
48
50{
51public:
52 int src, dest;
53 double weight;
54 EdgeGCG(): src(-1), dest(-1), weight(0.0) {}
55 EdgeGCG(int s, int d, double w): src(s), dest(d), weight(w) {}
56} ;
57
58class GraphGCG: public gcg::Bridge
59{
60private:
61 bool undirected;
62 bool locked; // true if we are not allowed to change the graph anymore
63 bool initialized; // true if at least 1 node
64 std::vector<int> nodes;
65#ifdef WITH_GSL
66 gsl_spmatrix* adj_matrix_sparse;
67 gsl_spmatrix* working_adj_matrix; // this one is used ONLY during MCL algorithm!
68#else
69 std::vector<std::vector<double>> adj_matrix; /** For undirected graphs, this matrix is symmetrical */
70#endif
71 std::vector<EdgeGCG*> edges;
72
73public:
74
75 GraphGCG();
76 GraphGCG(int _n_nodes, bool _undirected);
77
78 virtual ~GraphGCG();
79 virtual SCIP_RETCODE addNNodes(int _n_nodes);
80 virtual SCIP_RETCODE addNNodes(int _n_nodes, std::vector<int> weights);
81 virtual int getNNodes();
82 virtual int getNEdges();
83
84#ifdef WITH_GSL
85 virtual gsl_spmatrix* getAdjMatrix();
86 virtual void expand(int factor);
87 virtual void inflate(double factor);
88 virtual void colL1Norm();
89 virtual void prune();
90 virtual bool stopMCL(int iter);
91 virtual std::vector<int> getClustersMCL();
92 virtual void initMCL();
93 virtual void clearMCL();
94#else
95 virtual std::vector<std::vector<double>> getAdjMatrix();
96#endif
97 virtual SCIP_RETCODE getEdges(std::vector<void*>& edges);
98 virtual SCIP_Bool isEdge(int node_i, int node_j);
99 virtual int getNNeighbors(int node);
100 virtual std::vector<int> getNeighbors(int node);
101 virtual std::vector<std::pair<int, double> > getNeighborWeights(int node);
102 virtual SCIP_RETCODE addNode(int node, int weight);
103 virtual SCIP_RETCODE addNode(); /** Sets node weight to 0 and the ID to the next available. */
104 virtual SCIP_RETCODE deleteNode(int node);
105 virtual SCIP_RETCODE addEdge(int i, int j); /** Sets edge weight to 1. */
106 virtual SCIP_RETCODE addEdge(int node_i, int node_j, double weight);
107 virtual SCIP_RETCODE setEdge(int node_i, int node_j, double weight);
108 virtual SCIP_RETCODE deleteEdge(int node_i, int node_j);
109 virtual int graphGetWeights(int node);
110 virtual double getEdgeWeight(int node_i, int node_j);
111
112 virtual int edgeComp(const EdgeGCG* a, const EdgeGCG* b);
113
114 virtual SCIP_RETCODE flush(); // lock the graph and compresses the adj matrix if we use GSL
115 virtual SCIP_RETCODE normalize();
116 virtual double getEdgeWeightPercentile(double q);
117};
118
119} /* namespace gcg */
120#endif /* GCG_GRAPH_GCG_H_ */
bridge
SCIP_VAR * w
SCIP_VAR * a
SCIP_VAR ** b
EdgeGCG(int s, int d, double w)
Definition: graph_gcg.h:55
double weight
Definition: graph_gcg.h:53
virtual double getEdgeWeight(int node_i, int node_j)
Definition: graph_gcg.cpp:705
virtual SCIP_RETCODE addNNodes(int _n_nodes)
Definition: graph_gcg.cpp:96
virtual int graphGetWeights(int node)
Definition: graph_gcg.cpp:700
virtual double getEdgeWeightPercentile(double q)
Definition: graph_gcg.cpp:766
virtual std::vector< std::pair< int, double > > getNeighborWeights(int node)
Definition: graph_gcg.cpp:507
virtual SCIP_RETCODE flush()
Definition: graph_gcg.cpp:722
virtual int getNNeighbors(int node)
Definition: graph_gcg.cpp:449
virtual SCIP_RETCODE getEdges(std::vector< void * > &edges)
Definition: graph_gcg.cpp:800
virtual int getNNodes()
Definition: graph_gcg.cpp:128
virtual std::vector< std::vector< double > > getAdjMatrix()
Definition: graph_gcg.cpp:400
virtual SCIP_RETCODE addNode()
Definition: graph_gcg.cpp:587
virtual SCIP_RETCODE deleteNode(int node)
Definition: graph_gcg.cpp:596
virtual std::vector< int > getNeighbors(int node)
Definition: graph_gcg.cpp:476
virtual SCIP_RETCODE addEdge(int i, int j)
Definition: graph_gcg.cpp:606
virtual SCIP_RETCODE deleteEdge(int node_i, int node_j)
Definition: graph_gcg.cpp:695
virtual int getNEdges()
Definition: graph_gcg.cpp:408
virtual int edgeComp(const EdgeGCG *a, const EdgeGCG *b)
Definition: graph_gcg.cpp:817
virtual SCIP_RETCODE setEdge(int node_i, int node_j, double weight)
Definition: graph_gcg.cpp:658
virtual SCIP_Bool isEdge(int node_i, int node_j)
Definition: graph_gcg.cpp:431
virtual SCIP_RETCODE normalize()
Definition: graph_gcg.cpp:733
virtual ~GraphGCG()
Definition: graph_gcg.cpp:77
#define SCIP_Bool
enum SCIP_Retcode SCIP_RETCODE