-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilities.cpp
More file actions
64 lines (58 loc) · 1.47 KB
/
utilities.cpp
File metadata and controls
64 lines (58 loc) · 1.47 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
#include "utilities.h"
#include <iostream>
#include <fstream>
vector<vector<int>> utilities::subset(vector<int> arg)
{
//TODO: Find another way to generate the list of subsets, see the command line in CPLEX Studio
//Condition d'arrêt
if (arg.size() == 0)
{
vector<vector<int>> empty = { {} };
return empty;
}
//We create a copy
vector<int> newArg(arg);
//We remove the last element
newArg.pop_back();
vector<vector<int>> Pn = subset(newArg);
vector<vector<int>> truc;
for (int x = 0; x < Pn.size(); x++)
{
vector<int> temp{ arg.back() };
vector<int> combined;
combined.reserve(temp.size() + Pn[x].size()); // preallocate memory
combined.insert(combined.end(), temp.begin(), temp.end());
combined.insert(combined.end(), Pn[x].begin(), Pn[x].end());
truc.push_back(combined);
}
vector<vector<int>> allCombined;
allCombined.reserve(truc.size() + Pn.size()); // preallocate memory
allCombined.insert(allCombined.end(), Pn.begin(), Pn.end());
allCombined.insert(allCombined.end(), truc.begin(), truc.end());
return allCombined;
}
void utilities::print_subsets(vector<vector<int>> subsets)
{
//Debug
cout << "Subsets number: " << subsets.size() << endl;
//This code prints all subsets to console in Python format
cout << "Subsets: [";
for (vector<int> r : subsets)
{
cout << "[";
for (int t : r)
{
cout << t;
if (t != r.back())
{
cout << ", ";
}
}
cout << "]";
if (r != subsets.back())
{
cout << ", ";
}
}
cout << "]" << endl;
}