COIN-OR::LEMON - Graph Library

Ticket #604: da78005589e9.patch

File da78005589e9.patch, 2.9 KB (added by Alpar Juttner, 8 years ago)
  • lemon/matching.h

    # HG changeset patch
    # User Alpar Juttner <alpar@cs.elte.hu>
    # Date 1467812647 -7200
    #      Wed Jul 06 15:44:07 2016 +0200
    # Node ID da78005589e9653d8b57b000bcae9f0436471ed0
    # Parent  f51c01a1b88eead63515a8b22f6f380595245a42
    MaxMatching speed improvement for odd graphs (#604)
    
    diff --git a/lemon/matching.h b/lemon/matching.h
    a b  
    22 *
    33 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    5  * Copyright (C) 2003-2013
     5 * Copyright (C) 2003-2016
    66 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77 * (Egervary Research Group on Combinatorial Optimization, EGRES).
    88 *
     
    102102    const Graph& _graph;
    103103    MatchingMap* _matching;
    104104    StatusMap* _status;
     105    int _matching_size;
    105106
    106107    EarMap* _ear;
    107108
     
    401402        }
    402403      }
    403404      _tree_set->eraseClass(tree);
    404 
     405      _matching_size++;
    405406    }
    406407
    407408  public:
     
    437438        (*_matching)[n] = INVALID;
    438439        (*_status)[n] = UNMATCHED;
    439440      }
     441      _matching_size=0;
    440442    }
    441443
    442444    /// \brief Find an initial matching in a greedy way.
     
    444446    /// This function finds an initial matching in a greedy way.
    445447    void greedyInit() {
    446448      createStructures();
     449      _matching_size=0;
    447450      for (NodeIt n(_graph); n != INVALID; ++n) {
    448451        (*_matching)[n] = INVALID;
    449452        (*_status)[n] = UNMATCHED;
     
    457460              (*_status)[n] = MATCHED;
    458461              (*_matching)[v] = _graph.oppositeArc(a);
    459462              (*_status)[v] = MATCHED;
     463              _matching_size++;
    460464              break;
    461465            }
    462466          }
     
    474478    template <typename MatchingMap>
    475479    bool matchingInit(const MatchingMap& matching) {
    476480      createStructures();
     481      _matching_size=0;
    477482
    478483      for (NodeIt n(_graph); n != INVALID; ++n) {
    479484        (*_matching)[n] = INVALID;
     
    491496          if ((*_matching)[v] != INVALID) return false;
    492497          (*_matching)[v] = _graph.direct(e, false);
    493498          (*_status)[v] = MATCHED;
     499
     500          _matching_size++;
    494501        }
    495502      }
    496503      return true;
     
    503510    /// \pre \ref init(), \ref greedyInit() or \ref matchingInit() must be
    504511    /// called before using this function.
    505512    void startSparse() {
    506       for(NodeIt n(_graph); n != INVALID; ++n) {
     513      for(NodeIt n(_graph); _matching_size*2<_node_num-1 && n!=INVALID; ++n) {
    507514        if ((*_status)[n] == UNMATCHED) {
    508515          (*_blossom_rep)[_blossom_set->insert(n)] = n;
    509516          _tree_set->insert(n);
     
    522529    /// \pre \ref init(), \ref greedyInit() or \ref matchingInit() must be
    523530    /// called before using this function.
    524531    void startDense() {
    525       for(NodeIt n(_graph); n != INVALID; ++n) {
     532      for(NodeIt n(_graph);  _matching_size*2<_node_num-1 && n!=INVALID; ++n) {
    526533        if ((*_status)[n] == UNMATCHED) {
    527534          (*_blossom_rep)[_blossom_set->insert(n)] = n;
    528535          _tree_set->insert(n);