Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

EdgeWeightedGraphCopy.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/GraphCopy.h>
36 
37 namespace ogdf {
38 
39 template<typename T>
41 public:
43  explicit EdgeWeightedGraphCopy(const EdgeWeightedGraph<T> &wC);
47  void createEmpty(const Graph &wG);
48  void init(const EdgeWeightedGraph<T>& wG);
49  edge newEdge(node u, node v, T weight);
50  edge newEdge(edge eOrig, T weight);
51  T weight(const edge e) const {
52  return m_edgeWeight[e];
53  }
54  void setWeight(const edge e, T v) {
55  m_edgeWeight[e] = v;
56  }
57  const EdgeArray<T> &edgeWeights() const {
58  return m_edgeWeight;
59  }
60 
61 protected:
63 
64 private:
65  void initWGC(const EdgeWeightedGraphCopy &wGC, NodeArray<node> &vCopy, EdgeArray<edge> &eCopy);
66 };
67 
68 }
69 
70 // Implementation
71 
72 namespace ogdf {
73 
74 template<typename T>
76 {
77  m_pGraph = wGC.m_pGraph;
78 
79  m_vOrig.init(*this, 0);
80  m_eOrig.init(*this, 0);
81  m_vCopy.init(*m_pGraph, 0);
82  m_eCopy.init(*m_pGraph);
83  m_eIterator.init(*this, 0);
84 
85  for(node v : wGC.nodes) {
86  m_vOrig[vCopy[v]] = wGC.original(v);
87  }
88 
89  for(edge e : wGC.edges) {
90  m_eOrig[eCopy[e]] = wGC.original(e);
91  }
92 
93  for(node v : nodes) {
94  node w = m_vOrig[v];
95  if (w != nullptr) {
96  m_vCopy[w] = v;
97  }
98  }
99 
100  for(edge e : m_pGraph->edges) {
102  for (it = wGC.m_eCopy[e].begin(); it.valid(); ++it)
103  m_eIterator[eCopy[*it]] = m_eCopy[e].pushBack(eCopy[*it]);
104  }
105 
106  m_edgeWeight.init(*this);
107 
108  for(edge e : wGC.edges) {
109  m_edgeWeight[eCopy[e]] = wGC.weight(e);
110  }
111 }
112 
113 template<typename T>
115 {
117 
118  m_edgeWeight.init(*this);
119 
120  for(edge e : wGC.edges) {
121  const edge f = wGC.original(e);
122  m_edgeWeight[copy(f)] = wGC.weight(e);
123  }
124 
125  return *this;
126 }
127 
128 template<typename T>
130  : GraphCopy(wGC), m_edgeWeight(*this)
131 {
132  for(edge e : wGC.edges) {
133  const edge f = wGC.original(e);
134  m_edgeWeight[copy(f)] = wGC.weight(e);
135  }
136 }
137 
138 template<typename T>
140  : GraphCopy(wG), m_edgeWeight(*this)
141 {
142  for(edge e : edges) {
143  m_edgeWeight[e] = wG.weight(original(e));
144  }
145 }
146 
147 template<typename T>
149 {
150  GraphCopy::init(wG);
151 
152  m_edgeWeight.init(*this);
153  for (edge e : edges) {
154  m_edgeWeight[e] = wG.weight(original(e));
155  }
156 }
157 
158 template<typename T>
161  m_pGraph = &G;
162  m_edgeWeight.init(*this);
163 }
164 
165 template<typename T>
167  edge e = GraphCopy::newEdge(u, v);
168  m_edgeWeight[e] = weight;
169  return e;
170 }
171 
172 template<typename T>
174  edge e = GraphCopy::newEdge(eOrig);
175  m_edgeWeight[e] = weight;
176  return e;
177 }
178 
179 }
node copy(node v) const
Returns the node in the graph copy corresponding to v.
Definition: GraphCopy.h:335
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:492
void init(const Graph &G)
Re-initializes the copy using the graph G.
edge newEdge(node u, node v, T weight)
NodeArray< node > m_vOrig
The corresponding node in the original graph.
Definition: GraphCopy.h:253
void createEmpty(const Graph &G)
Associates the graph copy with G, but does not create any nodes or edges.
EdgeArray< List< edge > > m_eCopy
The corresponding list of edges in the graph copy.
Definition: GraphCopy.h:258
Dynamic arrays indexed with edges.
Definition: EdgeArray.h:112
GraphCopy & operator=(const GraphCopy &GC)
Assignment operator.
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:124
T weight(const edge e) const
edge newEdge(edge eOrig)
Creates a new edge (v,w) with original edge eOrig.
void createEmpty(const Graph &wG)
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition: Graph_d.h:568
void initWGC(const EdgeWeightedGraphCopy &wGC, NodeArray< node > &vCopy, EdgeArray< edge > &eCopy)
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:438
EdgeArray< edge > m_eOrig
The corresponding edge in the original graph.
Definition: GraphCopy.h:254
const EdgeArray< T > & edgeWeights() const
Declaration of graph copy classes.
Class for the representation of edges.
Definition: Graph_d.h:292
Declaration of class EdgeWeightedGraph.
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:249
void init(const EdgeWeightedGraph< T > &wG)
Class for the representation of nodes.
Definition: Graph_d.h:169
Encapsulates a pointer to a list element.
Definition: List.h:42
void setWeight(const edge e, T v)
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:286
NodeArray< node > m_vCopy
The corresponding node in the graph copy.
Definition: GraphCopy.h:257
EdgeWeightedGraphCopy & operator=(const EdgeWeightedGraphCopy &wGC)
const Graph * m_pGraph
The original graph.
Definition: GraphCopy.h:252
EdgeArray< ListIterator< edge > > m_eIterator
The position of copy edge in the list.
Definition: GraphCopy.h:255
The namespace for all OGDF objects.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:565