internal static Dictionary <hyperarc, List <hyperarc> > SolveMutualBlocking(designGraph assemblyGraph, Dictionary <hyperarc, List <hyperarc> > dbgDictionary) { for (var i = 0; i < dbgDictionary.Count - 1; i++) { var iKey = dbgDictionary.Keys.ToList()[i]; for (var j = i + 1; j < dbgDictionary.Count; j++) { var jKey = dbgDictionary.Keys.ToList()[j]; if (dbgDictionary[iKey].Contains(jKey) && dbgDictionary[jKey].Contains(iKey)) { var nodes = new List <node>(); nodes.AddRange(iKey.nodes); nodes.AddRange(jKey.nodes); var nodes2 = new List <node>(nodes); var last = assemblyGraph.addHyperArc(nodes2); last.localLabels.Add(DisConstants.SCC); var updatedBlocking = new List <hyperarc>(); updatedBlocking.AddRange(dbgDictionary[iKey].Where(hy => hy != jKey)); updatedBlocking.AddRange(dbgDictionary[jKey].Where(hy => hy != iKey && !updatedBlocking.Contains(hy))); var updatedBlocking2 = new List <hyperarc>(updatedBlocking); dbgDictionary.Remove(iKey); dbgDictionary.Remove(jKey); foreach (var key in dbgDictionary.Keys.ToList()) { if (dbgDictionary[key].Contains(iKey) || dbgDictionary[key].Contains(jKey)) { dbgDictionary[key].Add(last); dbgDictionary[key].Remove(iKey); dbgDictionary[key].Remove(jKey); } } assemblyGraph.removeHyperArc(iKey); assemblyGraph.removeHyperArc(jKey); dbgDictionary.Add(last, updatedBlocking2); i--; break; } } } return(dbgDictionary); }
//Calculate the heuristic value of a given assembly A protected static double H(HashSet <Component> A) { if (A.Count <= 1) { return(0); } if (Memo.ContainsKey(A)) { return(Memo[A].Value); } var L = Math.Log(A.Count, 2); double MinTreeDepth = Math.Ceiling(L); var hy = Graph.addHyperArc(A.Cast <node>().ToList()); List <double> Values = new List <double>(); foreach (Connection arc in hy.IntraArcs.Where(a => a is Connection)) { HashSet <Component> arcnodes = new HashSet <Component>(new Component[] { (Component)arc.From, (Component)arc.To }); Values.Add(Memo[arcnodes].Value); } Graph.removeHyperArc(hy); Values.Sort(); double total = 0; for (int x = 0; x < MinTreeDepth; x++) { total = total + Values[x]; } return(Math.Max(total, Values.Last())); /* * var intraArcs = new List<arc>(); * foreach (var Component in subassemblyNodes) * { * foreach (arc arc in Component.arcs) * { * if (Component == arc.From) * { * if (subassemblyNodes.Contains(arc.To)) * intraArcs.Add(arc); * } * else * if (subassemblyNodes.Contains(arc.From)) * intraArcs.Add(arc); * } * } */ }
private static bool MutualBlocking(designGraph assemblyGraph, Dictionary <hyperarc, List <hyperarc> > dbgDictionary) { for (var i = 0; i < dbgDictionary.Count - 1; i++) { var iKey = dbgDictionary.Keys.ToList()[i]; for (var j = i + 1; j < dbgDictionary.Count; j++) { var jKey = dbgDictionary.Keys.ToList()[j]; if (dbgDictionary[iKey].Contains(jKey) && dbgDictionary[jKey].Contains(iKey)) { var nodes = new List <node>(); nodes.AddRange(iKey.nodes); nodes.AddRange(jKey.nodes); assemblyGraph.removeHyperArc(iKey); assemblyGraph.removeHyperArc(jKey); var last = assemblyGraph.addHyperArc(nodes); last.localLabels.Add(DisConstants.SCC); return(true); } } } return(false); }
internal static Dictionary <hyperarc, List <hyperarc> > SolveMutualBlocking(designGraph assemblyGraph, Dictionary <hyperarc, List <hyperarc> > dbgDictionary, Dictionary <hyperarc, List <hyperarc> > dbgDictionaryAdjacent, bool relaxingSc = false) { foreach (var key in dbgDictionary.Keys) { if (dbgDictionary[key].Contains(key)) { dbgDictionary[key].Remove(key); } } for (var i = 0; i < dbgDictionary.Count - 1; i++) { var iKey = dbgDictionary.Keys.ToList()[i]; dbgDictionary[iKey].RemoveAll(a => a == null); for (var j = i + 1; j < dbgDictionary.Count; j++) { var jKey = dbgDictionary.Keys.ToList()[j]; dbgDictionary[jKey].RemoveAll(a => a == null); if (dbgDictionary[iKey].Contains(jKey) && dbgDictionary[jKey].Contains(iKey)) { if (relaxingSc) { // if these two keys are not phisically connected, update the dbg /*if ( * assemblyGraph.arcs.Where(a => a is Connection) * .Cast<Connection>() * .Any( * a => * (iKey.nodes.Any(n => n.name == a.From.name) && * jKey.nodes.Any(n => n.name == a.To.name)) || * (iKey.nodes.Any(n => n.name == a.To.name) && * jKey.nodes.Any(n => n.name == a.From.name)))) * continue;*/ if (dbgDictionaryAdjacent[iKey].Contains(jKey) && dbgDictionaryAdjacent[jKey].Contains(iKey)) { continue; } // take the one with less volume and delete it from the value of the otherone's key var volumei = iKey.nodes.Cast <Component>().Sum(n => n.Volume); var volumej = jKey.nodes.Cast <Component>().Sum(n => n.Volume); if ((dbgDictionary[iKey].Count == 1 && dbgDictionary[jKey].Count == 1) || (dbgDictionary[iKey].Count > 1 && dbgDictionary[jKey].Count > 1)) { if (!dbgDictionaryAdjacent[iKey].Contains(jKey) && !dbgDictionaryAdjacent[jKey].Contains(iKey)) { if (volumei < volumej) { if (!dbgDictionaryAdjacent[iKey].Contains(jKey)) { dbgDictionary[iKey].Remove(jKey); } } else { dbgDictionary[jKey].Remove(iKey); } } if (!dbgDictionaryAdjacent[iKey].Contains(jKey)) { dbgDictionary[iKey].Remove(jKey); } else { dbgDictionary[jKey].Remove(iKey); } dbgDictionary[iKey].RemoveAll(a => a == null); dbgDictionary[jKey].RemoveAll(a => a == null); } else { if (!dbgDictionaryAdjacent[iKey].Contains(jKey) && !dbgDictionaryAdjacent[jKey].Contains(iKey)) { if (dbgDictionary[iKey].Count == 1) { dbgDictionary[iKey].Remove(jKey); } else { dbgDictionary[jKey].Remove(iKey); } } if (!dbgDictionaryAdjacent[iKey].Contains(jKey)) { dbgDictionary[iKey].Remove(jKey); } else { dbgDictionary[jKey].Remove(iKey); } dbgDictionary[iKey].RemoveAll(a => a == null); dbgDictionary[jKey].RemoveAll(a => a == null); } continue; } var nodes = new List <node>(); nodes.AddRange(iKey.nodes); nodes.AddRange(jKey.nodes); var nodes2 = new List <node>(nodes); var last = assemblyGraph.addHyperArc(nodes2); last.localLabels.Add(DisConstants.SCC); var updatedBlocking = new List <hyperarc>(); updatedBlocking.AddRange(dbgDictionary[iKey].Where(hy => hy != jKey)); updatedBlocking.AddRange( dbgDictionary[jKey].Where(hy => hy != iKey && !updatedBlocking.Contains(hy))); var updatedBlocking2 = new List <hyperarc>(updatedBlocking); dbgDictionary.Remove(iKey); dbgDictionary.Remove(jKey); foreach (var key in dbgDictionary.Keys.ToList()) { if (dbgDictionary[key].Contains(iKey) || dbgDictionary[key].Contains(jKey)) { dbgDictionary[key].Add(last); dbgDictionary[key].Remove(iKey); dbgDictionary[key].Remove(jKey); dbgDictionary[key].RemoveAll(a => a == null); } } assemblyGraph.removeHyperArc(iKey); assemblyGraph.removeHyperArc(jKey); // if there is no connection between the keys dbgDictionary.Add(last, updatedBlocking2); i--; break; } } } return(dbgDictionary); }