Exemple #1
0
  @Override
  public String toString() {
    StringBuilder result = new StringBuilder();
    result.append("Fireable transitions: ");

    lock.readLock().lock();
    try {
      for (Transition transition : this.getAllEnabledTransitions()) {
        result.append(transition.getFullLabel() + " ");
      }
      if (this.getAllEnabledTransitions().isEmpty()) {
        result.append("-NONE-");
      }
      result.append("\nPlaces: ");
      for (Place place : petriNet.getRootSubnet().getPlacesRecursively()) {
        result.append(place.getLabel() + ":" + getTokens(place) + " ");
      }
      if (petriNet.getRootSubnet().getPlacesRecursively().isEmpty()) {
        result.append("-NONE-");
      }
    } finally {
      lock.readLock().unlock();
    }

    return result.toString();
  }
  // TODO: THIS IS RATHER UGLY, too many params but better than what was here before
  public void registerTab(
      PetriNet net,
      PetriNetTab tab,
      Observer historyObserver,
      UndoableEditListener undoListener,
      PropertyChangeListener zoomListener) {
    AnimationHistoryImpl animationHistory = new AnimationHistoryImpl();
    animationHistory.addObserver(historyObserver);
    GUIAnimator animator = new GUIAnimator(new PetriNetAnimator(net), animationHistory, this);

    CopyPasteManager copyPasteManager = new CopyPasteManager(undoListener, tab, net, this);

    ZoomController zoomController = new ZoomController(100);
    tab.addZoomListener(zoomController);
    PetriNetController petriNetController =
        new PetriNetController(net, undoListener, animator, copyPasteManager, zoomController, tab);
    netControllers.put(tab, petriNetController);
    tab.updatePreferredSize();

    PropertyChangeListener changeListener =
        new PetriNetChangeListener(applicationModel, tab, petriNetController);
    net.addPropertyChangeListener(changeListener);

    setActiveTab(tab);
    initialiseNet(net, changeListener);
  }
  @Override
  public boolean canFire(PetriNet petriNet, Arc<Transition, Place> arc) {
    Place place = arc.getTarget();
    if (place.getCapacity() == 0) { // No capacity restrictions
      return true;
    }

    int totalTokensIn = 0;
    int totalTokensOut = 0;

    Transition transition = arc.getSource();
    for (Token token : arc.getTokenWeights().keySet()) {
      IncidenceMatrix forwardsIncidenceMatrix = petriNet.getForwardsIncidenceMatrix(token);
      IncidenceMatrix backwardsIncidenceMatrix = petriNet.getBackwardsIncidenceMatrix(token);

      totalTokensIn += forwardsIncidenceMatrix.get(place, transition);
      totalTokensOut += backwardsIncidenceMatrix.get(place, transition);
    }

    return (place.getNumberOfTokensStored() + totalTokensIn - totalTokensOut
        <= place.getCapacity());
  }
Exemple #4
0
  /**
   * Sets the number of tokens to the specified PlaceNode (Place or ReferencePlace). If specified
   * PlaceNode is ReferencePlace, it will set number of tokens to its connected Place. If the
   * specified ReferencePlace is not connected to any Place, it will throw RuntimeException. If the
   * specified number of tokens is negative, it will throw RuntimeException. If the resulting Place
   * is static, number of tokens will be set to initial marking instead.
   */
  public void setTokens(PlaceNode placeNode, int tokens) {
    if (tokens < 0) {
      // throw new RuntimeException("Number of tokens must be non-negative");
      throw new IllegalStateException("Number of tokens must be non-negative");
    }

    Place place = placeNode.getPlace();

    if (place == null) {
      // throw new RuntimeException("setTokens() to disconnected ReferencePlace");
      throw new IllegalStateException("setTokens() to disconnected ReferencePlace");
    }

    if (place.isStatic()) {
      petriNet.getInitialMarking().map.put(place, tokens);
    } else {
      this.map.put(place, tokens);
    }
  }
Exemple #5
0
  /**
   * Returns the number of tokens based on the specified PlaceNode (Place or ReferencePlace). If
   * specified PlaceNode is ReferencePlace, it will return number of tokens of its connected Place.
   * If the specified ReferencePlace is not connected to any Place, it will return zero. If the
   * resulting Place is static, number of tokens will be given from initial marking instead.
   */
  public int getTokens(PlaceNode placeNode) {
    Place place = placeNode.getPlace();
    if (place
        == null) { // In case of disconnected ReferencePlace, we want it to appear with zero tokens.
      // Disconnected ReferencePlaces can be found in stored subnets.
      return 0;
    }

    Marking marking;
    if (place.isStatic()) {
      marking = petriNet.getInitialMarking();
    } else {
      marking = this;
    }

    if (marking.map.get(place)
        == null) { // Place has zero tokens in the beginning. Not every place is in map. Only those
      // previously edited.
      return 0;
    }

    return marking.map.get(place);
  }
  /**
   * This is a little hacky, I'm not sure how to make this better when it's so late If a better
   * implementation is clear please re-write
   *
   * <p>This method invokes the change listener which will create the view objects on the petri net
   * tab
   *
   * @param propertyChangeListener
   */
  private void initialiseNet(PetriNet net, PropertyChangeListener propertyChangeListener) {
    for (Token token : net.getTokens()) {
      PropertyChangeEvent changeEvent =
          new PropertyChangeEvent(net, PetriNet.NEW_TOKEN_CHANGE_MESSAGE, null, token);
      propertyChangeListener.propertyChange(changeEvent);
    }

    for (Place place : net.getPlaces()) {
      PropertyChangeEvent changeEvent =
          new PropertyChangeEvent(net, PetriNet.NEW_PLACE_CHANGE_MESSAGE, null, place);
      propertyChangeListener.propertyChange(changeEvent);
    }

    for (Transition transition : net.getTransitions()) {
      PropertyChangeEvent changeEvent =
          new PropertyChangeEvent(net, PetriNet.NEW_TRANSITION_CHANGE_MESSAGE, null, transition);
      propertyChangeListener.propertyChange(changeEvent);
    }

    for (Arc<? extends Connectable, ? extends Connectable> arc : net.getArcs()) {
      PropertyChangeEvent changeEvent =
          new PropertyChangeEvent(net, PetriNet.NEW_ARC_CHANGE_MESSAGE, null, arc);
      propertyChangeListener.propertyChange(changeEvent);
    }

    for (Annotation annotation : net.getAnnotations()) {
      PropertyChangeEvent changeEvent =
          new PropertyChangeEvent(net, PetriNet.NEW_ANNOTATION_CHANGE_MESSAGE, null, annotation);
      propertyChangeListener.propertyChange(changeEvent);
    }

    for (RateParameter rateParameter : net.getRateParameters()) {
      PropertyChangeEvent changeEvent =
          new PropertyChangeEvent(
              net, PetriNet.NEW_RATE_PARAMETER_CHANGE_MESSAGE, null, rateParameter);
      propertyChangeListener.propertyChange(changeEvent);
    }
  }
Exemple #7
0
  public static PetriNet convert(ConfigurableEPC baseEPC) {
    HashMap<EPCFunction, Transition> functionActivityMapping;
    HashMap<EPCConnector, Place> xorconnectorChoiceMapping;

    // HV: Initialize the mappings.
    functionActivityMapping = new HashMap<EPCFunction, Transition>();
    xorconnectorChoiceMapping = new HashMap<EPCConnector, Place>();

    // Check to use the weights if necessary
    // HV: Add both mappings. On completion, these will be filledd.
    PetriNet petrinet =
        EPCToPetriNetConverter.convert(
            baseEPC, new HashMap(), functionActivityMapping, xorconnectorChoiceMapping);

    HashSet visible = new HashSet();

    // HV: The next block is taken care of by the functionActivityMapping
    // below.
    /*
     * Iterator it = petrinet.getTransitions().iterator(); while
     * (it.hasNext()) { Transition t = (Transition) it.next(); if (t.object
     * instanceof EPCFunction) { // if (t.getLogEvent() != null) { // Add
     * transitions with LogEvent (i.e. referring to functions)
     * visible.add(t); } }
     */

    // HV: Prevent the places mapped onto from being reduced.
    visible.addAll(functionActivityMapping.values());
    visible.addAll(xorconnectorChoiceMapping.values());
    Message.add(visible.toString(), Message.DEBUG);

    Iterator it = petrinet.getPlaces().iterator();
    while (it.hasNext()) {
      Place p = (Place) it.next();
      if (p.inDegree() * p.outDegree() == 0) {
        // Add Initial and final places to visible, i.e. places that
        // refer to in and output events
        visible.add(p);
      }
    }

    // Reduce the PetriNet with Murata rules, while keeping the visible ones
    PetriNetReduction pnred = new PetriNetReduction();
    pnred.setNonReducableNodes(visible);

    HashMap pnMap = new HashMap(); // Used to map pre-reduction nodes to
    // post-reduction nodes.
    PetriNet reduced = pnred.reduce(petrinet, pnMap);

    if (reduced != petrinet) {
      // Update both mappings from pre-reduction nodes to post-reduction
      // nodes.
      HashMap<EPCFunction, Transition> newFunctionActivityMapping =
          new HashMap<EPCFunction, Transition>();
      for (EPCFunction function : functionActivityMapping.keySet()) {
        Transition transition = (Transition) functionActivityMapping.get(function);
        if (pnMap.keySet().contains(transition)) {
          newFunctionActivityMapping.put(function, (Transition) pnMap.get(transition));
        }
      }
      functionActivityMapping = newFunctionActivityMapping;
      HashMap<EPCConnector, Place> newXorconnectorChoiceMapping =
          new HashMap<EPCConnector, Place>();
      for (EPCConnector connector : xorconnectorChoiceMapping.keySet()) {
        Place place = (Place) xorconnectorChoiceMapping.get(connector);
        if (pnMap.keySet().contains(place)) {
          newXorconnectorChoiceMapping.put(connector, (Place) pnMap.get(place));
        }
      }
      xorconnectorChoiceMapping = newXorconnectorChoiceMapping;
    }
    reduced.makeClusters();

    // filter the \nunknown:normal
    ArrayList<Transition> alTrans = reduced.getVisibleTasks();
    for (int i = 0; i < alTrans.size(); i++) {
      Transition t = alTrans.get(i);
      String id = t.getIdentifier();
      int idx = id.indexOf("\\nunknown:normal");
      if (idx > 0) {
        id = id.substring(0, idx);
      }
      // �˴������ֵ��ѯ�滻���е�label
      String mappedId = htDict.get(id);
      if (mappedId != null) {
        t.setIdentifier(mappedId);
      } else {
        t.setIdentifier(id);
      }
    }

    return reduced;
  }
Exemple #8
0
 private Set<Transition> getTransitions() {
   return petriNet.getRootSubnet().getTransitionsRecursively();
 }