Beispiel #1
0
  /**
   * Checks whether its kernel rule is applicable at the specified graph by the specified matching
   * strategy or not.
   */
  public boolean isApplicable(
      final Graph g,
      final MorphCompletionStrategy strategy,
      final boolean doCheckIfReadyToTransform) {

    boolean result = this.enabled;

    if (result && doCheckIfReadyToTransform) {
      result = this.isReadyToTransform();
    }

    if (result) {
      result = false;
      Match m = BaseFactory.theFactory().createMatch(this.kernelRule, g);
      if (m != null) {
        m.setCompletionStrategy(strategy, true);
        m.enableInputParameter(false);

        //				((VarTuple) this.getAttrContext().getVariables()).showVariables();
        //				((VarTuple) m.getAttrContext().getVariables()).showVariables();

        if (m.nextCompletion()) {
          result = true;
        }
        m.dispose();
      }
    }
    return result;
  }
Beispiel #2
0
  /** Create new multi rule with embedding of the kernel rule. */
  public MultiRule createMultiRule(final String ruleName) {
    OrdinaryMorphism embL = this.kernelRule.getLeft().plainCopy();
    if (embL == null) {
      embL =
          new OrdinaryMorphism(
              this.kernelRule.getLeft(),
              BaseFactory.theFactory().createGraph(this.kernelRule.getLeft().getTypeSet(), false),
              agg.attribute.impl.AttrTupleManager.getDefaultManager()
                  .newContext(AttrMapping.PLAIN_MAP));
    }
    OrdinaryMorphism embR = this.kernelRule.getRight().plainCopy();
    if (embR == null) {
      embR =
          new OrdinaryMorphism(
              this.kernelRule.getRight(),
              BaseFactory.theFactory().createGraph(this.kernelRule.getRight().getTypeSet(), false),
              agg.attribute.impl.AttrTupleManager.getDefaultManager()
                  .newContext(AttrMapping.PLAIN_MAP));
    }
    MultiRule multiRule = new MultiRule(this.kernelRule, embL, embR);
    // add only variables of LHS and RHS
    if (this.kernelRule.hasNACs() || this.kernelRule.hasPACs()) {
      final Vector<String> list = this.kernelRule.getLeft().getVariableNamesOfAttributes();
      list.addAll(this.kernelRule.getRight().getVariableNamesOfAttributes());
      multiRule.addToAttrContextAccordingList(
          (VarTuple) this.kernelRule.getAttrContext().getVariables(), list);
    } else {
      multiRule.addToAttrContext((VarTuple) this.kernelRule.getAttrContext().getVariables());
    }

    multiRule.setRuleScheme(this);
    multiRule.setName(ruleName);
    multiRule.getLeft().setKind(GraphKind.LHS);
    multiRule.getRight().setKind(GraphKind.RHS);

    this.multiRules.add(multiRule);

    this.kernelRule.getLeft().addObserver(multiRule);
    this.kernelRule.getRight().addObserver(multiRule);
    this.kernelRule.addObserver(multiRule);

    this.kernelRule.setChanged(false);

    return multiRule;
  }
Beispiel #3
0
  /**
   * 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;
  }
Beispiel #4
0
 /** Returns a copy of this rule scheme by using the specified types. */
 public RuleScheme getClone(TypeSet types) {
   return BaseFactory.theFactory().cloneRuleScheme(this, types);
 }
Beispiel #5
0
 /** Returns a copy of this rule scheme by using its types. */
 public RuleScheme getClone() {
   return BaseFactory.theFactory().cloneRuleScheme(this);
 }
Beispiel #6
0
 /**
  * Creates if needed a match of the kernel rule.
  *
  * @param graph host graph to apply the kernel rule
  * @return match of the kernel rule
  */
 public Match getKernelMatch(final Graph graph) {
   if (this.kernelRule.getMatch() == null) {
     this.kernelRule.setMatch(BaseFactory.theFactory().createMatch(this.kernelRule, graph));
   }
   return this.kernelRule.getMatch();
 }
  /**
   * Reads the contents of a xml file to restore this object.
   *
   * @param h A helper object for loading.
   */
  public void XreadObject(XMLHelper h) {
    if (h.isTag("CriticalPairs", this)) {
      // System.out.println("LayerExcludePairContainer.XreadObject ...");
      Rule r1 = null;
      Rule r2 = null;
      boolean b = false;
      Vector<
              Pair<
                  Pair<OrdinaryMorphism, OrdinaryMorphism>,
                  Pair<OrdinaryMorphism, OrdinaryMorphism>>>
          allOverlappings = null;
      Vector<String> tagnames = new Vector<String>(1);
      Vector<String> tagnames2 = new Vector<String>(1);

      this.grammar = BaseFactory.theFactory().createGraGra();
      h.getObject("", this.grammar, true);

      tagnames.add("conflictContainer");
      tagnames.add("conflictsContainer");
      tagnames.add("excludeContainer");

      tagnames2.add("dependencyContainer");
      tagnames2.add("dependenciesContainer");

      this.switchDependency = false;

      if (h.readSubTag(tagnames2)) {
        this.conflictKind = CriticalPair.TRIGGER_DEPENDENCY;
        if (h.readAttr("kind").equals("trigger_switch_dependency")) {
          this.switchDependency = true;
          this.conflictKind = CriticalPair.TRIGGER_SWITCH_DEPENDENCY;
        }
      } else if (h.readSubTag(tagnames)) {
        this.conflictKind = CriticalPair.CONFLICT;
      }

      if (this.conflictKind == CriticalPair.TRIGGER_DEPENDENCY
          || this.conflictKind == CriticalPair.TRIGGER_SWITCH_DEPENDENCY
          || this.conflictKind == CriticalPair.CONFLICT) {
        Enumeration<?> r1s = h.getEnumeration("", null, true, "Rule");
        if (!r1s.hasMoreElements()) r1s = h.getEnumeration("", null, true, "Regel");
        while (r1s.hasMoreElements()) {
          h.peekElement(r1s.nextElement());
          /*
           * da ein referenziertes object geholt werden soll. muss nur
           * angegeben werden wie der Membername heisst.
           */
          r1 = (Rule) h.getObject("R1", null, false);
          Enumeration<?> r2s = h.getEnumeration("", null, true, "Rule");
          if (!r2s.hasMoreElements()) r2s = h.getEnumeration("", null, true, "Regel");
          while (r2s.hasMoreElements()) {
            h.peekElement(r2s.nextElement());
            r2 = (Rule) h.getObject("R2", null, false);
            String bool = h.readAttr("bool");
            allOverlappings = null;
            b = false;
            if (bool.equals("true")) {
              b = true;
              allOverlappings =
                  new Vector<
                      Pair<
                          Pair<OrdinaryMorphism, OrdinaryMorphism>,
                          Pair<OrdinaryMorphism, OrdinaryMorphism>>>();
              Enumeration<?> overlappings = h.getEnumeration("", null, true, "Overlapping_Pair");
              while (overlappings.hasMoreElements()) {
                h.peekElement(overlappings.nextElement());
                Graph g = (Graph) h.getObject("", new Graph(), true);

                while (h.readSubTag("Critical")) {
                  GraphObject o = (GraphObject) h.getObject("object", null, false);
                  if (o != null) o.setCritical(true);
                  h.close();
                }
                /*
                 * OrdinaryMorphism first =
                 * BaseFactory.theFactory().createMorphism(r1.getRight(),g);
                 * first.readMorphism(h); OrdinaryMorphism
                 * second =
                 * BaseFactory.theFactory().createMorphism(r2.getLeft(),g);
                 * second.readMorphism(h);
                 * allOverlappings.addElement(new
                 * Pair(first,second));
                 */

                Pair<
                        Pair<OrdinaryMorphism, OrdinaryMorphism>,
                        Pair<OrdinaryMorphism, OrdinaryMorphism>>
                    p = readOverlappingMorphisms(h, r1, r2, g);
                allOverlappings.addElement(p);

                h.close();
              }
            }
            addQuadruple(this.excludeContainer, r1, r2, b, allOverlappings);
            h.close();
          }
          h.close();
        }
        h.close();
        // System.out.println("excludeContainer
        // "+excludeContainer+"\n");
      } /* Ende readSubTag("excludeContainer") */
      if (h.readSubTag("conflictFreeContainer")) {
        Enumeration<?> r1s = h.getEnumeration("", null, true, "Rule");
        if (!r1s.hasMoreElements()) r1s = h.getEnumeration("", null, true, "Regel");
        while (r1s.hasMoreElements()) {
          h.peekElement(r1s.nextElement());
          /*
           * da ein referenziertes object geholt werden soll. muss nur
           * angegeben werden wie der Membername heisst.
           */
          r1 = (Rule) h.getObject("R1", null, false);
          Enumeration<?> r2s = h.getEnumeration("", null, true, "Rule");
          if (!r2s.hasMoreElements()) r2s = h.getEnumeration("", null, true, "Regel");
          while (r2s.hasMoreElements()) {
            h.peekElement(r2s.nextElement());
            r2 = (Rule) h.getObject("R2", null, false);
            String bool = h.readAttr("bool");
            b = false;
            if (bool.equals("true")) b = true;
            addQuadruple(this.conflictFreeContainer, r1, r2, b, null);

            if (!r1.isEnabled()) // test disabled rule
            this.getEntry(r1, r2).state = Entry.DISABLED;
            else if (r1.getLayer() != r2.getLayer()) // test rule
              // layer
              this.getEntry(r1, r2).state = Entry.NOT_RELATED;

            h.close();
          }
          h.close();
        }
        h.close();
        // System.out.println("conflictFreeContainer
        // "+conflictFreeContainer+"\n");
      }
    }
    // isComputed = true;
    h.close();
  }