File: EdgeStandardRep.h

package info (click to toggle)
tulip 4.8.0dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 179,264 kB
  • ctags: 64,517
  • sloc: cpp: 600,444; ansic: 36,311; makefile: 22,136; python: 1,304; sh: 946; yacc: 522; xml: 337; pascal: 157; php: 66; lex: 55
file content (218 lines) | stat: -rw-r--r-- 5,817 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
 * $Revision: 3505 $
 *
 * last checkin:
 *   $Author: beyer $
 *   $Date: 2013-05-16 14:49:47 +0200 (Thu, 16 May 2013) $
 ***************************************************************/

/** \file
 * \brief A declaration of EdgeStandardRep class representing a graph
 *        representation of a hypergraph in the edge standard form.
 *
 * This class provides a kind of an intermediate repsenetation of a
 * hypergraph between Hypergraph and edge standard based layout classes.
 * It is derived from HypergraphObserver and provides some additional
 * functionality to handle edge standard representation of hypergraph.
 * It follows Observer design pattern.
 *
 * \author Ondrej Moris
 *
 * \par License:
 * This file is part of the Open Graph Drawing Framework (OGDF).
 *
 * \par
 * Copyright (C)<br>
 * See README.txt in the root directory of the OGDF installation for details.
 *
 * \par
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * Version 2 or 3 as published by the Free Software Foundation;
 * see the file LICENSE.txt included in the packaging of this file
 * for details.
 *
 * \par
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * \par
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * \see  http://www.gnu.org/copyleft/gpl.html
 ***************************************************************/

#ifdef _MSC_VER
#pragma once
#endif

#ifndef OGDF_EDGE_STANDARD_REP_H
#define OGDF_EDGE_STANDARD_REP_H

#include <ogdf/basic/Graph_d.h>
#include <ogdf/basic/NodeArray.h>
#include <ogdf/basic/EdgeArray.h>
#include <ogdf/hypergraph/Hypergraph.h>
#include <ogdf/hypergraph/HypergraphArray.h>
#include <ogdf/hypergraph/HypergraphObserver.h>

namespace ogdf {

//!< Enumeration class of possible edge standard representations.
/**
 * There are the following possibilities:
 *
 * a) clique - no new dummy nodes are introduced, for every hyperedge
 *             e = (v_1, ..., v_l), we add a cliqie K_l connecting
 *             hypernodes incident with e,
 * b) star   - for every hyperedge e = {v_1, ..., v_l} a single new dummy
 *             node v_e is introduced, moreover, v_e becomes the center of
 *             a new star connecting all hypernodes incident with e (ie.
 *             {v_1, v_e}, ..., {v_l, v_e} are added)
 * c) tree   - for every hyperedge e a minimal subcubic tree connecting all
 *             hypernodes incident with e together is added with all its
 *             nodes and edges, leaves of tree are hypernodes, all non-leaf
 *             nodes are newly introduced dummy nodes.
 */
class OGDF_EXPORT EdgeStandardType
{
public:

	enum Type {
		clique = 0x0001,
		star   = 0x0002,
		tree   = 0x0003
	};
};

//! Edge standard representation of hypergraphs.
class OGDF_EXPORT EdgeStandardRep : public HypergraphObserver
{
private:

	//!< The type of edge standard representation.
	EdgeStandardType::Type m_type;

	//!< The reference to the original hypergraph.
	const Hypergraph *m_hypergraph;

	//!< Edge standard representation of the hypergraph.
	Graph m_graphRep;

	//!< The map from representation nodes to hypernodes.
	NodeArray<hypernode> m_hypernodeMap;

	//!< The map from representation hypernodes to nodes.
	HypernodeArray<node> m_nodeMap;

	//!< The map from representation edge to hyperedges.
	EdgeArray<hyperedge> m_hyperedgeMap;

	//!< The map from representation hyperedge to edges.
	HyperedgeArray<List<edge> > m_edgeMap;

	//!< The list of all newly created nodes.
	List<node> m_dummyNodes;

public:

	//!< Creates an edge standard representation.
	EdgeStandardRep();

	//!< Creates an edge standard rep. of a given type associated with \a H.
	EdgeStandardRep(const Hypergraph &pH, EdgeStandardType::Type pType);

	//!< Desctructor.
	virtual ~EdgeStandardRep();

	//!< Clears all cluster data.
	void clear();

	//! Conversion to original hypergraph reference.
	const Hypergraph & hypergraph() const
	{
		return *m_hypergraph;
	}

	//! Returns a reference to the representation graph.
	const Graph & constGraph() const
	{
		return m_graphRep;
	}

	//!< Returns the type of edge standard representation.
	EdgeStandardType::Type type() const {
		return m_type;
	}

	//!< Returns the node associated with the hypernode.
	node nodeMap(hypernode v)
	{
		return m_nodeMap[v];
	}

	//!< Returns the hypernode associated with the node (if any).
	hypernode hypernodeMap(node v)
	{
		return m_hypernodeMap[v];
	}

	//!< Returns the list of edges associated with the hyperedge.
	const List<edge> & edgeMap(hyperedge e)
	{
		return m_edgeMap[e];
	}

	//!< Returns the hyperedge associated with the edge.
	hyperedge hyperedgeMap(edge e)
	{
		return m_hyperedgeMap[e];
	}

	//!< Returns the list of dummy nodes.
	const List<node> & dummyNodes() const
	{
		return m_dummyNodes;
	}

protected:

	//!< Hypernode removal reaction.
	virtual void hypernodeDeleted(hypernode v);

	//!< Hypernode addition reaction.
	virtual void hypernodeAdded(hypernode v);

	//!< Hyperedge removal reaction.
	virtual void hyperedgeDeleted(hyperedge e);

	//!< Hyperedge addition reaction.
	virtual void hyperedgeAdded(hyperedge e);

	//!< Hypergraph clean-up reaction.
	virtual void cleared();

private:

	void constructCliqueRep();

	void constructStarRep();

	void constructTreeRep();

	void hyperedgeToTree(hyperedge e, int degree);

	void hyperedgeToClique(hyperedge e);

	void cloneHypernodes();

};

} // end namespace ogdf

#endif