Travelling_Salesman_Algorithms
arguments.h
Ir para a documentação deste ficheiro.
1 #pragma once
2 
3 #include <algorithm>
4 #include <iostream>
5 #include <locale>
6 #include <memory>
7 #include <string.h>
8 #include <vector>
9 
10 #include "TSP.h"
12 #include "algorithms/bruteForce.h"
15 
16 using namespace std;
17 
18 int csvOutput = 0;
19 
20 int readAlgorithms(int argc, char **argv, int i, vector<unique_ptr<TSP>> &algorithms)
21 {
22  string branch = "branchandbound";
23  string brute = "bruteforce";
24  string dynamic = "dynamicprogramming";
25  string genetic = "geneticalgorithm";
26  string arg = string(argv[i]);
27  transform(arg.begin(), arg.end(), arg.begin(),
28  [](char c) { return tolower(c); });
29 
30  if (branch.find(arg) != string::npos)
31  algorithms.push_back(make_unique<BranchAndBound>());
32 
33  else if (brute.find(arg) != string::npos)
34  algorithms.push_back(make_unique<BruteForce>());
35 
36  else if (dynamic.find(arg) != string::npos)
37  algorithms.push_back(make_unique<DynamicProgramming>());
38 
39  else if (genetic.find(arg) != string::npos)
40  algorithms.push_back(make_unique<GeneticAlgorithm>());
41 
42  return i;
43 }
44 
45 void showHelp()
46 {
47  printf("-------- TRAVELLING SALESMAN PROBLEM --------\n");
48  puts("");
49  printf("USAGE: main.exe [-h|--help|--csv] [branch|brute|dynamic|genetic]...\n");
50  puts("");
51  printf("EXAMPLE: main.exe -h\n");
52  printf("EXAMPLE: main.exe branch genetic # run 'branch and bound' and 'genetic' "
53  "approaches\n");
54  printf("EXAMPLE: main.exe branch genetic --csv # run algorithms and print the "
55  "mean time in CSV format\n");
56 }
57 
58 void readArgs(int argc, char **argv, vector<unique_ptr<TSP>> &algorithms)
59 {
60  for (size_t i = 1; i < argc; i++)
61  {
62  if (argv[i][0] != '-')
63  i = readAlgorithms(argc, argv, i, algorithms);
64  else if (strcmp(argv[i], "--csv") == 0)
65  csvOutput = 1;
66  else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0)
67  {
68  showHelp();
69  exit(0);
70  }
71  }
72 }
int readAlgorithms(int argc, char **argv, int i, vector< unique_ptr< TSP >> &algorithms)
Definition: arguments.h:20
int csvOutput
Definition: arguments.h:18
void readArgs(int argc, char **argv, vector< unique_ptr< TSP >> &algorithms)
Definition: arguments.h:58
void showHelp()
Definition: arguments.h:45