Exemplo n.º 1
0
 /**
  * Gets the arcs in the given Petrinet.
  *
  * @param PetrinetInterface $petrinet
  *
  * @return \Petrinet\Model\ArcInterface[]
  */
 private function getArcs(PetrinetInterface $petrinet)
 {
     $arcs = array();
     foreach ($petrinet->getPlaces() as $place) {
         foreach ($place->getInputArcs() as $inputArc) {
             $inputArcId = null === $inputArc->getId() ? spl_object_hash($inputArc) : $inputArc->getId();
             $arcs[$inputArcId] = $inputArc;
         }
         foreach ($place->getOutputArcs() as $outputArc) {
             $outputArcId = null === $outputArc->getId() ? spl_object_hash($outputArc) : $outputArc->getId();
             $arcs[$outputArcId] = $outputArc;
         }
     }
     foreach ($petrinet->getTransitions() as $transition) {
         foreach ($transition->getInputArcs() as $inputArc) {
             $inputArcId = null === $inputArc->getId() ? spl_object_hash($inputArc) : $inputArc->getId();
             $arcs[$inputArcId] = $inputArc;
         }
         foreach ($transition->getOutputArcs() as $outputArc) {
             $outputArcId = null === $outputArc->getId() ? spl_object_hash($outputArc) : $outputArc->getId();
             $arcs[$outputArcId] = $outputArc;
         }
     }
     return $arcs;
 }
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());
 }