forked from RodolfoALopes/decomposition_library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
differential_grouping_setting_parameter.cpp
87 lines (73 loc) · 2.57 KB
/
differential_grouping_setting_parameter.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <decomposition/differential_grouping.h>
#include <decomposition/optimization_problem.h>
#include <sstream>
using namespace decompose;
using namespace std;
class problem_example : public optimization_problem {
public:
using super = optimization_problem;
explicit problem_example(size_t dimension, vector<scalar> lower_bound,
vector<scalar> upper_bound)
: super(dimension, std::move(lower_bound), std::move(upper_bound)) {}
scalar value(const vector<scalar> &x) override {
scalar sum = 0.0;
for(size_t i = 0; i < dimension; i++){
if(i % 3 == 0){
sum += pow(x[i], 2) * pow(x[(i+1) % dimension], 2);
} else{
sum += pow(x[i], 2);
}
}
return sum;
}
};
int main(){
const size_t dimension = 7;
const scalar lower_bound = -5.0;
const scalar upper_bound = 10.0;
vector<set<size_t>> sub_problems;
size_t number_seps, number_non_seps;
problem_example f(dimension, vector<scalar>(dimension, lower_bound), vector<scalar>(dimension, upper_bound));
criteria criteria_;
options options_{};
options_.set_dg_epsilon(0.3);
differential_grouping method;
method.decompose(f, options_, criteria_);
cout << "Differential Grouping Method Example - Setting Epsilon Parameter" << endl;
sub_problems = f.get_problem_structure();
cout << " - Number of Function Evaluations: " << criteria_.evaluations << endl;
number_seps = 0;
number_non_seps = 0;
for(auto & sub_problem : sub_problems){
if(sub_problem.size() > 1){
number_non_seps += sub_problem.size();
}
else{
number_seps++;
}
}
ostringstream s;
s << "[";
for(size_t i = 0; i < sub_problems.size(); i++){
s << "[";
auto it = sub_problems[i].begin();
bool print = true;
while(print && !sub_problems.empty()){
s << (*it);
it++;
if(it != sub_problems[i].end()){
s << ", ";
}else{
print = false;
}
}
s << "]";
}
s << "]";
cout << " - Number of sub-problems found: " << sub_problems.size() << endl;
cout << " - Number of separable decision variables: " << number_seps << endl;
cout << " - Number of non-separable decision variables: " << number_non_seps << endl;
cout << " - Problem Structure Found: " << s.str() << endl;
cout << endl << endl;
return 0;
}