-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
88 lines (80 loc) · 3.29 KB
/
main.c
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
/**
* @file main.c
* @author B207
* @brief Simulates traditional routes or simulates routes created using filtering, clustering and a TSP-algorithm
* @version 1.0
* @date 2021-17-14
*
* @copyright Copyright (c) 2021
*
*/
/* typedef enum userControl{Exit, CalcRoutes, SimulateTraditional, SimulateNew} userControl; */
#include "./Simulation/SimModule.h"
#include "./WasteManagement/WasteManagement.h"
#include "./TraditionalRoutes/TraditionalRoutes.h"
#include "./CSVModule/matrixToCSV.h"
int main (void) {
int programRunning = 1;
char *distMatrixFilepath = ORIGIN_PATH;
char *latLonFilePath = LAT_LON_PATH;
double **distanceMatrix;
container* containerList;
int dataRows;
int dataColumns;
int answer;
int filteredListLength;
srand(time(NULL));
make_directory("Output");
while (programRunning) {
printf("\n"
"Choose\n"
"1 Calculate routes from file?\n"
"2 Simulate traditional routes?\n"
"3 Simulate new routes?\n"
"(Any other button exits the program)\n");
answer = 0;
scanf("%d", &answer);
fflush(stdin);
if (answer == 1) {
container* filteredContainerList;
// Data input from CSV
distanceMatrix = createMatrixFromFile(distMatrixFilepath, &dataRows, &dataColumns);
containerList = createCoordStructListFromFile(latLonFilePath, dataRows);
insertFillrateFromFile(FILL_LIST_PATH, containerList, dataRows);
int *filteredList = (int *)malloc(sizeof(int) * dataRows);
int numRoutes = filterFillRateList(containerList, filteredList, dataRows, &filteredListLength, TRUCK_LOAD);
filteredContainerList = filterContainerList(containerList, filteredList, filteredListLength);
int** routes = calculateRoutes(filteredContainerList, filteredListLength, &numRoutes, distanceMatrix, 1);
for(int i = 0; i < numRoutes; i++){
outputCSV(routes[i],i,TRUCK_LOAD);
}
freeIntMatrixPtr(routes, numRoutes);
}
else if (answer == 2 || answer == 3) {
// Data input from CSV
distanceMatrix = createMatrixFromFile(distMatrixFilepath, &dataRows, &dataColumns);
containerList = createCoordStructListFromFile(latLonFilePath, dataRows);
setUsersBasedOnEmptyFrequency(containerList, "data/afhentning.csv", dataRows);
printf("Enter year: ");
int year = 0;
scanf("%d", &year);
for (int i = 0; i < year; i++) {
double wastePerUser = AVERAGE_RATE_PER_USER * (i+1);
if (answer == 2) {
simulationResult simResult = simulateTraditionalRoutes(distanceMatrix, containerList, dataRows, wastePerUser);
printResult(simResult);
}
else if (answer == 3) {
simulationResult simResult = simulateNewRoutes(distanceMatrix, containerList, dataRows, wastePerUser);
printResult(simResult);
}
}
free(containerList);
freeDoubleMatrixPtr(distanceMatrix, dataRows);
}
else {
programRunning = false;
}
}
return EXIT_SUCCESS;
}