GCG 4.1.1 (dev)

Generic Column Generation

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