Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

EdgeWeightedGraphCopy.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Graph.h>
35 #include <ogdf/basic/GraphCopy.h>
36 #include <ogdf/basic/GraphList.h>
37 #include <ogdf/basic/List.h>
38 
39 namespace ogdf {
40 template<typename T>
41 class EdgeWeightedGraph;
42 
43 template<typename T>
45 public:
47 
48  explicit EdgeWeightedGraphCopy(const EdgeWeightedGraph<T>& wC);
51 
52  virtual ~EdgeWeightedGraphCopy() { }
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 
67 protected:
69 
70 private:
71  void initWGC(const EdgeWeightedGraphCopy& wGC, NodeArray<node>& vCopy, EdgeArray<edge>& eCopy);
72 };
73 
74 }
75 
76 // Implementation
77 
78 namespace ogdf {
79 
80 template<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 
120 template<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 
134 template<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 
143 template<typename T>
145  : GraphCopy(wG), m_edgeWeight(*this) {
146  for (edge e : edges) {
147  m_edgeWeight[e] = wG.weight(original(e));
148  }
149 }
150 
151 template<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 
161 template<typename T>
164  m_pGraph = G;
165  m_edgeWeight.init(*this);
166 }
167 
168 template<typename T>
170  edge e = GraphCopy::newEdge(u, v);
171  m_edgeWeight[e] = weight;
172  return e;
173 }
174 
175 template<typename T>
177  edge e = GraphCopy::newEdge(eOrig);
178  m_edgeWeight[e] = weight;
179  return e;
180 }
181 
182 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
Graph.h
Includes declaration of graph class.
ogdf::GraphCopyBase::m_pGraph
const Graph * m_pGraph
The original graph.
Definition: GraphCopy.h:53
ogdf::GraphCopy::setOriginalGraph
void setOriginalGraph(const Graph *G) override
Associates the graph copy with G, but does not create any nodes or edges.
ogdf::EdgeWeightedGraph::weight
T weight(const edge e) const
Definition: EdgeWeightedGraph.h:59
ogdf::EdgeWeightedGraphCopy::setOriginalGraph
void setOriginalGraph(const Graph *wG) override
Associates the graph copy with G, but does not create any nodes or edges.
Definition: EdgeWeightedGraphCopy.h:162
ogdf::EdgeWeightedGraphCopy::EdgeWeightedGraphCopy
EdgeWeightedGraphCopy()
Definition: EdgeWeightedGraphCopy.h:46
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:391
ogdf::ListIteratorBase::valid
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:153
ogdf::EdgeWeightedGraphCopy::newEdge
edge newEdge(node u, node v, T weight)
Definition: EdgeWeightedGraphCopy.h:169
ogdf::EdgeWeightedGraphCopy::m_edgeWeight
EdgeArray< T > m_edgeWeight
Definition: EdgeWeightedGraphCopy.h:68
ogdf::EdgeWeightedGraphCopy::init
void init(const EdgeWeightedGraph< T > &wG)
Definition: EdgeWeightedGraphCopy.h:152
ogdf::GraphCopy::newEdge
edge newEdge(edge eOrig)
Creates a new edge (v,w) with original edge eOrig.
ogdf::GraphCopyBase::init
void init(const Graph &G)
Re-initializes the copy using G, creating copies for all nodes and edges in G.
Definition: GraphCopy.h:73
ogdf::Graph::nodes
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:932
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:121
ogdf::EdgeWeightedGraph
Definition: GraphIO.h:56
ogdf::EdgeWeightedGraphCopy::~EdgeWeightedGraphCopy
virtual ~EdgeWeightedGraphCopy()
Definition: EdgeWeightedGraphCopy.h:52
GraphList.h
Decralation of GraphElement and GraphList classes.
GraphCopy.h
Declaration of graph copy classes.
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::GraphCopy::m_eCopy
EdgeArray< List< edge > > m_eCopy
The corresponding list of edges in the graph copy.
Definition: GraphCopy.h:394
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::GraphCopy::copy
edge copy(edge e) const override
Returns the first edge in the list of edges corresponding to edge e.
Definition: GraphCopy.h:464
ogdf::Graph::edges
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition: Graph_d.h:935
ogdf::EdgeWeightedGraphCopy::edgeWeights
const EdgeArray< T > & edgeWeights() const
Definition: EdgeWeightedGraphCopy.h:65
ogdf::EdgeWeightedGraphCopy::weight
T weight(const edge e) const
Definition: EdgeWeightedGraphCopy.h:61
ogdf::EdgeWeightedGraphCopy
Definition: EdgeWeightedGraphCopy.h:44
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
List.h
Declaration of doubly linked lists and iterators.
ogdf::ListIteratorBase
Encapsulates a pointer to a list element.
Definition: List.h:51
ogdf::EdgeWeightedGraphCopy::setWeight
void setWeight(const edge e, T v)
Definition: EdgeWeightedGraphCopy.h:63
ogdf::EdgeWeightedGraphCopy::initWGC
void initWGC(const EdgeWeightedGraphCopy &wGC, NodeArray< node > &vCopy, EdgeArray< edge > &eCopy)
Definition: EdgeWeightedGraphCopy.h:81
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::GraphCopyBase::original
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:105
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716
ogdf::GraphCopy::operator=
GraphCopy & operator=(const GraphCopy &other)