-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataLoader.cpp
More file actions
74 lines (53 loc) · 1.81 KB
/
Copy pathDataLoader.cpp
File metadata and controls
74 lines (53 loc) · 1.81 KB
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
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include "Pallet.h"
#include "TruckandPallet.h"
using namespace std;
/**
* @brief Implementação da função que carrega dados dos arquivos CSV para TruckandPallet.
*
* @param datasetId Identificador do dataset a carregar.
* @param data Estrutura onde os dados serão armazenados.
*
* @details
* Lê arquivo TruckAndPallets_<datasetId>.csv para capacidade e número de pallets,
* e Pallets_<datasetId>.csv para dados dos pallets.
*/
void loadData(string datasetId, TruckandPallet& data) {
if (datasetId.size() == 1) datasetId = "0" + datasetId;
string truckFile = "../datasets/TruckAndPallets_" + datasetId + ".csv";
string palletsFile = "../datasets/Pallets_" + datasetId + ".csv";
ifstream file1(truckFile);
string line;
getline(file1, line);
getline(file1, line);
stringstream ss(line);
string truckCapacity;
string truckPallets;
getline(ss, truckCapacity, ','); // Capacidade da truck
data.truckCapacity = stoi(truckCapacity);
getline(ss,truckPallets); // Número de paletes
data.numPallets = stoi(truckPallets);
file1.close();
ifstream file2(palletsFile);
getline(file2, line);
data.pallets.clear();
while (getline(file2, line)) {
stringstream ss(line);
Pallet pallet;
string palletNum;
string palletWeight;
string palletProfit;
getline(ss, palletNum, ',');
pallet.id = stoi(palletNum);
getline(ss, palletWeight, ',');
pallet.weight = stoi(palletWeight);
getline(ss, palletProfit, '\0');
pallet.profit = stoi(palletProfit);
data.pallets.push_back(pallet);
}
file2.close();
}