Пример #1
0
  public void buildNoMoreThanDayRule() {
    String ret = all + "*";
    for (int i = 0; i < 6; i++) ret += work;
    ret += all + "*";

    full = full.intersection(new RegExp(StringUtils.toCharExp(ret)).toAutomaton().complement());
    full.minimize();
  }
Пример #2
0
  public void buildRestAfterNight() {
    String ret = all + "*";
    ret += "1+0";
    ret += all + "*";

    full = full.intersection(new RegExp(StringUtils.toCharExp(ret)).toAutomaton().complement());
    full.minimize();
  }
  private Automaton intersect(Automaton automaton, Automaton candidateAutomaton) {
    Automaton intersectedAutomaton = automaton.intersection(candidateAutomaton);

    logger.trace(
        "Automaton states: "
            + intersectedAutomaton.getNumberOfStates()
            + "; transitions: "
            + intersectedAutomaton.getNumberOfTransitions());

    return intersectedAutomaton;
  }
  private void doubleCheckRedundancies() {
    this.secondPassStartTime = System.currentTimeMillis();

    sorter.setConstraints(this.safeProcess.getAllConstraints());
    // Let us take ALL constraints of the safe process
    ArrayList<Constraint> constraintsSortedForDoubleCheck =
        new ArrayList<Constraint>(sorter.sort(this.rankingPolicies));
    // Let us visit them in the reverse order with which they were added -- so as to be consistent
    // with the given ranking policy
    ListIterator<Constraint> iterator =
        constraintsSortedForDoubleCheck.listIterator(
            constraintsSortedForDoubleCheck.size()
                // The last one is the constraint that we checked last. In theory, it should not
                // constitute a problem
                - 2);
    Constraint candidateCon = null;
    Automaton secondPassGridCheckAutomaton = null;

    while (iterator.hasPrevious()) {
      candidateCon = iterator.previous();
      logger.trace("Second-pass grid check of constraint: " + candidateCon);

      secondPassGridCheckAutomaton =
          AutomatonFactory.buildAutomaton(
              this.safeProcess.bag,
              this.safeProcess.getTaskCharArchive().getIdentifiersAlphabet(),
              candidateCon);

      // If the safe automaton accepts
      if (secondPassGridCheckAutomaton.subsetOf(
          // ... all the constraints BUT the current one...
          //					this.safeAutomaton.minus(
          // ... accepts a subset of the languages that the current one accepts...
          //							new RegExp(candidateCon.getRegularExpression()).toAutomaton()))) {
          this.safeAutomaton)) {
        // ... then the current constraint is basically useless. Explanation is: some other
        // constraint had been added later that made an already saved constraint redundant.
        this.safeProcess.bag.remove(candidateCon);
        this.redundantConstraintsAtSecondPass.add(candidateCon);
        this.redundantConstraints.add(candidateCon);
        logger.warn(candidateCon + " is redundant (second-pass grid check)");
      }
      redundancyChecksPerformed++;
    }
  }
Пример #5
0
  public void buildNoNightBeforeFreeWE() {
    String ret = "((";
    for (int i = 0; i < 4; i++) {
      ret += all;
    }
    ret += "122";

    for (int j = 0; j < 3; j++) for (int i = 0; i < 7; i++) ret += all;
    ret += ")|(";

    for (int i = 0; i < 7; i++) ret += all;

    for (int i = 0; i < 4; i++) {
      ret += all;
    }
    ret += "122";

    for (int j = 0; j < 2; j++) for (int i = 0; i < 7; i++) ret += all;
    ret += ")|(";

    for (int j = 0; j < 2; j++) for (int i = 0; i < 7; i++) ret += all;

    for (int i = 0; i < 4; i++) {
      ret += all;
    }
    ret += "122";

    for (int i = 0; i < 7; i++) ret += all;

    ret += ")|(";

    for (int j = 0; j < 3; j++) for (int i = 0; i < 7; i++) ret += all;

    for (int i = 0; i < 4; i++) {
      ret += all;
    }
    ret += "122";
    ret += "))";

    full = full.intersection(new RegExp(StringUtils.toCharExp(ret)).toAutomaton().complement());
    full.minimize();
  }
Пример #6
0
  public void buildCompleteWE() {
    StringBuffer b = new StringBuffer("(");
    String patter = "((2(0|1))|((0|1)2))";
    int nd = 2;
    int nw = 4;
    int sd = 6;

    for (int w = 0; w < nw; w++) {
      b.append("(");
      for (int i = 1; i < sd + (7 * w); i++) b.append(all);
      b.append(patter);
      for (int i = (sd + 7 * w) + nd; i <= 28; i++) b.append(all);
      b.append(")|");
    }
    b.deleteCharAt(b.length() - 1).append(")");

    full =
        full.intersection(
            new RegExp(StringUtils.toCharExp(b.toString())).toAutomaton().complement());
    full.minimize();
  }
 private boolean checkRedundancy(
     Automaton safeAutomaton,
     ConstraintsBag safeBag,
     Automaton candidateAutomaton,
     Constraint candidateCon) {
   redundancyChecksPerformed++;
   logger.trace("Checking redundancy of " + candidateCon);
   // If candidateCon is not redundant, i.e., if the language of safeAutomaton is not a subset of
   // the language of automaton, then candidateCon can be included
   if (!safeAutomaton.subsetOf(candidateAutomaton)) {
     return true;
   } else {
     logger.warn(
         candidateCon
             + " is redundant. It is already implied"
             + (safeBag.howManyConstraints()
                     < ConflictAndRedundancyResolver
                         .MAXIMUM_VISIBLE_CONSTRAINTS_FOR_REDUNDANCY_CHECK
                 ? " by " + LinearConstraintsIndexFactory.getAllConstraints(safeBag)
                 : " by the current set of constraints."));
     this.redundantConstraints.add(candidateCon);
     return false;
   }
 }
Пример #8
0
 /**
  * Generates a random String that is guaranteed to match the regular expression passed to the
  * constructor.
  */
 public String generate() {
   StringBuilder builder = new StringBuilder();
   generate(builder, automaton.getInitialState());
   return builder.toString();
 }
 private boolean isAutomatonEmpty(Automaton automaton) {
   return automaton.isEmpty() || automaton.isEmptyString();
 }