6 * $Date: 2012-07-02 20:59:27 +0200 (Mon, 02 Jul 2012) $
7 ***************************************************************/
10 * \brief Extends the GraphCopy concept to weighted graphs
12 * \author Matthias Woste
15 * This file is part of the Open Graph Drawing Framework (OGDF).
19 * See README.txt in the root directory of the OGDF installation for details.
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * Version 2 or 3 as published by the Free Software Foundation;
25 * see the file LICENSE.txt included in the packaging of this file
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public
36 * License along with this program; if not, write to the Free
37 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
38 * Boston, MA 02110-1301, USA.
40 * \see http://www.gnu.org/copyleft/gpl.html
41 ***************************************************************/
47 #ifndef OGDF_EDGE_WEIGHTED_GRAPH_COPY_H_
48 #define OGDF_EDGE_WEIGHTED_GRAPH_COPY_H_
50 #include <ogdf/basic/GraphCopy.h>
51 #include <ogdf/internal/steinertree/EdgeWeightedGraph.h>
56 class EdgeWeightedGraphCopy
: public GraphCopy
{
58 EdgeWeightedGraphCopy() :
61 EdgeWeightedGraphCopy(const EdgeWeightedGraph
<T
> &wC
);
62 EdgeWeightedGraphCopy(const EdgeWeightedGraphCopy
&wGC
);
63 EdgeWeightedGraphCopy
&operator=(const EdgeWeightedGraphCopy
&wGC
);
64 virtual ~EdgeWeightedGraphCopy() {
67 void createEmpty(const EdgeWeightedGraph
<T
> &wG
);
68 edge
newEdge(node u
, node v
, T weight
);
69 T
weight(edge e
) const {
70 return m_edgeWeight
[e
];
72 void setWeight(edge e
, T v
) {
75 EdgeArray
<T
> edgeWeights() const {
80 EdgeArray
<T
> m_edgeWeight
;
83 void initWGC(const EdgeWeightedGraphCopy
&wGC
, NodeArray
<node
> &vCopy
, EdgeArray
<edge
> &eCopy
);
93 void EdgeWeightedGraphCopy
<T
>::initWGC(const EdgeWeightedGraphCopy
&wGC
, NodeArray
<node
> &vCopy
, EdgeArray
<edge
> &eCopy
) {
94 m_pGraph
= wGC
.m_pGraph
;
96 m_vOrig
.init(*this, 0);
97 m_eOrig
.init(*this, 0);
98 m_vCopy
.init(*m_pGraph
, 0);
99 m_eCopy
.init(*m_pGraph
);
100 m_eIterator
.init(*this, 0);
104 m_vOrig
[vCopy
[v
]] = wGC
.original(v
);
108 m_eOrig
[eCopy
[e
]] = wGC
.original(e
);
110 forall_nodes(v
, *this)
111 if ((w
= m_vOrig
[v
]) != 0)
114 forall_edges(e
, *m_pGraph
)
116 ListConstIterator
<edge
> it
;
117 for (it
= wGC
.m_eCopy
[e
].begin(); it
.valid(); ++it
)
118 m_eIterator
[eCopy
[*it
]] = m_eCopy
[e
].pushBack(eCopy
[*it
]);
121 m_edgeWeight
= EdgeArray
<T
>((*this));
125 m_edgeWeight
[eCopy
[e
]] = wGC
.weight(e
);
130 EdgeWeightedGraphCopy
<T
> &EdgeWeightedGraphCopy
<T
>::operator=(const EdgeWeightedGraphCopy
<T
> &wGC
) {
132 GraphCopy::operator =(wGC
);
134 m_edgeWeight
= EdgeArray
<T
>((*this));
140 m_edgeWeight
[copy(f
)] = wGC
.weight(e
);
146 EdgeWeightedGraphCopy
<T
>::EdgeWeightedGraphCopy(const EdgeWeightedGraphCopy
<T
> &wGC
) :
148 m_edgeWeight
= EdgeArray
<T
>((*this));
154 m_edgeWeight
[copy(f
)] = wGC
.weight(e
);
159 EdgeWeightedGraphCopy
<T
>::EdgeWeightedGraphCopy(const EdgeWeightedGraph
<T
> &wG
) :
161 m_edgeWeight
= EdgeArray
<T
>((*this));
164 forall_edges(e
, (*this))
166 m_edgeWeight
[e
] = wG
.weight(original(e
));
171 void EdgeWeightedGraphCopy
<T
>::createEmpty(const EdgeWeightedGraph
<T
> &wG
) {
172 GraphCopy::createEmpty(wG
);
174 m_edgeWeight
= EdgeArray
<T
>(*this);
178 edge EdgeWeightedGraphCopy
<T
>::newEdge(node u
, node v
, T weight
) {
179 edge e
= GraphCopy::newEdge(u
, v
);
180 m_edgeWeight
[e
] = weight
;
186 #endif /* OGDF_EDGE_WEIGHTED_GRAPH_COPY_H_ */