Skip to content

Commit bcf5b17

Browse files
committed
sync
1 parent 4247b75 commit bcf5b17

File tree

6 files changed

+29
-31
lines changed

6 files changed

+29
-31
lines changed

include/maxplus/base/analysis/mcm/mcm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace Graphs {
5555
* algorithm.
5656
*/
5757
CDouble maximumCycleMeanKarp(const MCMgraph& g);
58-
CDouble maximumCycleMeanKarpDouble(const MCMgraph& g, const MCMnode *criticalNode = nullptr);
58+
CDouble maximumCycleMeanKarpDouble(const MCMgraph& g, MCMnode **criticalNode = nullptr);
5959

6060
/**
6161
* mcmGetAdjacentActors ()

include/maxplus/base/analysis/mcm/mcmgraph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class MCMgraph {
208208
std::shared_ptr<MCMgraph> pruneEdges();
209209

210210
[[nodiscard]] CDouble calculateMaximumCycleMeanKarp() const;
211-
[[nodiscard]] CDouble calculateMaximumCycleMeanKarpDouble(const MCMnode *criticalNode = nullptr) const;
211+
[[nodiscard]] CDouble calculateMaximumCycleMeanKarpDouble(MCMnode** criticalNode = nullptr) const;
212212

213213
[[nodiscard]] CDouble calculateMaximumCycleRatioAndCriticalCycleYoungTarjanOrlin(std::shared_ptr<MCMedge> **cycle = nullptr,
214214
uint *len = nullptr);

src/algebra/mpmatrix.cc

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/base/analysis/mcm/mcmdg.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "base/analysis/mcm/mcmgraph.h"
4343
#include "base/math/cmath.h"
4444
#include <climits>
45+
#include <memory>
4546

4647

4748
namespace Graphs {
@@ -57,10 +58,10 @@ CDouble mcmDG(MCMgraph *mcmGraph) {
5758
int k, n;
5859
int *level;
5960
int **pi, **d;
60-
double l, ld;
61-
MCMnode *u;
61+
CDouble l, ld;
62+
std::shared_ptr<MCMnode> u;
6263
list<int> Q_k;
63-
list<MCMnode *> Q_u;
64+
list<std::shared_ptr<MCMnode>> Q_u;
6465

6566
// Allocate memory
6667
n = mcmGraph->nrVisibleNodes();
@@ -88,8 +89,8 @@ CDouble mcmDG(MCMgraph *mcmGraph) {
8889
Q_u.pop_front();
8990
do {
9091
for (MCMedgesIter iter = u->out.begin(); iter != u->out.end(); iter++) {
91-
MCMedge *e = *iter;
92-
MCMnode *v = e->dst;
92+
std::shared_ptr<MCMedge> e = *iter;
93+
std::shared_ptr<MCMnode> v = e->dst;
9394

9495
if (level[v->id] < k + 1) {
9596
Q_k.push_back(k + 1);
@@ -116,7 +117,7 @@ CDouble mcmDG(MCMgraph *mcmGraph) {
116117
ld = INT_MAX;
117118
k = pi[n][u->id];
118119
while (k > -1) {
119-
ld = MIN(ld, (double)(d[n][u->id] - d[k][u->id]) / (double)(n - k));
120+
ld = MIN(ld, (CDouble)(d[n][u->id] - d[k][u->id]) / (CDouble)(n - k));
120121
k = pi[k][u->id];
121122
}
122123
l = MAX(l, ld);

src/base/analysis/mcm/mcmgraph.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ std::shared_ptr<MCMgraph> MCMgraph::pruneEdges() {
819819

820820
CDouble MCMgraph::calculateMaximumCycleMeanKarp() const { return maximumCycleMeanKarp(*this); }
821821

822-
CDouble MCMgraph::calculateMaximumCycleMeanKarpDouble(const MCMnode *criticalNode) const {
822+
CDouble MCMgraph::calculateMaximumCycleMeanKarpDouble(MCMnode **criticalNode) const {
823823
return maximumCycleMeanKarpDouble(*this, criticalNode);
824824
}
825825

src/base/analysis/mcm/mcmhoward.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "base/exception/exception.h"
5454

5555
#include <math.h>
56+
#include <memory>
5657
#include <stddef.h>
5758
#include <stdio.h>
5859
#include <stdlib.h>
@@ -490,14 +491,15 @@ void Howard(int *ij,
490491
* The function converts a weighted directed graph used in the MCM algorithms
491492
* to a sparse matrix input for Howard's algorithm.
492493
*/
493-
void convertMCMgraphToMatrix(MCMgraph *g, int *ij, double *A) {
494+
void convertMCMgraphToMatrix(const MCMgraph& g, int *ij, double *A) {
494495
int k = 0;
495-
uint i = 0, j = 0;
496-
v_uint mapId(g->getNodes().size());
496+
uint i = 0;
497+
uint j = 0;
498+
v_uint mapId(g.getNodes().size());
497499

498500
// Re-map the id of all visible nodes back to the range [0, g->nrNodes())
499-
for (MCMnodesCIter iter = g->getNodes().begin(); iter != g->getNodes().end(); iter++) {
500-
MCMnode *n = *iter;
501+
for (auto iter = g.getNodes().begin(); iter != g.getNodes().end(); iter++) {
502+
const std::shared_ptr<MCMnode>& n = *iter;
501503

502504
if (n->visible) {
503505
mapId[i] = j;
@@ -507,8 +509,8 @@ void convertMCMgraphToMatrix(MCMgraph *g, int *ij, double *A) {
507509
}
508510

509511
// Create an entry in the matrices for each edge
510-
for (MCMedgesCIter iter = g->getEdges().begin(); iter != g->getEdges().end(); iter++) {
511-
MCMedge *e = *iter;
512+
for (auto iter = g.getEdges().begin(); iter != g.getEdges().end(); iter++) {
513+
const std::shared_ptr<MCMedge>& e = *iter;
512514

513515
// Is the edge a existing edge in the graph?
514516
if (e->visible) {

0 commit comments

Comments
 (0)