-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsp_main.cpp
170 lines (128 loc) · 3.83 KB
/
tsp_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
tsp_main.c
3-30-2017
Neil McGlohon
*/
//includes
#include "tsp.hpp"
#include "globals.hpp"
double jitter = 0.0;
double weight_multiplier = 0.0;
tw_stime lookahead = 0;
unsigned int nlp_per_pe = 0;
unsigned int custom_LPs_per_pe = 0;
int total_actors = 0;
int total_cities = 0;
int** weight_matrix;
tw_lptype model_lps[] =
{
{
(init_f) tsp_init,
(pre_run_f) tsp_prerun,
(event_f) tsp_event_handler,
(revent_f) tsp_RC_event_handler,
(commit_f) tsp_commit,
(final_f) tsp_final,
(map_f) tsp_map,
sizeof(tsp_actor_state)
},
{ 0 },
};
// // COMMAND OPS EXAMPLE
//
//Define command line arguments default values
int num_cities= 4;
int min_fanout= 1;
int max_fanout= 4;
//Command line opts
const tw_optdef model_opts[] = {
TWOPT_GROUP("TSP Models"),
TWOPT_UINT("cities", num_cities, "Total cities in simulation"),
TWOPT_UINT("minfanout", min_fanout, "Min Fanout of graph nodes (Not implemented yet)"),
TWOPT_UINT("maxfanout", max_fanout, "Max Fanout of graph nodes (Not Implemented yet)"),
TWOPT_END()
};
//Displays simple settings of the simulation
void displayModelSettings()
{
if(g_tw_mynode ==0)
{
for (int i = 0; i < 30; i++)
{
printf("*");
}
printf("\n");
printf("Traveling Salesman Problem Solver Configuration:\n");
printf("\tnnodes: %i\n", tw_nnodes());
printf("\tg_tw_nlp: %llu\n", g_tw_nlp);
printf("\tNLPs per PE: %i\n", nlp_per_pe);
printf("\tTotal Actors: %i\n", total_actors);
printf("\tTotal Cities: %i\n", num_cities);
printf("\n");
printf("\tuint64s needed: %i\n",MAX_INTS_NEEDED);
printf("\tAvl node count: %i\n", g_tw_avl_node_count);
// printf("\tMin Fanout: %i\n", min_fanout);
// printf("\tMax Fanout: %i\n", max_fanout);
//Put your settings to print here
for (int i = 0; i < 30; i++)
{
printf("*");
}
printf("\n");
}
}
//DO NOT USE THIS METHOD WITHIN AN LP
int rand_range(int low, int high)
{
return((int) (rand() % (high-low+1)) + low);
}
void initialize()
{
total_cities = num_cities;
weight_matrix = (int**) calloc(num_cities,sizeof(int*));
int i;
for(i = 0; i < num_cities; i++)
{
weight_matrix[i] = (int*)calloc(num_cities,sizeof(int));
}
srand(100);
//make symmetrical graph with random integer weights
for(int i = 0; i < num_cities; i++)
{
for(int j = 0; j < num_cities; j++)
{
if(j > i)
weight_matrix[i][j] = rand_range(MIN_CITY_SEPARATION,MAX_CITY_SEPARATION); //rand int in [MIN, MAX]
else if(i > j)
weight_matrix[i][j] = weight_matrix[j][i];
}
}
}
//for doxygen
#define lif_main main
int lif_main(int argc, char** argv, char **env)
{
tw_opt_add(model_opts);
tw_init(&argc, &argv);
initialize();
nlp_per_pe = 1;
custom_LPs_per_pe = 1;
jitter = .0001;
weight_multiplier = 1;
// g_tw_events_per_pe = 1000000;
// g_tw_avl_node_count = g_tw_avl_node_count * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2;
total_actors = total_cities*total_cities + total_cities; //N^2 + N, One for each city-position, and one for each ending city
g_tw_nlp = (total_actors);
g_tw_lookahead = jitter * .001;
custom_LPs_per_pe = ceil((double)g_tw_nlp/tw_nnodes());
nlp_per_pe = custom_LPs_per_pe;
displayModelSettings();
g_tw_lp_types = model_lps;
// g_tw_lp_typemap = lpTypeMapper;
tw_define_lps(custom_LPs_per_pe, sizeof(tsp_mess));
tw_lp_setup_types();
tw_run();
tw_end();
// exportFinalData();
return 0;
}