public static AbstractToken openFromXml(XmlNode node) { Token ret = new Token(AbstractItem.openNameAttrFromNode(node), AbstractItem.openUnidAttrFromNode(node), true); XmlNodeList list = node.ChildNodes; foreach (XmlNode childNode in list) { string namespaceUri = childNode.NamespaceURI; string localName = childNode.LocalName; switch (namespaceUri) { case NetworkVisualSettings.XML_COLOR_NAMESPACE: if ("TokenColor".Equals(localName)) { ret.TokenColor = NetworkVisualSettings.openColor(childNode); } break; } } return ret; }
public static List<AbstractToken> openTokensFromXml(XmlNodeList list, List<AbstractItem> alltokens) { List<AbstractToken> ret = new List<AbstractToken>(); foreach (XmlNode childNode in list) { string namespaceUri = childNode.NamespaceURI; string localName = childNode.LocalName; if ((PetriXmlHelper.XML_STATE_NAMESPACE.Equals(namespaceUri)) && ("Token".Equals(localName))) { long tokUnid = StateVector.openUnidAttrFromNode(childNode); AbstractToken token = (Token)AbstractItem.findItemByUnid(alltokens, tokUnid); if (token == null) { token = new Token("", tokUnid, true); } ret.Add(token); } } return ret; }
public StateVector simulateTransitionFire(Transition fireTransition, bool changeStatistics) { TransitionHistoryItem historyItem = null; if (changeStatistics) { fireTransition.Statistics.add(1); historyItem = new TransitionHistoryItem(fireTransition); } List<AbstractToken> tokens = new List<AbstractToken>(); List<AbstractEdge> inputs = this.getAllInputEdge(fireTransition); List<AbstractEdge> outputs = this.getAllOutputEdge(fireTransition); foreach (AbstractEdge edge in inputs) { if (edge.Start is Position) { Position position = (Position)edge.Start; if (EdgeType.NORMAL.Equals(edge.EdgeType)) { tokens.AddRange(position.takeAwayTokens(edge.Weight, changeStatistics)); } else if (EdgeType.RESET.Equals(edge.EdgeType)) { tokens.AddRange(position.takeAwayTokens(changeStatistics)); } else if (EdgeType.INHIBITOR.Equals(edge.EdgeType)) { // nothing to do } } } this.mixTokens(tokens); if (changeStatistics && historyItem != null) { historyItem.addToken(tokens); } int ti = 0; foreach (AbstractEdge edge in outputs) { if (edge.End is Position) { Position position = (Position)edge.End; for (int ei = 0; ei < edge.Weight; ei++) { AbstractToken token = null; if (ti < tokens.Count) { token = tokens[ti++]; } else { token = new Token(this.identityProvider.tokenIdentity(null), this.unidGenNumber++, true); } position.addToken(token); } if (changeStatistics) { position.addStatistics(); } } } if (changeStatistics && historyItem != null) { this.addItemToTransitionHistory(historyItem); } return this.getNewStateVector(null); }