@@ -66,14 +66,13 @@ CREATE TEMPLATE QUERY GDBMS_ALGO.community.label_prop(
66
66
67
67
// Initialization
68
68
All_Nodes = {v_type_set};
69
- Tmp =
70
- SELECT s
71
- FROM All_Nodes:s -(e_type_set:e)- :t
72
- POST-ACCUM
73
- s.@community_id = s,
74
- s.@vid = getvid(s),
75
- s.@batch_id = s.@vid % batch_num,
76
- s.@degree = s.outdegree(e_type_set);
69
+ Tmp = SELECT s
70
+ FROM All_Nodes:s -(e_type_set:e)- :t
71
+ POST-ACCUM
72
+ s.@community_id = s,
73
+ s.@vid = getvid(s),
74
+ s.@batch_id = s.@vid % batch_num,
75
+ s.@degree = s.outdegree(e_type_set);
77
76
@@vertex_num = All_Nodes.size();
78
77
@@vertex_num = @@vertex_num / batch_num;
79
78
@@ -84,104 +83,96 @@ CREATE TEMPLATE QUERY GDBMS_ALGO.community.label_prop(
84
83
hop = hop + 1;
85
84
// Find the best move
86
85
IF hop == 1 THEN // First iteration
87
- ChangedNodes =
88
- SELECT s
89
- FROM Candidates:s -(e_type_set:e)- :t
90
- WHERE s.@degree < t.@degree
91
- ACCUM s.@best_move += MoveScore(t.@degree, t.@community_id)
92
- POST-ACCUM
93
- IF s.@best_move.community != s.@community_id THEN
94
- s.@to_change_community = TRUE
95
- END
96
- HAVING s.@to_change_community == TRUE;
86
+ ChangedNodes = SELECT s
87
+ FROM Candidates:s -(e_type_set:e)- :t
88
+ WHERE s.@degree < t.@degree
89
+ ACCUM s.@best_move += MoveScore(t.@degree, t.@community_id)
90
+ POST-ACCUM
91
+ IF s.@best_move.community != s.@community_id THEN
92
+ s.@to_change_community = TRUE
93
+ END
94
+ HAVING s.@to_change_community == TRUE;
97
95
ELSE // Remaining iterations
98
96
IF Candidates.size() < @@vertex_num OR batch_num == 1 THEN // No batch processing
99
- ChangedNodes =
100
- SELECT s
101
- FROM Candidates:s -(e_type_set:e)- :t
102
- SAMPLE sample_edge_num EDGE WHEN s.outdegree(e_type_set) > sample_edge_num
103
- ACCUM s.@community_k_in_map += (t.@community_id -> 1)
104
- POST-ACCUM
105
- s.@best_move = MoveScore(@@min_double, s), // Reset best move
106
- FOREACH (community_id, k_in) IN s.@community_k_in_map DO
107
- s.@best_move += MoveScore(k_in, community_id)
108
- END,
109
- IF s.@best_move.community != s.@community_id THEN
110
- s.@to_change_community = TRUE
111
- END,
112
- s.@community_k_in_map.clear()
113
- HAVING s.@to_change_community == TRUE;
97
+ ChangedNodes = SELECT s
98
+ FROM Candidates:s -(e_type_set:e)- :t
99
+ SAMPLE sample_edge_num EDGE WHEN s.outdegree(e_type_set) > sample_edge_num
100
+ ACCUM s.@community_k_in_map += (t.@community_id -> 1)
101
+ POST-ACCUM
102
+ s.@best_move = MoveScore(@@min_double, s), // Reset best move
103
+ FOREACH (community_id, k_in) IN s.@community_k_in_map DO
104
+ s.@best_move += MoveScore(k_in, community_id)
105
+ END,
106
+ IF s.@best_move.community != s.@community_id THEN
107
+ s.@to_change_community = TRUE
108
+ END,
109
+ s.@community_k_in_map.clear()
110
+ HAVING s.@to_change_community == TRUE;
114
111
ELSE // Use batch processing
115
112
ChangedNodes = {};
116
113
FOREACH batch_id IN RANGE[0, batch_num-1] DO
117
- Nodes =
118
- SELECT s
119
- FROM Candidates:s
120
- WHERE s.@batch_id == batch_id;
121
- Nodes =
122
- SELECT s
123
- FROM Nodes:s -(e_type_set:e)- :t
124
- SAMPLE sample_edge_num EDGE WHEN s.outdegree(e_type_set) > sample_edge_num
125
- ACCUM s.@community_k_in_map += (t.@community_id -> 1)
126
- POST-ACCUM
127
- s.@best_move = MoveScore(@@min_double, s), // Reset best move
128
- FOREACH (community_id, k_in) IN s.@community_k_in_map DO
129
- s.@best_move += MoveScore(k_in, community_id)
130
- END,
131
- IF s.@best_move.community != s.@community_id THEN
132
- s.@to_change_community = TRUE
133
- END,
134
- s.@community_k_in_map.clear()
135
- HAVING s.@to_change_community == TRUE;
114
+ Nodes = SELECT s
115
+ FROM Candidates:s
116
+ WHERE s.@batch_id == batch_id;
117
+ Nodes = SELECT s
118
+ FROM Nodes:s -(e_type_set:e)- :t
119
+ SAMPLE sample_edge_num EDGE WHEN s.outdegree(e_type_set) > sample_edge_num
120
+ ACCUM s.@community_k_in_map += (t.@community_id -> 1)
121
+ POST-ACCUM
122
+ s.@best_move = MoveScore(@@min_double, s), // Reset best move
123
+ FOREACH (community_id, k_in) IN s.@community_k_in_map DO
124
+ s.@best_move += MoveScore(k_in, community_id)
125
+ END,
126
+ IF s.@best_move.community != s.@community_id THEN
127
+ s.@to_change_community = TRUE
128
+ END,
129
+ s.@community_k_in_map.clear()
130
+ HAVING s.@to_change_community == TRUE;
136
131
ChangedNodes = ChangedNodes UNION Nodes;
137
132
END;
138
133
END;
139
134
END;
140
135
141
136
// Handle nodes that swap communities
142
- SwapNodes =
143
- SELECT s
144
- FROM ChangedNodes:s -(e_type_set:e)- :t
145
- WHERE s.@best_move.community == t.@community_id
146
- AND t.@to_change_community == TRUE
147
- AND t.@best_move.community == s.@community_id
148
- AND (s.@best_move.score < t.@best_move.score
149
- OR (abs(s.@best_move.score - t.@best_move.score) < 0.00000000001
150
- AND s.@vid > t.@vid))
151
- POST-ACCUM
152
- s.@to_change_community = FALSE;
137
+ SwapNodes = SELECT s
138
+ FROM ChangedNodes:s -(e_type_set:e)- :t
139
+ WHERE s.@best_move.community == t.@community_id
140
+ AND t.@to_change_community == TRUE
141
+ AND t.@best_move.community == s.@community_id
142
+ AND (s.@best_move.score < t.@best_move.score
143
+ OR (abs(s.@best_move.score - t.@best_move.score) < 0.00000000001
144
+ AND s.@vid > t.@vid))
145
+ POST-ACCUM
146
+ s.@to_change_community = FALSE;
153
147
ChangedNodes = ChangedNodes MINUS SwapNodes;
154
148
155
149
// Update community IDs
156
- ChangedNodes =
157
- SELECT s
158
- FROM ChangedNodes:s
159
- POST-ACCUM
160
- s.@community_id = s.@best_move.community,
161
- s.@to_change_community = FALSE;
150
+ ChangedNodes = SELECT s
151
+ FROM ChangedNodes:s
152
+ POST-ACCUM
153
+ s.@community_id = s.@best_move.community,
154
+ s.@to_change_community = FALSE;
162
155
163
156
// Find candidates for the next iteration
164
- Candidates =
165
- SELECT t
166
- FROM ChangedNodes:s -(e_type_set:e)- :t
167
- WHERE t.@community_id != s.@community_id;
157
+ Candidates = SELECT t
158
+ FROM ChangedNodes:s -(e_type_set:e)- :t
159
+ WHERE t.@community_id != s.@community_id;
168
160
END;
169
161
170
162
// Output results
171
- Nodes =
172
- SELECT s
173
- FROM All_Nodes:s
174
- POST-ACCUM
175
- IF result_attribute != "" THEN
176
- s.setAttr(result_attribute, getvid(s.@community_id))
177
- END,
178
- IF print_results THEN
179
- @@comm_sizes_map += (s.@community_id -> 1)
180
- END,
181
- IF file_path != "" THEN
182
- f.println(s.id, s.@community_id)
183
- END
184
- LIMIT print_limit;
163
+ Nodes = SELECT s
164
+ FROM All_Nodes:s
165
+ POST-ACCUM
166
+ IF result_attribute != "" THEN
167
+ s.setAttr(result_attribute, getvid(s.@community_id))
168
+ END,
169
+ IF print_results THEN
170
+ @@comm_sizes_map += (s.@community_id -> 1)
171
+ END,
172
+ IF file_path != "" THEN
173
+ f.println(s.id, s.@community_id)
174
+ END
175
+ LIMIT print_limit;
185
176
186
177
// Print results if print_results is True
187
178
IF print_results THEN
0 commit comments