Skip to content

Commit 9c1ff29

Browse files
authored
Development (#3)
* V0.4 - Lazy Constraint Callback * Updated README.md * V0.5 - Added arguments support and writing results to a text file\nCan now be massively launched from a command line interface, all results will be printed to Results.txt * V0.6 - Added support for time/distance solving
1 parent 358f660 commit 9c1ff29

File tree

4 files changed

+38
-29
lines changed

4 files changed

+38
-29
lines changed

TIPEcppTest1/FileManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ vector<vector<string>> FileManager::read_file(string filename, bool EnableCout)
5555
}
5656
}
5757

58-
float** FileManager::read_standardized_csv(vector<vector<string>> lines, bool EnableCout)
58+
float** FileManager::read_standardized_csv(vector<vector<string>> lines, bool useTime, bool EnableCout)
5959
{
6060
//We define our dynamic matrix here
6161
int row_colCount = int(sqrt(lines.size() - 1));
@@ -68,10 +68,10 @@ float** FileManager::read_standardized_csv(vector<vector<string>> lines, bool En
6868
{
6969
int i = std::stoi(lines[p][0]);
7070
int j = std::stoi(lines[p][1]);
71-
Distance[i][j] = std::stof(lines[p][3]);
71+
Distance[i][j] = std::stof(lines[p][(useTime ? 2 : 3)]);
7272
if (EnableCout)
7373
{
74-
cout << "i: " << i << " j: " << j << " dist: " << std::stod(lines[p][3]) << endl;
74+
cout << "i: " << i << " j: " << j << " dist: " << Distance[i][j] << endl;
7575
}
7676
}
7777
return Distance;

TIPEcppTest1/FileManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ static class FileManager
2222
/// <param name="lines">The csv files, already organized</param>
2323
/// <param name="EnableCout">Enable debug output to console</param>
2424
/// <returns>A matrix containing the data of the csv</returns>
25-
static float** read_standardized_csv(vector<vector<string>> lines, bool EnableCout = false);
25+
static float** read_standardized_csv(vector<vector<string>> lines, bool useTime, bool EnableCout = false);
2626
};

TIPEcppTest1/Results.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
==========DONE==========
3+
Distance was used.
4+
Total elapsed time(ms): 383
5+
| Setup elapsed time(ms): 1
6+
| Solving elapsed time(ms): 382
7+
Solution (Optimal) with objective 51620.1
8+
0 → 6 → 4 → 2 → 3 → 8 → 5 → 7 → 1 → 0

TIPEcppTest1/TIPEcppTest1.cpp

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -174,39 +174,49 @@ ILOLAZYCONSTRAINTCALLBACK2(LazyCallback, NumVar2D, Xmatrix, IloInt, n)
174174

175175
void usage(char* progname)
176176
{
177-
cerr << "Usage:\t" << progname << " [-h] [csv_filename]" << endl;
178-
cerr << " -h: Prints this help menu" << endl;
179-
cerr << " filename: C.Murray's CSVs data file" << endl;
177+
cerr << "Usage:\t" << progname << " [-h] {0|1} [csv_filename]" << endl;
178+
cerr << " -h: Prints this help menu and terminates the programm" << endl;
179+
cerr << " 0: Uses distances to solve the Model (default)" << endl;
180+
cerr << " 1: Uses times to solve the Model" << endl;
181+
cerr << " csv_filename: C.Murray's CSVs data file" << endl;
180182
cerr << " File ../../../20170608T121355407419/tbl_truck_travel_data_PG.csv"
181183
<< " used if no name is provided." << endl;
182184
}
183185

184186
int main(int argc, char** argv)
185187
{
188+
bool useTime = false;
186189
#pragma region ArgumentsParsing
187190
string filename;
191+
// Help menu and end of the programm
192+
if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'h')
193+
{
194+
usage(argv[0]);
195+
throw;
196+
}
188197
// The name "_.exe" counts as the first argument
189198
switch (argc)
190199
{
191200
case 2:
192-
cout << "argv[1]: " << argv[1] << endl;
193-
if (argv[1][0] == '-' && argv[1][1] == 'h')
201+
// One argument
202+
if (argv[1][0] == '0' || argv[1][0] == '1')
194203
{
195-
usage(argv[0]);
196-
throw;
204+
useTime = (argv[1][0] == '0' ? false : true);
197205
}
198206
else
199207
{
200208
filename = argv[1];
201209
}
202210
break;
203211
case 3:
204-
if (argv[1][0] == '-' && argv[1][1] == 'h')
212+
// Two arguments
213+
if (argv[1][0] == '0' || argv[1][0] == '1')
205214
{
206-
usage(argv[0]);
215+
useTime = (argv[1][0] == '0' ? false : true);
207216
}
208217
else
209218
{
219+
// Error in the first argument
210220
usage(argv[0]);
211221
throw;
212222
}
@@ -228,7 +238,7 @@ int main(int argc, char** argv)
228238
cout << "n: " << n << endl;
229239
//Distances matrix, from 1..n
230240
float** Distance = new float* [n];
231-
Distance = FileManager::read_standardized_csv(func_out);
241+
Distance = FileManager::read_standardized_csv(func_out, useTime);
232242

233243
/*vector<int> arg;
234244
for (int i = 0; i < n; i++)
@@ -347,7 +357,7 @@ int main(int argc, char** argv)
347357
// Solving
348358
IloCplex cplex(Model);
349359
// Export the model, useful for debugging
350-
cplex.exportModel("model.lp");
360+
cplex.exportModel("Model.lp");
351361
// Set the output as stdout
352362
cplex.setOut(std::cout);
353363

@@ -393,7 +403,8 @@ int main(int argc, char** argv)
393403
auto ElapsedSolving = chrono::duration_cast<chrono::milliseconds>(end - start_1);
394404

395405
cout << "==========DONE==========" << endl;
396-
cout << "Total elapsed time(ms) : " << ElapsedTotal.count() << endl;
406+
cout << (useTime ? "Time was used." : "Distance was used.") << endl;
407+
cout << "Total elapsed time(ms): " << ElapsedTotal.count() << endl;
397408
cout << "|\tSetup elapsed time(ms): " << ElapsedSetup.count() << endl;
398409
cout << "|\tSolving elapsed time(ms): " << ElapsedSolving.count() << endl;
399410

@@ -423,7 +434,8 @@ int main(int argc, char** argv)
423434
{
424435
file << endl;
425436
file << "==========DONE==========" << endl;
426-
file << "Total elapsed time(ms) : " << ElapsedTotal.count() << endl;
437+
file << (useTime ? "Time was used." : "Distance was used.") << endl;
438+
file << "Total elapsed time(ms): " << ElapsedTotal.count() << endl;
427439
file << "|\tSetup elapsed time(ms): " << ElapsedSetup.count() << endl;
428440
file << "|\tSolving elapsed time(ms): " << ElapsedSolving.count() << endl;
429441
file << "Solution (" << cplex.getStatus() << ") with objective " << objective << endl;
@@ -449,15 +461,4 @@ int main(int argc, char** argv)
449461
cplex.end();
450462
env.end();
451463
#pragma endregion
452-
}
453-
454-
// Exécuter le programme : Ctrl+F5 ou menu Déboguer > Exécuter sans débogage
455-
// Déboguer le programme : F5 ou menu Déboguer > Démarrer le débogage
456-
457-
// Astuces pour bien démarrer :
458-
// 1. Utilisez la fenêtre Explorateur de solutions pour ajouter des fichiers et les gérer.
459-
// 2. Utilisez la fenêtre Team Explorer pour vous connecter au contrôle de code source.
460-
// 3. Utilisez la fenêtre Sortie pour voir la sortie de la génération et d'autres messages.
461-
// 4. Utilisez la fenêtre Liste d'erreurs pour voir les erreurs.
462-
// 5. Accédez à Projet > Ajouter un nouvel élément pour créer des fichiers de code, ou à Projet > Ajouter un élément existant pour ajouter des fichiers de code existants au projet.
463-
// 6. Pour rouvrir ce projet plus tard, accédez à Fichier > Ouvrir > Projet et sélectionnez le fichier .sln.
464+
}

0 commit comments

Comments
 (0)