Esempio n. 1
0
        public void OutEdges_Throws()
        {
            var graph1         = new AdjacencyGraph <EquatableTestVertex, Edge <EquatableTestVertex> >();
            var filteredGraph1 = new FilteredVertexAndEdgeListGraph
                                 <
                EquatableTestVertex,
                Edge <EquatableTestVertex>,
                AdjacencyGraph <EquatableTestVertex, Edge <EquatableTestVertex> >
                                 >(
                graph1,
                _ => true,
                _ => true);

            OutEdges_NullThrows_Test(filteredGraph1);
            OutEdges_Throws_Test(filteredGraph1);

            var graph2         = new AdjacencyGraph <int, Edge <int> >();
            var filteredGraph2 = new FilteredVertexAndEdgeListGraph <int, Edge <int>, AdjacencyGraph <int, Edge <int> > >(
                graph2,
                vertex => vertex < 4,
                _ => true);

            graph2.AddVertexRange(new[] { 1, 2, 3, 4, 5 });
            // ReSharper disable ReturnValueOfPureMethodIsNotUsed
            Assert.Throws <VertexNotFoundException>(() => filteredGraph2.OutEdges(4));
            Assert.Throws <VertexNotFoundException>(() => filteredGraph2.OutEdges(5));
            // ReSharper restore ReturnValueOfPureMethodIsNotUsed
        }
Esempio n. 2
0
        public void TryGetEdges_Throws()
        {
            var filteredGraph = new FilteredVertexAndEdgeListGraph <TestVertex, Edge <TestVertex>, AdjacencyGraph <TestVertex, Edge <TestVertex> > >(
                new AdjacencyGraph <TestVertex, Edge <TestVertex> >(),
                _ => true,
                _ => true);

            TryGetEdges_Throws_Test(filteredGraph);
        }
        public void ContainsVertex_Throws()
        {
            var filteredGraph = new FilteredVertexAndEdgeListGraph <TestVertex, Edge <TestVertex>, AdjacencyGraph <TestVertex, Edge <TestVertex> > >(
                new AdjacencyGraph <TestVertex, Edge <TestVertex> >(),
                vertex => true,
                edge => true);

            ContainsVertex_Throws_Test(filteredGraph);
        }
Esempio n. 4
0
        public void ContainsEdge_Throws()
        {
            var filteredGraph = new FilteredVertexAndEdgeListGraph <TestVertex, Edge <TestVertex>, AdjacencyGraph <TestVertex, Edge <TestVertex> > >(
                new AdjacencyGraph <TestVertex, Edge <TestVertex> >(),
                _ => true,
                _ => true);

            ContainsEdge_NullThrows_Test(filteredGraph);
            ContainsEdge_SourceTarget_Throws_Test(filteredGraph);
        }
Esempio n. 5
0
 public void Compute()
 {
     // filter nullabed edges out
     if (this.IgnoreAllowDBNull)
     {
         topo = new SourceFirstTopologicalSortAlgorithm(this.VisitedGraph);
     }
     else
     {
         FilteredVertexAndEdgeListGraph fgraph = new FilteredVertexAndEdgeListGraph(
             this.VisitedGraph,
             nonNullableRelationEdgePredicate,
             QuickGraph.Predicates.Preds.KeepAllVertices()
             );
         topo = new SourceFirstTopologicalSortAlgorithm(fgraph);
     }
     topo.Compute();
 }
Esempio n. 6
0
        public void OutEdge_Throws()
        {
            var graph1 = new AdjacencyGraph <int, Edge <int> >();

            OutEdge_Throws_Test(
                graph1,
                (vertexPredicate, edgePredicate) =>
                new FilteredVertexAndEdgeListGraph <int, Edge <int>, AdjacencyGraph <int, Edge <int> > >(
                    graph1,
                    vertexPredicate,
                    edgePredicate));

            var graph2         = new AdjacencyGraph <TestVertex, Edge <TestVertex> >();
            var filteredGraph2 = new FilteredVertexAndEdgeListGraph <TestVertex, Edge <TestVertex>, AdjacencyGraph <TestVertex, Edge <TestVertex> > >(
                graph2,
                _ => true,
                _ => true);

            OutEdge_NullThrows_Test(filteredGraph2);
        }
Esempio n. 7
0
        public void Construction()
        {
            VertexPredicate <int>            vertexPredicate = _ => true;
            EdgePredicate <int, Edge <int> > edgePredicate   = _ => true;

            var graph         = new AdjacencyGraph <int, Edge <int> >();
            var filteredGraph = new FilteredVertexAndEdgeListGraph <int, Edge <int>, AdjacencyGraph <int, Edge <int> > >(
                graph,
                vertexPredicate,
                edgePredicate);

            AssertGraphProperties(filteredGraph, graph);

            graph         = new AdjacencyGraph <int, Edge <int> >(false);
            filteredGraph = new FilteredVertexAndEdgeListGraph <int, Edge <int>, AdjacencyGraph <int, Edge <int> > >(
                graph,
                vertexPredicate,
                edgePredicate);
            AssertGraphProperties(filteredGraph, graph, false);

            #region Local function

            void AssertGraphProperties <TVertex, TEdge, TGraph>(
                FilteredVertexAndEdgeListGraph <TVertex, TEdge, TGraph> g,
                TGraph expectedGraph,
                bool parallelEdges = true)
                where TEdge : IEdge <TVertex>
                where TGraph : IVertexAndEdgeListGraph <TVertex, TEdge>
            {
                Assert.AreSame(expectedGraph, g.BaseGraph);
                Assert.IsTrue(g.IsDirected);
                Assert.AreEqual(parallelEdges, g.AllowParallelEdges);
                Assert.AreSame(vertexPredicate, g.VertexPredicate);
                Assert.AreSame(edgePredicate, g.EdgePredicate);
                AssertEmptyGraph(g);
            }

            #endregion
        }
Esempio n. 8
0
        private void FilterFsm()
        {
            AdjacencyGraph graph = GraphProvider.Fsm();

            // drawing the fsm
            DrawGraph(graph, "fsm");

            // filtering
            // putting all black besides S4
            // therefore all the edges touching s4 will be filtered out.
            VertexColorDictionary vertexColors = new VertexColorDictionary();
            IVertexPredicate      pred         = new NameEqualPredicate("S4");

            foreach (IVertex v in graph.Vertices)
            {
                if (pred.Test(v))
                {
                    vertexColors[v] = GraphColor.Black;
                }
                else
                {
                    vertexColors[v] = GraphColor.White;
                }
            }

            IVertexPredicate vp = new NoBlackVertexPredicate(vertexColors);
            IEdgePredicate   ep = new EdgePredicate(
                Preds.KeepAllEdges(),
                vp
                );
            IVertexAndEdgeListGraph filteredGraph = new FilteredVertexAndEdgeListGraph(graph,
                                                                                       ep,
                                                                                       vp
                                                                                       );

            DrawGraph(filteredGraph, "fsmfiltered");
        }