// Adds an indexed inequality to a dictionary private void AddIndexedIneq(Inequality ineq, LpNumber marginal, ListHyp hypermap) { IndexedInequality newIneq = new IndexedInequality(ineq, marginal, hypermap); string name = ineq.Id.name; // Ad hoc treatment of sums over faces if (name == "sol_sum" || name == "tau_sum") { DartList face = hypermap.Manager.TranslateIneq(hypermap, ineq.Id) as DartList; if (face == null) { throw new Exception("A face is expected for the constraint " + name); } name += face.list.Count.ToString(); } if (ineq.type == Inequality.IneqType.Eq && ineq.NegFlag) { name += "_neg"; } if (dict.ContainsKey(name)) { dict[name].Add(newIneq); } else { var list = new List <IndexedInequality>(); list.Add(newIneq); dict.Add(name, list); ineqNames.Add(name); } }
public override bool Equals(object obj) { DartList list2 = obj as DartList; if (list2 == null) { return(false); } int n = list.Count; for (int i = 0; i < n; i++) { if (!list[i].Equals(list2.list[i])) { return(false); } } return(true); }
/// <summary> /// Computes all sets of darts /// </summary> public void ComputeAllSets(List<int> facesPermutation) { // faces var faces = list.map(l => ListPairs(l)); var faces3 = faces.filter(f => f.Count == 3); var faces4 = faces.filter(f => f.Count == 4); var faces5 = faces.filter(f => f.Count == 5); var faces6 = faces.filter(f => f.Count == 6); // darts var darts = faces.flatten(); var darts3 = faces3.flatten(); var darts4 = faces4.flatten(); var darts5 = faces5.flatten(); var darts6 = faces6.flatten(); // edges var edges = darts.map(d => new List<Dart>(new Dart[] {d, new Dart(d.b, d.a)} )); // dartPairs var dartPairs = darts.map(x => darts.map(y => new List<Dart>(new Dart[] { x, y }))).flatten(); // nodes var elements = list.flatten().removeDuplicates(); var nodes = elements.map(x => darts.filter(d => d.a == x)); // Add everything to the collection of all sets sets = new Dictionary<string, List<HypermapElement>>(); sets.Add("faces", faces.ToHypermapElements()); sets.Add("darts", darts.ToHypermapElements()); sets.Add("edges", edges.ToHypermapElements()); sets.Add("nodes", nodes.ToHypermapElements()); sets.Add("darts3", darts3.ToHypermapElements()); sets.Add("darts4", darts4.ToHypermapElements()); sets.Add("darts5", darts5.ToHypermapElements()); sets.Add("darts6", darts6.ToHypermapElements()); sets.Add("faces3", faces3.ToHypermapElements()); sets.Add("faces4", faces4.ToHypermapElements()); sets.Add("faces5", faces5.ToHypermapElements()); sets.Add("faces6", faces6.ToHypermapElements()); sets.Add("dart_pairs", dartPairs.ToHypermapElements()); // Create the translation tables translationTables = new Dictionary<string, Dictionary<string, HypermapElement>>(); // e_darts, faces, darts Dictionary<string, HypermapElement> e_darts = new Dictionary<string, HypermapElement>(); Dictionary<string, HypermapElement> mod_faces = new Dictionary<string,HypermapElement>(); Dictionary<string, HypermapElement> mod_face3_darts = new Dictionary<string, HypermapElement>(); Dictionary<string, HypermapElement> mod_face4_darts = new Dictionary<string, HypermapElement>(); Dictionary<string, HypermapElement> mod_face5_darts = new Dictionary<string, HypermapElement>(); Dictionary<string, HypermapElement> mod_face6_darts = new Dictionary<string, HypermapElement>(); Dictionary<string, HypermapElement> mod_darts = new Dictionary<string, HypermapElement>(); Dictionary<string, HypermapElement> mod_edartPairs = new Dictionary<string, HypermapElement>(); Dictionary<string, HypermapElement> mod_dartPairsFst = new Dictionary<string, HypermapElement>(); Dictionary<string, HypermapElement> mod_edartPairsFst = new Dictionary<string, HypermapElement>(); for (int j = 0; j < list.Count; j++) { int mod_index = facesPermutation[j]; var f = list[j]; int n = f.Count; for (int i = 0; i < n; i++) { int i1 = f[i]; int i2 = f[(i + 1) % n]; int i3 = f[(i + 2) % n]; string e_dart = i1 + "," + i2 + "," + i3 + "," + mod_index; string dart = i2 + "," + mod_index; HypermapElement d = new Dart(i2, i3); // (i1,i2,i3,j) corresponds to (i2,i3); (i1,j) = f^(-1)(i2,j) and (i3,j) = f(i2,j) e_darts.Add(e_dart, d); mod_darts.Add(dart, d); } mod_faces.Add(mod_index.ToString(), new DartList(faces[j])); var mod_face_darts = mod_face3_darts; switch (n) { case 3: mod_face_darts = mod_face3_darts; break; case 4: mod_face_darts = mod_face4_darts; break; case 5: mod_face_darts = mod_face5_darts; break; case 6: mod_face_darts = mod_face6_darts; break; default: throw new Exception(String.Format("Unexpected face size {0}", n)); } mod_face_darts.Add(mod_index.ToString(), faces[j][0]); } // extended dart pairs foreach (string e_dart1 in e_darts.Keys) { var dart1 = e_darts[e_dart1] as Dart; foreach (string e_dart2 in e_darts.Keys) { var dart2 = e_darts[e_dart2] as Dart; String e_pair = e_dart1 + "," + e_dart2; DartList pair = new DartList(dart1, dart2); mod_edartPairs.Add(e_pair, pair); mod_edartPairsFst.Add(e_pair, dart1); } } // dart pairs foreach (string dart1 in mod_darts.Keys) { Dart d1 = mod_darts[dart1] as Dart; foreach (string dart2 in mod_darts.Keys) { String dart_pair = dart1 + "," + dart2; mod_dartPairsFst.Add(dart_pair, d1); } } // nodes Dictionary<string, HypermapElement> mod_nodes = new Dictionary<string, HypermapElement>(); foreach (int x in elements) { mod_nodes.Add(x.ToString(), new DartList(darts.filter(d => d.a == x))); } // edges Dictionary<string, HypermapElement> mod_edges = new Dictionary<string, HypermapElement>(); foreach (var e in edges) { Dart d1 = e[0]; Dart d2 = e[1]; int i1 = d1.a; int j1 = facesPermutation[FindFaceIndex(d1.a, d1.b)]; int i2 = d2.a; int j2 = facesPermutation[FindFaceIndex(d2.a, d2.b)]; string edge = i1 + "," + j1 + "," + i2 + "," + j2; mod_edges.Add(edge, new DartList(e)); } // Add everything into the global table translationTables.Add("e_dart", e_darts); translationTables.Add("dart", mod_darts); translationTables.Add("edge", mod_edges); translationTables.Add("face", mod_faces); translationTables.Add("node", mod_nodes); translationTables.Add("face3_dart", mod_face3_darts); translationTables.Add("face4_dart", mod_face4_darts); translationTables.Add("face5_dart", mod_face5_darts); translationTables.Add("face6_dart", mod_face6_darts); translationTables.Add("dart_pairs_fst", mod_dartPairsFst); translationTables.Add("e_dart_pairs", mod_edartPairs); translationTables.Add("e_dart_pairs_fst", mod_edartPairsFst); }
/// <summary> /// Computes all sets of darts /// </summary> public void ComputeAllSets(List <int> facesPermutation) { // faces var faces = list.map(l => ListPairs(l)); var faces3 = faces.filter(f => f.Count == 3); var faces4 = faces.filter(f => f.Count == 4); var faces5 = faces.filter(f => f.Count == 5); var faces6 = faces.filter(f => f.Count == 6); // darts var darts = faces.flatten(); var darts3 = faces3.flatten(); var darts4 = faces4.flatten(); var darts5 = faces5.flatten(); var darts6 = faces6.flatten(); // edges var edges = darts.map(d => new List <Dart>(new Dart[] { d, new Dart(d.b, d.a) })); // dartPairs var dartPairs = darts.map(x => darts.map(y => new List <Dart>(new Dart[] { x, y }))).flatten(); // nodes var elements = list.flatten().removeDuplicates(); var nodes = elements.map(x => darts.filter(d => d.a == x)); // Add everything to the collection of all sets sets = new Dictionary <string, List <HypermapElement> >(); sets.Add("faces", faces.ToHypermapElements()); sets.Add("darts", darts.ToHypermapElements()); sets.Add("edges", edges.ToHypermapElements()); sets.Add("nodes", nodes.ToHypermapElements()); sets.Add("darts3", darts3.ToHypermapElements()); sets.Add("darts4", darts4.ToHypermapElements()); sets.Add("darts5", darts5.ToHypermapElements()); sets.Add("darts6", darts6.ToHypermapElements()); sets.Add("faces3", faces3.ToHypermapElements()); sets.Add("faces4", faces4.ToHypermapElements()); sets.Add("faces5", faces5.ToHypermapElements()); sets.Add("faces6", faces6.ToHypermapElements()); sets.Add("dart_pairs", dartPairs.ToHypermapElements()); // Create the translation tables translationTables = new Dictionary <string, Dictionary <string, HypermapElement> >(); // e_darts, faces, darts Dictionary <string, HypermapElement> e_darts = new Dictionary <string, HypermapElement>(); Dictionary <string, HypermapElement> mod_faces = new Dictionary <string, HypermapElement>(); Dictionary <string, HypermapElement> mod_face3_darts = new Dictionary <string, HypermapElement>(); Dictionary <string, HypermapElement> mod_face4_darts = new Dictionary <string, HypermapElement>(); Dictionary <string, HypermapElement> mod_face5_darts = new Dictionary <string, HypermapElement>(); Dictionary <string, HypermapElement> mod_face6_darts = new Dictionary <string, HypermapElement>(); Dictionary <string, HypermapElement> mod_darts = new Dictionary <string, HypermapElement>(); Dictionary <string, HypermapElement> mod_edartPairs = new Dictionary <string, HypermapElement>(); Dictionary <string, HypermapElement> mod_dartPairsFst = new Dictionary <string, HypermapElement>(); Dictionary <string, HypermapElement> mod_edartPairsFst = new Dictionary <string, HypermapElement>(); for (int j = 0; j < list.Count; j++) { int mod_index = facesPermutation[j]; var f = list[j]; int n = f.Count; for (int i = 0; i < n; i++) { int i1 = f[i]; int i2 = f[(i + 1) % n]; int i3 = f[(i + 2) % n]; string e_dart = i1 + "," + i2 + "," + i3 + "," + mod_index; string dart = i2 + "," + mod_index; HypermapElement d = new Dart(i2, i3); // (i1,i2,i3,j) corresponds to (i2,i3); (i1,j) = f^(-1)(i2,j) and (i3,j) = f(i2,j) e_darts.Add(e_dart, d); mod_darts.Add(dart, d); } mod_faces.Add(mod_index.ToString(), new DartList(faces[j])); var mod_face_darts = mod_face3_darts; switch (n) { case 3: mod_face_darts = mod_face3_darts; break; case 4: mod_face_darts = mod_face4_darts; break; case 5: mod_face_darts = mod_face5_darts; break; case 6: mod_face_darts = mod_face6_darts; break; default: throw new Exception(String.Format("Unexpected face size {0}", n)); } mod_face_darts.Add(mod_index.ToString(), faces[j][0]); } // extended dart pairs foreach (string e_dart1 in e_darts.Keys) { var dart1 = e_darts[e_dart1] as Dart; foreach (string e_dart2 in e_darts.Keys) { var dart2 = e_darts[e_dart2] as Dart; String e_pair = e_dart1 + "," + e_dart2; DartList pair = new DartList(dart1, dart2); mod_edartPairs.Add(e_pair, pair); mod_edartPairsFst.Add(e_pair, dart1); } } // dart pairs foreach (string dart1 in mod_darts.Keys) { Dart d1 = mod_darts[dart1] as Dart; foreach (string dart2 in mod_darts.Keys) { String dart_pair = dart1 + "," + dart2; mod_dartPairsFst.Add(dart_pair, d1); } } // nodes Dictionary <string, HypermapElement> mod_nodes = new Dictionary <string, HypermapElement>(); foreach (int x in elements) { mod_nodes.Add(x.ToString(), new DartList(darts.filter(d => d.a == x))); } // edges Dictionary <string, HypermapElement> mod_edges = new Dictionary <string, HypermapElement>(); foreach (var e in edges) { Dart d1 = e[0]; Dart d2 = e[1]; int i1 = d1.a; int j1 = facesPermutation[FindFaceIndex(d1.a, d1.b)]; int i2 = d2.a; int j2 = facesPermutation[FindFaceIndex(d2.a, d2.b)]; string edge = i1 + "," + j1 + "," + i2 + "," + j2; mod_edges.Add(edge, new DartList(e)); } // Add everything into the global table translationTables.Add("e_dart", e_darts); translationTables.Add("dart", mod_darts); translationTables.Add("edge", mod_edges); translationTables.Add("face", mod_faces); translationTables.Add("node", mod_nodes); translationTables.Add("face3_dart", mod_face3_darts); translationTables.Add("face4_dart", mod_face4_darts); translationTables.Add("face5_dart", mod_face5_darts); translationTables.Add("face6_dart", mod_face6_darts); translationTables.Add("dart_pairs_fst", mod_dartPairsFst); translationTables.Add("e_dart_pairs", mod_edartPairs); translationTables.Add("e_dart_pairs_fst", mod_edartPairsFst); }