protected StateVector addOrFetchStateToOrFromHierarchy(StateVector stateVector) { StateVector findStateVector = this.stateHierarchy.find(stateVector); if (findStateVector == null) { this.stateHierarchy.addState(stateVector); findStateVector = stateVector; } return findStateVector; }
public StateVector find(StateVector stateVector) { StateVector ret = null; foreach (StateVector sv in this.states) { if (sv.Equals(stateVector)) { ret = sv; break; } } return ret; }
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); } }
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; }
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; }
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; }
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; }
public EdgeStateState(StateVector startState, StateVector endState) { this.startState = startState; this.endState = endState; }
internal void addState(StateVector state) { if (!(this.states.Contains(state))) { this.states.Add(state); } }
internal void addEdge(StateVector start, StateVector end) { this.addEdge(new EdgeStateState(start, end)); }