Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
EdgeWeightedGraphCopy.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Graph.h>
37#include <ogdf/basic/List.h>
38
39namespace ogdf {
40template<typename T>
41class EdgeWeightedGraph;
42
43template<typename T>
45public:
47
51
53
54 void setOriginalGraph(const Graph* wG) override;
56
57 void init(const EdgeWeightedGraph<T>& wG);
58 edge newEdge(node u, node v, T weight);
59 edge newEdge(edge eOrig, T weight);
60
61 T weight(const edge e) const { return m_edgeWeight[e]; }
62
63 void setWeight(const edge e, T v) { m_edgeWeight[e] = v; }
64
65 const EdgeArray<T>& edgeWeights() const { return m_edgeWeight; }
66
67protected:
69
70private:
71 void initWGC(const EdgeWeightedGraphCopy& wGC, NodeArray<node>& vCopy, EdgeArray<edge>& eCopy);
72};
73
74}
75
76// Implementation
77
78namespace ogdf {
79
80template<typename T>
82 EdgeArray<edge>& eCopy) {
83 m_pGraph = wGC.m_pGraph;
84
85 m_vOrig.init(*this, 0);
86 m_eOrig.init(*this, 0);
87 m_vCopy.init(*m_pGraph, 0);
88 m_eCopy.init(*m_pGraph);
89 m_eIterator.init(*this, 0);
90
91 for (node v : wGC.nodes) {
92 m_vOrig[vCopy[v]] = wGC.original(v);
93 }
94
95 for (edge e : wGC.edges) {
96 m_eOrig[eCopy[e]] = wGC.original(e);
97 }
98
99 for (node v : nodes) {
100 node w = m_vOrig[v];
101 if (w != nullptr) {
102 m_vCopy[w] = v;
103 }
104 }
105
106 for (edge e : m_pGraph->edges) {
108 for (it = wGC.m_eCopy[e].begin(); it.valid(); ++it) {
109 m_eIterator[eCopy[*it]] = m_eCopy[e].pushBack(eCopy[*it]);
110 }
111 }
112
113 m_edgeWeight.init(*this);
114
115 for (edge e : wGC.edges) {
116 m_edgeWeight[eCopy[e]] = wGC.weight(e);
117 }
118}
119
120template<typename T>
123
124 m_edgeWeight.init(*this);
125
126 for (edge e : wGC.edges) {
127 const edge f = wGC.original(e);
128 m_edgeWeight[copy(f)] = wGC.weight(e);
129 }
130
131 return *this;
132}
133
134template<typename T>
136 : GraphCopy(wGC), m_edgeWeight(*this) {
137 for (edge e : wGC.edges) {
138 const edge f = wGC.original(e);
139 m_edgeWeight[copy(f)] = wGC.weight(e);
140 }
141}
142
143template<typename T>
145 : GraphCopy(wG), m_edgeWeight(*this) {
146 for (edge e : edges) {
147 m_edgeWeight[e] = wG.weight(original(e));
148 }
149}
150
151template<typename T>
153 GraphCopy::init(wG);
154
155 m_edgeWeight.init(*this);
156 for (edge e : edges) {
157 m_edgeWeight[e] = wG.weight(original(e));
158 }
159}
160
161template<typename T>
164 m_pGraph = G;
165 m_edgeWeight.init(*this);
166}
167
168template<typename T>
170 edge e = GraphCopy::newEdge(u, v);
171 m_edgeWeight[e] = weight;
172 return e;
173}
174
175template<typename T>
177 edge e = GraphCopy::newEdge(eOrig);
178 m_edgeWeight[e] = weight;
179 return e;
180}
181
182}
Includes declaration of graph class.
Declaration of graph copy classes.
Decralation of GraphElement and GraphList classes.
Declaration of doubly linked lists and iterators.
Class for the representation of edges.
Definition Graph_d.h:364
edge newEdge(node u, node v, T weight)
void setOriginalGraph(const Graph *wG) override
Re-initializes the copy using G (which might be null), but does not create any nodes or edges.
const EdgeArray< T > & edgeWeights() const
void initWGC(const EdgeWeightedGraphCopy &wGC, NodeArray< node > &vCopy, EdgeArray< edge > &eCopy)
void init(const EdgeWeightedGraph< T > &wG)
void setWeight(const edge e, T v)
EdgeWeightedGraphCopy & operator=(const EdgeWeightedGraphCopy &wGC)
T weight(const edge e) const
void init(const Graph &G)
Re-initializes the copy using G, creating copies for all nodes and edges in G.
Definition GraphCopy.h:72
const Graph * m_pGraph
The original graph.
Definition GraphCopy.h:52
const Graph & original() const
Returns a reference to the original graph.
Definition GraphCopy.h:104
Copies of graphs supporting edge splitting.
Definition GraphCopy.h:390
void setOriginalGraph(const Graph *G) override
Associates the graph copy with G, but does not create any nodes or edges.
edge copy(edge e) const override
Returns the first edge in the list of edges corresponding to edge e.
Definition GraphCopy.h:463
EdgeArray< List< edge > > m_eCopy
The corresponding list of edges in the graph copy.
Definition GraphCopy.h:393
GraphCopy & operator=(const GraphCopy &other)
edge newEdge(edge eOrig)
Creates a new edge (v,w) with original edge eOrig.
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition Graph_d.h:929
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition Graph_d.h:932
Encapsulates a pointer to a list element.
Definition List.h:113
bool valid() const
Returns true iff the iterator points to an element.
Definition List.h:153
Class for the representation of nodes.
Definition Graph_d.h:241
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
The namespace for all OGDF objects.