Exemplo n.º 1
0
  @Override
  public boolean satisfied() {

    return (p.singleton()
        && r.singleton()
        && r.value() - p.value() - c < FloatDomain.epsilon(r.value() - p.value() - c));
  }
Exemplo n.º 2
0
  @Override
  public void notConsistency(Store store) {

    do {

      store.propagationHasOccurred = false;

      if (r.singleton()) p.domain.inComplement(store.level, p, r.min() - c);

      if (p.singleton()) r.domain.inComplement(store.level, r, p.min() + c);

    } while (store.propagationHasOccurred);
  }
Exemplo n.º 3
0
 @Override
 public boolean satisfied() {
   return x.singleton() && p.singleton() && x.min() <= p.max() && x.max() >= p.min();
 }
  double value(FloatVar f) {

    if (map.get(f) != null) return map.get(f);
    // else if (f.singleton())
    //     return f.value();

    Constraint c = constraint(f);
    if (c != null) eval.push(c);
    else if (f.singleton()) return f.value();

    // if (debug)
    //      System.out.println ("current constraint for variable " + f + " is " + c);

    double result = 0.0;

    if (c instanceof PmulQeqR) {
      if (f.equals(((PmulQeqR) c).r)) {
        result = value(((PmulQeqR) c).p) * value(((PmulQeqR) c).q);
      } else {
        System.out.println(
            "!!! Anable to compute middle value for "
                + f
                + "; + Constraint "
                + c
                + " does not define a function for variable\n");
        System.exit(0);
      }
    } else if (c instanceof PmulCeqR) {
      if (f.equals(((PmulCeqR) c).r)) result = value(((PmulCeqR) c).p) * ((PmulCeqR) c).c;
      else {
        System.out.println(
            "!!! Anable to compute middle value for "
                + f
                + "; + Constraint "
                + c
                + " does not define a function for variable\n");
        System.exit(0);
      }
    } else if (c instanceof PdivQeqR) {
      if (f.equals(((PdivQeqR) c).r)) {
        result = value(((PdivQeqR) c).p) / value(((PdivQeqR) c).q);
      } else {
        System.out.println(
            "!!! Anable to compute middle value for "
                + f
                + "; + Constraint "
                + c
                + " does not define a function for variable\n");
        System.exit(0);
      }
    } else if (c instanceof PplusQeqR) {
      if (f.equals(((PplusQeqR) c).r)) result = value(((PplusQeqR) c).p) + value(((PplusQeqR) c).q);
      else {
        System.out.println(
            "!!! Anable to compute middle value for "
                + f
                + "; + Constraint "
                + c
                + " does not define a function for variable\n");
        System.exit(0);
      }
    } else if (c instanceof PplusCeqR) {
      if (f.equals(((PplusCeqR) c).r)) result = value(((PplusCeqR) c).p) + ((PplusCeqR) c).c;
      else {
        System.out.println(
            "!!! Anable to compute middle value for "
                + f
                + "; + Constraint "
                + c
                + " does not define a function for variable\n");
        System.exit(0);
      }
    } else if (c instanceof PminusQeqR) {
      if (f.equals(((PminusQeqR) c).r))
        result = value(((PminusQeqR) c).p) - value(((PminusQeqR) c).q);
      else {
        System.out.println(
            "!!! Anable to compute middle value for "
                + f
                + "; + Constraint "
                + c
                + " does not define a function for variable\n");
        System.exit(0);
      }
    } else if (c instanceof LinearFloat) {

      FloatVar[] v = ((LinearFloat) c).list;
      double[] w = ((LinearFloat) c).weights;
      double sum = ((LinearFloat) c).sum;

      FloatVar vOut = null;
      double wOut = 1000.0;

      for (int i = 0; i < v.length; i++) {
        if (!v[i].equals(f)) sum -= value(v[i]) * w[i];
        else {
          vOut = v[i];
          wOut = w[i];
        }
      }

      if (vOut != null) result = sum / wOut;
      else {
        System.out.println(
            "!!! Anable to compute middle value for "
                + f
                + "; + Constraint "
                + c
                + " does not define a function for variable\n");
        System.exit(0);
      }
    } else {
      System.out.println("!!! Constraint " + c + " is not yet supported in Newtoen method\n");
      System.exit(0);
    }

    eval.pop();

    // if (debug)
    //     System.out.println ("returns " + result);

    return result;
  }