-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.h
45 lines (41 loc) · 1.19 KB
/
parser.h
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
#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;
#include <time.h>
#include <map>
#include <vector>
#include <sstream>
#include <algorithm>
#include <cmath>
/*
* Ex de lecture et d'écriture de csv/txt verts des maps, à adapter
*
template <typename Element>
void readCsvToMap(map<int,Element> & readMap, string filename){
ifstream read(filename.c_str());
if (!read.is_open()) throw;
string line;
getline(read, line); // nbElements or objective value
getline(read, line); // Description line
while (getline(read, line)){
removeOneSubstring(line, ",");
Element elem(line);
readMap.insert(pair<int, Element>(elem.getIndex(), elem));
}
}
template <typename Element>
void printMapToCsv(map<int,Element> printedMap, string filename, int sol){
ofstream write(filename.c_str());
if (!write.is_open())
{
throw;
}
write << "Objective: " << sol << endl;
write << printedMap.begin()->second.classDescription() << endl;
for (typename map<int,Element>::iterator it = printedMap.begin(); it!= printedMap.end(); ++it){
write << it->second.toString() << endl;
}
}*/