Beispiel #1
0
 public MultiRule getMultiRule(final Graph g) {
   for (int i = 0; i < this.multiRules.size(); i++) {
     final Rule multiRule = this.multiRules.get(i);
     if (multiRule.getLeft() == g || multiRule.getRight() == g) return (MultiRule) multiRule;
   }
   return null;
 }
Beispiel #2
0
  public boolean isInputParameterSet(boolean left) {
    Rule r = this.kernelRule;
    this.addToAttrContext((VarTuple) r.getAttrContext().getVariables());

    if (r.getMatch() != null) {
      this.adaptAttrContextValues(r.getMatch().getAttrContext());
    } else {
      this.adaptAttrContextValues(r.getAttrContext());
    }

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

    for (int i = 0; i < this.multiRules.size(); i++) {
      r = this.multiRules.get(i);
      if (r.isEnabled()) {
        this.addToAttrContext((VarTuple) r.getAttrContext().getVariables());
        if (r.getMatch() != null) {
          this.adaptAttrContextValues(r.getMatch().getAttrContext());
        }
      }
    }
    //		((VarTuple) this.getAttrContext().getVariables()).showVariables();

    return isInputParameterSet(this.getAttrContext(), left);
  }
Beispiel #3
0
 /**
  * Propagate application conditions (NAC / PAC) of the kernel rule along embedding morphism of
  * each multi rule (left embedding: kernel.LHS -> multi.LHS, right embedding: kernel.RHS ->
  * multi.RHS). Propagated application conditions are added to the list of the own application
  * conditions of each multi rule.
  */
 public void propagateApplCondsOfKernelToMultiRules() {
   if (!this.shiftDone) {
     for (int j = 0; j < this.multiRules.size(); j++) {
       Rule mRule = this.multiRules.get(j);
       if (mRule.isEnabled()) {
         shiftApplCondsOfKernelToMultiRule((MultiRule) mRule);
       }
     }
     this.shiftDone = true;
   }
 }
Beispiel #4
0
  public boolean isElement(Graph g) {
    if (this.kernelRule.isElement(g)) {
      return true;
    }
    for (int i = 0; i < this.multiRules.size(); i++) {
      Rule r = this.multiRules.get(i);
      if (r.isElement(g)) return true;
    }

    return false;
  }
 void setInputParameter(Rule r) {
   VarTuple vars = (VarTuple) r.getAttrContext().getVariables();
   for (int i = 0; i < vars.getNumberOfEntries(); i++) {
     VarMember var = (VarMember) vars.getMemberAt(i);
     if (var.isInputParameter())
       System.out.println(var.getName() + "  is already input parameter of rule: " + r.getName());
     else {
       // this var should be an input parameter
       var.setInputParameter(true);
       System.out.println(var.getName() + "  is now input parameter of rule: " + r.getName());
     }
   }
 }
 // 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;
 }
  void setPars(Rule r) throws IOException {
    System.out.println("\n TAKING INPUTS to APPLY Rule: " + r.getName() + "\n");
    List<String> list = r.getInputParameterNames();
    System.out.println("The parameters for " + r.getName() + " are: " + list);
    //		System.out.println("The parameters values for " + r.getName() + " are: " +
    // r.getInputParameters());
    System.out.println("The parameters values:");
    for (int i = 0; i < list.size(); i++) {
      String pname = list.get(i);
      VarMember var = (VarMember) ((VarTuple) r.getAttrContext().getVariables()).getMemberAt(pname);
      if (var.isSet()) System.out.println(pname + " is set to value: " + var.getExprAsText());
      else System.out.println(pname + " is not set");
    }

    VarTuple vars = (VarTuple) r.getAttrContext().getVariables();

    for (int i = 0; i < vars.getNumberOfEntries(); i++) {
      VarMember var = (VarMember) vars.getMemberAt(i);
      if (var.isInputParameter()) {
        // olga:
        if (!var.isSet()) {
          System.out.println(
              var.getName() + "  is already input parameter of rule: " + r.getName());

          System.out.println(
              "\n \n Please Enter the value for input parameter for rule -- "
                  + r.getName()
                  + " --, parameter name -- "
                  + var.getName()
                  + " --: ");
          Scanner scan = new Scanner(System.in);
          String value = scan.nextLine();
          System.out.println("The given input was: " + value);
          var.setInputParameter(true);
          var.setExprAsText(value);
          // in1.close();
          System.out.println(var.getName() + "  is now input parameter of rule: " + r.getName());
        } else {
          System.out.println(
              var.getExprAsText()
                  + " is value of the INPUT parameter: "
                  + var.getName()
                  + "  of rule: "
                  + r.getName());
        }
      }
    }
    // in.close();
  }
Beispiel #8
0
 private void removeAttrCondsOfKernelFromMultiRule(final Rule multiRule) {
   CondTuple conds = (CondTuple) multiRule.getAttrContext().getConditions();
   for (int i = 0; i < conds.getNumberOfEntries(); i++) {
     CondMember cond = conds.getCondMemberAt(i);
     if (cond.isShifted()) {
       conds.getTupleType().deleteMemberAt(i);
       i--;
     }
   }
 }
  // olga
  List<VarMember> getOutputParameters(Rule r, List<VarMember> list) {
    if (list == null) list = new Vector<VarMember>();
    else list.clear();

    VarTuple vars = (VarTuple) r.getAttrContext().getVariables();
    for (int i = 0; i < vars.getNumberOfEntries(); i++) {
      VarMember var = (VarMember) vars.getMemberAt(i);
      if (var.isOutputParameter()) {
        System.out.println(var.getName() + "  is OUTPUT parameter of rule: " + r.getName());
        list.add(var);
      }
      //			else {
      // if this var should be an output parameter
      //				var.setOutputParameter(true);
      //				System.out.println(var.getName()+"  is now OUTPUT parameter of rule: "+r.getName());
      //			}
    }
    return list;
  }
Beispiel #10
0
 private void addAttrCondsOfKernelToMultiRule(final Rule multiRule) {
   CondTuple kernConds = (CondTuple) this.kernelRule.getAttrContext().getConditions();
   CondTuple multiConds = (CondTuple) multiRule.getAttrContext().getConditions();
   for (int i = 0; i < kernConds.getNumberOfEntries(); i++) {
     String kernCond = kernConds.getCondMemberAt(i).getExprAsText();
     if (!multiConds.contains(kernCond)) {
       CondMember cm = (CondMember) multiConds.addCondition(0, kernCond);
       cm.setShifted(true);
     }
   }
 }
 // olga: propagate value of OUTPUT parameters of rule r1 to INPUT parameters of rule r2
 void propagateOutParamToInParamOfRule(Hashtable<String, String> outPars, Rule r) {
   if (outPars != null && !outPars.isEmpty()) {
     VarTuple vars = (VarTuple) r.getAttrContext().getVariables();
     for (int i = 0; i < vars.getNumberOfEntries(); i++) {
       VarMember var = vars.getVarMemberAt(i);
       String outVal = outPars.get(var.getName());
       if (outVal != null && var.isInputParameter()) {
         var.setExprAsText(outVal);
       }
     }
   }
 }
Beispiel #12
0
  /**
   * Create new rule scheme with the given kernel rule. The typeSet of this RuleScheme is the
   * TypeSet of the KernelRule.
   */
  public RuleScheme(final String aSchemeName, KernelRule kernel) {
    super(kernel.getTypeSet());
    super.trimToSize();

    this.itsName = aSchemeName;
    this.schemeName = aSchemeName;

    this.kernelRule = kernel;
    this.kernelRule.setRuleScheme(this);

    //		this.kernelRule.getLeft().addObserver(this);
    //		this.kernelRule.getRight().addObserver(this);
  }
Beispiel #13
0
  /**
   * Create new rule scheme with an empty kernel rule and empty set of multi rules.
   *
   * @param aSchemeName
   * @param types
   */
  public RuleScheme(final String aSchemeName, TypeSet types) {
    super(types);
    super.trimToSize();

    this.itsName = aSchemeName;
    this.schemeName = aSchemeName;

    this.kernelRule = new KernelRule(types);
    this.kernelRule.setRuleScheme(this);

    //		this.kernelRule.getLeft().addObserver(this);
    //		this.kernelRule.getRight().addObserver(this);
  }
Beispiel #14
0
  public void dispose() {
    super.dispose();

    this.clearMatches();

    if (this.amalgamRule != null) {
      this.amalgamRule.dispose();
      this.amalgamRule = null;
    }

    for (int i = 0; i < this.multiRules.size(); i++) {
      this.multiRules.get(i).dispose();
    }
    this.multiRules.clear();

    this.kernelRule.dispose();
  }
  /**
   * Computes if the first rule exclude the second rule. The result is added to the container.
   *
   * @param r1 The first rule.
   * @param r2 The second rule.
   */
  protected synchronized void computeCritical(Rule r1, Rule r2) {
    Report.trace("LayeredDependencyPairContainer: starte computeCritical", 2);
    // System.out.println("LayeredDependencyPairContainer.computeCritical(r1,
    // r2): "+r1.getName()+" "+r2.getName()+" "+this.getEntry(r1,
    // r2).state);
    // mark Entry
    if (!r1.isEnabled() || !r2.isEnabled()) { // test disabled rule
      this.getEntry(r1, r2).state = Entry.DISABLED;
      addEntry(r1, r2, false, null);
      addQuadruple(this.excludeContainer, r1, r2, false, null);
      addQuadruple(this.conflictFreeContainer, r1, r2, false, null);
      firePairEvent(
          new CriticalPairEvent(
              this,
              r1,
              r2,
              "<" + r1.getName() + ">  and  <" + r2.getName() + ">  should not be computed."));
      return;
    }

    if (r1.getLayer() != r2.getLayer()) { // test rule layer
      this.getEntry(r1, r2).state = Entry.NOT_RELATED;
      addEntry(r1, r2, false, null);
      addQuadruple(this.excludeContainer, r1, r2, false, null);
      addQuadruple(this.conflictFreeContainer, r1, r2, false, null);
      firePairEvent(new CriticalPairEvent(this, r1, r2, ""));
      return;
    }

    if ((this.layer > -1) && (r1.getLayer() != this.layer)) {
      return;
    }

    if ((this.getEntry(r1, r2).state == Entry.SCHEDULED_FOR_COMPUTING)
        || (this.getEntry(r1, r2).state == Entry.NOT_SET)) {
      getEntry(r1, r2).setState(Entry.COMPUTING_IS_RUNNING);

      firePairEvent(
          new CriticalPairEvent(
              this,
              r1,
              r2,
              "Computing critical rule pair  [  " + r1.getName() + "  ,  " + r2.getName() + "  ]"));

      if (!this.complete) {
        this.layeredPair = null;

        this.layeredSimplePair = new LayeredSimpleDependencyPair();
        this.excludePair = this.layeredSimplePair;
      } else {
        this.layeredSimplePair = null;

        this.layeredPair = new LayeredDependencyPair();
        this.excludePair = this.layeredPair;
      }

      setOptionsOfExcludePair();

      Vector<
              Pair<
                  Pair<OrdinaryMorphism, OrdinaryMorphism>,
                  Pair<OrdinaryMorphism, OrdinaryMorphism>>>
          overlapping = null;

      try {
        if (this.layeredPair != null) {
          overlapping = this.layeredPair.isCritical(CriticalPair.EXCLUDE, r1, r2);
        } else if (this.layeredSimplePair != null) {
          overlapping = this.layeredSimplePair.isCritical(CriticalPair.EXCLUDE, r1, r2);
        }
      } catch (InvalidAlgorithmException iae) {
        System.out.println(iae.getLocalizedMessage());
      }

      if (this.excludePair != null) this.excludePair.dispose();
      this.excludePair = null;
      this.layeredPair = null;
      this.layeredSimplePair = null;
      //			System.gc();

      boolean critic = (overlapping != null);

      // new container
      addEntry(r1, r2, critic, overlapping);

      /*
       * Wenn overlapping Elemente enthaelt sind r1/r2 kritisch critic
       * wird daher true. Alle wichtigen Informationen werden eingetragen.
       * Enthaelt r1/r2 keine Elementen, so wird critic auf false gesetzt.
       * Wenn excludeContainer nach r1/r2 gefragt wird, liefert die
       * Antwort auch false. overlapping kann daher null sein.
       */

      /*
       * Achtung, wenn r1 r2 nicht kritisch ist gibt es keine
       * Ueberlappungen
       */
      addQuadruple(this.excludeContainer, r1, r2, critic, overlapping);

      /*
       * conflictfree braucht keine ueberlappungsgraphen daher ist das
       * letzte Argument null
       */
      addQuadruple(this.conflictFreeContainer, r1, r2, !critic, null);

      if (overlapping != null)
        firePairEvent(
            new CriticalPairEvent(
                this,
                r1,
                r2,
                "<" + r1.getName() + ">  and  <" + r2.getName() + ">  have critical pairs"));
      else
        firePairEvent(
            new CriticalPairEvent(
                this,
                r1,
                r2,
                "<" + r1.getName() + ">  and  <" + r2.getName() + ">  have no critical pairs"));
    }
    Report.trace("LayeredDependencyPairContainer: beende computeCritical", -2);
  }
  /**
   * 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();
  }