Open
Graph Drawing
Framework

 v. 2022.02 (Dogwood)
 

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 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::GraphCopy::original
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:292
ogdf::GraphCopy::operator=
GraphCopy & operator=(const GraphCopy &GC)
Assignment operator.
ogdf::EdgeWeightedGraph::weight
T weight(const edge e) const
Definition: EdgeWeightedGraph.h:68
ogdf::EdgeWeightedGraphCopy::EdgeWeightedGraphCopy
EdgeWeightedGraphCopy()
Definition: EdgeWeightedGraphCopy.h:42
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:255
ogdf::ListIteratorBase::valid
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:124
ogdf::EdgeWeightedGraphCopy::newEdge
edge newEdge(node u, node v, T weight)
Definition: EdgeWeightedGraphCopy.h:166
ogdf::GraphCopy::createEmpty
void createEmpty(const Graph &G)
Associates the graph copy with G, but does not create any nodes or edges.
ogdf::GraphCopy::init
void init(const Graph &G)
Re-initializes the copy using the graph G.
ogdf::GraphCopy::m_pGraph
const Graph * m_pGraph
The original graph.
Definition: GraphCopy.h:258
ogdf::NodeArray
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:441
ogdf::EdgeWeightedGraphCopy::m_edgeWeight
EdgeArray< T > m_edgeWeight
Definition: EdgeWeightedGraphCopy.h:62
ogdf::EdgeArray
Dynamic arrays indexed with edges.
Definition: EdgeArray.h:112
ogdf::EdgeWeightedGraphCopy::init
void init(const EdgeWeightedGraph< T > &wG)
Definition: EdgeWeightedGraphCopy.h:148
ogdf::GraphCopy::copy
node copy(node v) const
Returns the node in the graph copy corresponding to v.
Definition: GraphCopy.h:341
ogdf::GraphCopy::newEdge
edge newEdge(edge eOrig)
Creates a new edge (v,w) with original edge eOrig.
ogdf::Graph::nodes
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:568
Minisat::Internal::copy
static void copy(const T &from, T &to)
Definition: Alg.h:61
ogdf::EdgeWeightedGraphCopy::operator=
EdgeWeightedGraphCopy & operator=(const EdgeWeightedGraphCopy &wGC)
Definition: EdgeWeightedGraphCopy.h:114
ogdf::EdgeWeightedGraph
Definition: EdgeWeightedGraph.h:39
ogdf::EdgeWeightedGraphCopy::~EdgeWeightedGraphCopy
virtual ~EdgeWeightedGraphCopy()
Definition: EdgeWeightedGraphCopy.h:46
GraphCopy.h
Declaration of graph copy classes.
ogdf::GraphCopy::m_eCopy
EdgeArray< List< edge > > m_eCopy
The corresponding list of edges in the graph copy.
Definition: GraphCopy.h:264
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:495
ogdf::Graph::edges
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition: Graph_d.h:571
EdgeWeightedGraph.h
Declaration of class EdgeWeightedGraph.
ogdf::EdgeWeightedGraphCopy::edgeWeights
const EdgeArray< T > & edgeWeights() const
Definition: EdgeWeightedGraphCopy.h:57
ogdf::EdgeWeightedGraphCopy::weight
T weight(const edge e) const
Definition: EdgeWeightedGraphCopy.h:51
ogdf::EdgeWeightedGraphCopy
Definition: EdgeWeightedGraphCopy.h:40
ogdf::EdgeWeightedGraphCopy::createEmpty
void createEmpty(const Graph &wG)
Definition: EdgeWeightedGraphCopy.h:159
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:292
ogdf::ListIteratorBase
Encapsulates a pointer to a list element.
Definition: List.h:42
ogdf::EdgeWeightedGraphCopy::setWeight
void setWeight(const edge e, T v)
Definition: EdgeWeightedGraphCopy.h:54
ogdf::EdgeWeightedGraphCopy::initWGC
void initWGC(const EdgeWeightedGraphCopy &wGC, NodeArray< node > &vCopy, EdgeArray< edge > &eCopy)
Definition: EdgeWeightedGraphCopy.h:75
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:169