-
Notifications
You must be signed in to change notification settings - Fork 3
/
Sample01-1-Variables.cpp
90 lines (77 loc) · 2.71 KB
/
Sample01-1-Variables.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
88
89
90
/**
* Author: Andrea Casalino
* Created: 03.01.2020
*
* report any bug to andrecasa91@gmail.com.
**/
// what is required from the EFG core library
#include <EasyFactorGraph/Error.h>
#include <EasyFactorGraph/categoric/GroupRange.h>
#include <EasyFactorGraph/categoric/Variable.h>
using namespace EFG::categoric;
// just a bunch of utilities needed by the sample
#include <Printing.h>
#include <SampleSection.h>
#include <iostream>
using namespace std;
int main() {
SAMPLE_SECTION("Managing group of variables", "4.1.1.1", [] {
// define a group of variables, all with size = 2
Group groupABCD(make_variable(2, "A"), make_variable(2, "B"));
cout << "groupABCD with only A and B for the moment: " << groupABCD << endl;
groupABCD.add(make_variable(2, "C"));
groupABCD.add(make_variable(2, "D"));
cout << "groupABCD after adding also C and D: " << groupABCD << endl;
});
SAMPLE_SECTION("Managing group of variables", "4.1.1.1", [] {
// define a group of variables, all with size = 2
Group groupABCD(make_variable(2, "A"), make_variable(2, "B"));
cout << "groupABCD with only A and B for the moment: " << groupABCD << endl;
groupABCD.add(make_variable(2, "C"));
groupABCD.add(make_variable(2, "D"));
cout << "groupABCD after adding also C and D: " << groupABCD << endl;
// try to add an already existing variable
try {
groupABCD.add(make_variable(2, "C"));
} catch (...) {
cout << "insertion of C in ABCD group correctly refused" << endl;
}
});
SAMPLE_SECTION("Joint domain of variables", "4.1.1.2", [] {
// build some variables
auto A = make_variable(2, "A");
auto B = make_variable(4, "B");
auto C = make_variable(3, "C");
{
Group AB_group(VariablesSoup{A, B});
cout << AB_group.getVariables() << endl;
// display all combinations in the joint domain
GroupRange range(AB_group);
for_each_combination(range, [](const std::vector<std::size_t> &comb) {
cout << comb << std::endl;
});
cout << endl;
}
{
Group AC_group(VariablesSoup{A, C});
cout << AC_group.getVariables() << endl;
// display all combinations in the joint domain
GroupRange range(AC_group);
for_each_combination(range, [](const std::vector<std::size_t> &comb) {
cout << comb << std::endl;
});
cout << endl;
}
{
Group ABC_group(VariablesSoup{A, C, B});
cout << ABC_group.getVariables() << endl;
// display all combinations in the joint domain
GroupRange range(ABC_group);
for_each_combination(range, [](const std::vector<std::size_t> &comb) {
cout << comb << std::endl;
});
cout << endl;
}
});
return EXIT_SUCCESS;
}