Skip to content

Commit ceb0444

Browse files
committed
Seeds implementation and randomness in simulations
1 parent 6e85441 commit ceb0444

2 files changed

Lines changed: 45 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### ROADMAP
99
- Switch to new domain.
1010

11+
## [2.1.0] - 2025-04-XX
12+
13+
### Added
14+
- Seeds implementation and randomness in simulations.
15+
- FirstFit as default algorithm inside main.cpp file.
16+
1117
## [2.0.2] - 2025-03-12
1218

1319
### Added
@@ -108,4 +114,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
108114
[1.1.1]: https://github.com/MirkoZETA/FlexNetSim-API/compare/v1.1.0...pipeline-fix
109115
[2.0.0]: https://github.com/MirkoZETA/FlexNetSim-API/compare/pipeline-fix...v2.0.0
110116
[2.0.1]: https://github.com/MirkoZETA/FlexNetSim-API/compare/v2.0.0...v2.0.1
111-
[2.0.2]: https://github.com/MirkoZETA/FlexNetSim-API/compare/v2.0.1...v2.0.2
117+
[2.0.2]: https://github.com/MirkoZETA/FlexNetSim-API/compare/v2.0.1...v2.0.2
118+
[2.1.0]: https://github.com/MirkoZETA/FlexNetSim-API/compare/v2.0.2...v2.1.0

src/main.cpp

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "simulator.hpp"
2+
#include <random>
3+
#include <chrono>
24

35
unsigned int K;
46

@@ -120,7 +122,16 @@ END_ALLOC_FUNCTION
120122
int main(int argc, char *argv[])
121123
{
122124
if (argc < 10) {
123-
std::cerr << "Uso: " << argv[0] << " <AlgorithmName> <networkType> <goalConnections> <confidence> <lambda> <mu> <networkName> <bitrate> <K>" << std::endl;
125+
std::cerr << "Uso: " << argv[0] << "<AlgorithmName> "
126+
<< "<networkType> "
127+
<< "<goalConnections> "
128+
<< "<confidence> "
129+
<< "<lambda> "
130+
<< "<mu> "
131+
<< "<networkName> "
132+
<< "<bitrate> "
133+
<< "<K> "
134+
<< std::endl;
124135
return 1;
125136
}
126137

@@ -132,32 +143,41 @@ int main(int argc, char *argv[])
132143
K = std::stoi(argv[9]);
133144
std::string networkName = argv[7];
134145
std::string bitrate = argv[8];
135-
136-
// We're no longer doing validation here as it's handled by the API layer
146+
147+
std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
137148

138149
Simulator sim(
139150
std::string("./networks/" + networkName + ".json"),
140151
std::string("./networks/" + networkName + "_routes.json"),
141152
std::string("./bitrates/" + bitrate + ".json"),
142153
networkType);
143154

144-
char algoritmo = argv[1][0];
145-
switch (algoritmo)
155+
std::string algoritmo = argv[1];
156+
157+
if (algoritmo == "FirstFit")
146158
{
147-
case 'F':
148159
USE_ALLOC_FUNCTION(FirstFit, sim);
149-
break;
150-
151-
case 'B':
160+
}
161+
else if (algoritmo == "BestFit")
162+
{
152163
USE_ALLOC_FUNCTION(BestFit, sim);
153-
break;
154-
155-
default:
156-
// Still keep this validation for safety
157-
std::cerr << "Invalid algorithm" << std::endl;
158-
return 1;
159-
break;
160164
}
165+
else
166+
{
167+
USE_ALLOC_FUNCTION(FirstFit, sim);
168+
}
169+
170+
int seedArrive = rng();
171+
int seedDeparture = rng();
172+
int seedBitRate = rng();
173+
int seedDst = rng();
174+
int seedSrc = rng();
175+
176+
sim.setSeedArrive(seedArrive);
177+
sim.setSeedDeparture(seedDeparture);
178+
sim.setSeedBitRate(seedBitRate);
179+
sim.setSeedDst(seedDst);
180+
sim.setSeedSrc(seedSrc);
161181

162182
sim.setGoalConnections(goalConnections);
163183
sim.setConfidence(confidence);
@@ -167,7 +187,7 @@ int main(int argc, char *argv[])
167187
sim.run();
168188

169189
// Print the results with flush
170-
// Set the precision to 6 decimal places
190+
// Set the precision to 4 decimal places
171191
std::cout.precision(4);
172192
std::cout << "final_blocking: " << sim.getBlockingProbability() << "\n" << std::flush;
173193

0 commit comments

Comments
 (0)