예제 #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);
            }
        }