-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
83 lines (63 loc) · 2.05 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <vector>
#include <cstdlib>
#include "simulator.h"
using namespace std;
int read_params( Simulator::params &p, int argc, char **argv );
void print_params( Simulator::params &p );
/***********************************************************************
* Take simulation parameters from command line and create an appropriate
* instance of Simulator, then run the simulator.
***********************************************************************/
int main( int argc, char **argv )
{
Simulator::params p;
int valid = read_params(p, argc, argv);
if (!valid) {
cerr << "Error: Invalid parameters!" << endl;
return -1;
}
print_params(p);
try {
Simulator sim(p);
sim.run();
} catch (int e) {
cerr << "Something went horribly wrong!" << endl;
}
return 0;
}
/***********************************************************************
* Read the command line arguments into the SimParams struct
***********************************************************************/
int read_params( Simulator::params &p, int argc, char **argv )
{
int valid = 1;
int i;
if (argc > 6) {
p.protocol = argv[1][0];
p.num_stations = atoi(argv[2]);
p.gen_prob = atof(argv[3]);
p.num_slots = atoi(argv[4]);
p.num_trials = atoi(argv[5]);
if (argc == p.num_trials + 6 ) {
for ( i = 0; i < p.num_trials; i++ ) {
p.seeds.push_back( atoi( argv[ 6 + i ] ) );
}
} else {
valid = 0;
}
} else {
valid = 0;
}
return valid;
}
/***********************************************************************
* Print the simulation params as parsed from the command line args
***********************************************************************/
void print_params( Simulator::params &p ) {
cout << p.protocol << " " <<
p.num_stations << " " <<
fixed << p.gen_prob << " " <<
p.num_slots << " " <<
p.num_trials << endl;
}