Esempio n. 1
0
        // Changed the get path method
        public List<Edge> GetPath(Node target)
        {
            var path = new List<Edge>();
            var node = target;
            var containsKey = Distance.ContainsKey(node);
            if (!containsKey)
            {
                return null;
            }

            path.Add(GetEdgeFromNodes(Predecessors[node], node));
            while (Predecessors[node] != null)
            {

                node = Predecessors[node];
                var isFinished = Predecessors.ContainsKey(node);
                if (!isFinished)
                {
                    break;
                }
                path.Add(GetEdgeFromNodes(Predecessors[node], node));
            }
            path.Reverse();
            return path;
        }
Esempio n. 2
0
 /// <summary>
 /// Vorwärtsterminierung. Berechnet den frühesten Anfangs- und Endzeitpunkt des Vorgangs.
 /// </summary>
 internal void ForwardPassCalculation()
 {
     EarliestStartingPoint = IsInitial
         ? 0
         : Predecessors.Select(pre => pre.EarliestFinishingPoint).Max();
     EarliestFinishingPoint = EarliestStartingPoint + Duration;
 }
 public void AddPredecessor(IReactiveNode node)
 {
     ValidatePredecessor(node);
     if (Predecessors.Contains(node) == false)
     {
         Predecessors.Add(node);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Erzeugt eine textuelle Repräsentation des Vorgangs. Angelehnt an die Syntax des Prozessplans.
        /// </summary>
        /// <returns>Textuelle Repräsentation des Vorgangs.</returns>
        internal string GetInfo()
        {
            string predecessors = String.Join(",", Predecessors.Select(n => n.ID));
            string ancestors    = String.Join(",", Successors.Select(n => n.ID));

            predecessors = String.IsNullOrWhiteSpace(predecessors) ? "-" : predecessors;
            ancestors    = String.IsNullOrWhiteSpace(ancestors) ? "-" : ancestors;

            return($"{ID} | {Description} | {Duration} | {predecessors} | {ancestors}");
        }
Esempio n. 5
0
 public MessageMemento GetMemento()
 {
     return(new MessageMemento()
     {
         Hash = Hash.ToString(),
         MessageType = Type,
         Predecessors = Predecessors
                        .Select(p => p.ToString())
                        .ToList(),
         ObjectId = ObjectId,
         Body = Body
     });
 }
Esempio n. 6
0
 private void FindShortestDistance(Node node)
 {
     var adjNodes = GetNeighbors(node);
     foreach (var target in adjNodes)
     {
         if (GetShortestDistance(target) > GetShortestDistance(node) + GetDistance(node, target))
         {
             Distance.Add(target, GetShortestDistance(node) + GetDistance(node, target));
             Predecessors.Add(target, node);
             UnSettledNodes.Add(target);
         }
     }
 }
Esempio n. 7
0
        public bool Activate(bool activateDependencies)
        {
            if (MissingDependencies.Count > 0)
            {
                return(false);
            }

            if (IsActive)
            {
                return(true);
            }

            //check whether all predececcors are active -> actual plugin depends on
            if (activateDependencies)
            {
                //try to activate depend plugins
                if (Predecessors.Count(elem => !((PluginNode)elem).Activate(true)) > 0)
                {
                    return(false);
                }
            }
            else
            {
                //just count inactive plugins
                if (Predecessors.Count(elem => !((PluginNode)elem).IsActive) > 0)
                {
                    return(false);
                }
            }

            PluginInstance = Graph.PluginManager.CreatePluginInstance(Value);

            if (PluginInstance == null)
            {
                return(false);
            }

            Graph.NotifyPlugins(PluginInstance, PluginNotification.Created);

            PluginContext = Graph.PluginManager.CreatePluginContext(PluginInstance);

            PluginInstance.ActivatePlugin(PluginContext);

            IsActive = true;

            Graph.NotifyPlugins(PluginInstance, PluginNotification.Activated);

            return(true);
        }
        /// <summary>
        /// Returns the path leading to the vertex v.
        /// </summary>
        /// <param name="v">end of the path</param>
        /// <returns>path leading to v</returns>
        public EdgeCollection Path(IVertex v)
        {
            EdgeCollection path = new EdgeCollection();

            IVertex vc = v;

            while (Predecessors.Contains(v))
            {
                IEdge e = Predecessors[v];
                path.Insert(0, e);
                v = e.Source;
            }

            return(path);
        }
Esempio n. 9
0
        /// <summary>
        /// Unbinds all predecessors and successors from this node.
        /// </summary>
        internal void UnBindAll()
        {
            while (Predecessors.Count > 0)
            {
                FlowNode <T> pre = Predecessors.First();
                pre.Successors.Remove(this);
                Predecessors.Remove(pre);
            }

            while (Successors.Count > 0)
            {
                FlowNode <T> succ = Successors.First();
                succ.Predecessors.Remove(this);
                Successors.Remove(succ);
            }
            //System.Diagnostics.Debug.Assert(DebugConsistencyCheck(pred, succ));
        }
Esempio n. 10
0
        public bool Deactivate(bool deactivateDependencies)
        {
            if (!IsActive)
            {
                return(true);
            }

            //check all successors -> these are the ones which depends on actual plugin
            if (deactivateDependencies)
            {
                //try to activate depend plugins
                if (Predecessors.Count(elem => !((PluginNode)elem).Deactivate(true)) > 0)
                {
                    return(false);
                }
            }
            else
            {
                //just count active plugins
                if (Predecessors.Count(elem => ((PluginNode)elem).IsActive) > 0)
                {
                    return(false);
                }
            }

            PluginInstance.DeactivatePlugin(PluginContext);

            IsActive = false;

            Graph.NotifyPlugins(PluginInstance, PluginNotification.Deactivated);

            PluginInstance.Dispose();

            Graph.NotifyPlugins(PluginInstance, PluginNotification.Disposed);

            PluginInstance = null;
            PluginContext  = null;

            return(true);
        }
Esempio n. 11
0
        //public virtual void RecalcDuration()
        //{
        //    if (Children != null && Children.Where(c => c.Deleted == Core.DomainModel.BaseStatusDeleted.None).Any())
        //        Duration =  Children.Where(c => c.Deleted == Core.DomainModel.BaseStatusDeleted.None).Select(c=>c.Duration).Sum();
        //    if (Parent == null)
        //        Project.RecalcDuration();
        //    else
        //        Parent.RecalcDuration();

        //}
        private String PredecessorsToIdString()
        {
            return(String.Join(";", Predecessors.Where(p => p.Target != null).OrderBy(p => p.Target.Id).Select(p => p.Target.Id.ToString() + p.Type.ToString() + p.LeadLag.ToString()).ToList()));
        }
 public void RemovePredecessor(IReactiveNode node)
 {
     Predecessors.Remove(node);
 }
Esempio n. 13
0
        public void Validate()
        {
            if (RefSuccessors.Count > 0)
            {
                throw new ValidatorException("Basic block contains a reference to successors that could not be resolved. Basic block: " + ID);
            }
            if (RefPredecessors.Count > 0)
            {
                throw new ValidatorException("Basic block contains a reference to successors that could not be resolved. Basic block: " + ID);
            }

            if (Instructions.Last().statementType == Common.StatementType.ConditionalJump && Successors.Count != 2)
            {
                throw new ValidatorException("Basic block with ConditionalJump statement type must have exactly 2 successors.");
            }
            if (Predecessors.Count == 0 && Successors.Count == 0)
            {
                throw new ValidatorException("No predecessors and no successors found for basic block " + ID);
            }
            if (Instructions.Count == 0)
            {
                throw new ValidatorException("No instructions found for basic block " + ID);
            }
            if (Successors.Count > 2)
            {
                throw new ValidatorException("More than two successors found in basic block " + ID);
            }
            if (Predecessors.Count == 0 && !parent.BasicBlocks.First().Equals(this))
            {
                throw new ValidatorException("No predecessors found at basic block " + ID + ". By convention, only the first basic block has empty Predecessors list.");
            }
            if (Successors.Count == 0 && (Instructions.Count != 1 || Instructions[0].TACtext != "return"))
            {
                throw new ValidatorException("No successors found at basic block " + ID + ". By convention, only the 'fake exit block' has empty Successors list.");
            }
            if (Successors.Count == 2)
            {
                if (Instructions.Last().statementType != Common.StatementType.ConditionalJump)
                {
                    throw new ValidatorException("To have 2 successors, the last instruction of a basic block must be a ConditionalJump. Basic block: " + ID);
                }
                string resultString = Regex.Match(Instructions.Last().TACtext, @"\bID_[A-F0-9]{8}(?:-[A-F0-9]{4}){3}-[A-F0-9]{12}\b").Value;
                if (!resultString.Equals(Successors[0].ID))
                {
                    throw new ValidatorException("The first successor ID does not match the GOTO instruction. Basic block: " + ID);
                }
            }
            if (Predecessors.Count > 1 && Successors.Count > 0)
            {
                int preds_goto = Predecessors.Count(x =>
                                                    (x.Instructions.Last().statementType == Common.StatementType.ConditionalJump && this.Equals(x.getSuccessors.First())) ||
                                                    x.Instructions.Last().statementType == Common.StatementType.UnconditionalJump);
                if (Predecessors.Count - preds_goto > 1)
                {
                    throw new ValidatorException("Basic block has more that one direct predecessor (without GOTO). Basic block: " + ID);
                }
            }
            if (Successors.Count == 0)
            {
                int preds_proc = Predecessors.Count(x =>
                                                    x.Instructions.Last().statementType == Common.StatementType.Procedural);
                if (Predecessors.Count - preds_proc > 0)
                {
                    throw new ValidatorException("The 'fake exit block' can only have predecessors with last 'return' statement. Basic block: " + ID);
                }
            }

            // If a basic block has one predecessor, then it should be a direct predecessor without goto
            //if(Predecessors.Count==1 && Predecessors[0].Instructions.Last().statementType == Common.StatementType.UnconditionalJump)
            //    throw new ValidatorException("A basic block: " + ID + " has a single direct predecessor with unconditional GOTO.");

            // Checking Successor-Predecessor links
            foreach (BasicBlock succ in Successors)
            {
                if (!succ.Predecessors.Contains(this) && succ.RefPredecessors.Count == 0)
                {
                    throw new ValidatorException("Broken successor-predecessor link in basic block " + ID);
                }
            }
            foreach (BasicBlock pred in Predecessors)
            {
                if (!pred.Successors.Contains(this) && pred.RefSuccessors.Count == 0)
                {
                    throw new ValidatorException("Broken predecessor-successor link in basic block " + ID);
                }
            }

            foreach (Instruction inst in this.Instructions)
            {
                if (inst.parent != this)
                {
                    throw new ValidatorException("Instruction's 'parent' property is incorrect. Instruction: " + inst.ID);
                }
                inst.Validate();
            }
        }
Esempio n. 14
0
 public override string ToString()
 {
     return($"{Id} P:[{string.Join(",", Predecessors.Select(p => p.Id))}] S:[{string.Join(",", Successors.Select(s => s.Id))}]");
 }