@@ -1099,16 +1099,16 @@ Matrix::mp_generalized_eigenvectors() const {
10991099 stronglyConnectedMCMgraph (precGraph, sccs, true );
11001100
11011101 // map from number of SCC to SCC
1102- std::map<uint, MCMgraph * > sccMapInv;
1102+ std::map<uint, std::shared_ptr< MCMgraph> > sccMapInv;
11031103
11041104 // map from node of precGraph to its SCC
1105- std::map<MCMnode * , uint> sccMap;
1105+ std::map<std::weak_ptr< MCMnode> , uint> sccMap;
11061106
11071107 // map from nodes of precGraph to the cycle mean of its SCC
1108- std::map<MCMnode * , MPTime> cycleMeansMap;
1108+ std::map<std::weak_ptr< MCMnode> , MPTime> cycleMeansMap;
11091109
11101110 // vector such that element k is a node from precGraph in the critical path of SCC k
1111- std::vector<MCMnode * > criticalNodes;
1111+ std::vector<std::shared_ptr< MCMnode> > criticalNodes;
11121112
11131113 // vector such that element k is the maximum cycle mean of SCC k
11141114 std::vector<MPTime> cycleMeans;
@@ -1117,7 +1117,7 @@ Matrix::mp_generalized_eigenvectors() const {
11171117 uint k = 0 ;
11181118 // for each SCC
11191119 for (auto scci = sccs.cbegin (); scci != sccs.cend (); scci++, k++) {
1120- MCMgraph * scc = *scci;
1120+ std::shared_ptr< MCMgraph> scc = *scci;
11211121 sccMapInv[k] = scc;
11221122
11231123 // MCM calculation requires node relabelling
@@ -1126,8 +1126,8 @@ Matrix::mp_generalized_eigenvectors() const {
11261126
11271127 if (scc->nrVisibleEdges () > 0 ) {
11281128 // compute MCM mu and critical node n of scc
1129- MCMnode* n;
1130- MPTime mu = MPTime (scc->calculateMaximumCycleMeanKarpDouble (&n));
1129+ MCMnode* n = nullptr ;
1130+ auto mu = MPTime (scc->calculateMaximumCycleMeanKarpDouble (&n));
11311131 criticalNodes.push_back (precGraph.getNode (sccNodeIdMap[n->id ]));
11321132 cycleMeans.push_back (mu);
11331133 } else {
@@ -1136,8 +1136,8 @@ Matrix::mp_generalized_eigenvectors() const {
11361136 cycleMeans.push_back (MP_MINUSINFINITY);
11371137 }
11381138 // for each node in the scc
1139- for (auto *nn : scc-> getNodes ()) {
1140- auto * nnn = precGraph.getNode (sccNodeIdMap[nn ->id ]);
1139+ for (auto nn=precGraph. getNodes (). begin (); nn != precGraph. getNodes (). end (); nn++ ) {
1140+ auto nnn = precGraph.getNode (sccNodeIdMap[(*nn) ->id ]);
11411141 // map node to SCC index
11421142 sccMap[nnn] = k;
11431143 // map node to the cycle mean of its SCC
@@ -1165,7 +1165,7 @@ Matrix::mp_generalized_eigenvectors() const {
11651165 while (change) {
11661166 change = false ;
11671167 // for all edges in precGraph
1168- for (auto * i : precGraph.getEdges ()) {
1168+ for (auto i : precGraph.getEdges ()) {
11691169 MCMedge &e = *i;
11701170 if (trCycleMeans[e.src ->id ] > trCycleMeans[e.dst ->id ]) {
11711171 change = true ;
@@ -1221,11 +1221,6 @@ Matrix::mp_generalized_eigenvectors() const {
12211221 }
12221222 }
12231223
1224- // the SCC graphs still need to be destroyed
1225- for (auto *g : sccs) {
1226- delete g;
1227- }
1228-
12291224 return std::make_pair (eigenVectors, genEigenVectors);
12301225}
12311226
0 commit comments