public Group ComputeGroup() { List <Split> groups = new List <Split>(); Group result = new Group(affinity.F); Queue <Split> q = new Queue <Split>(); q.Enqueue(firstSplit); groups.Add(firstSplit); while (q.Count != 0) { Tuple <int[], int[]> res; Split current = q.Dequeue(); // Debug.WriteLine("Try to divide " + current); if (current.divide(out res)) { // Debug.Write("Divided: "); groups.Remove(current); //remove current split --> usa equals if (res.Item1 != null && res.Item1.Length > 1) { Split sub1 = new Split(res.Item1, this); // Debug.Write(sub1 + ", "); groups.Add(sub1); q.Enqueue(sub1); } if (res.Item2 != null && res.Item2.Length > 1) { Split sub2 = new Split(res.Item2, this); groups.Add(sub2); // Debug.WriteLine(sub2); q.Enqueue(sub2); } } } foreach (Split s in groups) { List <Person> p = new List <Person>(); foreach (int n in s.members) { p.Add(affinity.F.getPersonByHelpLabel(n)); } result.addSubGroup(p); } return(result); }
public List <Group> readGT(List <Frame> frames) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); List <Group> groups = new List <Group>(); string[] gtLines = null; //read lines from gt file try { gtLines = File.ReadAllLines(GtFile); } catch (FileNotFoundException e) { Console.Write("Error file gt: "); Console.WriteLine(e.Message); } int i = 0; while (i < gtLines?.Length) { //first line has to be a frame header Match m = Regex.Match(gtLines[i], framePattern); if (m.Success) { int id = Int32.Parse(m.Groups[1].Value); //frame id int n = Int32.Parse(m.Groups[2].Value); //frame groups // trova il frame con ID == id Frame currentFrame = frames.Find(x => x.IdFrame == id); Group newGroup = FactoryGroup.createGroup(currentFrame); for (int j = 1; j <= n; j++) //for each subgroup { List <Person> peopleGroup = new List <Person>(); string[] elements = gtLines[i + j].Split(new Char[] { ' ' }); //space is the separator foreach (string s in elements) { int personId = Int32.Parse(s); Person p = currentFrame.getPersonById(personId); peopleGroup.Add(p); } newGroup.addSubGroup(peopleGroup); } //add the new grouping groups.Add(newGroup); //update i i = i + n + 1; } else { i++; } } Debug.WriteLine("Parser: Groups created: " + groups.Count + " grouping"); return(groups); }