Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getPlaceMarking(PlaceInterface $place)
 {
     foreach ($this->placeMarkings as $placeMarking) {
         if ($placeMarking->getPlace() === $place || null !== $place->getId() && $placeMarking->getPlace()->getId() === $place->getId()) {
             return $placeMarking;
         }
     }
     return null;
 }
Exemplo n.º 2
0
 function it_dumps_a_petrinet_with_marking(PetrinetInterface $petrinet, PlaceInterface $placeOne, PlaceInterface $placeTwo, PlaceInterface $placeThree, PlaceInterface $placeFour, TransitionInterface $transitionOne, TransitionInterface $transitionTwo, InputArcInterface $arcOne, OutputArcInterface $arcTwo, InputArcInterface $arcThree, OutputArcInterface $arcFour, OutputArcInterface $arcFive, InputArcInterface $arcSix, MarkingInterface $marking, PlaceMarkingInterface $placeOneMarking, PlaceMarkingInterface $placeThreeMarking, TokenInterface $token)
 {
     // Petrinet
     $petrinet->getPlaces()->willReturn(array($placeOne, $placeTwo, $placeThree, $placeFour));
     $petrinet->getTransitions()->willReturn(array($transitionOne, $transitionTwo));
     $petrinet->getId()->willReturn(1);
     $placeOne->getInputArcs()->willReturn(array());
     $placeOne->getOutputArcs()->willReturn(array($arcOne));
     $placeOne->getId()->willReturn(1);
     $arcOne->getPlace()->willReturn($placeOne);
     $arcOne->getTransition()->willReturn($transitionOne);
     $arcOne->getId()->willReturn(1);
     $arcOne->getWeight()->willReturn(1);
     $transitionOne->getInputArcs()->willReturn(array($arcOne));
     $transitionOne->getOutputArcs()->willReturn(array($arcTwo, $arcFive));
     $transitionOne->getId()->willReturn(1);
     $arcTwo->getTransition()->willReturn($transitionOne);
     $arcTwo->getPlace()->willReturn($placeTwo);
     $arcTwo->getId()->willReturn(2);
     $arcTwo->getWeight()->willReturn(1);
     $placeTwo->getInputArcs()->willReturn(array($arcTwo));
     $placeTwo->getOutputArcs()->willReturn(array($arcThree));
     $placeTwo->getId()->willReturn(2);
     $arcThree->getPlace()->willReturn($placeTwo);
     $arcThree->getTransition()->willReturn($transitionTwo);
     $arcThree->getId()->willReturn(3);
     $arcThree->getWeight()->willReturn(2);
     $transitionTwo->getInputArcs()->willReturn(array($arcThree));
     $transitionTwo->getOutputArcs()->willReturn(array($arcFour));
     $transitionTwo->getId()->willReturn(2);
     $arcFour->getTransition()->willReturn($transitionTwo);
     $arcFour->getPlace()->willReturn($placeThree);
     $arcFour->getId()->willReturn(4);
     $arcFour->getWeight()->willReturn(1);
     $placeThree->getInputArcs()->willReturn(array($arcFour));
     $placeThree->getOutputArcs()->willReturn(array());
     $placeThree->getId()->willReturn(3);
     $arcFive->getTransition()->willReturn($transitionOne);
     $arcFive->getPlace()->willReturn($placeFour);
     $arcFive->getId()->willReturn(5);
     $arcFive->getWeight()->willReturn(1);
     $placeFour->getInputArcs()->willReturn(array($arcFive));
     $placeFour->getOutputArcs()->willReturn(array($arcSix));
     $placeFour->getId()->willReturn(4);
     $arcSix->getPlace()->willReturn($placeFour);
     $arcSix->getTransition()->willReturn($transitionTwo);
     $arcSix->getId()->willReturn(6);
     $arcSix->getWeight()->willReturn(1);
     // Marking
     $placeOneMarking->getTokens()->willReturn(array($token));
     $placeThreeMarking->getTokens()->willReturn(array($token, $token));
     $marking->getPlaceMarking($placeOne)->willReturn($placeOneMarking);
     $marking->getPlaceMarking($placeTwo)->willReturn(null);
     $marking->getPlaceMarking($placeThree)->willReturn($placeThreeMarking);
     $marking->getPlaceMarking($placeFour)->willReturn(null);
     $this->dump($petrinet, $marking)->shouldReturn($this->getSecondExpectedDotContent());
 }
Exemplo n.º 3
0
 function it_throws_an_exception_when_adding_a_duplicated_place_marking(PlaceInterface $placeOne, PlaceInterface $placeTwo, PlaceMarkingInterface $markingOne, PlaceMarkingInterface $markingTwo)
 {
     $placeOne->getId()->willReturn(5);
     $placeTwo->getId()->willReturn(5);
     $markingOne->getPlace()->willReturn($placeOne);
     $markingTwo->getPlace()->willReturn($placeTwo);
     $this->addPlaceMarking($markingOne);
     $this->shouldThrow(new \InvalidArgumentException('Cannot add two markings for the same place.'))->duringAddPlaceMarking($markingTwo);
 }
Exemplo n.º 4
0
 private function getPlaceLabel(PlaceInterface $place, MarkingInterface $marking = null)
 {
     $placeLabel = null === $place->getId() ? '' : $place->getId();
     $tokensCount = $this->getPlaceTokensCount($place, $marking);
     if ($tokensCount > 1) {
         return sprintf('%s (%s tokens)', $placeLabel, $tokensCount);
     }
     return sprintf('%s (%s token)', $placeLabel, $tokensCount);
 }