internal static List <AssemblyCandidate> Run(designGraph assemblyGraph, List <TessellatedSolid> solids, List <int> globalDirPool, List <TessellatedSolid> solides) { //DisassemblyDirections.Directions = TemporaryDirections(); var solutions = new List <AssemblyCandidate>(); assemblyEvaluator = new AssemblyEvaluator(solids); //Updates.UpdateGlobalDirections(globalDirPool); assemblyGraph.addHyperArc(assemblyGraph.nodes); var iniHy = assemblyGraph.hyperarcs[assemblyGraph.hyperarcs.Count - 1]; iniHy.localLabels.Add(DisConstants.SeperateHyperarcs); var candidates = new SortedList <List <double>, AssemblyCandidate>(new MO_optimizeSort()); var found = false; AssemblyCandidate goal = null; var ini = new AssemblyCandidate(new candidate(assemblyGraph, 1)); candidates.Add(new List <double>(), ini); while (candidates.Count != 0 && !found) { var current = candidates.Values[0]; candidates.Clear(); if (isCurrentTheGoal(current)) { goal = current; found = true; break; } var options = new List <option>(); foreach (var cndDirInd in globalDirPool) { foreach ( var seperateHy in current.graph.hyperarcs.Where(h => h.localLabels.Contains(DisConstants.SeperateHyperarcs)) .ToList()) { SCC.StronglyConnectedComponents(current.graph, seperateHy, cndDirInd); //BoostedSCC.StronglyConnectedComponents(current.graph, seperateHy, cndDirInd); var blockingDic = DBG.DirectionalBlockingGraph(current.graph, cndDirInd); options.AddRange(OptionGeneratorPro.GenerateOptions(current.graph, seperateHy, blockingDic, options)); } } foreach (var opt in options) { //var child = (AssemblyCandidate) current.copy(); //SearchProcess.transferLmappingToChild(child.graph, current.graph, opt); //var rest = Updates.AddSecondHyperToOption(child, opt); //Updates.ApplyChild(child, opt); //if (assemblyEvaluator.Evaluate(child, opt, rest, solides) > 0) // candidates.Add(child.performanceParams, child); //child.addToRecipe(opt); } } solutions.Add(goal); TemporaryFixingSequence(goal); return(solutions); }
// OptimizedSCC is the modified SCC. In this class, a dictionary of SCCs for each direction is created // to take benefit from premade SCC hyperarcs. The dictionary will be updated after each "apply" internal static void StronglyConnectedComponents(designGraph assemblyGraph, hyperarc seperateHy, int cndDir) { var preAddedSccs = new List <Component>(); if (BeamSearch.SccTracker.Keys.Contains(cndDir)) { foreach (var premadeSCC in BeamSearch.SccTracker[cndDir]) { var c = 0; foreach (var node in premadeSCC) { c += seperateHy.nodes.Count(n => n.name == node.name); } if (c != premadeSCC.Count) { continue; } var nodes = new List <node>(); foreach (var n in premadeSCC) { nodes.AddRange(seperateHy.nodes.Where(a => a.name == n.name)); } var last = assemblyGraph.addHyperArc(nodes); last.localLabels.Add(DisConstants.SCC); preAddedSccs.AddRange(premadeSCC); } //foreach (var premadeSCC in DisassemblyProcess.SccTracker[cndDir].Where(pmSCC => pmSCC.All(n => seperateHy.nodes.Contains(n)))) //{ // var last = assemblyGraph.addHyperArc(premadeSCC); // last.localLabels.Add(DisConstants.SCC); // preAddedSccs.AddRange(premadeSCC); //} } var globalVisited = new List <Component>(); var stack = new Stack <Component>(); var visited = new HashSet <Component>(); var sccTrackerNodes = new List <List <Component> >(); foreach (Component node in seperateHy.nodes.Where(n => !globalVisited.Contains(n))) { if (preAddedSccs.Any(n => n.name == node.name)) { continue; } stack.Clear(); visited.Clear(); stack.Push(node); while (stack.Count > 0) { var pNode = stack.Pop(); visited.Add(pNode); globalVisited.Add(pNode); foreach (Connection pNodeArc in pNode.arcs.Where(a => a.GetType() == typeof(Connection))) { if (SCC.Removable(pNodeArc, cndDir)) { continue; } var otherNode = (Component)(pNodeArc.From == pNode ? pNodeArc.To : pNodeArc.From); if (visited.Contains(otherNode)) { continue; } stack.Push(otherNode); } } assemblyGraph.addHyperArc(visited.Cast <node>().ToList()); assemblyGraph.hyperarcs[assemblyGraph.hyperarcs.Count - 1].localLabels.Add(DisConstants.SCC); sccTrackerNodes.Add(visited.ToList()); } if (BeamSearch.SccTracker.Keys.Contains(cndDir)) { BeamSearch.SccTracker[cndDir] = sccTrackerNodes; } else { BeamSearch.SccTracker.Add(cndDir, sccTrackerNodes); } }