Exemplo n.º 1
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;
  }
Exemplo n.º 2
0
  @Override
  protected void initChildren(Element eThis) throws OmException {
    Node nPrevious = eThis.getPreviousSibling();
    if (nPrevious != null && nPrevious instanceof Text) {
      String sText = ((Text) nPrevious).getData();
      if (sText.length() > 0 && Character.isWhitespace(sText.charAt(sText.length() - 1)))
        bSpaceBefore = true;
    }
    Node nAfter = eThis.getNextSibling();
    if (nAfter != null && nAfter instanceof Text) {
      String sText = ((Text) nAfter).getData();
      if (sText.length() > 0 && Character.isWhitespace(sText.charAt(0))) bSpaceAfter = true;
    }

    List<Place> lPlaces = new LinkedList<Place>();
    int iPlace = 0;
    StringBuffer sbText = new StringBuffer();
    for (Node n = eThis.getFirstChild(); n != null; n = n.getNextSibling()) {
      if (n instanceof Element) {
        Element eplace = (Element) n;
        if (!eplace.getTagName().equals("eplace"))
          throw new OmFormatException("<equation> may only contain text and <eplace> tags");
        Element[] aeChildren = XML.getChildren(eplace);
        QComponent qcChild;
        boolean bImplicit = false;
        if (aeChildren.length != 1) // Treats more than one child as inside <t>
        {
          qcChild = getQDocument().build(this, eplace, "t");
          bImplicit = true;
        } else // Treats single child as specific component (auto-sizing works)
        qcChild = getQDocument().build(this, aeChildren[0], null);
        addChild(qcChild); // Must be stored in standard child array so it
        // can be found etc.

        // See if width/height is specified
        int iWidth, iHeight;
        if (eplace.hasAttribute("width") && eplace.hasAttribute("height")) {
          try {
            iWidth = Integer.parseInt(eplace.getAttribute("width"));
            iHeight = Integer.parseInt(eplace.getAttribute("height"));
          } catch (NumberFormatException nfe) {
            throw new OmFormatException("<equation> <eplace>: width= and height= must be integers");
          }
        } else {
          Dimension d = qcChild.getApproximatePixelSize();
          if (d == null)
            throw new OmFormatException(
                "<equation> <eplace>: Except for components that support automatic "
                    + "size estimation and fixing, <eplace> must include width= and height=");
          iWidth = d.width;
          iHeight = d.height;
        }

        Place p = new Place();
        p.sID = "p" + (iPlace++);
        p.qc = qcChild;
        p.iWidth = iWidth;
        p.iHeight = iHeight;
        p.bImplicit = bImplicit;
        if (!eplace.hasAttribute("label"))
          throw new OmFormatException("<equation> <eplace>: Must include label=");
        if (eplace.hasAttribute("label")) p.sLabel = eplace.getAttribute("label");
        else p.sLabel = null;
        if (eplace.hasAttribute("for")) p.sLabelFor = eplace.getAttribute("for");
        else if (qcChild instanceof Labelable) p.sLabelFor = qcChild.getID();
        lPlaces.add(p);

        // Add in the equation format text representing the placeholder
        sbText.append("\\placeholder{" + p.sID + "}{" + p.iWidth + "," + p.iHeight + "}");
      } else if (n instanceof Text) {
        sbText.append(n.getNodeValue());
      }
    }
    sEquation = sbText.toString();
    apPlaces = lPlaces.toArray(new Place[0]);
  }