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/GraphCopy.h>
36 
37 namespace ogdf {
38 
39 template<typename T>
41 public:
43 
44  explicit EdgeWeightedGraphCopy(const EdgeWeightedGraph<T>& wC);
47 
48  virtual ~EdgeWeightedGraphCopy() { }
49 
50  void setOriginalGraph(const Graph* wG) override;
52 
53  void init(const EdgeWeightedGraph<T>& wG);
54  edge newEdge(node u, node v, T weight);
55  edge newEdge(edge eOrig, T weight);
56 
57  T weight(const edge e) const { return m_edgeWeight[e]; }
58 
59  void setWeight(const edge e, T v) { m_edgeWeight[e] = v; }
60 
61  const EdgeArray<T>& edgeWeights() const { return m_edgeWeight; }
62 
63 protected:
65 
66 private:
67  void initWGC(const EdgeWeightedGraphCopy& wGC, NodeArray<node>& vCopy, EdgeArray<edge>& eCopy);
68 };
69 
70 }
71 
72 // Implementation
73 
74 namespace ogdf {
75 
76 template<typename T>
78  EdgeArray<edge>& eCopy) {
79  m_pGraph = wGC.m_pGraph;
80 
81  m_vOrig.init(*this, 0);
82  m_eOrig.init(*this, 0);
83  m_vCopy.init(*m_pGraph, 0);
84  m_eCopy.init(*m_pGraph);
85  m_eIterator.init(*this, 0);
86 
87  for (node v : wGC.nodes) {
88  m_vOrig[vCopy[v]] = wGC.original(v);
89  }
90 
91  for (edge e : wGC.edges) {
92  m_eOrig[eCopy[e]] = wGC.original(e);
93  }
94 
95  for (node v : nodes) {
96  node w = m_vOrig[v];
97  if (w != nullptr) {
98  m_vCopy[w] = v;
99  }
100  }
101 
102  for (edge e : m_pGraph->edges) {
104  for (it = wGC.m_eCopy[e].begin(); it.valid(); ++it) {
105  m_eIterator[eCopy[*it]] = m_eCopy[e].pushBack(eCopy[*it]);
106  }
107  }
108 
109  m_edgeWeight.init(*this);
110 
111  for (edge e : wGC.edges) {
112  m_edgeWeight[eCopy[e]] = wGC.weight(e);
113  }
114 }
115 
116 template<typename T>
119 
120  m_edgeWeight.init(*this);
121 
122  for (edge e : wGC.edges) {
123  const edge f = wGC.original(e);
124  m_edgeWeight[copy(f)] = wGC.weight(e);
125  }
126 
127  return *this;
128 }
129 
130 template<typename T>
132  : GraphCopy(wGC), m_edgeWeight(*this) {
133  for (edge e : wGC.edges) {
134  const edge f = wGC.original(e);
135  m_edgeWeight[copy(f)] = wGC.weight(e);
136  }
137 }
138 
139 template<typename T>
141  : GraphCopy(wG), m_edgeWeight(*this) {
142  for (edge e : edges) {
143  m_edgeWeight[e] = wG.weight(original(e));
144  }
145 }
146 
147 template<typename T>
149  GraphCopy::init(wG);
150 
151  m_edgeWeight.init(*this);
152  for (edge e : edges) {
153  m_edgeWeight[e] = wG.weight(original(e));
154  }
155 }
156 
157 template<typename T>
160  m_pGraph = G;
161  m_edgeWeight.init(*this);
162 }
163 
164 template<typename T>
166  edge e = GraphCopy::newEdge(u, v);
167  m_edgeWeight[e] = weight;
168  return e;
169 }
170 
171 template<typename T>
173  edge e = GraphCopy::newEdge(eOrig);
174  m_edgeWeight[e] = weight;
175  return e;
176 }
177 
178 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::GraphCopyBase::m_pGraph
const Graph * m_pGraph
The original graph.
Definition: GraphCopy.h:46
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:58
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:158
ogdf::EdgeWeightedGraphCopy::EdgeWeightedGraphCopy
EdgeWeightedGraphCopy()
Definition: EdgeWeightedGraphCopy.h:42
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:384
ogdf::ListIteratorBase::valid
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:143
ogdf::EdgeWeightedGraphCopy::newEdge
edge newEdge(node u, node v, T weight)
Definition: EdgeWeightedGraphCopy.h:165
ogdf::EdgeWeightedGraphCopy::m_edgeWeight
EdgeArray< T > m_edgeWeight
Definition: EdgeWeightedGraphCopy.h:64
ogdf::EdgeWeightedGraphCopy::init
void init(const EdgeWeightedGraph< T > &wG)
Definition: EdgeWeightedGraphCopy.h:148
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:66
ogdf::Graph::nodes
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:924
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:117
ogdf::EdgeWeightedGraph
Definition: EdgeWeightedGraph.h:39
ogdf::EdgeWeightedGraphCopy::~EdgeWeightedGraphCopy
virtual ~EdgeWeightedGraphCopy()
Definition: EdgeWeightedGraphCopy.h:48
GraphCopy.h
Declaration of graph copy classes.
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:651
ogdf::GraphCopy::m_eCopy
EdgeArray< List< edge > > m_eCopy
The corresponding list of edges in the graph copy.
Definition: GraphCopy.h:387
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:862
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:457
ogdf::Graph::edges
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition: Graph_d.h:927
EdgeWeightedGraph.h
Declaration of class EdgeWeightedGraph.
ogdf::EdgeWeightedGraphCopy::edgeWeights
const EdgeArray< T > & edgeWeights() const
Definition: EdgeWeightedGraphCopy.h:61
ogdf::EdgeWeightedGraphCopy::weight
T weight(const edge e) const
Definition: EdgeWeightedGraphCopy.h:57
ogdf::EdgeWeightedGraphCopy
Definition: EdgeWeightedGraphCopy.h:40
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:356
ogdf::ListIteratorBase
Encapsulates a pointer to a list element.
Definition: List.h:46
ogdf::EdgeWeightedGraphCopy::setWeight
void setWeight(const edge e, T v)
Definition: EdgeWeightedGraphCopy.h:59
ogdf::EdgeWeightedGraphCopy::initWGC
void initWGC(const EdgeWeightedGraphCopy &wGC, NodeArray< node > &vCopy, EdgeArray< edge > &eCopy)
Definition: EdgeWeightedGraphCopy.h:77
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
ogdf::GraphCopyBase::original
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:98
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:709
ogdf::GraphCopy::operator=
GraphCopy & operator=(const GraphCopy &other)