-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.cpp
83 lines (69 loc) · 3.3 KB
/
logic.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
//
// Created by neriy on 05/09/2022.
//
#include "logic.h"
/**
* return the functioning component. (in case the network wasn't build before calling the function)
* @param network1
* @param network2
* @param node_in_cluster
* @param reinforced
* @return
*/
set<int> conjunction_functional(nNetwork network1, nNetwork network2, int node_in_cluster, const vector<int>& reinforced){
set<int> functioning_c_1 = get_functional(network1, node_in_cluster, reinforced);
set<int> functioning_c_2 = get_functional(network2, node_in_cluster, reinforced);
set<int> nodes_to_remove;
int old_shape1 = functioning_c_1.size(),old_shape2 = functioning_c_2.size();
while(true) {
subtract_sec_from_first(functioning_c_1, functioning_c_2); // remove nodes in A and not in B(from A)
for (auto node_id:functioning_c_1){
remove_node_from_network(network1, node_id);
}
functioning_c_1 = get_functional(network1, node_in_cluster, reinforced);
subtract_sec_from_first(functioning_c_2, functioning_c_1);
for (auto node_id:functioning_c_2){
remove_node_from_network(network2, node_id);
}
functioning_c_2 = get_functional(network2, node_in_cluster, reinforced);
if (old_shape1 == functioning_c_1.size() && old_shape2 == functioning_c_2.size()) break;
old_shape1 = functioning_c_1.size();
old_shape2 = functioning_c_2.size();
}
return functioning_c_1;
}
/**
* return the functioning component. (in case the network WAS build before calling the function)
* differance:
* @param network1 is &network1, not network1
* @param network2
* @param node_in_cluster
* @param reinforced
* @return
*/
set<int> conjunction_functional(nNetwork &network1, nNetwork &network2, int node_in_cluster, const vector<int>& reinforced){
set<int> functioning_c_1 = get_functional(network1, node_in_cluster, reinforced);
set<int> functioning_c_2 = get_functional(network2, node_in_cluster, reinforced);
set<int> nodes_to_remove;
int old_shape1 = functioning_c_1.size(),old_shape2 = functioning_c_2.size();
while(true) {
subtract_sec_from_first(functioning_c_1, functioning_c_2); // remove nodes in A and not in B(from A)
for (auto node_id:functioning_c_1){
remove_node_from_network(network1, node_id);
}
functioning_c_1 = get_functional(network1, node_in_cluster, reinforced);
subtract_sec_from_first(functioning_c_2, functioning_c_1);
for (auto node_id:functioning_c_2){
remove_node_from_network(network2, node_id);
}
functioning_c_2 = get_functional(network2, node_in_cluster, reinforced);
if (old_shape1 == functioning_c_1.size() && old_shape2 == functioning_c_2.size()) break;
old_shape1 = functioning_c_1.size();
old_shape2 = functioning_c_2.size();
}
return functioning_c_1;
}
vector<int> conjunction_functional_translator(yNetwork &network1, yNetwork &network2, int node_in_cluster, const vector<bool>& reinforced){
return convertSet2Veclvalue(conjunction_functional(convertYaelNW2NerNW(network1), convertYaelNW2NerNW(network2), node_in_cluster,
convert_bool_vec_2_indicies_vec(reinforced)));
}