예제 #1
0
        private static Dictionary <hyperarc, List <hyperarc> > UpdateBlockingDic(Dictionary <hyperarc, List <hyperarc> > blockingDic)
        {
            var newBlocking = new Dictionary <hyperarc, List <hyperarc> >();

            foreach (var sccHy in blockingDic.Keys)
            {
                Preceedings.Clear();
                Counter0 = 0;
                PreceedingFinder(sccHy, blockingDic);
                Preceedings = Updates.UpdatePreceedings(Preceedings);
                Visited.Clear();
                var cpy = new List <hyperarc>(Preceedings);
                newBlocking.Add(sccHy, cpy);
            }
            return(newBlocking);
        }
        internal static void GenerateOptions(designGraph assemblyGraph, hyperarc seperate,
                                             Dictionary <hyperarc, List <hyperarc> > blockingDic)
        {
            // This sorting is not necessary, but I think it will speed up the search. Let's see!
            blockingDic = blockingDic.OrderBy(a => a.Value.Count).ToDictionary(x => x.Key, x => x.Value);
            var localRemovableHy   = new List <List <hyperarc> >();
            var trash              = new List <hyperarc>();
            var visitedStatesCount = 0;
            var visitedStates      = new List <hyperarc>();

            while (visitedStatesCount != blockingDic.Count)
            {
                foreach (var sccHy in blockingDic.Keys.Where(scc => !visitedStates.Contains(scc)))
                {
                    if (blockingDic[sccHy].Count == 0)
                    {
                        sccHy.localLabels.Add(DisConstants.Removable);
                        trash.Add(sccHy);
                        visitedStatesCount++;
                        visitedStates.Add(sccHy);
                        localRemovableHy.Add(new List <hyperarc> {
                            sccHy
                        });
                    }
                    else
                    {
                        if (blockingDic[sccHy].All(trash.Contains))
                        {
                            Preceedings.Clear();
                            visitedStatesCount++;
                            visitedStates.Add(sccHy);
                            PreceedingFinder(sccHy, blockingDic);
                            Preceedings = Updates.UpdatePreceedings(Preceedings);
                            var nodes = new List <node>();
                            foreach (var hyperarc in Preceedings)
                            {
                                nodes.AddRange(hyperarc.nodes);
                            }
                            if (nodes.Count == seperate.nodes.Count)
                            {
                                continue;
                            }
                            assemblyGraph.addHyperArc(nodes);
                            assemblyGraph.hyperarcs[assemblyGraph.hyperarcs.Count - 1].localLabels.Add(
                                DisConstants.Removable);
                            trash.Add(sccHy);
                            localRemovableHy.Add(new List <hyperarc>(Preceedings));
                            Preceedings.Clear();
                        }
                    }
                }
            }
            //I am not done yet, not all of the options are generated by this point!
            for (var i = 0; i < localRemovableHy.Count - 1; i++)
            {
                for (var j = i + 1; j < localRemovableHy.Count; j++)
                {
                    if (localRemovableHy[i].All(localRemovableHy[j].Contains) ||
                        localRemovableHy[j].All(localRemovableHy[i].Contains))
                    {
                        continue;
                    }
                    var merged = new List <hyperarc>();
                    merged.AddRange(localRemovableHy[i]);
                    foreach (var l in localRemovableHy[j].Where(l => !merged.Contains(l)))
                    {
                        merged.Add(l);
                    }

                    var exists = false;
                    for (var k = j + 1; k < localRemovableHy.Count; k++)
                    {
                        if (localRemovableHy[k].All(merged.Contains) &&
                            merged.All(localRemovableHy[k].Contains))
                        {
                            exists = true;
                            break;
                        }
                    }
                    if (exists)
                    {
                        continue;
                    }
                    var nodes = new List <node>();
                    foreach (var hy in merged)
                    {
                        nodes.AddRange(hy.nodes);
                    }
                    if (nodes.Count == seperate.nodes.Count)
                    {
                        continue;
                    }
                    assemblyGraph.addHyperArc(nodes);
                    assemblyGraph.hyperarcs[assemblyGraph.hyperarcs.Count - 1].localLabels.Add(
                        DisConstants.Removable);
                    localRemovableHy.Add(merged);
                }
            }
            //for (var i = 0; i < assemblyGraph.hyperarcs.Count; i++)
            //{
            //    var hyScc = assemblyGraph.hyperarcs[i];
            //    if (hyScc.localLabels.Contains(DisConstants.SCC) &&
            //        !hyScc.localLabels.Contains(DisConstants.Removable))
            //        assemblyGraph.hyperarcs.Remove(hyScc);
            //}
            foreach (var SCCHy in assemblyGraph.hyperarcs.Where(hyScc =>
                                                                hyScc.localLabels.Contains(DisConstants.SCC) &&
                                                                !hyScc.localLabels.Contains(DisConstants.Removable)).ToList())
            {
                assemblyGraph.hyperarcs.Remove(SCCHy);
            }
        }
예제 #3
0
        internal static List <AssemblyCandidate> Run(designGraph assemblyGraph, List <TessellatedSolid> solids, List <int> globalDirPool)
        {
            //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 beam               = new Queue <AssemblyCandidate>(DisConstants.BeamWidth);
            var found              = false;
            AssemblyCandidate goal = null;

            beam.Enqueue(new AssemblyCandidate(new candidate(assemblyGraph, 1)));
            while (beam.Count != 0 && !found)
            {
                candidates.Clear();
                foreach (var current in beam)
                {
                    var seperateHys = current.graph.hyperarcs.Where(h => h.localLabels.Contains(DisConstants.SeperateHyperarcs)).ToList();
                    var options     = new List <option>();
                    foreach (var cndDirInd in globalDirPool)
                    {
                        foreach (var seperateHy in seperateHys)
                        {
                            SCC.StronglyConnectedComponents(current.graph, seperateHy, cndDirInd);
                            //OptimizedSCC.StronglyConnectedComponents(current.graph, seperateHy, cndDirInd);
                            var blockingDic = DBG.DirectionalBlockingGraph(current.graph, cndDirInd);
                            //OptionGeneratorPro.GenerateOptions(current.graph, seperateHy, blockingDic);
                            options.AddRange(OptionGeneratorPro.GenerateOptions(current.graph, seperateHy, blockingDic, options));
                        }
                    }
                    //var ruleChoices = recogRule.recognize(current.graph);
                    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) > 0)
                        //    lock (candidates)
                        //        candidates.Add(child.performanceParams, child);
                        //child.addToRecipe(opt);
                    }
                }
                beam.Clear();
                var count = 0;
                foreach (var c in candidates.Values)
                {
                    if (isCurrentTheGoal(c))
                    {
                        goal  = c;
                        found = true;
                        break;
                    }
                    if (++count > DisConstants.BeamWidth)
                    {
                        break;
                    }
                    beam.Enqueue(c);
                }
            }
            solutions.Add(goal);
            return(solutions);
        }