internal static void UpdateBinding(Quantifier quant, Dictionary <string, MergedQuantifierInfo> quantifierNameToInfo) { var qName = normalizeName(quant); MergedQuantifierInfo info; if (!quantifierNameToInfo.TryGetValue(qName, out info)) { info = new MergedQuantifierInfo { Name = qName, Cost = 0, Conflicts = 0, Instances = new List <Instantiation>(), AllQuantifiers = new List <Quantifier>() }; quantifierNameToInfo.Add(qName, info); } info.Cost += quant.Cost; info.Conflicts += quant.GeneratedConflicts; if (quant.Instances.Any()) // Virtually every non-nested quantifier has two or three copies, all of them but one with 0 instantiations, and these copies often have incorrect body text { info.AllQuantifiers.Add(quant); } info.Instances.AddRange(quant.Instances); }
internal static Graph ComputeGraph(Model model) { const int MIN_COST = 0, MIN_COUNT = 0; var quantifierNameToInfo = new Dictionary <string, MergedQuantifierInfo>(); foreach (var source in model.GetRootNamespaceQuantifiers().Values) { MergedQuantifierInfo.UpdateBinding(source, quantifierNameToInfo); } var edges = new List <Edge>(); var nodes = new List <Node>(); var quantifiers = new HashSet <MergedQuantifierInfo>(); foreach (var source in quantifierNameToInfo.Values) { if (source.Cost > MIN_COST) { quantifiers.Add(source); var edgesTo = new Dictionary <string, int>(); foreach (var instance in source.Instances) { foreach (var dependants in instance.DependantInstantiations) { var dName = normalizeName(dependants.Quant); int count; edgesTo.TryGetValue(dName, out count); edgesTo[dName] = count + 1; } } foreach (var other in edgesTo.Keys) { var count = edgesTo[other]; if (quantifierNameToInfo.ContainsKey(other) && quantifierNameToInfo[other].Cost > MIN_COST && count > MIN_COUNT) { quantifiers.Add(quantifierNameToInfo[other]); edges.Add(new Edge { from = source.Name, to = other, value = count }); } } } } foreach (var quantifier in quantifiers) { const string titleFormat = "<b>Cost:</b> {1:0.}{0}<b>Instances:</b> {2}{0}<b>Conflicts:</b> {3}{0}<b>Triggers:</b> {4}{0}<b>Nested:</b> {5}{0}{0}{6}"; const string searchFormat = "Cost: {1:0.}{0}Instances: {2}{0}Conflicts: {3}{0}Triggers: {4}{0}Nested: {5}{0}{6}"; var one = quantifier.AllQuantifiers.First(); var title = string.Format(titleFormat, Environment.NewLine, quantifier.Cost, quantifier.Instances.Count, FormatConflicts(quantifier), FormatTriggers(one), FormatMerged(quantifier), FormatBody(quantifier.AllQuantifiers)); var search = string.Format(searchFormat, Environment.NewLine, quantifier.Cost, quantifier.Instances.Count, FormatConflicts(quantifier), FormatTriggers(one, false), FormatMerged(quantifier), FormatBody(quantifier.AllQuantifiers, false)); nodes.Add(new Node { id = quantifier.Name, value = (int)quantifier.Cost, label = quantifier.Name, title = title, search = search, mergedCount = quantifier.AllQuantifiers.Count }); } return(new Graph { edges = edges, nodes = nodes }); }
private static object FormatMerged(MergedQuantifierInfo quantifier) { var count = quantifier.AllQuantifiers.Count; return(count > 1 ? string.Format("merged {0} ({1})", count > 10 ? "many" : "some", count) : "none"); }
private static string FormatConflicts(MergedQuantifierInfo quantifier) { return(quantifier.Conflicts > 0 ? string.Format("found {0}", quantifier.Conflicts) : "none"); }