diff --git a/lemon/fractional_matching.h b/lemon/fractional_matching.h --- a/lemon/fractional_matching.h +++ b/lemon/fractional_matching.h @@ -658,10 +658,11 @@ /// After it the matching (the primal solution) and the dual solution /// can be obtained using the query functions. /// - /// If the value type is integer, then the primal and the dual - /// solutions are multiplied by - /// \ref MaxWeightedFractionalMatching::primalScale "2" and - /// \ref MaxWeightedFractionalMatching::dualScale "4" respectively. + /// The primal solution is multiplied by + /// \ref MaxWeightedFractionalMatching::primalScale "2". + /// If the value type is integer, then the dual + /// solution is scaled by + /// \ref MaxWeightedFractionalMatching::dualScale "4". /// /// \tparam GR The undirected graph type the algorithm runs on. /// \tparam WM The type edge weight map. The default type is @@ -688,10 +689,8 @@ /// \brief Scaling factor for primal solution /// - /// Scaling factor for primal solution. It is equal to 2 or 1 - /// according to the value type. - static const int primalScale = - std::numeric_limits::is_integer ? 2 : 1; + /// Scaling factor for primal solution. + static const int primalScale = 2; /// \brief Scaling factor for dual solution /// @@ -1329,10 +1328,9 @@ /// "primal scale". /// /// \pre Either run() or start() must be called before using this function. - Value matching(const Edge& edge) const { - return Value(edge == (*_matching)[_graph.u(edge)] ? 1 : 0) - * primalScale / 2 + Value(edge == (*_matching)[_graph.v(edge)] ? 1 : 0) - * primalScale / 2; + int matching(const Edge& edge) const { + return (edge == (*_matching)[_graph.u(edge)] ? 1 : 0) + + (edge == (*_matching)[_graph.v(edge)] ? 1 : 0); } /// \brief Return the fractional matching arc (or edge) incident @@ -1423,11 +1421,12 @@ /// The algorithm can be executed with the run() function. /// After it the matching (the primal solution) and the dual solution /// can be obtained using the query functions. - - /// If the value type is integer, then the primal and the dual - /// solutions are multiplied by - /// \ref MaxWeightedPerfectFractionalMatching::primalScale "2" and - /// \ref MaxWeightedPerfectFractionalMatching::dualScale "4" respectively. + /// + /// The primal solution is multiplied by + /// \ref MaxWeightedPerfectFractionalMatching::primalScale "2". + /// If the value type is integer, then the dual + /// solution is scaled by + /// \ref MaxWeightedPerfectFractionalMatching::dualScale "4". /// /// \tparam GR The undirected graph type the algorithm runs on. /// \tparam WM The type edge weight map. The default type is @@ -1454,10 +1453,8 @@ /// \brief Scaling factor for primal solution /// - /// Scaling factor for primal solution. It is equal to 2 or 1 - /// according to the value type. - static const int primalScale = - std::numeric_limits::is_integer ? 2 : 1; + /// Scaling factor for primal solution. + static const int primalScale = 2; /// \brief Scaling factor for dual solution /// @@ -2064,10 +2061,9 @@ /// "primal scale". /// /// \pre Either run() or start() must be called before using this function. - Value matching(const Edge& edge) const { - return Value(edge == (*_matching)[_graph.u(edge)] ? 1 : 0) - * primalScale / 2 + Value(edge == (*_matching)[_graph.v(edge)] ? 1 : 0) - * primalScale / 2; + int matching(const Edge& edge) const { + return (edge == (*_matching)[_graph.u(edge)] ? 1 : 0) + + (edge == (*_matching)[_graph.v(edge)] ? 1 : 0); } /// \brief Return the fractional matching arc (or edge) incident diff --git a/test/fractional_matching_test.cc b/test/fractional_matching_test.cc --- a/test/fractional_matching_test.cc +++ b/test/fractional_matching_test.cc @@ -236,6 +236,12 @@ } check(pv == mfm.matchingSize(), "Wrong matching size"); + for (SmartGraph::EdgeIt e(graph); e != INVALID; ++e) { + check((e == mfm.matching(graph.u(e)) ? 1 : 0) + + (e == mfm.matching(graph.v(e)) ? 1 : 0) == + mfm.matching(e), "Invalid matching"); + } + SmartGraph::NodeMap processed(graph, false); for (SmartGraph::NodeIt n(graph); n != INVALID; ++n) { if (processed[n]) continue; @@ -284,6 +290,11 @@ check(mfm.matching(n) != INVALID, "Invalid matching"); check(indeg == 1, "Invalid matching"); } + for (SmartGraph::EdgeIt e(graph); e != INVALID; ++e) { + check((e == mfm.matching(graph.u(e)) ? 1 : 0) + + (e == mfm.matching(graph.v(e)) ? 1 : 0) == + mfm.matching(e), "Invalid matching"); + } } else { int anum = 0, bnum = 0; SmartGraph::NodeMap neighbours(graph, false); @@ -337,6 +348,12 @@ } } + for (SmartGraph::EdgeIt e(graph); e != INVALID; ++e) { + check((e == mwfm.matching(graph.u(e)) ? 1 : 0) + + (e == mwfm.matching(graph.v(e)) ? 1 : 0) == + mwfm.matching(e), "Invalid matching"); + } + int dv = 0; for (SmartGraph::NodeIt n(graph); n != INVALID; ++n) { dv += mwfm.nodeValue(n); @@ -391,6 +408,12 @@ SmartGraph::Node o = graph.target(mwpfm.matching(n)); } + for (SmartGraph::EdgeIt e(graph); e != INVALID; ++e) { + check((e == mwpfm.matching(graph.u(e)) ? 1 : 0) + + (e == mwpfm.matching(graph.v(e)) ? 1 : 0) == + mwpfm.matching(e), "Invalid matching"); + } + int dv = 0; for (SmartGraph::NodeIt n(graph); n != INVALID; ++n) { dv += mwpfm.nodeValue(n);