コード例 #1
0
ファイル: RuleScheme.java プロジェクト: mubalu/Henshin-Editor
  private NestedApplCond shiftNestedApplCondAlongEmbMorphism(
      final NestedApplCond cond, final OrdinaryMorphism embedding, final AttrContext ac) {

    if (cond.getSource() == embedding.getSource()) {
      final OrdinaryMorphism condIso = cond.getTarget().isomorphicCopy();
      if (condIso == null) return null;

      final NestedApplCond shiftCond =
          new NestedApplCond(embedding.getTarget(), condIso.getTarget(), ac);
      if (this.propagateMapping(cond, shiftCond, embedding, condIso)) {

        for (int i = 0; i < cond.getNestedACs().size(); i++) {
          NestedApplCond nc = cond.getNestedACAt(i);
          final NestedApplCond shiftnc =
              shiftNestedApplCondAlongEmbMorphism(nc, condIso, cond.getAttrContext());
          if (shiftnc != null) {
            shiftnc.setName(nc.getName());
            shiftnc.setEnabled(nc.isEnabled());
            shiftCond.addNestedAC(shiftnc);
          } else return null;
        }

        return shiftCond;
      }

      shiftCond.dispose();
      condIso.dispose();
    }
    return null;
  }
コード例 #2
0
ファイル: RuleScheme.java プロジェクト: mubalu/Henshin-Editor
  private boolean propagateMapping(
      final OrdinaryMorphism from,
      final OrdinaryMorphism to,
      final OrdinaryMorphism above1,
      final OrdinaryMorphism above2) {

    final Enumeration<GraphObject> condDom = from.getDomain();
    while (condDom.hasMoreElements()) {
      GraphObject go = condDom.nextElement();
      GraphObject condImg = from.getImage(go);
      if (condImg != null) {
        GraphObject embedImg = above1.getImage(go);
        GraphObject isoImg = above2.getImage(condImg);
        if (embedImg != null && isoImg != null) {
          try {
            to.addMapping(embedImg, isoImg);
          } catch (BadMappingException ex) {
            return false;
          }
        }
        //				else
        //					return false;
      }
    }
    return true;
  }
コード例 #3
0
 // olga: use comatch after step ia done to get values of OUTPUT parameters of a rule
 String getValueOfOutputParameter(VarMember p, Rule r, OrdinaryMorphism comatch) {
   if (p != null && r != null && comatch != null) {
     Enumeration<GraphObject> rightObjs = comatch.getDomain();
     while (rightObjs.hasMoreElements()) {
       GraphObject obj = rightObjs.nextElement();
       if (obj.getAttribute() != null) {
         ValueTuple vt = (ValueTuple) obj.getAttribute();
         for (int i = 0; i < vt.getNumberOfEntries(); i++) {
           ValueMember vm = vt.getEntryAt(i);
           if (vm.isSet() && vm.getExpr().isVariable() && vm.getExprAsText().equals(p.getName())) {
             // we found an object obj inside of the RHS which uses the output parameter p,
             // now we will find an appropriate graph object
             // and to get the value of the output parameter
             GraphObject go = comatch.getImage(obj);
             ValueTuple vt_go = (ValueTuple) go.getAttribute();
             ValueMember vm_go = vt_go.getEntryAt(vm.getName());
             String parVal = vm_go.getExprAsText();
             System.out.println(
                 parVal
                     + "  is value of OUTPUT parameter: --"
                     + p.getName()
                     + "--  of rule: "
                     + r.getName());
             return parVal;
           }
         }
       }
     }
   }
   return null;
 }
コード例 #4
0
ファイル: RuleScheme.java プロジェクト: mubalu/Henshin-Editor
  /** Create mapping pairs of objects of the embedding morphisms. */
  private void mapKernel2MultiObject(final MultiRule multiRule) {
    final OrdinaryMorphism embLeft = multiRule.getEmbeddingLeft();
    final Enumeration<GraphObject> domLeft = embLeft.getDomain();
    while (domLeft.hasMoreElements()) {
      final GraphObject kern = domLeft.nextElement();
      multiRule.mapKernel2MultiObject(kern, embLeft.getImage(kern));
    }
    //		final Enumeration<GraphObject> enLeft = multiRule.getLeft().getElements();
    //	  	while (enLeft.hasMoreElements()) {
    //	  		final GraphObject obj = enLeft.nextElement();
    //	       	if (embLeft.getInverseImage(obj).hasMoreElements()){
    //	       		multiRule.mapKernel2MultiObject(embLeft.getInverseImage(obj).nextElement(), obj);
    //	       	}
    //	  	}

    final OrdinaryMorphism embRight = multiRule.getEmbeddingRight();
    final Enumeration<GraphObject> domRight = embRight.getDomain();
    while (domRight.hasMoreElements()) {
      final GraphObject kern = domRight.nextElement();
      multiRule.mapKernel2MultiObject(kern, embRight.getImage(kern));
    }
    //	  	final Enumeration<GraphObject> enRight = multiRule.getRight().getElements();
    //	  	while (enRight.hasMoreElements()) {
    //	  		final GraphObject obj = enRight.nextElement();
    //	  		if (embRight.getInverseImage(obj).hasMoreElements()) {
    //	  			multiRule.mapKernel2MultiObject(embRight.getInverseImage(obj).nextElement(), obj);
    //	  		}
    //	  	}
  }
コード例 #5
0
ファイル: RuleScheme.java プロジェクト: mubalu/Henshin-Editor
  private boolean nacIsUsingVariable(
      final VarMember var, final AttrConditionTuple act, final List<OrdinaryMorphism> nacs) {

    for (int l = 0; l < nacs.size(); l++) {
      final OrdinaryMorphism nac = nacs.get(l);
      if (nac.getTarget().isUsingVariable(var)) {
        return true;
      }
      Vector<String> nacVars = nac.getTarget().getVariableNamesOfAttributes();
      for (int j = 0; j < nacVars.size(); j++) {
        String varName = nacVars.get(j);
        for (int k = 0; k < act.getNumberOfEntries(); k++) {
          CondMember cond = (CondMember) act.getMemberAt(k);
          Vector<String> condVars = cond.getAllVariables();
          if (condVars.contains(varName) && condVars.contains(var.getName())) {
            return true;
          }
        }
      }
    }
    return false;
  }
コード例 #6
0
  public boolean doStep(Rule r) {
    Match match = gratra.createMatch(r);
    System.out.println("The match was: " + match.getRule().getName().toString());

    // olga
    while (match.nextCompletion()) {
      if (match.isValid()) {
        try {
          Morphism co = StaticStep.execute(match);
          System.out.println("Rule  " + match.getRule().getName() + " : step is done");
          didTransformation = true;
          Graph graph = co.getOriginal();
          Graph graph2 = co.getImage();
          System.out.println();
          //					System.out.println("The image parameters are: " + graph.toString());
          //					System.out.println("The OUTPUT parameters are: " + graph2.toString());

          // olga
          outPar = getOutputParameters(r, outPar);
          for (int i = 0; i < outPar.size(); i++) {
            VarMember p = outPar.get(i);
            String parVal = getValueOfOutputParameter(p, r, (OrdinaryMorphism) co);
            this.outParVal.put(p.getName(), parVal);
          }

          ((OrdinaryMorphism) co).dispose();
          return true;
        } catch (TypeException ex) {
          ex.printStackTrace();
          gragra.destroyMatch(match);
          System.out.println(
              "Rule  "
                  + match.getRule().getName()
                  + " : step of match failed : "
                  + ex.getMessage());
        }
      } else
        System.out.println(
            "Rule  "
                + match.getRule().getName()
                + " : a match completion is not valid; try to find the next ones");
    }
    System.out.println("Rule  " + match.getRule().getName() + " : match could not be found");
    return false;
    // gragra.destroyMatch(match);
    // match.clear();
  }
コード例 #7
0
ファイル: RuleScheme.java プロジェクト: mubalu/Henshin-Editor
  /**
   * Shift application conditions (NAC / PAC) of the kernel rule along embedding morphism of the
   * given multi rule (left embedding: kernel.LHS -> multi.LHS, right embedding: kernel.RHS ->
   * multi.RHS). Shifted application condition is added to the list of the own application
   * conditions of the multi rule.
   */
  private boolean shiftApplCondsOfKernelToMultiRule(final MultiRule multiRule) {
    // shift PACS
    List<OrdinaryMorphism> kernConds = this.kernelRule.getPACsList();
    for (int i = 0; i < kernConds.size(); i++) {
      OrdinaryMorphism kernCond = kernConds.get(i);
      if (kernCond.isEnabled()) {
        OrdinaryMorphism shiftCond =
            this.shiftApplCondAlongMorph(kernCond, multiRule.getEmbeddingLeft());
        if (shiftCond != null) {
          shiftCond.setName(kernCond.getName().concat("(shifted)"));
          shiftCond.setEnabled(kernCond.isEnabled());

          multiRule.addShiftedKernelApplCond(shiftCond, true);
          this.shiftDone = true;
        }
      }
    }
    // shift NACs
    kernConds = this.kernelRule.getNACsList();
    for (int i = 0; i < kernConds.size(); i++) {
      OrdinaryMorphism kernCond = kernConds.get(i);
      if (kernCond.isEnabled()) {
        OrdinaryMorphism shiftCond =
            this.shiftApplCondAlongMorph(kernCond, multiRule.getEmbeddingLeft());
        if (shiftCond != null) {
          shiftCond.setName(kernCond.getName().concat("(shifted)"));
          shiftCond.setEnabled(kernCond.isEnabled());

          multiRule.addShiftedKernelApplCond(shiftCond, false);
          this.shiftDone = true;
        }
      }
    }

    // shift NestedACs
    kernConds = this.kernelRule.getNestedACsList();
    for (int i = 0; i < kernConds.size(); i++) {
      if (kernConds.get(i) instanceof NestedApplCond) {
        NestedApplCond kernCond = (NestedApplCond) kernConds.get(i);
        if (kernCond.isEnabled()) {
          NestedApplCond shiftCond =
              this.shiftNestedApplCondAlongEmbMorphism(
                  kernCond,
                  multiRule.getEmbeddingLeft(),
                  this.kernelRule.getRight().getAttrContext());
          if (shiftCond != null) {
            shiftCond.setName(kernCond.getName().concat("(shifted)"));
            shiftCond.setEnabled(kernCond.isEnabled());

            multiRule.addShiftedKernelNestedApplCond(shiftCond);
            this.shiftDone = true;
          }
        }
      } else break;
    }

    addAttrCondsOfKernelToMultiRule(multiRule);

    return true;
  }
コード例 #8
0
ファイル: RuleScheme.java プロジェクト: mubalu/Henshin-Editor
  /**
   * Shift the specified application condition (NAC / PAC / General AC) along the specified
   * embedding morphism. Required:<br>
   * cond.getSource() == embedding.getSource()<br>
   * Result morphism:<br>
   * embedding.getTarget() -> copy of cond.getSource()
   *
   * @param cond an application condition
   * @param morph an embedding morphism
   * @return shifted application condition, Returns null if shifting failed.
   */
  private OrdinaryMorphism shiftApplCondAlongMorph(
      final OrdinaryMorphism cond, final OrdinaryMorphism morph) {

    if (cond.getSource() == morph.getSource()) {
      final OrdinaryMorphism condIso = cond.getTarget().isomorphicCopy();
      if (condIso == null) return null;

      final OrdinaryMorphism shiftCond =
          (cond instanceof NestedApplCond)
              ? BaseFactory.theFactory()
                  .createGeneralMorphism(morph.getTarget(), condIso.getTarget())
              : BaseFactory.theFactory().createMorphism(morph.getTarget(), condIso.getTarget());

      final Enumeration<GraphObject> condDom = cond.getDomain();
      while (condDom.hasMoreElements()) {
        GraphObject go = condDom.nextElement();
        GraphObject condImg = cond.getImage(go);
        if (condImg != null) {
          GraphObject embedImg = morph.getImage(go);
          GraphObject isoImg = condIso.getImage(condImg);
          if (embedImg != null && isoImg != null) {
            try {
              shiftCond.addMapping(embedImg, isoImg);
            } catch (BadMappingException ex) {
              shiftCond.dispose();
              condIso.dispose(false, true);
              return null;
            }
          } else {
            shiftCond.dispose();
            condIso.dispose(false, true);
            return null;
          }
        }
      }
      return shiftCond;
    }
    return null;
  }
コード例 #9
0
  /**
   * Writes the contents of this object to a file in a xml format.
   *
   * @param h A helper object for storing.
   */
  public void XwriteObject(XMLHelper h) {
    h.openNewElem("CriticalPairs", this);
    h.addObject("GraGra", getGrammar(), true);
    h.openSubTag("dependenciesContainer");

    String kind = "trigger_dependency";
    if (this.switchDependency) kind = "trigger_switch_dependency";
    h.addAttr("kind", kind);

    // Inhalt von excludeContainer schreiben (save)
    for (Enumeration<Rule> keys = this.excludeContainer.keys(); keys.hasMoreElements(); ) {
      Rule r1 = keys.nextElement();
      h.openSubTag("Rule");
      h.addObject("R1", r1, false);

      Hashtable<
              Rule,
              Pair<
                  Boolean,
                  Vector<
                      Pair<
                          Pair<OrdinaryMorphism, OrdinaryMorphism>,
                          Pair<OrdinaryMorphism, OrdinaryMorphism>>>>>
          secondPart = this.excludeContainer.get(r1);
      for (Enumeration<Rule> k2 = secondPart.keys(); k2.hasMoreElements(); ) {
        Rule r2 = k2.nextElement();
        h.openSubTag("Rule");
        h.addObject("R2", r2, false);
        Pair<
                Boolean,
                Vector<
                    Pair<
                        Pair<OrdinaryMorphism, OrdinaryMorphism>,
                        Pair<OrdinaryMorphism, OrdinaryMorphism>>>>
            p = secondPart.get(r2);
        Boolean b = p.first;
        h.addAttr("bool", b.toString());
        if (b.booleanValue()) {
          Vector<
                  Pair<
                      Pair<OrdinaryMorphism, OrdinaryMorphism>,
                      Pair<OrdinaryMorphism, OrdinaryMorphism>>>
              v = p.second;
          for (int i = 0; i < v.size(); i++) {
            Pair<Pair<OrdinaryMorphism, OrdinaryMorphism>, Pair<OrdinaryMorphism, OrdinaryMorphism>>
                p2i = v.elementAt(i);
            Pair<OrdinaryMorphism, OrdinaryMorphism> p2 = p2i.first;
            h.openSubTag("Overlapping_Pair");
            OrdinaryMorphism first = p2.first;
            Graph overlapping = first.getImage();
            /*
             * durch das true macht der String am Anfang keinen Sinn
             */
            h.addObject("", overlapping, true);

            Iterator<?> e = overlapping.getNodesSet().iterator();
            while (e.hasNext()) {
              GraphObject o = (GraphObject) e.next();
              if (o.isCritical()) {
                h.openSubTag("Critical");
                h.addObject("object", o, false);
                h.close();
              }
            }
            e = overlapping.getArcsSet().iterator();
            while (e.hasNext()) {
              GraphObject o = (GraphObject) e.next();
              if (o.isCritical()) {
                h.openSubTag("Critical");
                h.addObject("object", o, false);
                h.close();
              }
            }

            /*
             * first.writeMorphism(h);
             * ((OrdinaryMorphism)p2.second).writeMorphism(h);
             */

            writeOverlapMorphisms(h, r1, r2, p2i);

            h.close();
          }
        }
        h.close();
      }

      h.close();
    }
    h.close();
    h.openSubTag("conflictFreeContainer");
    for (Enumeration<Rule> keys = this.excludeContainer.keys(); keys.hasMoreElements(); ) {
      Rule r1 = keys.nextElement();
      h.openSubTag("Rule");
      h.addObject("R1", r1, false);

      Hashtable<
              Rule,
              Pair<
                  Boolean,
                  Vector<
                      Pair<
                          Pair<OrdinaryMorphism, OrdinaryMorphism>,
                          Pair<OrdinaryMorphism, OrdinaryMorphism>>>>>
          secondPart = this.conflictFreeContainer.get(r1);
      for (Enumeration<Rule> k2 = secondPart.keys(); k2.hasMoreElements(); ) {
        Rule r2 = k2.nextElement();
        h.openSubTag("Rule");
        h.addObject("R2", r2, false);
        Boolean b = secondPart.get(r2).first;
        h.addAttr("bool", b.toString());
        h.close();
      }

      h.close();
    }
    h.close();
    h.close();
  }