public void BiggerSituation()
        {
            SimpleGraph graph = new SimpleGraph();

            Vertex A = graph.CreateVertex( "A" );
            Vertex B = graph.CreateVertex( "B" );
            Vertex C = graph.CreateVertex( "C" );
            Vertex D = graph.CreateVertex( "D" );
            Vertex E = graph.CreateVertex( "E" );
            Vertex F = graph.CreateVertex( "F" );
            Vertex G = graph.CreateVertex( "G" );

            graph.CreateEdge( B, C );
            graph.CreateEdge( A, C );
            graph.CreateEdge( C, E );
            graph.CreateEdge( B, E );
            graph.CreateEdge( A, E );
            graph.CreateEdge( E, F );
            graph.CreateEdge( F, G );

            Vertex[] vertices = TopologicalSort.Perform( graph );
            Vertex[] expected = new Vertex[] { A, B, D, C, E, F, G };

            AssertNotNull( vertices );
            AssertEquals( expected, vertices );
        }
예제 #2
0
 /// <summary>
 /// Creates and returns an edge which connects two 
 /// vertex in a direct manner.
 /// </summary>
 /// <param name="from"></param>
 /// <param name="to"></param>
 /// <returns></returns>
 public Edge CreateEdge(Vertex from, Vertex to)
 {
     Edge edge = new Edge(from, to);
     m_edges.Add(edge);
     from.AddSuccessor(to);
     return edge;
 }
 protected void AssertEquals( Vertex[] expected, Vertex[] result )
 {
     AssertEquals( expected.Length, result.Length );
     for(int i=0; i < expected.Length ; i++)
     {
         AssertEquals( expected[i], result[i] );
     }
 }
예제 #4
0
 private static int ObtainInDegree(Vertex vertex, Hashtable inDegree)
 {
     int value = 0;
     if (inDegree.ContainsKey(vertex))
     {
         value = (int) inDegree[ vertex ];
     }
     return value;
 }
        public void SimpleUse()
        {
            SimpleGraph graph = new SimpleGraph();

            Vertex A = graph.CreateVertex( "A" );
            Vertex B = graph.CreateVertex( "B" );
            Vertex C = graph.CreateVertex( "C" );
            Vertex D = graph.CreateVertex( "D" );
            Vertex E = graph.CreateVertex( "E" );

            graph.CreateEdge( A, B );
            graph.CreateEdge( A, C );
            graph.CreateEdge( C, D );

            Vertex[] vertices = TopologicalSort.Perform( graph );
            Vertex[] expected = new Vertex[] { A, E, B, C, D };

            AssertNotNull( vertices );
            AssertEquals( expected, vertices );
        }
예제 #6
0
 private static void IncrementDegree(Vertex vertex, Hashtable inDegree)
 {
     int value = ObtainInDegree(vertex, inDegree);
     inDegree[ vertex ] = ++value;
 }
예제 #7
0
 private static int DecrementDegree(Vertex vertex, Hashtable inDegree)
 {
     int value = ObtainInDegree(vertex, inDegree);
     inDegree[ vertex ] = --value;
     return value;
 }
예제 #8
0
 /// <summary>
 /// Constructs a Edge.
 /// </summary>
 /// <param name="from"></param>
 /// <param name="to"></param>
 public Edge(Vertex from, Vertex to)
 {
     m_source = from;
     m_target = to;
 }
예제 #9
0
 /// <summary>
 /// Creates and returns a vertex with a specified content.
 /// </summary>
 /// <param name="content"></param>
 /// <returns></returns>
 public Vertex CreateVertex(object content)
 {
     Vertex vertex = new Vertex(content);
     m_content2Vertex[ content ] = vertex;
     m_vertices.Add(vertex);
     return vertex;
 }
예제 #10
0
 /// <summary>
 /// Adds a vertex accessible from this Vertex instance.
 /// </summary>
 /// <param name="target"></param>
 public void AddSuccessor(Vertex target)
 {
     m_successors.Add( target );
 }