Ejemplo n.º 1
0
 private void Initialize(IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph)
 {
     foreach (var cfgBlock in graph.Vertices)
     {
         _analysis.Initialize(cfgBlock);
     }
 }
        public void EmptyGraph(IBidirectionalGraph<string, Edge<string>> g)
        {
            this.dfs = new BidirectionalDepthFirstSearchAlgorithm<string, Edge<string>>(g);
            this.dfs.Compute();

            VerifyDfs();
        }
 /// <summary>
 /// Construct a filtered graph with an edge and a vertex predicate.
 /// </summary>
 /// <param name="g">graph to filter</param>
 /// <param name="edgePredicate">edge predicate</param>
 /// <param name="vertexPredicate">vertex predicate</param>
 /// <exception cref="ArgumentNullException">
 /// g, edgePredicate or vertexPredicate are null
 /// </exception>
 public FilteredBidirectionalGraph(
     IBidirectionalGraph g,
     IEdgePredicate edgePredicate,
     IVertexPredicate vertexPredicate)
     : base(g,edgePredicate,vertexPredicate)
 {
 }
Ejemplo n.º 4
0
 private void AddStartingBlocksToWorklist(IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph)
 {
     foreach (var startBlock in _traversalTechnique.GetStartBlocks(graph))
     {
         _workList.Add(startBlock);
     }
 }
Ejemplo n.º 5
0
        public void Analyze(IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph)
        {
            Preconditions.NotNull(graph, "graph");

            Initialize(graph);
            AddStartingBlocksToWorklist(graph);
            WorklistTraversal2(graph);
        }
 public TreeAdaptorGraph(IBidirectionalGraph wrapped)
 {
     if (wrapped == null)
     {
         throw new ArgumentNullException("wrapped");
     }
     this.wrapped = wrapped;
 }
Ejemplo n.º 7
0
        public void Sort <TVertex, TEdge>([PexAssumeNotNull] IBidirectionalGraph <TVertex, TEdge> g, TopologicalSortDirection direction)
            where TEdge : IEdge <TVertex>
        {
            var topo = new SourceFirstBidirectionalTopologicalSortAlgorithm <TVertex, TEdge>(g, direction);

            try
            {
                topo.Compute();
            }
            catch (NonAcyclicGraphException)
            { }
        }
 private static IEnumerable <TVertex> IsolatedVerticesIterator <TVertex, TEdge>(
     IBidirectionalGraph <TVertex, TEdge> visitedGraph)
     where TEdge : IEdge <TVertex>
 {
     foreach (var v in visitedGraph.Vertices)
     {
         if (visitedGraph.Degree(v) == 0)
         {
             yield return(v);
         }
     }
 }
 private static IEnumerable <TVertex> RootsIterator <TVertex, TEdge>(
     IBidirectionalGraph <TVertex, TEdge> visitedGraph)
     where TEdge : IEdge <TVertex>
 {
     foreach (var v in visitedGraph.Vertices)
     {
         if (visitedGraph.IsInEdgesEmpty(v))
         {
             yield return(v);
         }
     }
 }
Ejemplo n.º 10
0
        public void OutDegreeSumEqualsEdgeCount([PexAssumeNotNull] IBidirectionalGraph <string, Edge <string> > graph)
        {
            int edgeCount = graph.EdgeCount;
            int degCount  = 0;

            foreach (string v in graph.Vertices)
            {
                degCount += graph.OutDegree(v);
            }

            Assert.AreEqual(edgeCount, degCount);
        }
Ejemplo n.º 11
0
 private static void GenerateHierarchicalVertices(BidirectionalGraph <HierarchicalGraphVertex, HierarchicalGraphEdge> graph, HierarchicalGraphVertex vertex,
                                                  IBidirectionalGraph <Cluster <Variety>, ClusterEdge <Variety> > tree, Cluster <Variety> cluster)
 {
     foreach (ClusterEdge <Variety> edge in tree.OutEdges(cluster))
     {
         double depth     = vertex.Depth + edge.Length;
         var    newVertex = edge.Target.DataObjects.Count == 1 ? new HierarchicalGraphVertex(edge.Target.DataObjects.First(), depth) : new HierarchicalGraphVertex(depth);
         graph.AddVertex(newVertex);
         graph.AddEdge(new HierarchicalGraphEdge(vertex, newVertex, edge.Length));
         GenerateHierarchicalVertices(graph, newVertex, tree, edge.Target);
     }
 }
Ejemplo n.º 12
0
        public ResultWindow(List <object> vertices)
        {
            var g = new BidirectionalGraph <object, IEdge <object> >();

            foreach (object vertex in vertices)
            {
                g.AddVertex(vertex);
            }
            _graphToVisualize = g;

            InitializeComponent();
        }
        public EdgeMergeCondensationGraphAlgorithm(
            IBidirectionalGraph <TVertex, TEdge> visitedGraph,
            IMutableBidirectionalGraph <TVertex, MergedEdge <TVertex, TEdge> > condensatedGraph,
            VertexPredicate <TVertex> vertexPredicate
            ) : base(visitedGraph)
        {
            Contract.Requires(condensatedGraph != null);
            Contract.Requires(vertexPredicate != null);

            this.condensatedGraph = condensatedGraph;
            this.vertexPredicate  = vertexPredicate;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates an immutable array bidirectional graph from the input graph
        /// </summary>
        /// <typeparam name="TVertex">type of the vertices</typeparam>
        /// <typeparam name="TEdge">type of the edges</typeparam>
        /// <param name="graph"></param>
        /// <returns></returns>
        public static ArrayBidirectionalGraph <TVertex, TEdge> ToArrayBidirectionalGraph <TVertex, TEdge>(
#if !NET20
            this
#endif
            IBidirectionalGraph <TVertex, TEdge> graph
            )
            where TEdge : IEdge <TVertex>
        {
            Contract.Requires(graph != null);

            return(new ArrayBidirectionalGraph <TVertex, TEdge>(graph));
        }
        public void DependentClassifcation()
        {
            var classifiers   = new List <Classifier>();
            var dependentTree = new DependenceTree(this.vectors);

            foreach (var c in this.Classes)
            {
                classifiers.Add(new DependenceTreeClassifier(c.classId, dependentTree));
            }

            this.GraphToVisualize = dependentTree.GraphToVisualize;
            this.ClassifyData(classifiers);
        }
Ejemplo n.º 16
0
        public static IEnumerable <TEdge> GetOutEdges <TVertex, TEdge>(this IBidirectionalGraph <TVertex, TEdge> graph, TVertex vertex)
            where TEdge : IEdge <TVertex>
        {
            var result = new List <TEdge>();
            IEnumerable <TEdge> edges;

            graph.TryGetOutEdges(vertex, out edges);
            if (edges != null)
            {
                result.AddRange(edges);
            }
            return(result);
        }
Ejemplo n.º 17
0
        private static void Compute <TVertex, TEdge>([NotNull] IBidirectionalGraph <TVertex, TEdge> graph)
            where TEdge : IEdge <TVertex>
        {
            var dfs = new BidirectionalDepthFirstSearchAlgorithm <TVertex, TEdge>(graph);

            dfs.Compute();

            foreach (TVertex vertex in graph.Vertices)
            {
                Assert.IsTrue(dfs.VerticesColors.ContainsKey(vertex));
                Assert.AreEqual(dfs.VerticesColors[vertex], GraphColor.Black);
            }
        }
Ejemplo n.º 18
0
        public BidirectionalDepthFirstSearchAlgorithm(
            IBidirectionalGraph <TVertex, TEdge> visitedGraph,
            IDictionary <TVertex, GraphColor> colors
            )
            : base(visitedGraph)
        {
            if (colors == null)
            {
                throw new ArgumentNullException("VertexColors");
            }

            this.colors = colors;
        }
Ejemplo n.º 19
0
        public bool Analyze2(CFGBlock block, IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph)
        {
            var oldTaint = Taints[block];

            var newTaint = AnalyzeNode2(block, graph);

            if (MonotonicChange(oldTaint, newTaint))
            {
                _taints[block] = newTaint;
                return true;
            }
            return false;
        }
Ejemplo n.º 20
0
        public bool Analyze2(CFGBlock block, IBidirectionalGraph <CFGBlock, TaggedEdge <CFGBlock, EdgeTag> > graph)
        {
            var oldTaint = Taints[block];

            var newTaint = AnalyzeNode2(block, graph);

            if (MonotonicChange(oldTaint, newTaint))
            {
                _taints[block] = newTaint;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 21
0
        private static void Sort <TVertex, TEdge>([NotNull] IBidirectionalGraph <TVertex, TEdge> graph, TopologicalSortDirection direction)
            where TEdge : IEdge <TVertex>
        {
            var algorithm = new SourceFirstBidirectionalTopologicalSortAlgorithm <TVertex, TEdge>(graph, direction);

            try
            {
                algorithm.Compute();
            }
            catch (NonAcyclicGraphException)
            {
            }
        }
Ejemplo n.º 22
0
        private static void AssertDegreeSumEqualsTwiceEdgeCount <TVertex, TEdge>(
            IBidirectionalGraph <TVertex, TEdge> graph)
            where TEdge : IEdge <TVertex>
        {
            int totalDegree = 0;

            foreach (TVertex vertex in graph.Vertices)
            {
                totalDegree += graph.Degree(vertex);
            }

            Assert.AreEqual(graph.EdgeCount * 2, totalDegree);
        }
Ejemplo n.º 23
0
        private static void AssertInDegreeSumEqualsEdgeCount <TVertex, TEdge>(
            [NotNull] IBidirectionalGraph <TVertex, TEdge> graph)
            where TEdge : IEdge <TVertex>
        {
            int totalInDegree = 0;

            foreach (TVertex vertex in graph.Vertices)
            {
                totalInDegree += graph.InDegree(vertex);
            }

            Assert.AreEqual(graph.EdgeCount, totalInDegree);
        }
Ejemplo n.º 24
0
        private void OutDegreeSumEqualsEdgeCount <TVertex, TEdge>(
            IBidirectionalGraph <TVertex, TEdge> graph)
            where TEdge : IEdge <TVertex>
        {
            int edgeCount = graph.EdgeCount;
            int degCount  = 0;

            foreach (var v in graph.Vertices)
            {
                degCount += graph.OutDegree(v);
            }

            Assert.Equal(edgeCount, degCount);
        }
Ejemplo n.º 25
0
        public static IEnumerable <TVertex> IsolatedVertices <TVertex, TEdge>(
            IBidirectionalGraph <TVertex, TEdge> visitedGraph)
            where TEdge : IEdge <TVertex>
        {
            GraphContracts.AssumeNotNull(visitedGraph, "visitedGraph");

            foreach (var v in visitedGraph.Vertices)
            {
                if (visitedGraph.Degree(v) == 0)
                {
                    yield return(v);
                }
            }
        }
Ejemplo n.º 26
0
        public void OutDegreeSumEqualsEdgeCount <TVertex, TEdge>(
            [NotNull] IBidirectionalGraph <TVertex, TEdge> graph)
            where TEdge : IEdge <TVertex>
        {
            int edgeCount = graph.EdgeCount;
            int degCount  = 0;

            foreach (TVertex vertex in graph.Vertices)
            {
                degCount += graph.OutDegree(vertex);
            }

            Assert.AreEqual(edgeCount, degCount);
        }
        public void Compute <TVertex, TEdge>(IBidirectionalGraph <TVertex, TEdge> g)
            where TEdge : IEdge <TVertex>
        {
            var dfs = new BidirectionalDepthFirstSearchAlgorithm <TVertex, TEdge>(g);

            dfs.Compute();

            // let's make sure
            foreach (var v in g.Vertices)
            {
                Assert.IsTrue(dfs.VertexColors.ContainsKey(v));
                Assert.AreEqual(dfs.VertexColors[v], GraphColor.Black);
            }
        }
Ejemplo n.º 28
0
        public void InDegreeSumEqualsEdgeCount <TVertex, TEdge>(
            [PexAssumeNotNull] IBidirectionalGraph <TVertex, TEdge> graph)
            where TEdge : IEdge <TVertex>
        {
            int edgeCount = graph.EdgeCount;
            int degCount  = 0;

            foreach (var v in graph.Vertices)
            {
                degCount += graph.InDegree(v);
            }

            Assert.AreEqual(edgeCount, degCount);
        }
Ejemplo n.º 29
0
        public IBidirectionalGraph <HierarchicalGraphVertex, HierarchicalGraphEdge> GenerateHierarchicalGraph(HierarchicalGraphType graphType,
                                                                                                              ClusteringMethod clusteringMethod, SimilarityMetric similarityMetric)
        {
            switch (clusteringMethod)
            {
            case ClusteringMethod.Upgma:
                Func <Variety, Variety, double> upgmaGetDistance = null;
                switch (similarityMetric)
                {
                case SimilarityMetric.Lexical:
                    upgmaGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].LexicalSimilarityScore;
                    break;

                case SimilarityMetric.Phonetic:
                    upgmaGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].PhoneticSimilarityScore;
                    break;
                }

                var upgma = new UpgmaClusterer <Variety>(upgmaGetDistance);
                IBidirectionalGraph <Cluster <Variety>, ClusterEdge <Variety> > upgmaTree = upgma.GenerateClusters(_projectService.Project.Varieties);
                return(BuildHierarchicalGraph(upgmaTree));

            case ClusteringMethod.NeighborJoining:
                Func <Variety, Variety, double> njGetDistance = null;
                switch (similarityMetric)
                {
                case SimilarityMetric.Lexical:
                    njGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].LexicalSimilarityScore;
                    break;

                case SimilarityMetric.Phonetic:
                    njGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].PhoneticSimilarityScore;
                    break;
                }
                var nj = new NeighborJoiningClusterer <Variety>(njGetDistance);
                IUndirectedGraph <Cluster <Variety>, ClusterEdge <Variety> > njTree = nj.GenerateClusters(_projectService.Project.Varieties);
                switch (graphType)
                {
                case HierarchicalGraphType.Dendrogram:
                    IBidirectionalGraph <Cluster <Variety>, ClusterEdge <Variety> > rootedTree = njTree.ToRootedTree();
                    return(BuildHierarchicalGraph(rootedTree));

                case HierarchicalGraphType.Tree:
                    return(BuildHierarchicalGraph(njTree));
                }
                break;
            }

            return(null);
        }
Ejemplo n.º 30
0
        private static void RunSourceFirstTopologicalSortAndCheck <TVertex, TEdge>(
            [NotNull] IBidirectionalGraph <TVertex, TEdge> graph,
            TopologicalSortDirection direction)
            where TEdge : IEdge <TVertex>
        {
            var algorithm = new SourceFirstBidirectionalTopologicalSortAlgorithm <TVertex, TEdge>(graph, direction);

            algorithm.Compute();

            Assert.IsNotNull(algorithm.SortedVertices);
            Assert.AreEqual(graph.VertexCount, algorithm.SortedVertices.Length);
            Assert.IsNotNull(algorithm.InDegrees);
            Assert.AreEqual(graph.VertexCount, algorithm.InDegrees.Count);
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Recursively collects all vertices that can be reached from a given vertex
        /// by traversing only those edges that are chosen by a given predicate.
        /// </summary>
        public static IEnumerable <TVertex> GetAdjacentVertices <TVertex, TEdge>(this IBidirectionalGraph <TVertex, TEdge> graph,
                                                                                 TVertex vertex, EdgeDirection direction, EdgePredicate <TVertex, TEdge> edgePredicate = null, bool recursive = false)
            where TEdge : IEdge <TVertex>
        {
            if (!graph.ContainsVertex(vertex))
            {
                return(Enumerable.Empty <TVertex>());
            }

            var collectedVertices = new List <TVertex>();

            CollectAdjacentVerticesRecursive(graph, vertex, direction, collectedVertices, edgePredicate, recursive);
            return(collectedVertices.Except(vertex));
        }
Ejemplo n.º 32
0
        public ActionGraph(IEngineConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            var graph = new BidirectionalGraph <IAction, Edge <IAction> >(false);

            graph.AddVertexRange(config.Actions);
            var edges = config.Links.Select(x => new Edge <IAction>(x.From, x.To));

            graph.AddEdgeRange(edges);
            _graph = graph;
        }
Ejemplo n.º 33
0
        public static IEnumerable <TVertex> Roots <TVertex, TEdge>(
            IBidirectionalGraph <TVertex, TEdge> visitedGraph)
            where TEdge : IEdge <TVertex>
        {
            GraphContracts.AssumeNotNull(visitedGraph, "visitedGraph");

            foreach (var v in visitedGraph.Vertices)
            {
                if (visitedGraph.IsInEdgesEmpty(v))
                {
                    yield return(v);
                }
            }
        }
Ejemplo n.º 34
0
        public static bool FoundTarget <TVertex, TEdge>(IBidirectionalGraph <TVertex, TEdge> g, TVertex root, TVertex target) where TEdge : IEdge <TVertex>
        {
            IDistanceRelaxer distanceRelaxer = DistanceRelaxers.EdgeShortestDistance;
            var  algorithm     = new BestFirstFrontierSearchAlgorithm <TVertex, TEdge>(g, edgeWeights => 1.0, distanceRelaxer);
            bool targetReached = false;

            algorithm.TargetReached += (sender, args) => targetReached = true;

            var recorder = new VertexPredecessorRecorderObserver <TVertex, TEdge>();

            using (recorder.Attach(algorithm))
                algorithm.Compute(root, target);

            return(targetReached);
        }
Ejemplo n.º 35
0
        public static IEnumerable <TVertex> SourceFirstBidirectionalTopologicalSort <TVertex, TEdge>(
#if !NET20
            this
#endif
            IBidirectionalGraph <TVertex, TEdge> visitedGraph,
            TopologicalSortDirection direction)
            where TEdge : IEdge <TVertex>
        {
            Contract.Requires(visitedGraph != null);

            var vertices = new List <TVertex>(visitedGraph.VertexCount);

            SourceFirstBidirectionalTopologicalSort(visitedGraph, vertices, direction);
            return(vertices);
        }
        /// <summary>
        /// Constructs a new ArrayBidirectionalGraph instance from a
        /// IBidirectionalGraph instance
        /// </summary>
        /// <param name="visitedGraph"></param>
        public ArrayBidirectionalGraph(
            IBidirectionalGraph <TVertex, TEdge> visitedGraph
            )
        {
            Contract.Requires(visitedGraph != null);

            this.vertexEdges = new Dictionary <TVertex, InOutEdges>(visitedGraph.VertexCount);
            this.edgeCount   = visitedGraph.EdgeCount;
            foreach (var vertex in visitedGraph.Vertices)
            {
                var outEdges = Enumerable.ToArray(visitedGraph.OutEdges(vertex));
                var inEdges  = Enumerable.ToArray(visitedGraph.InEdges(vertex));
                this.vertexEdges.Add(vertex, new InOutEdges(outEdges, inEdges));
            }
        }
Ejemplo n.º 37
0
        public static void ShowGraphCircular(GraphLayout layout, IBidirectionalGraph <object, IEdge <object> > graph, int horizontalGap = 25, int verticalGap = 10)
        {
            var overlapParameters = new OverlapRemovalParameters();

            overlapParameters.HorizontalGap    = horizontalGap;
            overlapParameters.VerticalGap      = verticalGap;
            layout.OverlapRemovalParameters    = overlapParameters;
            layout.OverlapRemovalAlgorithmType = "FSA";
            layout.OverlapRemovalConstraint    = AlgorithmConstraints.Must;

            layout.LayoutMode          = LayoutMode.Simple;
            layout.LayoutAlgorithmType = "Circular";

            layout.Graph = graph;
        }
Ejemplo n.º 38
0
        private void WorklistTraversal(IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph)
        {
            while (_workList.Any())
            {
                var block = _workList.GetNext();
                var nextEdges = _traversalTechnique.NextEdges(graph, block);
                foreach (var edge in nextEdges)
                {
                    var didChange = _analysis.Analyze(edge);
                    var target =_traversalTechnique.EdgeTarget(edge);

                    if ((didChange || !_visited.Contains(target)) && !_workList.Contains(target))
                    {
                        _workList.Add(target);
                    }

                    _visited.Add(target);
                }
            }
        }
Ejemplo n.º 39
0
        private void CreateGraphToVisualize()
        {
            var g = new BidirectionalGraph<object, IEdge<object>>();

            //add the vertices to the graph
            string[] vertices = new string[5];
            for (int i = 0; i < 5; i++)
            {
                vertices[i] = i.ToString();
                g.AddVertex(vertices[i]);
            }

            //add some edges to the graph
            g.AddEdge(new Edge<object>(vertices[0], vertices[1]));
            g.AddEdge(new Edge<object>(vertices[1], vertices[2]));
            g.AddEdge(new Edge<object>(vertices[2], vertices[3]));
            g.AddEdge(new Edge<object>(vertices[3], vertices[1]));
            g.AddEdge(new Edge<object>(vertices[1], vertices[4]));

            _graphToVisualize = g;
        }
Ejemplo n.º 40
0
        private void WorklistTraversal2(IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph)
        {
            while (_workList.Any())
            {
                var block = _workList.GetNext();

                var didChange = _analysis.Analyze2(block, graph);

                var successors = graph.OutEdges(block)
                                      .OrderBy(e => e.Tag.EdgeType)
                                      .Select(e => e.Target);

                foreach (var successor in successors)
                {
                    if (didChange || !_visited.Contains(successor))
                    {
                        _workList.Add(successor);
                    }
                }

                _visited.Add(block);
            }
        }
Ejemplo n.º 41
0
 public IEnumerable<CFGBlock> GetStartBlocks(IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph)
 {
     return graph.Roots().Where(r => r.IsRoot);
 }
Ejemplo n.º 42
0
 private static IBidirectionalGraph<HierarchicalGraphVertex, HierarchicalGraphEdge> BuildHierarchicalGraph(IBidirectionalGraph<Cluster<Variety>, ClusterEdge<Variety>> tree)
 {
     var graph = new BidirectionalGraph<HierarchicalGraphVertex, HierarchicalGraphEdge>();
     var root = new HierarchicalGraphVertex(0);
     graph.AddVertex(root);
     GenerateHierarchicalVertices(graph, root, tree, tree.Roots().First());
     return graph;
 }
Ejemplo n.º 43
0
        private static void GenerateHierarchicalVertices(BidirectionalGraph<HierarchicalGraphVertex, HierarchicalGraphEdge> graph, HierarchicalGraphVertex vertex,
			IBidirectionalGraph<Cluster<Variety>, ClusterEdge<Variety>> tree, Cluster<Variety> cluster)
        {
            foreach (ClusterEdge<Variety> edge in tree.OutEdges(cluster))
            {
                double depth = vertex.Depth + edge.Length;
                var newVertex = edge.Target.DataObjects.Count == 1 ? new HierarchicalGraphVertex(edge.Target.DataObjects.First(), depth) : new HierarchicalGraphVertex(depth);
                graph.AddVertex(newVertex);
                graph.AddEdge(new HierarchicalGraphEdge(vertex, newVertex, edge.Length));
                GenerateHierarchicalVertices(graph, newVertex, tree, edge.Target);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="g"></param>
        /// <param name="assg"></param>
        public void Transform(IBidirectionalGraph g, IMutableVertexAndEdgeListGraph assg)
        {
            VertexCollection avs = new VertexCollection();
            // adding vertices
            foreach(IEdge e in g.Edges)
            {
                // xi_-(L) = g(xi_-(0), xi_+(L))
                CharacteristicVertex avm = (CharacteristicVertex)assg.AddVertex();
                avm.IncomingEdge = e;
                avm.Vertex = e.Target;
                avs.Add(avm);

                // xi_+(0) = g(xi_-(0), xi_+(L))
                CharacteristicVertex avp = (CharacteristicVertex)assg.AddVertex();
                avp.IncomingEdge = e;
                avp.Vertex = e.Source;
                avs.Add(avp);
            }

            // adding out edges
            foreach(CharacteristicVertex av in avs)
            {
                foreach(IEdge e in g.OutEdges(av.Vertex))
                {
                    // find target vertex:
                    CharacteristicVertex avtarget = FindTargetVertex(e);
                    // add xi_-
                    CharacteristicEdge aem = (CharacteristicEdge)assg.AddEdge(av,avtarget);
                    aem.Positive = false;
                    aem.Edge = e;
                }
                foreach(IEdge e in g.InEdges(av.Vertex))
                {
                    // find target vertex:
                    CharacteristicVertex avtarget = FindTargetVertex(e);
                    // add xi_-
                    CharacteristicEdge aem = (CharacteristicEdge)assg.AddEdge(av,avtarget);
                    aem.Positive = true;
                    aem.Edge = e;
                }
            }
        }
Ejemplo n.º 45
0
 /// <summary>
 /// Source vertex prodicate
 /// </summary>
 /// <param name="graph"></param>
 /// <returns></returns>
 public static SourceVertexPredicate SourceVertex(IBidirectionalGraph graph)
 {
     return new SourceVertexPredicate(graph);
 }
        public static void AddGraph(IBidirectionalGraph<object, IEdge<object>> graph, List<double> expectedValues, List<double> actualValues)
        {
            if (selfPtr == null)
            {
                selfPtr = new VisualizationManager();
            }
            while (selfPtr.graphList == null || selfPtr.expectedGraphOutputDataList == null || selfPtr.actualGraphOutputDataList == null)
            {
                Thread.Sleep(1);
            }

            selfPtr.graphList.Add(graph);
            selfPtr.expectedGraphOutputDataList.Add(ConvertDoubleListToPointCollection(expectedValues));
            selfPtr.actualGraphOutputDataList.Add(ConvertDoubleListToPointCollection(actualValues));
        }
Ejemplo n.º 47
0
        private CFGTaintInfo AnalyzeNode2(CFGBlock block, IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph)
        {
            var oldTaint = Taints[block];

            var predecessorsOut = graph.InEdges(block);
            var outTaints = predecessorsOut.Select(p => new { EdgeType = p.Tag, Source = p.Source })
                                           .Where(s => Taints[s.Source].Out != null && Taints[s.Source].Out.Any())
                                           .Select(s => Taints[s.Source].Out[s.EdgeType.EdgeType])
                                           .Where(o => o != null);
            ImmutableVariableStorage newInTaint;
            if (outTaints.Any())
            {
                newInTaint = oldTaint.In.Merge(outTaints.Aggregate((current, next) => current.Merge(next)));
            }
            else
            {
                newInTaint = oldTaint.In;
            }

            ImmutableDictionary<EdgeType, ImmutableVariableStorage> newOutTaint;

            if (block.AstEntryNode == null)
            {
                newOutTaint = ImmutableDictionary<EdgeType, ImmutableVariableStorage>.Empty.Add(EdgeType.Normal, newInTaint);
            }
            else
            {
                var newOut = _blockAnalyzer.Analyze(block.AstEntryNode, newInTaint);
                var newOutWithCondSani = _conditionTaintAnalyser.AnalyzeCond(block.AstEntryNode, newOut);

                newOutTaint = newOutWithCondSani.ToImmutableDictionary();
            }

            return new CFGTaintInfo(newInTaint, newOutTaint);
        }
Ejemplo n.º 48
0
 public IEnumerable<CFGBlock> GetStartBlocks(IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph)
 {
     return graph.Vertices.Where(v => v.IsLeaf);
 }
Ejemplo n.º 49
0
 public IEnumerable<TaggedEdge<CFGBlock, EdgeTag>> NextEdges(IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph, CFGBlock block)
 {
     return graph.InEdges(block);
 }
Ejemplo n.º 50
0
        private void Calculate()
        {
            initialList = new List<List<string>>();

            foreach (var item in initialStrings)
            {
                initialList.Add(Extensions.GetSplittedWords(item.Value));
            }

            comparationList = Operands.CompareLines(initialStrings.Values.ToList());

            List<List<int>> groupsList = Groupping.Group(comparationList);
            gropsFull = Operands.GetUniqueInGroups(initialStrings, groupsList);
            groupsSimplified = Groupping.Simplify(initialStrings, gropsFull);

            modulesFull = new Dictionary<List<int>, string>();
            graphsListInitial = new List<IBidirectionalGraph<object, IEdge<object>>>();
            graphsListModuled = new List<IBidirectionalGraph<object, IEdge<object>>>();

            int counter = 0;

            foreach (var item in groupsSimplified)
            {
                graphsListInitial.Add(Graph.AdjacentyMatrixToGraph(Modules.CreateRelationMatrix(initialStrings, item)));

                var modulesMatrix = Modules.GetModulesMatrix(initialStrings, item);
                graphsListModuled.Add(Graph.AdjacentyMatrixToGraph(modulesMatrix));

                modulesFull.Add(item.Key, String.Join("  ", modulesMatrix.Headers.Values.ToList()));
                counter++;
            }

            modulesUnique = Modules.GetModulesUnique(modulesFull);

            graphFlows = Modules.GetFlows(initialStrings.Values.ToList(),groupsSimplified.Values.ToList(), modulesUnique);

            initialized = true;
        }
 /// <summary>
 /// Create the predicate over <paramref name="graph"/>.
 /// </summary>
 /// <param name="graph">graph to visit</param>
 public SourceVertexPredicate(IBidirectionalGraph graph)
 {
     if (graph==null)
         throw new ArgumentNullException("graph");
     this.graph = graph;
 }
        public static void ContainsEdgeAssertions(IBidirectionalGraph<int, IEdge<int>> g,
            IEdge<int> e12,
            IEdge<int> f12,
            IEdge<int> e21,
            IEdge<int> f21)
        {
            Assert.AreEqual(0, g.InDegree(1));
            Assert.AreEqual(1, g.OutDegree(1));
            Assert.AreEqual(1, g.InDegree(2));
            Assert.AreEqual(0, g.OutDegree(2));
            Assert.AreEqual(1, g.OutEdges(1).Count());
            Assert.AreEqual(1, g.InEdges(2).Count());

            // e12 must be present in u, because we added it.
            Assert.IsTrue(g.ContainsEdge(e12));

            // f12 is also in u, because e12 == f12.
            Assert.IsTrue(g.ContainsEdge(f12));

            // e21 and f21 are not in u, because it's a directed graph.
            if (e21 != null) Assert.IsFalse(g.ContainsEdge(e21));
            if (f21 != null) Assert.IsFalse(g.ContainsEdge(f21));

            // there must be an edge between vertices 1, 2.
            Assert.IsTrue(g.ContainsEdge(1, 2));

            // no edge between vertices 2, 1, because the graph is directed.
            Assert.IsFalse(g.ContainsEdge(2, 1));

            // ContainsEdge(1, 3) raises contracts violation in IIncidenceGraphContract, because 3 is not in the graph.
            // obviously no edge between vertices 1, 3, as vertex 3 is not even present in the graph.
            // Assert.IsFalse(g.ContainsEdge(1, 3));
        }