Ejemplo n.º 1
0
        public void test()
        {
            AllCyclesInDirectedGraphJohnson johnson = new AllCyclesInDirectedGraphJohnson();
            var allCycles = johnson.simpleCyles(graph);

            foreach (var cycle in allCycles)
            {
                string printCycles = $"->";
                foreach (var vertex in cycle)
                {
                    printCycles += vertex.getId();
                }
                System.Console.WriteLine(printCycles);
            }
        }
Ejemplo n.º 2
0
        public List <EdgePortPair> CutToAcyclicGraph()
        {
            var guid2LongMap = new Dictionary <Guid, long>();
            var long2GuidMap = new Dictionary <long, Guid>();

            foreach (var(guid, index) in _adjacencyList.Select((node, index) => (node.Id, index)))
            {
                guid2LongMap.Add(guid, index);
                long2GuidMap.Add(index, guid);
            }

            AllCyclesInDirectedGraphJohnson johnson = new AllCyclesInDirectedGraphJohnson();
            Graph <int> graph = new Graph <int>(true);

            foreach (var node in _adjacencyList)
            {
                foreach (var toNode in node.OutputLinks)
                {
                    graph.addEdge(guid2LongMap[node.Id], guid2LongMap[toNode.Id]);
                }
            }
            List <List <Vertex <int> > > allCycles = johnson.SimpleCycles(graph);
            var allCyclesGuid = new List <List <Guid> >();

            foreach (var cycle in allCycles)
            {
                var guidCycle = cycle.Select(vertex => long2GuidMap[vertex.GetId()]).ToList();
                allCyclesGuid.Add(guidCycle);
            }

            /*
             * 変更箇所
             */
            //var cutEdge = new Edge(allCyclesGuid.Last()[0], allCyclesGuid.Last()[1]);

            //Cut
            var cutEdges = ResolveAllCycle(allCyclesGuid);

            var edgePortPair = new List <EdgePortPair>();

            foreach (var cutEdge in cutEdges)
            {
                RemoveEdge(cutEdge.Vertex1, cutEdge.Vertex2);
                int port = _edgeToPort[cutEdge];
                edgePortPair.Add(new EdgePortPair(cutEdge, port));
            }
            return(edgePortPair);
        }
Ejemplo n.º 3
0
 private void Test()
 {
     AllCyclesInDirectedGraphJohnson.Test();
 }