//Perform closure checking public bool back_scan(ref Dictionary <string, List <BETiep> > f_acc) { //For each i for (int i = 0; i < trans_db[0].Item2.tieps.Count; i++) { Dictionary <string, BETiep> acc = null; Dictionary <string, BETiep> rem = null; int counter = 0; int entity_idx = -1; foreach (Tuple <CoincidenceSequence, PatternInstance> entry in trans_db) { PatternInstance pi = entry.Item2; Tiep occ = pi.tieps[i]; Coincidence curr = pi.nexts[i]; if (counter == 0 || !entry.Item1.entity.Equals(trans_db[counter - 1].Item1.entity)) { entity_idx++; acc = rem; if (acc != null && acc.Count == 0) { break; } rem = new Dictionary <string, BETiep>(); } string p = curr.isCo ? Constants.CO_REP + "" : (curr.isMeet ? Constants.MEET_REP + "" : "*"); string tmp; //For ith before detection while (curr.index != occ.c.index) { bool meet = curr.index == occ.c.index - 1 && occ.c.isMeet; if (meet) { foreach (Tiep s in curr.tieps) { tmp = p + Constants.MEET_REP + s.premitive_rep; if (entity_idx == 0 || acc.ContainsKey(tmp)) { if (!rem.ContainsKey(tmp)) { if (entity_idx == 0) { rem.Add(tmp, new BETiep()); } else { rem.Add(tmp, acc[tmp]); } } rem[tmp].addOcc(counter, s.e); } } } else { foreach (Tiep s in curr.tieps) { tmp = p + "*" + s.premitive_rep; if ((entity_idx == 0 || acc.ContainsKey(tmp)) && maxGapHolds(s.e.fin_time, occ)) { if (!rem.ContainsKey(tmp)) { if (entity_idx == 0) { rem.Add(tmp, new BETiep()); } else { rem.Add(tmp, acc[tmp]); } } rem[tmp].addOcc(counter, s.e); } } } p = curr.isCo && curr.next.isMeet ? Constants.MEET_REP + "" : "*"; curr = curr.next; } //For ith co detection foreach (Tiep s in curr.tieps) { if (s.Equals(occ) || occ.Equals(s.orig)) { break; } tmp = p + Constants.CO_REP + s.premitive_rep; if (entity_idx == 0 || acc.ContainsKey(tmp)) { if (!rem.ContainsKey(tmp)) { if (entity_idx == 0) { rem.Add(tmp, new BETiep()); } else { rem.Add(tmp, acc[tmp]); } } rem[tmp].addOcc(counter, s.e); } } counter++; } acc = rem; if (acc.Count == 0) { continue; } //Fill the backward extension tieps foreach (KeyValuePair <string, BETiep> t in acc) { string tiep = t.Key.Substring(2); if (tiep[tiep.Length - 1] == Constants.ST_REP) { if (!f_acc.ContainsKey(tiep)) { f_acc.Add(tiep, new List <BETiep>()); } f_acc[tiep].Add(t.Value); } } //Look for a finish one whose start one is also there foreach (KeyValuePair <string, BETiep> t in acc) { string tiep = t.Key.Substring(2); if (tiep[tiep.Length - 1] == Constants.FIN_REP) { tiep = tiep.Replace(Constants.FIN_REP, Constants.ST_REP); if (f_acc.ContainsKey(tiep) && checkStFinMatch(f_acc[tiep], t.Value)) { return(false); } } } } return(true); }