Пример #1
0
 public TransitionHistoryItem(Transition transition)
 {
     this.transition = transition;
     this.transitionNameAtFire = this.transition.Name;
     this.tokens = new List<AbstractToken>();
     this.nameOfTokensAtFire = new List<string>();
 }
Пример #2
0
 public static AbstractNetworkItem openFromXml(XmlNode node)
 {
     PointF origo = new PointF(0, 0);
     PointF labelOffset = new PointF(0,0);
     PointF clockOffset = new PointF(0, 0);
     SizeF size = new SizeF(0, 0);
     XmlNodeList list = node.ChildNodes;
     List<PetriEvent> events = null;
     foreach (XmlNode childNode in list)
     {
         string namespaceUri = childNode.NamespaceURI;
         string localName = childNode.LocalName;
         switch (namespaceUri)
         {
             case PetriXmlHelper.XML_POINTF_NAMESPACE:
                 if ("Origo".Equals(localName))
                 {
                     origo = PetriXmlHelper.openPointF(childNode);
                 }
                 else if ("LabelOffset".Equals(localName))
                 {
                     labelOffset = PetriXmlHelper.openPointF(childNode);
                 }
                 else if ("ClockOffset".Equals(localName))
                 {
                     clockOffset = PetriXmlHelper.openPointF(childNode);
                 }
                 break;
             case PetriXmlHelper.XML_SIZEF_NAMESPACE:
                 if ("Size".Equals(localName))
                 {
                     size = PetriXmlHelper.openSizeF(childNode);
                 }
                 break;
             case PetriXmlHelper.XML_ITEM_NAMESPACE:
                 switch (localName)
                 {
                     case "Events":
                         events = PetriEvent.openEvents(childNode.ChildNodes, "ItemEvent");
                         break;
                 }
                 break;
         }
     }
     string name = AbstractItem.openNameAttrFromNode(node);
     long unid = AbstractItem.openUnidAttrFromNode(node);
     bool showAnnotation = AbstractItem.openShowAnnotationAttrFromNode(node);
     float angle = AbstractTransition.openAngleAttrFromNode(node);
     int priority = AbstractTransition.openPriorityAttrFromNode(node);
     TransitionType transitionType = AbstractTransition.openTransitionTypeAttrFromNode(node);
     int delay = AbstractTransition.openDelayAttrFromNode(node);
     float clockRadius = AbstractTransition.openClockRadiusAttrFromNode(node);
     Transition ret = new Transition(name, unid, showAnnotation, angle, origo, size, priority, transitionType, delay, clockRadius, clockOffset);
     ret.PetriEvents.addEvent(events);
     ret.LabelOffset = labelOffset;
     return ret;
 }
Пример #3
0
 public AbstractEdge(string name, long unid, bool showAnnotation, int weight, Position position, Transition transition, PointF curveMiddlePoint, EdgeType edgeType)
     : base(name, unid, showAnnotation)
 {
     this.weight = weight;
     this.position = position;
     this.transition = transition;
     this.curveMiddlePointOffset = curveMiddlePoint;
     this.edgeType = edgeType;
 }
Пример #4
0
 public EdgeTransitionPosition(string name, long unid, bool showAnnotation, int weight, Transition transition, Position position, PointF curveMiddlePoint, EdgeType edgeType)
     : base(name, unid, showAnnotation, weight, position, transition, curveMiddlePoint, edgeType)
 {
 }
Пример #5
0
 public FireReturn(FireEvent fireEvent, Transition fireTransition)
 {
     this.fireEvent = fireEvent;
     this.fireTransition = fireTransition;
 }
Пример #6
0
 private void transitionHistory_selectTransition(Transition selectedTransition)
 {
     if (this.ActiveMdiChild is PetriNetworkForm)
     {
         (this.ActiveMdiChild as PetriNetworkForm).singleSelectItem(selectedTransition);
         (this.ActiveMdiChild as PetriNetworkForm).parentCallReDraw(NetworkToolboxAction.REFRESH, false);
     }
 }
Пример #7
0
 private List<AbstractEdge> getAllInputEdge(Transition transition)
 {
     List<AbstractEdge> inputs = new List<AbstractEdge>();
     foreach (AbstractEdge edge in this.edges)
     {
         if (transition.Equals(edge.End))
         {
             inputs.Add(edge);
         }
     }
     return inputs;
 }
Пример #8
0
 private List<AbstractEdge> getAllOutputEdge(Transition transition)
 {
     List<AbstractEdge> outputs = new List<AbstractEdge>();
     foreach (AbstractEdge edge in this.edges)
     {
         if (transition.Equals(edge.Start))
         {
             outputs.Add(edge);
         }
     }
     return outputs;
 }
Пример #9
0
 protected void addEdgeTransitionPosition(int weight, Transition transition, Position position, PointF curveMiddlePoint)
 {
     this.addEdge(new EdgeTransitionPosition("", this.unidGenNumber++, true, weight, transition, position, curveMiddlePoint, EdgeType.NORMAL));
 }
Пример #10
0
 private bool checkCapacityLimit(Transition transition, Dictionary<Position, Int32> touchedPositions)
 {
     bool cFire = true;
     List<AbstractEdge> outputs = this.getAllOutputEdge(transition);
     if (outputs.Count > 0)
     {
         foreach (AbstractEdge edge in outputs)
         {
             if (edge.End is Position)
             {
                 int needCapacity = edge.Weight;
                 Position tmpPos = (Position)edge.End;
                 if (touchedPositions.ContainsKey(tmpPos))
                 {
                     needCapacity -= touchedPositions[tmpPos];
                 }
                 if (tmpPos.isCapcityLimitInjured(needCapacity))
                 {
                     cFire = false;
                 }
             }
         }
     }
     return cFire;
 }
Пример #11
0
 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);
 }
Пример #12
0
 public int getPlusWeight(Position position, Transition transition)
 {
     int ret = 0;
     foreach (AbstractEdge edge in this.edges)
     {
         if (edge is EdgeTransitionPosition)
         {
             if (EdgeType.NORMAL.Equals(edge.EdgeType))
             {
                 EdgeTransitionPosition etp = (EdgeTransitionPosition)edge;
                 if (etp.StartTransition.Equals(transition) && etp.EndPosition.Equals(position))
                 {
                     ret = etp.Weight;
                     break;
                 }
             }
         }
     }
     return ret;
 }
Пример #13
0
 public int getMinusWeight(Position position, Transition transition)
 {
     int ret = 0;
     foreach (AbstractEdge edge in this.edges)
     {
         if (edge is EdgePositionTransition)
         {
             if (EdgeType.NORMAL.Equals(edge.EdgeType))
             {
                 EdgePositionTransition ept = (EdgePositionTransition)edge;
                 if ( ept.StartPosition.Equals(position) && ept.EndTransition.Equals(transition) )
                 {
                     ret = ept.Weight;
                     break;
                 }
             }
         }
     }
     return ret;
 }
Пример #14
0
 public void changeTransitionType(Transition transition, TransitionType transitionType)
 {
     if ((transition != null) && (transitionType != null))
     {
         List<AbstractEdge> edgesToDelete = new List<AbstractEdge>();
         if ( TransitionType.SINK.Equals(transitionType))
         {
             edgesToDelete = this.getAllOutputEdge(transition);
         } else if ( TransitionType.SOURCE.Equals(transitionType)) {
             edgesToDelete = this.getAllInputEdge(transition);
         }
         if (edgesToDelete.Count > 0)
         {
             this.deleteEdges(edgesToDelete);
         }
     }
 }
Пример #15
0
 public AbstractNetworkItem addTransition(string name, double angle, PointF origo, SizeF size)
 {
     Transition transition = new Transition(this.identityProvider.transitionIdentity(name), this.unidGenNumber++, true, angle, origo, size, 0, TransitionType.NORMAL, 0, AbstractTransition.DEFAULT_CLOCK_RADIUS, new PointF(10, 10));
     this.addItem(transition);
     return transition;
 }