public void Run()
        {
            ComputeNodesToProcess();
            ComputeSlot();

            if (!slotBitSet.Any())
            {
                Done = true;

                return;
            }

            log.InfoFormat($"Slot bits {slotBitSet.Count}");

            CreateVectors();
            InitVectors();

            DAG.BFS_VLevels(
                rdaContext.CFG,
                GraphDirection.Forward,
                nodeVLevels,
                currentLevel,
                ComputeVectors,
                _ => true);

            ComputeDefUsePairSet();
            ClearVectors();

            slotBitSet.Clear();
            Done = true;
        }
Exemple #2
0
        public void CreateCommodityGraphs()
        {
            lock (objectToLock)
            {
                log.DebugFormat(
                    "CreateCommodityGraphs: {0}",
                    meapContext.Commodities.Count);

                foreach (KeyValuePair <long, Commodity> p in meapContext.Commodities)
                {
                    long      commodityId = p.Key;
                    Commodity commodity   = p.Value;

                    DAG Gi = new("Gi");
                    DAG.MakeCommodity(meapContext.TArbSeqCFG, commodity.sNodeId, commodity.tNodeId, Gi);

                    commodity.Gi = Gi;
                }

                ICommonOptions       commonOptions       = configuration.Get <ICommonOptions>();
                ICheckDataStructures checkDataStructures = configuration.Get <ICheckDataStructures>();

                if (commonOptions.CheckDataStructures)
                {
                    checkDataStructures.CheckCommoditiesHaveNoSingleNodes(meapContext);
                }

                ExcludeDefs();

                if (commonOptions.CheckDataStructures)
                {
                    checkDataStructures.CheckCommoditiesHaveNoSingleNodes(meapContext);
                }
            }
        }
        private static void MakePathsSubgraph_t(
            DAG graph,
            long sNodeId,
            long tNodeId,
            DAG subgraph)
        {
            SortedSet <long> labelBMap = new();

            PropagateProperties(
                graph,
                tNodeId,
                GraphDirection.Backward,
                (_) => true,
                _ => true,
                w => { labelBMap.Add(w.Id); return(true); },
                _ => true);

            labelBMap.Add(sNodeId);
            labelBMap.Add(tNodeId);

            MakeSubgraph(
                graph,
                sNodeId,
                tNodeId,
                labelBMap,
                subgraph);
        }
Exemple #4
0
        private bool RemoveNotConnectedCommodities(SortedSet <long> excludedComms)
        {
            SortedSet <long> toRemove = new();

            foreach (KeyValuePair <long, Commodity> idCommList in commoditiesSubset)
            {
                long      commodityId = idCommList.Key;
                Commodity commodity   = idCommList.Value;

                DAG Gi = commodity.Gi;

                bool isGiConnected = DAG.IsConnected(
                    Gi,
                    u => !tapeSegContext.TArbSeqCFGUnusedNodes.Contains(u.Id));

                if (!isGiConnected)
                {
                    toRemove.Add(commodity.Id);
                    log.DebugFormat("Removed not connected commodity {0}", commodity.Id);
                }
            }

            toRemove.ForEach(c => nodesCoverageKeeper.RemoveCommodity(c, excludedComms));

            return(toRemove.Any());
        }
        public static void BFS_VLevels(
            DAG dag,
            GraphDirection dir,
            SortedDictionary <long, SortedSet <long> > nodeVLevels,
            long currentLevel,
            Func <DAGNode, bool> nodeAction,
            Func <long, bool> levelAction)
        {
            SortedDictionary <long, DAGNode> nodeEnumeration = dag.NodeEnumeration;

            foreach (KeyValuePair <long, SortedSet <long> > currentLevelNodes in
                     (dir == GraphDirection.Forward ? nodeVLevels : nodeVLevels.Reverse()))
            {
                if (currentLevel > currentLevelNodes.Key)
                {
                    continue;
                }

                foreach (long vNodeId in currentLevelNodes.Value)
                {
                    if (nodeEnumeration.TryGetValue(vNodeId, out DAGNode? vNode))
                    {
                        nodeAction(vNode);
                    }
                }

                levelAction(currentLevelNodes.Key);
            }
        }
Exemple #6
0
        public static bool FindPath_DFS(
            DAG dag,
            DAGNode s,
            GraphDirection direction,
            Predicate <DAGNode> nodeFilter,
            Predicate <DAGEdge> edgeFilter,
            Action <DAGNode, long> nodeAction,
            Action <DAGEdge, long> edgeAction,
            List <long> path)
        {
            SortedSet <long> processedNodes = new();

            bool pathFound = FindPath_DFS(
                s,
                dag.t,
                processedNodes,
                direction,
                0,
                nodeFilter,
                edgeFilter,
                nodeAction,
                edgeAction,
                path);

            return(pathFound);
        }
Exemple #7
0
        private void AddIntoDAG(IDependencyNode node, DAG <IDependencyNode> dag)
        {
            if (Excluded(node))
            {
                return;
            }
            dag.Add(node);
            var projectNode = node as ProjectNode;

            if (null == projectNode)
            {
                return;
            }

            var referenceNodes = context.LoadAssemblyNodes(projectNode.AssemblyReferences)
                                 .Where(n => !Excluded(n)).ToArray();

            Array.ForEach(referenceNodes, p => AddReferenceIntoDAG(p, dag, projectNode));
            var projectReferences = projectNode.ProjectReferences
                                    .Where(n => !Excluded(n.Node)).ToArray();

            Array.ForEach(projectReferences, p => AddProjectReferenceIntoDAG(dag, p.Node, projectNode));
            var runtimeReferenceNodes = context.LoadAssemblyNodes(projectNode.RuntimeReferences)
                                        .Where(n => !Excluded(n)).ToArray();

            Array.ForEach(runtimeReferenceNodes, p => AddReferenceIntoDAG(p, dag, projectNode));
        }
Exemple #8
0
 public Commodity(String name, long id, long variable, DAG Gi)
 {
     this.Name     = name;
     this.Id       = id;
     this.Variable = variable;
     this.Gi       = Gi;
 }
Exemple #9
0
        /// <summary>
        /// Executes one task and await for it and as a part of continuation run the next
        /// set of tasks in the ready queue.
        /// </summary>
        /// <param name="node">The node containing task</param>
        /// <param name="cancellationToken">Enable cancellation</param>
        /// <returns></returns>
        private async Task ExecuteNodeTaskAsync(DAGNode <ITaskItem <TaskResultT> > node,
                                                CancellationToken cancellationToken)
        {
            try
            {
                TaskResultT cachedResult = node.Data.CreatedResource;
                if (cachedResult != null && !DAG.IsRootNode(node))
                {
                    DAG.ReportCompleted(node);
                }
                else
                {
                    await node.Data.ExecuteAsync(cancellationToken);

                    DAG.ReportCompleted(node);
                    if (DAG.IsRootNode(node))
                    {
                        taskCompletionSource.SetResult(null);
                        return;
                    }
                }
                ExecuteReadyTasksAsync(cancellationToken);
            }
            catch (Exception exception)
            {
                taskCompletionSource.TrySetException(exception);
            }
        }
Exemple #10
0
        public override void CreateTArbSeqCFG(uint[] states)
        {
            log.Info("Building TArbSeqCFG");

            Ensure.That(meapContext.AcceptingNodes).HasItems();

            log.Info("Create sink node");
            CreateSinkNode();

            log.Info("Connect bottomNodes with sink node");
            ConnectBottomNodesWithSinkNode(G, states);

            log.Info("Create TArbSeqGraph copy");
            TypedDAG <TASGNodeInfo, StdEdgeInfo> cfg = new("CFG");

            DAG.CreateCopy(G, cfg);
            cfg.CopyIdToNodeInfoMap(idToInfoMap);

            log.Info("Cut chains");
            meapContext.TArbSeqCFG = new TypedDAG <TASGNodeInfo, StdEdgeInfo>("CFG");
            DAG.CutChains(cfg, meapContext.TArbSeqCFG);

            log.Info("Create CFG idToInfoMap");
            meapContext.TArbSeqCFG.CopyIdToNodeInfoMap(idToInfoMap);

            RemoveUnusedNodeVLevels();

            log.InfoFormat(
                "idToInfoMap: {0} {1}",
                idToInfoMap.Count,
                meapContext.TArbSeqCFG.IdToNodeInfoMap.Count);

            Trace_TArbSeqCFG();
        }
        private static void CopyNodesAndEdges(
            DAG graph,
            SortedSet <long> nodeIdSubset,
            DAG subgraph)
        {
            subgraph.NodeEnumeration = new SortedDictionary <long, DAGNode>();

            foreach (long nodeId in nodeIdSubset)
            {
                DAGNode subgraphNode = new(nodeId);
                subgraph.AddNode(subgraphNode);
            }

            List <KeyValuePair <KeyValuePair <long, long>, DAGEdge> > nodePairList1 =
                graph.NodePairEnumeration.Where(
                    t => subgraph.NodeEnumeration.ContainsKey(t.Key.Key)).ToList();
            List <KeyValuePair <KeyValuePair <long, long>, DAGEdge> > nodePairList2 =
                nodePairList1.Where(
                    t => subgraph.NodeEnumeration.ContainsKey(t.Key.Value)).ToList();

            subgraph.NodePairEnumeration =
                new SortedDictionary <KeyValuePair <long, long>, DAGEdge>(
                    new KeyValueComparer());

            foreach (KeyValuePair <KeyValuePair <long, long>, DAGEdge> nodePair in nodePairList2)
            {
                DAGNode uSubgraphNode = subgraph.NodeEnumeration[nodePair.Key.Key];
                DAGNode vSubgraphNode = subgraph.NodeEnumeration[nodePair.Key.Value];

                DAGEdge subgraphEdge = new(nodePair.Value.Id, uSubgraphNode, vSubgraphNode);
                subgraph.AddEdge(subgraphEdge);
            }
        }
Exemple #12
0
 public void Prepare()
 {
     if (IsPreparer)
     {
         DAG.Prepare();
     }
 }
Exemple #13
0
        public override void CreateTArbSeqCFG(uint[] states)
        {
            log.Info("Building TArbSeqCFG");

            log.Info("Create TArbSeqGraph copy");
            TypedDAG <TASGNodeInfo, StdEdgeInfo> cfg = new("CFG");

            DAG.CreateCopy(G, cfg);
            cfg.CopyIdToNodeInfoMap(idToInfoMap);

            log.Info("Connect bottomNodes with sink node");
            ConnectBottomNodesWithSinkNode(cfg, states);

            log.Info("Cut chains");
            meapContext.TArbSeqCFG = new TypedDAG <TASGNodeInfo, StdEdgeInfo>("CFG");
            DAG.CutChains_t(cfg, meapContext.TArbSeqCFG);

            log.Info("Create CFG idToInfoMap");
            meapContext.TArbSeqCFG.CopyIdToNodeInfoMap(idToInfoMap);

            log.InfoFormat(
                "idToInfoMap: {0} {1}",
                idToInfoMap.Count,
                meapContext.TArbSeqCFG.IdToNodeInfoMap.Count);

            Trace_TArbSeqCFG();

            endNodes.Clear();
            acceptingNodes.Clear();
        }
Exemple #14
0
        public DAG <IDependencyNode> BuildDAG()
        {
            var dag = new DAG <IDependencyNode>();

            Array.ForEach(projectsNode, p => AddIntoDAG(p, dag));
            return(dag);
        }
Exemple #15
0
        // save spreadsheet outputs to a CellDict
        public static CellDict SaveOutputs(AST.Address[] formula_nodes, DAG dag)
        {
            var cd = new CellDict();

            foreach (AST.Address formula_addr in formula_nodes)
            {
                // throw an exception in debug mode, because this should never happen
                #if DEBUG
                if (!(bool)(dag.getCOMRefForAddress(formula_addr).Range.HasFormula))
                {
                    String fstring = dag.getFormulaAtAddress(formula_addr);
                    throw new Exception("Formula address is not a formula.");
                }
                #endif

                // save value
                if (cd.ContainsKey(formula_addr))
                {
                    throw new Exception(String.Format("Failed in SaveOutputs."));
                }
                else
                {
                    cd.Add(formula_addr, dag.readCOMValueAtAddress(formula_addr));
                }
            }
            return(cd);
        }
Exemple #16
0
        public void should_get_correct_count()
        {
            var graph = new DAG<int>();
            Assert.Equal(graph.Out().Count(), 0);

            graph.Add(0);
            Assert.Equal(graph.Out().Count(), 1);
        }
 public static void MakeCommodity(
     DAG graph,
     long sNodeId,
     long tNodeId,
     DAG commodity)
 {
     MakePathsSubgraph_st(graph, sNodeId, tNodeId, commodity);
 }
Exemple #18
0
 private void AddProjectReferenceIntoDAG(DAG<IDependencyNode> dag, IDependencyNode p, IDependencyNode project)
 {
     if (!dag.Contains(p))
     {
         AddIntoDAG(p, dag);
     }
     dag.AddMergePath(project, p);
 }
Exemple #19
0
            public DAG Intersect(DAG dag1, DAG dag2)
            {
                throw new NotImplementedException();

                //DAG(nodeSet1 x nodeSet2, (nodeStart1, nodeStart2), (nodeEnd1, nodeEnd2), edgeSet12, mapping12),
                //  where edgeSet12 = {<(node1, node2), (nodePrime1, nodePrime2)> | <node1, nodePrime1> in edgeSet1, <node2, nodePrime2> in edgeSet2},
                //  and mapping12(<(node1, node2), (nodePrime1, nodePrime2)>) = { Intersect( funcSet, funcPrimeSet) | funcSet in W1(<node1, nodePrime1>) funcPrimeSet in W2(<node2, nodePrime2>)}
            }
Exemple #20
0
 private void AddProjectReferenceIntoDAG(DAG <IDependencyNode> dag, IDependencyNode p, IDependencyNode project)
 {
     if (!dag.Contains(p))
     {
         AddIntoDAG(p, dag);
     }
     dag.AddMergePath(project, p);
 }
Exemple #21
0
        private void ToDOTButton_Click(object sender, RibbonControlEventArgs e)
        {
            var app = Globals.ThisAddIn.Application;
            var dag = new DAG(app.ActiveWorkbook, app, true);

            System.Windows.Forms.Clipboard.SetText(dag.ToDOT());
            System.Windows.Forms.MessageBox.Show("In clipboard");
        }
Exemple #22
0
 private static CopyItemSet[] CollectCopies(IEnumerable<ProjectNode> projects, DAG<IDependencyNode> dag, ResolveContext context)
 {
     return projects
         .Select(p => CreateCopyLocalSet(p, context))
         .Where(c => c.CopyLocalSources.Length > 0)
         .ToArray()
         .Select(cls => cls.CreateCopyTaskItem(dag))
         .ToArray();
 }
Exemple #23
0
        public void Apply(ref LinkedList <ThreeCode> program)
        {
            _apply  = false;
            Program = program;
            var dag = new DAG(Program.ToList());

            Program = dag.Optimize(ref _apply);
            program = Program;
        }
Exemple #24
0
        // Get dictionary of inputs and the error they produce
        public static CellDict GenImportantErrors(AST.Address[] output_nodes,
                                                  CellDict inputs,
                                                  int k,         // number of alternatives to consider
                                                  CellDict correct_outputs,
                                                  Excel.Application app,
                                                  Excel.Workbook wb,
                                                  Classification c,
                                                  DAG dag)
        {
            var eg = new ErrorGenerator();
            var max_error_produced_dictionary = new Dictionary <AST.Address, Tuple <string, double> >();

            foreach (KeyValuePair <AST.Address, string> pair in inputs)
            {
                AST.Address addr       = pair.Key;
                string      orig_value = pair.Value;

                //Load in the classification's dictionaries
                double max_error_produced = 0.0;
                string max_error_string   = "";

                // get k strings
                string[] errorstrings = eg.GenerateErrorStrings(orig_value, c, k);

                for (int i = 0; i < k; i++)
                {
                    CellDict cd = new CellDict();
                    cd.Add(addr, errorstrings[i]);
                    //inject the typo
                    InjectValues(app, wb, cd);

                    // save function outputs
                    CellDict incorrect_outputs = SaveOutputs(output_nodes, dag);

                    //remove the typo that was introduced
                    cd.Clear();
                    cd.Add(addr, orig_value);
                    InjectValues(app, wb, cd);

                    double total_error = Utility.CalculateTotalError(correct_outputs, incorrect_outputs);

                    //keep track of the largest observed max error
                    if (total_error > max_error_produced)
                    {
                        max_error_produced = total_error;
                        max_error_string   = errorstrings[i];
                    }
                }
                //Add entry for this TreeNode in our dictionary with its max_error_produced
                max_error_produced_dictionary.Add(addr, new Tuple <string, double>(max_error_string, max_error_produced));
            }

            // sort by max_error_produced
            var maxen = max_error_produced_dictionary.OrderByDescending(pair => pair.Value.Item2).Select(pair => new Tuple <AST.Address, string>(pair.Key, pair.Value.Item1)).ToList();

            return(maxen.Take((int)Math.Ceiling(0.05 * inputs.Count)).ToDictionary(tup => tup.Item1, tup => tup.Item2));
        }
        public static void CreateCopy(DAG graph, DAG copy)
        {
            CopyNodesAndEdges(
                graph,
                new SortedSet <long>(graph.GetAllNodeIds()),
                copy);

            copy.SetSourceNode(copy.GetNode(graph.GetSourceNodeId()));
            copy.SetSinkNode(copy.GetNode(graph.GetSinkNodeId()));
        }
Exemple #26
0
        public static bool PropagateProperties(
            DAG dag,
            long fromNodeId,
            GraphDirection direction,
            Predicate <DAGNode> nodeFilter,
            Predicate <DAGEdge> edgeFilter,
            Predicate <DAGNode> nodeAction,
            Predicate <DAGEdge> edgeAction)
        {
            QueueWithIdSet <DAGNode> nodeQueue = new();
            bool             status            = false;
            SortedSet <long> processedNodes    = new();
            DAGNode          s = dag.NodeEnumeration[fromNodeId];

            if (nodeFilter(s))
            {
                nodeQueue.Enqueue(s);
            }

            while (nodeQueue.Any())
            {
                DAGNode u = nodeQueue.Dequeue();
                if (processedNodes.Contains(u.Id))
                {
                    continue;
                }

                processedNodes.Add(u.Id);

                bool nodeActionStatus = nodeAction(u);
                status = status || nodeActionStatus;

                foreach (DAGEdge e in (direction == GraphDirection.Forward ?
                                       u.OutEdges : u.InEdges))
                {
                    DAGNode v = (direction == GraphDirection.Forward ? e.ToNode : e.FromNode);

                    if (!edgeFilter(e))
                    {
                        continue;
                    }

                    bool edgeActionStatus = edgeAction(e);
                    status = status || edgeActionStatus;

                    if (nodeFilter(v) && (!nodeQueue.Contains(v)))
                    {
                        nodeQueue.Enqueue((direction == GraphDirection.Forward ? e.ToNode : e.FromNode));
                    }
                }
            }

            return(status);
        }
Exemple #27
0
        protected DAGEquationsSet(DAG graph)
        {
            this.Graph = graph;

            this.FVars     = new List <long>();
            this.HVars     = new List <long>();
            this.Equations = new List <long>();

            this.NodeToVar = new SortedDictionary <long, long>();
            this.EdgeToVar = new SortedDictionary <long, long>();
        }
Exemple #28
0
 public ReachDefAnalysisContext(
     DAG CFG,
     IEnumerable <long> Vars,
     IDictionary <long, ICollection <long> > Assignments,
     IDictionary <long, ICollection <long> > Usages)
 {
     this.CFG         = CFG;
     this.Vars        = Vars;
     this.Assignments = Assignments;
     this.Usages      = Usages;
 }
        public override void FindTConsistPath()
        {
            tapeSegContext.TapeSegTConsistPath = new List <long>();
            tapeSegContext.TapeSegPathFound    = false;

            if (tapeSegContext.KSetZetaSubset.Count == 1)
            {
                if (FindPathInCaseSingleZeta())
                {
                    tapeSegContext.TapeSegPathExists = true;
                    tapeSegContext.TapeSegPathFound  = true;

                    log.Info("Found path in case of single zeta");

                    return;
                }
            }

            List <long> partialTConsistPath = tapeSegContext.PartialTConsistPath;

            while (true)
            {
                if (!SelectNode(partialTConsistPath, out long initNodeId))
                {
                    log.Info("Path not found (select node)");

                    return;
                }

                DAGNode initNode = meapContext.TArbSeqCFG.NodeEnumeration[initNodeId];
                processedNodes.Add(initNodeId);

                (List <long> tConsistPath, bool KPathFound) = DAG.FindPath_Greedy(
                    initNode,
                    meapContext.TArbSeqCFG.t,
                    GraphDirection.Forward,
                    u => !tapeSegContext.TArbSeqCFGUnusedNodes.Contains(u.Id),
                    d => NodeInChain(d.ToNode),
                    u => processedNodes.Add(u.Id),
                    (_) => { });

                if (KPathFound)
                {
                    tapeSegContext.TapeSegTConsistPath.AddRange(partialTConsistPath);
                    tapeSegContext.TapeSegTConsistPath.AddRange(tConsistPath);

                    tapeSegContext.TapeSegPathExists = true;
                    tapeSegContext.TapeSegPathFound  = true;

                    return;
                }
            }
        }
Exemple #30
0
        public void should_cut()
        {
            var graph = new DAG<int>();
            graph.AddPath(1, 2);
            graph.AddPath(1, 3);
            graph.AddPath(3, 2);
            graph.AddPath(3, 4);
            graph.Cut(v => v.Data == 2);

            var ints = graph.Out();
            Assert.DoesNotContain(4, ints);
        }
Exemple #31
0
        public CopyItemSet CreateCopyTaskItem(DAG<IDependencyNode> dag)
        {
            var copies = GetCopyNodes(dag);
            var copyItemProjectNodes = copies.OfType<ProjectNode>().Select(n => n.FullPath).ToArray();
            var minimizedCopies = copies.Except(CopyLocalSources.Concat(new IDependencyNode[] { Dest })).ToArray();
            var copyProjectNodes = minimizedCopies.OfType<ProjectNode>().Select(n=> n.FullPath).ToArray();
            var copyAssemblyNodes = minimizedCopies.OfType<AssemblyNode>().Select(n => n.FullPath).ToArray();

            var copyItemSet = new CopyItemSet(Dest.FullPath)
                {ItemProjects = copyItemProjectNodes, Projects = copyProjectNodes, Libs = copyAssemblyNodes};
            return copyItemSet;
        }
Exemple #32
0
        public void should_cut_to_empty()
        {
            var graph = new DAG<int>();
            graph.AddPath(1, 2);
            graph.AddPath(1, 3);
            graph.AddPath(3, 2);
            graph.AddPath(3, 4);
            graph.Cut(v => v.Data == 9);

            var ints = graph.Out();
            Assert.Empty(ints);
        }
Exemple #33
0
        // allow mix of C# classes and schema types defined in json
        // not complete
        void ProcessJsonType(JToken jtok, string parent, DAG <string, JToken> references)
        {
            switch (jtok)
            {
            case JArray jArray:
                foreach (var t in jArray.Children())
                {
                    ProcessJsonType(t, parent, references);
                }
                break;

            case JObject jObject:
                var typeProp = jObject.Property("type").Value as JValue;
                if (typeProp == null)
                {
                    return;
                }
                var typeVal = typeProp.Value as JToken;
                if (typeVal == null)
                {
                    ProcessJsonType(typeProp, parent, references);
                }
                else if ((typeProp.Value as JValue).Value as string == "record")
                {
                    var name  = jObject.Property("name").Value as JValue;
                    var props = jObject.Property("properties").Value as JArray;
                    foreach (var p in props)
                    {
                        ProcessJsonType(p, name.Value as string, references);
                    }
                }
                break;

            case JValue jValue:
                var val = jValue.Value as string;
                if (val == null)
                {
                    return;
                }
                switch (val)
                {
                case "string":
                case "int":
                case "double":
                    break;

                default:
                    break;
                }
                break;
            }
        }
Exemple #34
0
        private IDependencyNode[] GetCopyNodes(DAG <IDependencyNode> dag)
        {
            var compiletimeCopies = AssemblyCopySource.OfType <ProjectNode>()
                                    .SelectMany(assemblyNode => new [] { assemblyNode }.Concat(dag.GetSubOf(assemblyNode)))
                                    .Concat(ProjectCopySource.SelectMany(dag.GetSubOf))
                                    .Distinct();
            var runtimeDependentProjectNodes = RuntimeCopySources.OfType <ProjectNode>();
            var runtimeCopies = runtimeDependentProjectNodes.SelectMany(dag.GetSubOf)
                                .Concat(RuntimeCopySources)
                                .Distinct();

            return(compiletimeCopies.Concat(runtimeCopies).Distinct().ToArray());
        }
Exemple #35
0
        public void should_cut_to_empty()
        {
            var graph = new DAG <int>();

            graph.AddPath(1, 2);
            graph.AddPath(1, 3);
            graph.AddPath(3, 2);
            graph.AddPath(3, 4);
            graph.Cut(v => v.Data == 9);

            var ints = graph.Out();

            Assert.Empty(ints);
        }
Exemple #36
0
        public void should_cut()
        {
            var graph = new DAG <int>();

            graph.AddPath(1, 2);
            graph.AddPath(1, 3);
            graph.AddPath(3, 2);
            graph.AddPath(3, 4);
            graph.Cut(v => v.Data == 2);

            var ints = graph.Out();

            Assert.DoesNotContain(4, ints);
        }
Exemple #37
0
        public void should_get_sub_vertexes_for_square()
        {
            var graph = new DAG<int>();
            const int v0 = 0;
            const int v1 = 1;
            const int v2 = 2;
            const int v3 = 3;
            graph.AddPath(v0, v1);
            graph.AddPath(v0, v2);
            graph.AddPath(v1, v3);
            graph.AddPath(v2, v3);

            var subOf0 = graph.GetSubOf(v0);
            Assert.Equal(3, subOf0.Length);
        }
Exemple #38
0
        public void should_get_sub_vertexes_for_one()
        {
            var graph = new DAG<int>();
            const int from = 0;
            const int to = 1;
            graph.Add(from);
            graph.AddPath(from, to);

            var subOfTo = graph.GetSubOf(to);
            Assert.Equal(0, subOfTo.Length);

            var subOfFrom = graph.GetSubOf(from);
            Assert.Equal(1, subOfFrom.Length);
            Assert.Equal(to, subOfFrom[0]);
        }
Exemple #39
0
 private void AddReferenceIntoDAG(IDependencyNode child, DAG<IDependencyNode> dag, IDependencyNode parent)
 {
     var project = child as ProjectNode;
     if (project != null)
     {
         if (!dag.Contains(project))
         {
             AddIntoDAG(project, dag);
         }
         dag.AddPath(parent, child);
     }
     var assemblyReference = child as AssemblyNode;
     if (assemblyReference != null)
     {
         dag.AddMergePath(parent, child);
     }
 }
Exemple #40
0
        public void should_deal_with_merge_path()
        {
            var graph = new DAG<int>();
            const int v1 = 1;
            const int v2 = 2;
            const int v3 = 3;
            graph.AddMergePath(v1, v2);
            graph.AddPath(v1, v3);
            graph.AddMergePath(v2, v3);

            graph.Simplify();

            Assert.Null(graph.Get(v2));
            Assert.Equal(0, graph.Get(v1).Incommings.Count);
            Assert.Equal(1, graph.Get(v1).Outcommings.Count);
            Assert.Equal(1, graph.Get(v3).Incommings.Count);
            Assert.Equal(0, graph.Get(v3).Outcommings.Count);
        }
Exemple #41
0
        private void AddIntoDAG(IDependencyNode node, DAG<IDependencyNode> dag)
        {
            if (Excluded(node))
            {
                return;
            }
            dag.Add(node);
            var projectNode = node as ProjectNode;
            if (null == projectNode)
            {
                return;
            }

            var referenceNodes = context.LoadAssemblyNodes(projectNode.AssemblyReferences)
                .Where(n => !Excluded(n)).ToArray();
            Array.ForEach(referenceNodes, p => AddReferenceIntoDAG(p, dag, projectNode));
            var projectReferences = projectNode.ProjectReferences
                .Where(n => !Excluded(n.Node)).ToArray();
            Array.ForEach(projectReferences, p => AddProjectReferenceIntoDAG(dag, p.Node, projectNode));
            var runtimeReferenceNodes = context.LoadAssemblyNodes(projectNode.RuntimeReferences)
                .Where(n => !Excluded(n)).ToArray();
            Array.ForEach(runtimeReferenceNodes, p => AddReferenceIntoDAG(p, dag, projectNode));
        }
Exemple #42
0
        public void should_simplify_more_complex()
        {
            var graph = new DAG<string>();

            const string securityCore = "security-core";
            const string securityCoreWeb = "security-core-web";
            const string extensions = "extensions";
            const string container = "container";
            const string containerApi = "container-api";
            const string web = "web";
            const string modelApi = "model-api";
            const string loggingApi = "logging-api";
            const string loggingSpi = "logging-spi";
            const string logging = "logging";
            const string persistenceApi = "persistence-api";
            const string templateApi = "template-api";
            const string persistenceSpi = "persistence-spi";
            const string template = "template";
            const string templateSpi = "template-spi";

            graph.AddPath(securityCore, extensions);
            graph.AddPath(securityCoreWeb, container);
            graph.AddPath(securityCoreWeb, containerApi);
            graph.AddPath(securityCoreWeb, extensions);
            graph.AddPath(securityCoreWeb, web);

            graph.AddMergePath(container, containerApi);
            graph.AddMergePath(container, extensions);
            graph.AddMergePath(container, loggingApi);

            graph.AddMergePath(containerApi, extensions);

            graph.AddMergePath(loggingApi, extensions);
            graph.AddMergePath(loggingApi, modelApi);

            graph.AddMergePath(modelApi, extensions);

            graph.AddMergePath(web, containerApi);
            graph.AddMergePath(web, container);
            graph.AddMergePath(web, extensions);
            graph.AddMergePath(web, loggingApi);
            graph.AddMergePath(web, loggingSpi);
            graph.AddMergePath(web, logging);
            graph.AddMergePath(web, modelApi);
            graph.AddMergePath(web, persistenceApi);
            graph.AddMergePath(web, templateSpi);
            graph.AddMergePath(web, template);

            graph.AddMergePath(loggingSpi, containerApi);
            graph.AddMergePath(loggingSpi, container);
            graph.AddMergePath(loggingSpi, extensions);
            graph.AddMergePath(loggingSpi, loggingApi);
            graph.AddMergePath(loggingSpi, modelApi);
            graph.AddMergePath(loggingSpi, persistenceApi);
            graph.AddMergePath(loggingSpi, persistenceSpi);

            graph.AddMergePath(persistenceApi, extensions);
            graph.AddMergePath(persistenceApi, modelApi);

            graph.AddMergePath(persistenceSpi, containerApi);
            graph.AddMergePath(persistenceSpi, extensions);
            graph.AddMergePath(persistenceSpi, modelApi);
            graph.AddMergePath(persistenceSpi, persistenceApi);

            graph.AddMergePath(logging, containerApi);
            graph.AddMergePath(logging, container);
            graph.AddMergePath(logging, extensions);
            graph.AddMergePath(logging, loggingApi);
            graph.AddMergePath(logging, loggingSpi);
            graph.AddMergePath(logging, modelApi);
            graph.AddMergePath(logging, persistenceApi);
            graph.AddMergePath(logging, persistenceSpi);
            graph.AddMergePath(logging, templateApi);
            graph.AddMergePath(logging, template);

            graph.AddMergePath(templateApi, extensions);

            graph.AddMergePath(template, containerApi);
            graph.AddMergePath(template, container);
            graph.AddMergePath(template, extensions);
            graph.AddMergePath(template, templateApi);
            graph.AddMergePath(template, templateSpi);

            graph.AddMergePath(templateSpi, container);
            graph.AddMergePath(templateSpi, extensions);
            graph.AddMergePath(templateSpi, templateApi);

            graph.Simplify();

            Assert.NotNull(graph.Get(securityCore));
            Assert.NotNull(graph.Get(securityCoreWeb));
            Assert.NotNull(graph.Get(web));
            var vertexes = graph.Out();
            Assert.Equal(3, vertexes.Length);
            Assert.Equal(web, vertexes[0]);
            Assert.Equal(securityCore, vertexes[1]);
            Assert.Equal(securityCoreWeb, vertexes[2]);
        }
Exemple #43
0
        public void should_simplify_complex()
        {
            var graph = new DAG<int>();
            const int v1 = 1;
            const int v2 = 2;
            const int v3 = 3;
            const int v4 = 4;
            graph.AddPath(v1, v2);
            graph.AddPath(v1, v3);
            graph.AddPath(v1, v4);
            graph.AddMergePath(v3, v2);
            graph.AddPath(v3, v4);
            graph.AddPath(v4, v2);

            graph.Simplify();

            Assert.NotNull(graph.Get(v2));
            Assert.Equal(3, graph.Get(v2).Incommings.Count);
            Assert.Equal(0, graph.Get(v2).Outcommings.Count);
            Assert.Equal(1, graph.Get(v3).Incommings.Count);
            Assert.Equal(2, graph.Get(v3).Outcommings.Count);
        }
Exemple #44
0
        public void should_get_vertexes_for_complex_direct()
        {
            var graph = new DAG<int>();
            const int v1 = 1;
            const int v2 = 2;
            const int v3 = 3;
            const int v4 = 4;
            graph.AddPath(v1, v2);
            graph.AddPath(v1, v3);
            graph.AddPath(v1, v4);
            graph.AddPath(v3, v2);
            graph.AddPath(v2, v4);
            graph.AddPath(v3, v4);

            var items = graph.Out();
            Assert.Equal(4, items.Length);
            Assert.Equal(v4, items[0]);
            Assert.Equal(v2, items[1]);
            Assert.Equal(v3, items[2]);
            Assert.Equal(v1, items[3]);
        }
Exemple #45
0
        public void should_get_vertexes_for_simple_direct()
        {
            var graph = new DAG<int>();
            const int from = 0;
            const int to = 1;
            graph.Add(from);
            graph.AddPath(from, to);

            var items = graph.Out();
            Assert.Equal(2, items.Length);
            Assert.Equal(to, items[0]);
            Assert.Equal(from, items[1]);
        }
Exemple #46
0
 public void should_detect_cycle()
 {
     var graph = new DAG<int>();
     graph.AddPath(0, 1);
     Assert.Throws<CyclePathException>(() => graph.AddPath(1, 0));
 }
Exemple #47
0
 public DAG<IDependencyNode> BuildDAG()
 {
     var dag = new DAG<IDependencyNode>();
     Array.ForEach(projectsNode, p => AddIntoDAG(p, dag));
     return dag;
 }
Exemple #48
0
 public void should_simplify_all_virtual()
 {
     var graph = new DAG<string>();
     const string extensions = "extensions";
     const string modelApi = "model-api";
     const string persistenceApi = "persistence-api";
     const string containerApi = "container-api";
     graph.AddMergePath(modelApi, extensions);
     graph.AddMergePath(persistenceApi, extensions);
     graph.AddMergePath(persistenceApi, modelApi);
     graph.AddMergePath(containerApi, extensions);
     graph.Simplify();
     var vertexes = graph.Out();
     Assert.Equal(2, vertexes.Length);
     Assert.Equal(persistenceApi, vertexes[0]);
     Assert.Equal(containerApi, vertexes[1]);
 }
Exemple #49
0
        public void should_simplify()
        {
            var graph = new DAG<int>();
            const int v1 = 1;
            const int v2 = 2;
            const int v3 = 3;
            const int v4 = 4;
            graph.AddPath(v1, v2);
            graph.AddPath(v1, v3);
            graph.AddPath(v1, v4);
            graph.AddMergePath(v3, v2);
            graph.AddPath(v2, v4);
            graph.AddPath(v3, v4);

            graph.Simplify();

            Assert.Null(graph.Get(v2));
            var incommings = graph.Get(v3).Incommings;
            Assert.Equal(1, incommings.Count);
            Assert.Equal(v1, incommings.First().Data);
            var outcommings = graph.Get(v3).Outcommings;
            Assert.Equal(1, outcommings.Count);
            Assert.Equal(v4, outcommings.First().Data);
        }
Exemple #50
0
 private IDependencyNode[] GetCopyNodes(DAG<IDependencyNode> dag)
 {
     var compiletimeCopies = AssemblyCopySource.OfType<ProjectNode>()
         .SelectMany(assemblyNode => new []{assemblyNode}.Concat(dag.GetSubOf(assemblyNode)))
         .Concat(ProjectCopySource.SelectMany(dag.GetSubOf))
         .Distinct();
     var runtimeDependentProjectNodes = RuntimeCopySources.OfType<ProjectNode>();
     var runtimeCopies = runtimeDependentProjectNodes.SelectMany(dag.GetSubOf)
         .Concat(RuntimeCopySources)
         .Distinct();
     return compiletimeCopies.Concat(runtimeCopies).Distinct().ToArray();
 }
Exemple #51
0
 public void should_not_merge_virtual_if_will_create_cycle()
 {
     var graph = new DAG<int>();
     const int v1 = 1;
     const int v2 = 2;
     const int v3 = 3;
     graph.AddMergePath(v3, v1);
     graph.AddPath(v3, v2);
     graph.AddPath(v2, v1);
     graph.Simplify();
     var ints = graph.Out();
     Assert.Equal(1, ints[0]);
     Assert.Equal(2, ints[1]);
     Assert.Equal(3, ints[2]);
 }