Exemplo n.º 1
0
 protected StateVector addOrFetchStateToOrFromHierarchy(StateVector stateVector)
 {
     StateVector findStateVector = this.stateHierarchy.find(stateVector);
     if (findStateVector == null)
     {
         this.stateHierarchy.addState(stateVector);
         findStateVector = stateVector;
     }
     return findStateVector;
 }
Exemplo n.º 2
0
 public StateVector find(StateVector stateVector)
 {
     StateVector ret = null;
     foreach (StateVector sv in this.states)
     {
         if (sv.Equals(stateVector))
         {
             ret = sv;
             break;
         }
     }
     return ret;
 }
Exemplo n.º 3
0
 protected void saveState(string name, StateVector stateVector)
 {
     StateVector findStateVector = null;
     foreach (StateVector sv in this.stateMatrix)
     {
         if (sv.Equals(stateVector))
         {
             findStateVector = sv;
             break;
         }
     }
     if (findStateVector == null)
     {
         findStateVector = this.addOrFetchStateToOrFromHierarchy(stateVector);
         if (this.actualStateVector != null)
         {
             this.checkHandler(this.actualStateVector, EventType.PREACTIVATE); // BEFOREDEACTIVATE
             this.stateHierarchy.addEdge(this.actualStateVector, findStateVector);
         }
         this.stateMatrix.Add(findStateVector);
         this.actualStateVector = findStateVector;
         findStateVector.Statistics.add(1);
         this.checkHandler(this.actualStateVector, EventType.POSTACTIVATE);
     }
     else
     {
         if (this.actualStateVector != null)
         {
             this.checkHandler(this.actualStateVector, EventType.PREACTIVATE); // BEFOREDEACTIVATE
             this.stateHierarchy.addEdge(this.actualStateVector, findStateVector);
         }
         this.actualStateVector = findStateVector;
         findStateVector.Statistics.add(1);
         this.checkHandler(this.actualStateVector, EventType.POSTACTIVATE);
     }
 }
Exemplo n.º 4
0
 private void returnToState(StateVector stateVector)
 {
     List<Position> positions = this.Positions;
     foreach (Position position in positions)
     {
         List<Token> tokens = stateVector.getTokensByPositionUnid(position.Unid);
         position.changeTokens(tokens);
     }
     this.actualStateVector = stateVector;
 }
Exemplo n.º 5
0
 private void cutStateMatrix(StateVector last)
 {
     List<StateVector> newStateMatrix = new List<StateVector>();
     foreach (StateVector stateVector in this.stateMatrix)
     {
         if (stateVector.Equals(last))
         {
             break;
         }
         newStateMatrix.Add(stateVector);
     }
     newStateMatrix.Add(last);
     this.stateMatrix = newStateMatrix;
 }
Exemplo n.º 6
0
        internal static StateVector openFromXml(XmlNode node, List<Token> alltokens)
        {
            XmlNodeList list = node.ChildNodes;
            Dictionary<Int64, List<Token>> tokenDistribution = null;
            List<PetriEvent> events = null;
            foreach (XmlNode childNode in list)
            {
                string namespaceUri = childNode.NamespaceURI;
                string localName = childNode.LocalName;
                switch (namespaceUri)
                {
                    case PetriXmlHelper.XML_STATE_NAMESPACE:
                        switch (localName)
                        {
                            case "TokenDistributions":
                                tokenDistribution = StateVector.openTokenDistributionFromXml(childNode.ChildNodes, alltokens);
                                break;
                            case "Events":
                                events = PetriEvent.openEvents(childNode.ChildNodes, "StateEvent");
                                break;
                        }
                        break;
                }
            }
            string name = AbstractItem.readItemName(node, PetriXmlHelper.XML_STATE_NAMESPACE);
            long unid = AbstractItem.readItemUnid(node, PetriXmlHelper.XML_STATE_NAMESPACE);

            StateVector ret = new StateVector(name, unid, tokenDistribution);
            ret.EventTrunk.addEvents(events);
            return ret;
        }
Exemplo n.º 7
0
 public bool Equals(StateVector sv)
 {
     bool ret = false;
     if (sv != null)
     {
         ret = true;
         foreach (KeyValuePair<Int64, List<Token>> entry in sv.tokenDistribution)
         {
             Int64 positionUnid = entry.Key;
             if (this.tokenDistribution[positionUnid] != null)
             {
                 List<Token> thisTokens = this.tokenDistribution[positionUnid];
                 List<Token> tokens = entry.Value;
                 if ((tokens != null) && (thisTokens != null))
                 {
                     if (tokens.Count != thisTokens.Count)
                     {
                         ret = false;
                         break;
                     }
                 }
             }
             else
             {
                 ret = false;
                 break;
             }
         }
     }
     return ret;
 }
Exemplo n.º 8
0
 public EdgeStateState(StateVector startState, StateVector endState)
 {
     this.startState = startState;
     this.endState = endState;
 }
Exemplo n.º 9
0
 internal void addState(StateVector state)
 {
     if (!(this.states.Contains(state)))
     {
         this.states.Add(state);
     }
 }
Exemplo n.º 10
0
 internal void addEdge(StateVector start, StateVector end)
 {
     this.addEdge(new EdgeStateState(start, end));
 }