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-2018 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 
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:
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 
93  ~Hypergraph();
94 
96  SCIP_RETCODE addNode(int i,int weight);
97 
99  SCIP_RETCODE addHyperedge(std::vector<int> &edge, int weight);
100 
102  SCIP_RETCODE addNodeToHyperedge(int node, int hedge);
103 
105  int getNNodes();
106 
108  int getNHyperedges();
109 
111  int getNNeighbors(
112  int i
113  );
114 
116  std::vector<int> getNeighbors(
117  int i
118  );
119 
121  std::vector<int> getHyperedgeNodes(
122  int i
123  );
124 
126  int getNHyperedgeNodes(
127  int i
128  );
129 
131  void setPartition(int i, int ID);
132 
136  SCIP_RETCODE writeToFile(
137  int fd,
138  SCIP_Bool writeweights
139  );
140 
145  SCIP_RETCODE readPartition(
146  const char* filename
147  );
148 
150  int getWeight(
151  int i
152  );
153 
155  int getHyperedgeWeight(
156  int i
157  );
158 
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
Hypergraph(SCIP *scip)
std::vector< int > getNeighbors(int i)
std::vector< int > hedges
Definition: hypergraph.h:61
void setPartition(int i, int ID)
SCIP_RETCODE flush()
std::string name
Definition: hypergraph.h:56
std::vector< int > nodes
Definition: hypergraph.h:60
void swap(Hypergraph &other)
Definition: hypergraph.h:72
int getNHyperedgeNodes(int i)
weight class for graphs
SCIP_RETCODE readPartition(const char *filename)
SCIP_RETCODE addNodeToHyperedge(int node, int hedge)
Graph< T > * graph
Definition: hypergraph.h:59
std::vector< int > mapping
Definition: hypergraph.h:62
SCIP_RETCODE addHyperedge(std::vector< int > &edge, int weight)
Hypergraph & operator=(Hypergraph other)
Definition: hypergraph.h:84
miscellaneous graph methods for structure detection
SCIP_RETCODE writeToFile(int fd, SCIP_Bool writeweights)
miscellaneous graph interface methods
int getNNeighbors(int i)
int getWeight(int i)
std::vector< int > getHyperedgeNodes(int i)
int getDummynodes() const
Definition: hypergraph.h:166
std::vector< int > partition
void setDummynodes(int dummynodes_)
Definition: hypergraph.h:160
int getHyperedgeWeight(int i)
public methods for working with decomposition structures
SCIP_RETCODE addNode(int i, int weight)