Scippy

GCG

Branch-and-Price & Column Generation for Everyone

hypergraph.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 hypergraph.h
29  * @brief miscellaneous hypergraph methods for structure detection
30  * @author Martin Bergner
31  * @author Annika Thome
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 
37 
38 #ifndef GCG_HYPERGRAPH_H_
39 #define GCG_HYPERGRAPH_H_
40 #include "objscip/objscip.h"
41 #include "tclique/tclique.h"
42 #include "weights.h"
43 #include "pub_decomp.h"
44 #include "graph.h"
45 #include "graph_interface.h"
46 
47 #include <exception>
48 #include <vector>
49 #include <string>
50 
51 namespace gcg {
52 
53 template <class T>
54 class Hypergraph : public GraphInterface {
55 public:
56  std::string name;
57 protected:
58  SCIP* scip_;
60  std::vector<int> nodes;
61  std::vector<int> hedges;
62  std::vector<int> mapping;
63  int lastnode;
65 
66 public:
67  /** Constructor */
68  Hypergraph(
69  SCIP* scip
70  );
71 
72  void swap(Hypergraph & other) // the swap member function (should never fail!)
73  {
74  // swap all the members (and base subobject, if applicable) with other
75  std::swap(partition, other.partition);
76  std::swap(scip_ , other.scip_);
77  std::swap(graph , other.graph);
78  std::swap(hedges , other.hedges);
79  std::swap(nodes , other.nodes);
80  std::swap(lastnode, other.lastnode);
81  std::swap(dummynodes, other.dummynodes);
82  }
83 
84  Hypergraph& operator=(Hypergraph other) // note: argument passed by value!
85  {
86  // swap this with other
87  swap(other);
88 
89  return *this;
90  }
91 
92  /** Destruktor */
93  ~Hypergraph();
94 
95  /** adds the node with the given weight to the graph */
96  SCIP_RETCODE addNode(int i,int weight);
97 
98  /** adds the edge to the graph */
99  SCIP_RETCODE addHyperedge(std::vector<int> &edge, int weight);
100 
101  /** adds the edge to the graph */
102  SCIP_RETCODE addNodeToHyperedge(int node, int hedge);
103 
104  /** return the number of nodes */
105  int getNNodes();
106 
107  /** return the number of edges (or hyperedges) */
108  int getNHyperedges();
109 
110  /** return the number of neighbor nodes of given node */
111  int getNNeighbors(
112  int i /**< the given node */
113  );
114 
115  /** return the neighboring nodes of a given node */
116  std::vector<int> getNeighbors(
117  int i /**< the given node */
118  );
119 
120  /** return the nodes spanned by hyperedge */
121  std::vector<int> getHyperedgeNodes(
122  int i
123  );
124 
125  /** return the number of nodes spanned by hyperedge */
126  int getNHyperedgeNodes(
127  int i
128  );
129 
130  /** assigns partition to a given node*/
131  void setPartition(int i, int ID);
132 
133  /** writes the hypergraph to the given file.
134  * The format is hypergraph dependent
135  */
136  SCIP_RETCODE writeToFile(
137  int fd, /**< filename where the graph should be written to */
138  SCIP_Bool writeweights /**< whether to write weights */
139  );
140 
141  /**
142  * reads the partition from the given file.
143  * The format is hypergraph dependent. The default is a file with one line for each node a
144  */
145  SCIP_RETCODE readPartition(
146  const char* filename /**< filename where the partition is stored */
147  );
148 
149  /** return the weight of given node */
150  int getWeight(
151  int i /**< the given node */
152  );
153 
154  /** return the weight of given hyperedge */
155  int getHyperedgeWeight(
156  int i /**< the given hyperedge */
157  );
158 
159  /** set the number of dummy nodes */
160  void setDummynodes(int dummynodes_)
161  {
162  dummynodes = dummynodes_;
163  }
164 
165 
166  int getDummynodes() const
167  {
168  return dummynodes;
169  }
170 
171  SCIP_RETCODE flush();
172 private:
173  int computeNodeId(int i);
174 };
175 
176 }
177 
178 #endif
int getHyperedgeWeight(int i)
void setDummynodes(int dummynodes_)
Definition: hypergraph.h:160
miscellaneous graph interface methods
std::vector< int > nodes
Definition: hypergraph.h:60
std::vector< int > getNeighbors(int i)
weight class for graphs
void swap(Hypergraph &other)
Definition: hypergraph.h:72
std::string name
Definition: hypergraph.h:56
SCIP_RETCODE addNodeToHyperedge(int node, int hedge)
std::vector< int > hedges
Definition: hypergraph.h:61
void setPartition(int i, int ID)
SCIP_RETCODE flush()
std::vector< int > mapping
Definition: hypergraph.h:62
int getNHyperedgeNodes(int i)
Graph< T > * graph
Definition: hypergraph.h:59
int getNNeighbors(int i)
int getWeight(int i)
SCIP_RETCODE readPartition(const char *filename)
std::vector< int > partition
std::vector< int > getHyperedgeNodes(int i)
SCIP_RETCODE addHyperedge(std::vector< int > &edge, int weight)
miscellaneous graph methods for structure detection
Hypergraph & operator=(Hypergraph other)
Definition: hypergraph.h:84
int getDummynodes() const
Definition: hypergraph.h:166
SCIP_RETCODE writeToFile(int fd, SCIP_Bool writeweights)
Hypergraph(SCIP *scip)
SCIP_RETCODE addNode(int i, int weight)
public methods for working with decomposition structures