Ejemplo n.º 1
0
        protected virtual BackTrackCheckingResult BackTrackChecking(TreeNode node)
        {
            //backtrack
            var trackNode = node.Parent;
            List<int> omegaPlaces;
            while (trackNode != null)
            {
                bool nodesEqual = true;
                bool less = true;
                omegaPlaces = new List<int>();
                for (int p = 0; p < PetriNet.PlacesCount; p++)
                {
                    if (trackNode.Marking[p] != node.Marking[p])
                        nodesEqual = false;
                    if (trackNode.Marking[p] > node.Marking[p])
                        less = false;
                    if (less && trackNode.Marking[p] < node.Marking[p])
                    {
                        omegaPlaces.Add(p);
                        //break; //todo fix here
                    }
                }
                if (nodesEqual) // node is equal to some parent, marking as leaf
                    return BackTrackCheckingResult.NodeIsEqualToParent;

                if (less && omegaPlaces.Count > 0) // some parent[p] < node[p] marking as omega leaf
                {
                    for (int i = 0; i < omegaPlaces.Count; i++)
                        node.Marking[omegaPlaces[i]] = double.PositiveInfinity;
                    return BackTrackCheckingResult.NodeIsOmegaLeaf;
                }
                trackNode = trackNode.Parent;
            }
            return BackTrackCheckingResult.Nothing;
        }
Ejemplo n.º 2
0
        protected virtual List<int> GetAvailableTransitions(TreeNode node)
        {
            List<int> tSet = new List<int>();
            for (int i = 0; i < node.Marking.rows; i++)
            {
                if (node.Marking[i] > 0)
                {
                    tSet = tSet.Union(GetPostPSet(i, (int)node.Marking[i])).ToList();
                }
            }

            List<int> tRes = new List<int>();
            for (int i = 0; i < tSet.Count; i++)
            {
                bool available = true, dead = true;
                for (int p = 0; p < PetriNet.PlacesCount; p++)
                {
                    if (PetriNet.WeightMatrix[p, tSet[i]] != null &&
                        PetriNet.WeightMatrix[p, tSet[i]].PT > 0 && PetriNet.WeightMatrix[p, tSet[i]].PT > node.Marking[p])
                    {
                        available = false;
                    }
                    //if (PetriNet.WeightMatrix[p, tSet[i]] != null && PetriNet.WeightMatrix[p, tSet[i]].TP > 0)
                    //{
                    //    dead = false;
                    //}
                }
                if (available )//&& !dead)
                    tRes.Add(tSet[i]);
            }
            return tRes;
        }
Ejemplo n.º 3
0
        private void BuildFromNode(TreeNode node)
        {
            var tSet = GetAvailableTransitions(node);
            if (tSet != null && tSet.Count > 0)
            {
                switch (BackTrackChecking(node))
                {
                    case BackTrackCheckingResult.NodeIsEqualToParent:
                    case BackTrackCheckingResult.NodeIsOmegaLeaf:
                        return;
                    case BackTrackCheckingResult.Nothing:
                        break;
                }

                //building child nodes
                foreach (var t in tSet)
                {
                    var newMarking = new Vector(PetriNet.PlacesCount);
                    for (int p = 0; p < PetriNet.PlacesCount; p++)
                    {
                        newMarking[p] = node.Marking[p] + PetriNet.IncedentMatrix[p, t];
                    }
                    node.AddChild(new TreeNode(newMarking), t);
                }
                foreach (var childNode in node.Child)
                {
                    BuildFromNode(childNode);
                }
            }
        }
Ejemplo n.º 4
0
        private bool TraverseAnyChecking(Func<TreeNode, bool> predicate, TreeNode node)
        {
            if (predicate(node))
                return true;

            return node.Child != null && node.Child.Any(child => TraverseAnyChecking(predicate, child));
        }
Ejemplo n.º 5
0
 private void Trace(TreeNode node)
 {
     if (node.IsOmegaLeaf)
     {
         var newNode = new TreeNode(node.Marking);
         BuildFromNode(newNode);
         node.Child = newNode.Child;
         node.Marking = newNode.Marking;
         node.ChildTransitions = newNode.ChildTransitions;
         return;
     }
     if(node.Child!=null)
         foreach (var child in node.Child)
             Trace(child);
 }
Ejemplo n.º 6
0
 public void FillGraph(Graph graph, TreeNode node)
 {
     graph.AddNode(node.Id);
     if (node.Child != null)
     {
         for (int i = 0; i < node.Child.Count; i++)
         {
             FillGraph(graph, node.Child[i]);
             string edgeId = node.Id + "t" + node.ChildTransitions[i] + node.Child[i].Id;
             if (!_edges.Contains(edgeId))
             {
                 _edges.Add(edgeId);
                 graph.AddEdge(node.Id, "t" + node.ChildTransitions[i], node.Child[i].Id);
             }
         }
     }
 }
Ejemplo n.º 7
0
 public void AddChild(TreeNode node, int transition)
 {
     if (Child == null)
         Child = new List<TreeNode>();
     if (ChildTransitions == null)
         ChildTransitions = new List<int>();
     node.Parent = this;
     Child.Add(node);
     ChildTransitions.Add(transition);
 }