Skip to content

Commit ff24673

Browse files
committed
warnings
1 parent 21d2156 commit ff24673

File tree

12 files changed

+39
-34
lines changed

12 files changed

+39
-34
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class MCMgraph {
198198
e.dst->in.remove(&e);
199199
}
200200

201-
void relabelNodeIds(std::map<int, int> *nodeIdMap = nullptr);
201+
void relabelNodeIds(std::map<CId, CId> *nodeIdMap = nullptr);
202202

203203
// reduce the MCM graph by removing obviously redundant edges
204204
// in particular if there are multiple edges between the same pair

src/algebra/mpmatrix.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ Matrix::mp_generalized_eigenvectors() const {
10891089
sccMapInv[k] = scc.get();
10901090

10911091
// MCM calculation requires node relabelling
1092-
std::map<int, int> sccNodeIdMap;
1092+
std::map<CId, CId> sccNodeIdMap;
10931093
scc->relabelNodeIds(&sccNodeIdMap);
10941094

10951095
if (scc->nrVisibleEdges() > 0) {

src/base/analysis/mcm/mcmdg.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace Graphs {
6161
CDouble mcmDG_SCC(MCMgraph &mcmGraph) {
6262

6363
// Allocate memory
64-
const int n = mcmGraph.nrVisibleNodes();
64+
const int n = static_cast<int>(mcmGraph.nrVisibleNodes());
6565
std::vector<int> level(n);
6666
std::vector<std::vector<int>> pi(n + 1, std::vector<int>(n));
6767
std::vector<std::vector<int>> d(n + 1, std::vector<int>(n));
@@ -134,7 +134,7 @@ CDouble mcmDG(MCMgraph &mcmGraph) {
134134
MCMgraphs sccs;
135135
stronglyConnectedMCMgraph(mcmGraph, sccs, false);
136136

137-
CDouble mcm = -INFINITY;
137+
auto mcm = static_cast<CDouble>(-INFINITY);
138138
for (auto &scc : sccs) {
139139
scc->relabelNodeIds();
140140
CDouble cmcm = mcmDG_SCC(*scc);

src/base/analysis/mcm/mcmgraph.cc

+8-4
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,12 @@ static void addLongestDelayEdgeForNode(MCMgraph &g, MCMnode &n, MCMedge &e) {
225225
// Node m reachable from n and not connected directly to n via e?
226226
if (d[m->id] > 0 && e.dst->id != m->id) {
227227
// Create an edge between n and m
228-
MCMedge *eN = g.addEdge(
229-
static_cast<CId>(g.getEdges().size()), n, *m, d[m->id], e.d, false); // e.d should always be 1
228+
MCMedge *eN = g.addEdge(static_cast<CId>(g.getEdges().size()),
229+
n,
230+
*m,
231+
d[m->id],
232+
e.d,
233+
false); // e.d should always be 1
230234
n.out.push_back(eN);
231235
m->in.push_back(eN);
232236
}
@@ -435,7 +439,7 @@ static void addNodeToComponent(const MCMnode &n, MCMgraph &comp) {
435439
// in the previous loop already
436440
for (const auto &e : n.in) {
437441
// Is source node in the component?
438-
for (auto& iterN : comp.getNodes()) {
442+
for (auto &iterN : comp.getNodes()) {
439443
// if the source node is in the component and it is not a self-edge
440444
if ((e->src->id == iterN.id) && (e->src->id != e->dst->id)) {
441445
// Add a copy of the edge to the component
@@ -757,7 +761,7 @@ CDouble MCMgraph::calculateMaximumCycleRatioAndCriticalCycleYoungTarjanOrlin(
757761
return maxCycleRatioAndCriticalCycleYoungTarjanOrlin(*this, cycle);
758762
}
759763

760-
void MCMgraph::relabelNodeIds(std::map<int, int> *nodeIdMap) {
764+
void MCMgraph::relabelNodeIds(std::map<CId, CId> *nodeIdMap) {
761765
int k = 0;
762766
for (auto &i : this->nodes) {
763767
MCMnode &n = i;

src/base/analysis/mcm/mcmhoward.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ CDouble maximumCycleMeanHowardGeneral(MCMgraph &g, MCMnode **criticalNode) {
575575
*criticalNode = nullptr;
576576
}
577577
for (auto &scc : sccs) {
578-
std::map<int, int> nodeMap;
578+
std::map<CId, CId> nodeMap;
579579
scc->relabelNodeIds(&nodeMap);
580580
MCMnode *sccCriticalNode = nullptr;
581581
;

src/base/analysis/mcm/mcmkarp.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ CDouble maximumCycleMeanKarpGeneral(MCMgraph& g) {
109109
MCMgraphs sccs;
110110
stronglyConnectedMCMgraph(g, sccs, false);
111111

112-
CDouble mcm = -INFINITY;
112+
auto mcm = static_cast<CDouble>(-INFINITY);
113113
for (auto &scc : sccs) {
114-
std::map<int, int> nodeMap;
114+
std::map<CId, CId> nodeMap;
115115
scc->relabelNodeIds(&nodeMap);
116116
MCMnode *sccCriticalNode = nullptr;
117117
;
@@ -189,12 +189,12 @@ CDouble maximumCycleMeanKarpDoubleGeneral(MCMgraph &g, const MCMnode **criticalN
189189
MCMgraphs sccs;
190190
stronglyConnectedMCMgraph(g, sccs, false);
191191

192-
CDouble mcm = -INFINITY;
192+
auto mcm = static_cast<CDouble>(-INFINITY);
193193
if (criticalNode != nullptr) {
194194
*criticalNode = nullptr;
195195
}
196196
for (auto &scc : sccs) {
197-
std::map<int, int> nodeMap;
197+
std::map<CId, CId> nodeMap;
198198
scc->relabelNodeIds(&nodeMap);
199199
const MCMnode *sccCriticalNode = nullptr;
200200
;

src/base/analysis/mcm/mcmyto.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -940,20 +940,20 @@ void convertMCMgraphToYTOgraph(MCMgraph &g,
940940
CDouble (*costFunction)(const MCMedge& e),
941941
CDouble (*transit_timeFunction)(const MCMedge& e)) {
942942

943-
gr.n_nodes = g.nrVisibleNodes();
944-
gr.n_arcs = g.nrVisibleEdges();
943+
gr.n_nodes = static_cast<int>(g.nrVisibleNodes());
944+
gr.n_arcs = static_cast<int>(g.nrVisibleEdges());
945945
// allocate space for the nodes, plus one for the exta source node that will be added
946946
gr.nodes.resize(gr.n_nodes + 1);
947947
gr.arcs.resize(gr.n_arcs + gr.n_nodes);
948948

949949
// create nodes
950950
// keep an index of node id's
951-
std::map<int,int> nodeIndex;
951+
std::map<CId,CId> nodeIndex;
952952
uint ind = 0;
953953
for (const auto &n : g.getNodes()) {
954954
nodeIndex[n.id] = ind;
955955
node& x = (gr.nodes)[ind];
956-
x.id = n.id + 1;
956+
x.id = static_cast<int>(n.id + 1);
957957
x.first_arc_out = nullptr;
958958
x.first_arc_in = nullptr;
959959

src/graph/mpautomaton.cc

+11-11
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ CDouble MaxPlusAutomatonWithRewards::calculateMCR(){
1616

1717
std::map<const ::FSM::Abstract::State*, MCMnode*> nodeMap;
1818

19-
for (auto s: this->getStates()) {
20-
auto n = g.addNode(nId++);
19+
for (const auto& s: this->getStates()) {
20+
auto *n = g.addNode(nId++);
2121
nodeMap[&(*(s.second))] = n;
2222
}
2323

2424
CId eId = 0;
25-
for (auto s: this->getStates()) {
26-
for(auto e: (s.second)->getOutgoingEdges()) {
27-
auto mpae = dynamic_cast<MPAREdge*>(e);
25+
for (const auto& s: this->getStates()) {
26+
for(auto *e: (s.second)->getOutgoingEdges()) {
27+
auto *mpae = dynamic_cast<MPAREdge*>(e);
2828
g.addEdge(eId++, *nodeMap[&(mpae->getSource())], *nodeMap[&(mpae->getDestination())], static_cast<CDouble>(mpae->getLabel().delay), mpae->getLabel().reward);
2929
}
3030
}
@@ -42,17 +42,17 @@ CDouble MaxPlusAutomatonWithRewards::calculateMCRAndCycle(std::shared_ptr<std::v
4242
CId nId = 0;
4343
std::map<const ::FSM::Abstract::State*, MCMnode*> nodeMap;
4444

45-
for (auto s: this->getStates()) {
46-
auto n = g.addNode(nId++);
45+
for (const auto& s: this->getStates()) {
46+
auto *n = g.addNode(nId++);
4747
nodeMap[&(*(s.second))] = n;
4848
}
4949

5050
CId eId = 0;
5151
std::map<const MCMedge*, const MPAREdge*> edgeMap;
5252

53-
for (auto s: this->getStates()) {
54-
for(auto e: (s.second)->getOutgoingEdges()) {
55-
auto mpae = dynamic_cast<MPAREdge*>(e);
53+
for (const auto& s: this->getStates()) {
54+
for(auto *e: (s.second)->getOutgoingEdges()) {
55+
auto *mpae = dynamic_cast<MPAREdge*>(e);
5656
g.addEdge(eId++, *nodeMap[&(mpae->getSource())], *nodeMap[&(mpae->getDestination())], static_cast<CDouble>(mpae->getLabel().delay), mpae->getLabel().reward);
5757
}
5858
}
@@ -61,7 +61,7 @@ CDouble MaxPlusAutomatonWithRewards::calculateMCRAndCycle(std::shared_ptr<std::v
6161
CDouble mcr = maxCycleRatioAndCriticalCycleYoungTarjanOrlin(g, &mcmCycle);
6262
if (cycle != nullptr) {
6363
*cycle = std::make_shared<std::vector<const MPAREdge*>>();
64-
for (auto e: *mcmCycle) {
64+
for (const auto *e: *mcmCycle) {
6565
(*cycle)->push_back(edgeMap[e]);
6666
}
6767
}

src/testbench/algebra/testing.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace testing {
4040

4141
#define ASSERT_APPROX_EQUAL( x, y, eps ) \
4242
{ \
43-
if( abs(( x ) - ( y )) > eps ) \
43+
if( std::abs(( x ) - ( y )) > eps ) \
4444
{ \
4545
throw std::runtime_error( std::string( "Asserted approximate equality violated." ) \
4646
+ std::string( "\nIn:" ) \

src/testbench/base/mcmtest.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "mcmtest.h"
1010
#include "testing.h"
1111
#include <random>
12+
#include <type_traits>
1213

1314

1415
using namespace MaxPlus;
@@ -216,7 +217,7 @@ void MCMTest::test_yto() {
216217
ASSERT_THROW(eid == 6);
217218

218219
// TODO: check of the cycle ratio are identical to old SDF3
219-
CDouble expectedMinCycleRatios[] = {
220+
std::array<CDouble,250> expectedMinCycleRatios = {
220221
0.526141, 0.124523, 0.0389826, 0.289127, 0.11451, 0.723313, 1.07027,
221222
0.956067, 0.570066, 0.746341, 0.33622, 0.475978, 0.902663, 1.02951,
222223
0.088711, 0.269878, 0.213763, 0.468927, 2.13632, 0.564086, 0.656227,
@@ -262,12 +263,12 @@ void MCMTest::test_yto() {
262263
//std::cout << "MCM: " << result << "cycle length: " << cycle->size() << std::endl;
263264
}
264265

265-
CDouble expectedMaxCycleRatios[] = {
266+
std::array<CDouble, 25> expectedMaxCycleRatios = {
266267
304.647, 122.759, 104.209, 126.85, 1341.83, 135.611, 186.801, 151.854, 341.077,
267268
216.21, 148.74, 117.382, 127.863, 246.385, 92.0357, 72.9353, 124.893, 202.074,
268269
281.92, 481.408, 253.295, 849.381, 123.668, 64.0955, 219.92};
269270
// go through a bunch of (deterministic) big pseudo-random graphs
270-
for (int k = 0; k < 25; k++) {
271+
for (int k = 0; k < expectedMaxCycleRatios.size(); k++) {
271272
MCMgraph gr = makeRandomGraph(1000, 100000, k);
272273
result = maxCycleRatioAndCriticalCycleYoungTarjanOrlin(gr, &cycle);
273274
ASSERT_APPROX_EQUAL(expectedMaxCycleRatios[k], result, 1e-2);

src/testbench/base/testing.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace testing {
4040

4141
#define ASSERT_APPROX_EQUAL( x, y, eps ) \
4242
{ \
43-
if( abs(( x ) - ( y )) > eps ) \
43+
if( std::abs(( x ) - ( y )) > eps ) \
4444
{ \
4545
throw std::runtime_error( std::string( "Asserted approximate equality violated." ) \
4646
+ std::string( "\nIn:" ) \

src/testbench/graph/testing.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace testing {
3838

3939
#define ASSERT_APPROX_EQUAL( x, y, eps ) \
4040
{ \
41-
if( abs(( x ) - ( y )) > eps ) \
41+
if( std::abs(( x ) - ( y )) > eps ) \
4242
{ \
4343
throw std::runtime_error( std::string( "Asserted approximate equality violated." ) \
4444
+ std::string( "\nIn:" ) \

0 commit comments

Comments
 (0)