Skip to content

Commit 0edaa5a

Browse files
committed
remove unnecessary shared_ptr
1 parent def6642 commit 0edaa5a

File tree

6 files changed

+33
-36
lines changed

6 files changed

+33
-36
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class MCMgraph {
211211
calculateMaximumCycleMeanKarpDouble(const MCMnode **criticalNode = nullptr);
212212

213213
[[nodiscard]] CDouble calculateMaximumCycleRatioAndCriticalCycleYoungTarjanOrlin(
214-
std::shared_ptr<std::vector<const MCMedge*>> *cycle = nullptr);
214+
std::vector<const MCMedge*> *cycle = nullptr);
215215

216216
[[nodiscard]] std::shared_ptr<MCMgraph> normalize(CDouble mu) const;
217217
[[nodiscard]] std::shared_ptr<MCMgraph> normalize(const std::map<CId, CDouble> &mu) const;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ CDouble maxCycleMeanYoungTarjanOrlin(MCMgraph& mcmGraph);
116116
/// @param cycle Pointer to the critical cycle
117117
/// @return the MCM and a critical cycle
118118
CDouble
119-
maxCycleMeanAndCriticalCycleYoungTarjanOrlin(MCMgraph& mcmGraph, std::shared_ptr<std::vector<const MCMedge*>> *cycle);
119+
maxCycleMeanAndCriticalCycleYoungTarjanOrlin(MCMgraph& mcmGraph, std::vector<const MCMedge*> *cycle);
120120

121121

122122
/**
@@ -135,7 +135,7 @@ CDouble maxCycleRatioYoungTarjanOrlin(MCMgraph& mcmGraph);
135135
* to an array of *MCMEdges of the critical cycle/
136136
*/
137137
CDouble
138-
maxCycleRatioAndCriticalCycleYoungTarjanOrlin(MCMgraph& mcmGraph, std::shared_ptr<std::vector<const MCMedge*>> *cycle);
138+
maxCycleRatioAndCriticalCycleYoungTarjanOrlin(MCMgraph& mcmGraph, std::vector<const MCMedge*> *cycle);
139139

140140
/**
141141
* minCycleRatioYoungTarjanOrlin ()
@@ -153,7 +153,7 @@ CDouble minCycleRatioYoungTarjanOrlin(MCMgraph& mcmGraph);
153153
* to an array of *MCMEdges of the critical cycle.
154154
*/
155155
CDouble
156-
minCycleRatioAndCriticalCycleYoungTarjanOrlin(MCMgraph& mcmGraph, std::shared_ptr<std::vector<const MCMedge*>> *cycle);
156+
minCycleRatioAndCriticalCycleYoungTarjanOrlin(MCMgraph& mcmGraph, std::vector<const MCMedge*> *cycle);
157157

158158
/**
159159
* getDelay ()
@@ -186,7 +186,7 @@ void convertMCMgraphToYTOgraph(MCMgraph& g,
186186
* edges, alternatively called "length" or "weight".
187187
*/
188188

189-
void mmcycle(graph& gr, CDouble *lambda, std::shared_ptr<std::vector<const arc*>> *cycle);
189+
void mmcycle(graph& gr, CDouble *lambda, std::vector<const arc*> *cycle);
190190

191191
} // namespace Graphs
192192

src/base/analysis/mcm/mcmgraph.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ CDouble MCMgraph::calculateMaximumCycleMeanKarpDouble(const MCMnode **criticalNo
730730
}
731731

732732
CDouble MCMgraph::calculateMaximumCycleRatioAndCriticalCycleYoungTarjanOrlin(
733-
std::shared_ptr<std::vector<const MCMedge *>> *cycle) {
733+
std::vector<const MCMedge *> *cycle) {
734734
return maxCycleRatioAndCriticalCycleYoungTarjanOrlin(*this, cycle);
735735
}
736736

src/base/analysis/mcm/mcmyto.cc

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ class AlgYTO {
658658
* TODO: see if the algorithms can be unified to remove duplicate code
659659
**/
660660

661-
void mmcycle_robust(graph &gr, CDouble *lambda, std::shared_ptr<std::vector<const arc*>> *cycle) {
661+
void mmcycle_robust(graph &gr, CDouble *lambda, std::vector<const arc*> *cycle) {
662662
const CDouble MCR_EPSILON_RATIO = 1.0e-8L;
663663

664664
// set up initial tree
@@ -914,12 +914,12 @@ class AlgYTO {
914914
}
915915

916916
if (cycle != nullptr) {
917-
*cycle = std::make_shared<std::vector<const arc*>>();
917+
*cycle = std::vector<const arc*>();
918918
if (min_a_ptr != NILA) {
919-
(*cycle)->push_back(min_a_ptr);
919+
cycle -> push_back(min_a_ptr);
920920
a_ptr = min_a_ptr->tail->parent_in;
921921
while (a_ptr->head != min_a_ptr->head) {
922-
(*cycle)->push_back(a_ptr);
922+
cycle -> push_back(a_ptr);
923923
a_ptr = a_ptr->tail->parent_in;
924924
}
925925
}
@@ -1078,7 +1078,7 @@ CDouble getDelay(const MCMedge& e) { return e.d; }
10781078
*/
10791079
CDouble
10801080
maxCycleMeanAndCriticalCycleYoungTarjanOrlin(MCMgraph &mcmGraph,
1081-
std::shared_ptr<std::vector<const MCMedge *>> *cycle) {
1081+
std::vector<const MCMedge *> *cycle) {
10821082
graph ytoGraph;
10831083

10841084
// Convert the graph to an input graph for the YTO algorithm
@@ -1088,17 +1088,17 @@ maxCycleMeanAndCriticalCycleYoungTarjanOrlin(MCMgraph &mcmGraph,
10881088

10891089
CDouble min_cr = 0;
10901090
if (cycle != nullptr) {
1091-
std::shared_ptr<std::vector<const arc*>> ytoCycle = nullptr;
1091+
std::vector<const arc*> ytoCycle;
10921092

10931093
// Find maximum cycle mean
10941094
std::int32_t ytoCycLen = 0;
10951095
alg.mmcycle_robust(ytoGraph, &min_cr, &ytoCycle);
10961096

1097-
size_t len = ytoCycle->size();
1097+
size_t len = ytoCycle.size();
10981098

1099-
*cycle = std::make_shared<std::vector<const MCMedge*>>(len);
1099+
*cycle = std::vector<const MCMedge*>(len);
11001100
for (uint i = 0; i < len; i++) {
1101-
(*cycle)->at(i) = ytoCycle->at(i)->mcmEdge;
1101+
(*cycle).at(i) = ytoCycle.at(i)->mcmEdge;
11021102
}
11031103

11041104
} else {
@@ -1131,14 +1131,11 @@ CDouble maxCycleMeanYoungTarjanOrlin(MCMgraph &mcmGraph) {
11311131
*/
11321132

11331133
CDouble maxCycleRatioAndCriticalCycleYoungTarjanOrlin(MCMgraph &mcmGraph,
1134-
std::shared_ptr<std::vector<const MCMedge*>> *cycle) {
1134+
std::vector<const MCMedge*> *cycle) {
11351135
graph ytoGraph;
11361136

11371137
// catch special case when the graph has no edges
11381138
if (mcmGraph.nrVisibleEdges() == 0) {
1139-
if (cycle != nullptr) {
1140-
*cycle = nullptr;
1141-
}
11421139
return 0.0;
11431140
}
11441141

@@ -1150,19 +1147,19 @@ CDouble maxCycleRatioAndCriticalCycleYoungTarjanOrlin(MCMgraph &mcmGraph,
11501147
CDouble min_cr = 0;
11511148
if (cycle != nullptr) {
11521149

1153-
std::shared_ptr<std::vector<const arc*>> ytoCycle = nullptr;
1150+
std::vector<const arc*> ytoCycle;
11541151

11551152
// Find maximum cycle ratio
11561153
std::int32_t ytoCycLen = 0;
11571154
alg.mmcycle_robust(ytoGraph, &min_cr, &ytoCycle);
11581155

1159-
*cycle = std::make_shared<std::vector<const MCMedge *>>(ytoCycle->size());
1156+
*cycle = std::vector<const MCMedge *>(ytoCycle.size());
11601157

11611158
// note that mmcycle returns the critical cycle following edges backwards
11621159
// therefore reverse the order of the edges.
1163-
size_t len = ytoCycle->size();
1160+
size_t len = ytoCycle.size();
11641161
for (uint i = 0; i < len; i++) {
1165-
(*cycle)->at(i) = (*ytoCycle)[len - 1 - i]->mcmEdge;
1162+
cycle->at(i) = ytoCycle[len - 1 - i]->mcmEdge;
11661163
}
11671164

11681165
} else {
@@ -1193,7 +1190,7 @@ CDouble maxCycleRatioYoungTarjanOrlin(MCMgraph &mcmGraph) {
11931190
*/
11941191

11951192
CDouble minCycleRatioAndCriticalCycleYoungTarjanOrlin(MCMgraph &mcmGraph,
1196-
std::shared_ptr<std::vector<const MCMedge*>> *cycle) {
1193+
std::vector<const MCMedge*> *cycle) {
11971194
graph ytoGraph;
11981195

11991196
// Convert the graph to an input graph for the YTO algorithm
@@ -1204,18 +1201,18 @@ CDouble minCycleRatioAndCriticalCycleYoungTarjanOrlin(MCMgraph &mcmGraph,
12041201
CDouble min_cr = 0;
12051202
if (cycle != nullptr) {
12061203

1207-
std::shared_ptr<std::vector<const arc*>> ytoCycle = nullptr;
1204+
std::vector<const arc*> ytoCycle;
12081205

12091206
// Find minimum cycle ratio
12101207
std::int32_t ytoCycLen = 0;
12111208
alg.mmcycle_robust(ytoGraph, &min_cr, &ytoCycle);
12121209

1213-
size_t len = (*ytoCycle).size();
1214-
*cycle = std::make_shared<std::vector<const MCMedge*>>(len);
1210+
size_t len = ytoCycle.size();
1211+
*cycle = std::vector<const MCMedge*>(len);
12151212

12161213

12171214
for (uint i = 0; i < len; i++) {
1218-
(*cycle)->at(i) = (*ytoCycle)[i]->mcmEdge;
1215+
cycle->at(i) = ytoCycle[i]->mcmEdge;
12191216
}
12201217

12211218
} else {

src/graph/mpautomaton.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CDouble MaxPlusAutomatonWithRewards::calculateMCR(){
2929
}
3030
}
3131

32-
std::shared_ptr<std::vector<const MCMedge*>> cycle;
32+
std::vector<const MCMedge*> cycle;
3333
CDouble mcr = maxCycleRatioAndCriticalCycleYoungTarjanOrlin(g, &cycle);
3434

3535
return mcr;
@@ -57,11 +57,11 @@ CDouble MaxPlusAutomatonWithRewards::calculateMCRAndCycle(std::shared_ptr<std::v
5757
}
5858
}
5959

60-
std::shared_ptr<std::vector<const MCMedge*>> mcmCycle;
60+
std::vector<const MCMedge*> mcmCycle;
6161
CDouble mcr = maxCycleRatioAndCriticalCycleYoungTarjanOrlin(g, &mcmCycle);
6262
if (cycle != nullptr) {
6363
*cycle = std::make_shared<std::vector<const MPAREdge*>>();
64-
for (const auto *e: *mcmCycle) {
64+
for (const auto *e: mcmCycle) {
6565
(*cycle)->push_back(edgeMap[e]);
6666
}
6767
}

src/testbench/base/mcmtest.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,27 +193,27 @@ void MCMTest::test_yto() {
193193
CDouble result = maxCycleMeanYoungTarjanOrlin(g1);
194194
ASSERT_APPROX_EQUAL(2.5, result, 1e-5);
195195

196-
std::shared_ptr<std::vector<const MCMedge *>> cycle;
196+
std::vector<const MCMedge *> cycle;
197197
result = maxCycleMeanAndCriticalCycleYoungTarjanOrlin(g1, &cycle);
198198
ASSERT_APPROX_EQUAL(2.5, result, 1e-5);
199-
ASSERT_THROW(cycle->size() == 4);
200-
int eid = cycle->at(0)->id;
199+
ASSERT_THROW(cycle.size() == 4);
200+
int eid = cycle.at(0)->id;
201201
ASSERT_THROW(eid == 0 || eid == 1 || eid == 2 || eid == 3);
202202

203203
result = maxCycleRatioYoungTarjanOrlin(g1);
204204
ASSERT_APPROX_EQUAL(10.0 / 3.0, result, 1e-5);
205205

206206
result = maxCycleRatioAndCriticalCycleYoungTarjanOrlin(g1, &cycle);
207207
ASSERT_APPROX_EQUAL(10.0 / 3.0, result, 1e-5);
208-
eid = cycle->at(0)->id;
208+
eid = cycle.at(0)->id;
209209
ASSERT_THROW(eid == 4);
210210

211211
result = minCycleRatioYoungTarjanOrlin(g1);
212212
ASSERT_APPROX_EQUAL(1.0, result, 1e-5);
213213

214214
result = minCycleRatioAndCriticalCycleYoungTarjanOrlin(g1, &cycle);
215215
ASSERT_APPROX_EQUAL(1.0, result, 1e-5);
216-
eid = cycle->at(0)->id;
216+
eid = cycle.at(0)->id;
217217
ASSERT_THROW(eid == 6);
218218

219219
// TODO: check of the cycle ratio are identical to old SDF3

0 commit comments

Comments
 (0)