Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

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  edge newEdge(node u, node v, T weight);
49  edge newEdge(edge eOrig, T weight);
50  T weight(const edge e) const {
51  return m_edgeWeight[e];
52  }
53  void setWeight(const edge e, T v) {
54  m_edgeWeight[e] = v;
55  }
56  const EdgeArray<T> &edgeWeights() const {
57  return m_edgeWeight;
58  }
59 
60 protected:
62 
63 private:
64  void initWGC(const EdgeWeightedGraphCopy &wGC, NodeArray<node> &vCopy, EdgeArray<edge> &eCopy);
65 };
66 
67 }
68 
69 // Implementation
70 
71 namespace ogdf {
72 
73 template<typename T>
75 {
76  m_pGraph = wGC.m_pGraph;
77 
78  m_vOrig.init(*this, 0);
79  m_eOrig.init(*this, 0);
80  m_vCopy.init(*m_pGraph, 0);
81  m_eCopy.init(*m_pGraph);
82  m_eIterator.init(*this, 0);
83 
84  for(node v : wGC.nodes) {
85  m_vOrig[vCopy[v]] = wGC.original(v);
86  }
87 
88  for(edge e : wGC.edges) {
89  m_eOrig[eCopy[e]] = wGC.original(e);
90  }
91 
92  for(node v : nodes) {
93  node w = m_vOrig[v];
94  if (w != nullptr) {
95  m_vCopy[w] = v;
96  }
97  }
98 
99  for(edge e : m_pGraph->edges) {
101  for (it = wGC.m_eCopy[e].begin(); it.valid(); ++it)
102  m_eIterator[eCopy[*it]] = m_eCopy[e].pushBack(eCopy[*it]);
103  }
104 
105  m_edgeWeight.init(*this);
106 
107  for(edge e : wGC.edges) {
108  m_edgeWeight[eCopy[e]] = wGC.weight(e);
109  }
110 }
111 
112 template<typename T>
114 {
116 
117  m_edgeWeight.init(*this);
118 
119  for(edge e : wGC.edges) {
120  const edge f = wGC.original(e);
121  m_edgeWeight[copy(f)] = wGC.weight(e);
122  }
123 
124  return *this;
125 }
126 
127 template<typename T>
129  : GraphCopy(wGC), m_edgeWeight(*this)
130 {
131  for(edge e : wGC.edges) {
132  const edge f = wGC.original(e);
133  m_edgeWeight[copy(f)] = wGC.weight(e);
134  }
135 }
136 
137 template<typename T>
139  : GraphCopy(wG), m_edgeWeight(*this)
140 {
141  for(edge e : edges) {
142  m_edgeWeight[e] = wG.weight(original(e));
143  }
144 }
145 
146 template<typename T>
149  m_pGraph = &G;
150  m_edgeWeight.init(*this);
151 }
152 
153 template<typename T>
155  edge e = GraphCopy::newEdge(u, v);
156  m_edgeWeight[e] = weight;
157  return e;
158 }
159 
160 template<typename T>
162  edge e = GraphCopy::newEdge(eOrig);
163  m_edgeWeight[e] = weight;
164  return e;
165 }
166 
167 }
node copy(node v) const
Returns the node in the graph copy corresponding to v.
Definition: GraphCopy.h:336
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
edge newEdge(node u, node v, T weight)
NodeArray< node > m_vOrig
The corresponding node in the original graph.
Definition: GraphCopy.h:254
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:259
Dynamic arrays indexed with edges.
Definition: EdgeArray.h:112
GraphCopy & operator=(const GraphCopy &GC)
Assignment operator.
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:548
void initWGC(const EdgeWeightedGraphCopy &wGC, NodeArray< node > &vCopy, EdgeArray< edge > &eCopy)
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:423
EdgeArray< edge > m_eOrig
The corresponding edge in the original graph.
Definition: GraphCopy.h:255
const EdgeArray< T > & edgeWeights() const
Declaration of graph copy classes.
Class for the representation of edges.
Definition: Graph_d.h:291
Declaration of class EdgeWeightedGraph.
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:250
Class for the representation of nodes.
Definition: Graph_d.h:167
Encapsulates a pointer to a list element.
Definition: List.h:41
void setWeight(const edge e, T v)
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:287
NodeArray< node > m_vCopy
The corresponding node in the graph copy.
Definition: GraphCopy.h:258
EdgeWeightedGraphCopy & operator=(const EdgeWeightedGraphCopy &wGC)
const Graph * m_pGraph
The original graph.
Definition: GraphCopy.h:253
EdgeArray< ListIterator< edge > > m_eIterator
The position of copy edge in the list.
Definition: GraphCopy.h:256
The namespace for all OGDF objects.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:545
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:112