示例#1
0
 @Override
 public boolean equals(Object obj) {
   if (obj == null) {
     return false;
   }
   if (getClass() != obj.getClass()) {
     return false;
   }
   final Marking other = (Marking) obj;
   if (this.petriNet != other.petriNet
       && (this.petriNet == null || !this.petriNet.equals(other.petriNet))) {
     return false;
   }
   if (this.map == other.map) {
     return true;
   }
   Set<Place> places = new HashSet<Place>(); // because map is sparse
   places.addAll(this.map.keySet());
   places.addAll(other.map.keySet());
   for (Place place : places) {
     if (this.getTokens(place) != other.getTokens(place)) {
       return false;
     }
   }
   return true;
 }
示例#2
0
  private Set<FiringSequence> getAllFiringSequencesRecursively(
      Marking marking, Set<Marking> visitedMarkings) throws PetriNetException {
    Set<FiringSequence> firingSequences = new HashSet<FiringSequence>();

    Set<Transition> enabledTransitions = marking.getAllEnabledTransitions();
    for (Transition transition : enabledTransitions) {
      Marking newMarking = marking.getMarkingAfterFiring(transition);

      if (visitedMarkings.contains(newMarking)) {
        throw new PetriNetException("There is a loop.");
      }
      visitedMarkings.add(newMarking);

      if (!newMarking.isEnabledByAnyTransition()) { // leaf marking
        FiringSequence firingSequence = new FiringSequence();
        firingSequence.add(transition);
        firingSequences.add(firingSequence);
      }

      for (FiringSequence nextFiringSequence :
          getAllFiringSequencesRecursively(newMarking, visitedMarkings)) {
        FiringSequence firingSequence = new FiringSequence();
        firingSequence.add(transition);
        firingSequence.addAll(nextFiringSequence);
        firingSequences.add(firingSequence);
      }

      visitedMarkings.remove(newMarking);
    }
    return firingSequences;
  }
示例#3
0
 /**
  * Returns a new marking after firing a transition. Original marking is not changed.
  *
  * @param transition transition to be fired
  * @return new marking with fired transition
  */
 public Marking getMarkingAfterFiring(Transition transition) {
   if (!this.isEnabled(transition)) {
     return null;
   }
   Marking newMarking = new Marking(this);
   newMarking.fire(transition);
   return newMarking;
 }
示例#4
0
 /**
  * Copy constructor.
  *
  * @param marking the marking to be copied.
  */
 public Marking(Marking marking) {
   marking.getLock().readLock().lock();
   try {
     this.map = new ConcurrentHashMap<Place, Integer>(marking.map);
   } finally {
     marking.getLock().readLock().unlock();
   }
   this.petriNet = marking.petriNet;
 }
示例#5
0
 /**
  * Returns a marking after firing a sequence of transitions. The original marking is not changed.
  *
  * @param firingSequence sequence of transitions to be fired one after the other
  * @return a new marking after firing a sequence of transitions
  */
 public Marking getMarkingAfterFiring(FiringSequence firingSequence) {
   Marking newMarking = new Marking(this);
   for (Transition transition : firingSequence) {
     if (!newMarking.isEnabled(transition)) {
       return null;
     }
     newMarking.fire(transition);
   }
   return newMarking;
 }