Here is my modified cycle detection query,
CREATE OR REPLACE QUERY cycle_detection (SET<STRING> e_types, SET<INT> depths, INT max_degree = 50, INT n_batch = 1, BOOL print_accum = TRUE, STRING file_path = "") SYNTAX V2 {
ListAccum<ListAccum<VERTEX>> @curr_v_list, @new_v_list;
ListAccum<ListAccum<STRING>> @curr_e_list, @new_e_list;
ListAccum<ListAccum<INT>> @curr_accident_list, @new_accident_list;
ListAccum<ListAccum<VERTEX>> @@cycles_list;
SetAccum<VERTEX> @@persons_to_exclude, @@claims_to_exclude, @@tgt_to_exclude;
FILE f (file_path);
f.println("v_ids", "v_types", "e_types", "depth", "accident_ids");
persons_to_exclude = SELECT p FROM Person:p
WHERE p.id == "unknown" OR NOT p.is_resident_id OR p.outdegree(e_types) < 2
ACCUM @@persons_to_exclude += p;
claims_to_exclude = SELECT cl FROM Claim:cl
WHERE cl.outdegree(e_types) < 2
OR cl.accident_time == to_datetime("1970-01-01 00:00:00")
ACCUM @@claims_to_exclude += cl;
@@tgt_to_exclude = @@persons_to_exclude UNION @@claims_to_exclude;
claims = {Claim.*};
claims = claims MINUS claims_to_exclude;
INT max_depth = max(depths);
FOREACH i IN RANGE[0, n_batch-1] DO
# initialization and Early Pruning for batch i
Active (ANY) = SELECT s FROM claims:s
WHERE getvid(s) % n_batch == i
ACCUM s.@curr_v_list = [s],
s.@curr_accident_list = [s.accident_id];
WHILE Active.size() > 0 LIMIT max_depth DO
Active = SELECT t
FROM Active:s -(e_types:e)- :t
WHERE t.outdegree(e_types) BETWEEN 2 AND max_degree AND t NOT IN @@tgt_to_exclude
ACCUM
INT n = s.@curr_v_list.size(),
FOREACH j IN RANGE[0, n-1] DO
IF t == s.@curr_v_list.get(j).get(0) AND s.@curr_v_list.get(j).size() IN depths THEN
IF (s.@curr_accident_list.get(j).size() == (s.@curr_v_list.get(j).size() / 2)) THEN
STRING seq_str = "",
IF print_accum THEN
@@cycles_list += s.@curr_v_list.get(j)
END,
IF file_path != "" THEN
FOREACH v in s.@curr_v_list.get(j) DO
seq_str = seq_str + " " + v.type
END,
f.println(s.@curr_v_list.get(j), trim(seq_str), s.@curr_e_list.get(j)+[e.type], s.@curr_v_list.get(j).size(), s.@curr_accident_list.get(j))
END
END
ELSE IF s.@curr_v_list.get(j).contains(t) == FALSE THEN
IF t.type != "Claim" THEN
t.@new_v_list += [s.@curr_v_list.get(j) + [t]], // store sequences in @newList to avoid confliction with @currList
t.@new_e_list += [s.@curr_e_list.get(j) + [e.type]],
t.@new_accident_list += [s.@curr_accident_list.get(j)]
ELSE IF t.type == "Claim" AND getvid(s.@curr_v_list.get(j).get(0)) < getvid(t) THEN
t.@new_v_list += [s.@curr_v_list.get(j) + [t]],
t.@new_e_list += [s.@curr_e_list.get(j) + [e.type]],
t.@new_accident_list += [s.@curr_accident_list.get(j) + [t.accident_id]]
END
END
END
POST-ACCUM s.@curr_v_list.clear(),
s.@curr_accident_list.clear(),
s.@curr_e_list.clear();
Active = SELECT t FROM Active:t
POST-ACCUM t.@curr_v_list = t.@new_v_list,
t.@curr_accident_list = t.@new_accident_list,
t.@curr_e_list = t.@new_e_list,
t.@new_v_list.clear(),
t.@new_accident_list.clear(),
t.@new_e_list.clear()
HAVING t.@curr_v_list.size() > 0; # IF receive no sequences, deactivate it;
END;
_t = SELECT t FROM Active:t
POST-ACCUM t.@curr_v_list.clear(),
t.@curr_accident_list.clear(),
t.@curr_e_list.clear();
END;
IF print_accum THEN
PRINT @@cycles_list as cycles;
END;
}
Installing it again this time didn’t produce the shared memory not enough but some connection error (see image
).