示例#1
0
文件: XeqP.java 项目: mnmlist/jacop
  @Override
  public void consistency(Store store) {

    do {

      // domain consistency
      int xMin;
      if (Math.abs(p.min()) < (double) IntDomain.MaxInt)
        xMin = (int) (Math.round(Math.ceil(p.min())));
      else xMin = IntDomain.MinInt;

      int xMax;
      if (Math.abs(p.max()) < (double) IntDomain.MaxInt)
        xMax = (int) (Math.round(Math.floor(p.max())));
      else xMax = IntDomain.MaxInt;

      if (xMin > xMax) {
        int t = xMax;
        xMax = xMin;
        xMin = t;
      }

      x.domain.in(store.level, x, xMin, xMax);

      store.propagationHasOccurred = false;

      p.domain.in(store.level, p, x.min(), x.max());

    } while (store.propagationHasOccurred);
  }
  Constraint constraint(FloatVar v) {

    ArrayList<Constraint> list = new ArrayList<Constraint>();

    for (int i = 0; i < v.dom().modelConstraints.length; i++)
      if (v.dom().modelConstraints[i] != null)
        for (int j = 0; j < v.dom().modelConstraints[i].length; j++) {
          if (v.dom().modelConstraints[i][j] != null) {

            Constraint c = v.dom().modelConstraints[i][j];

            if (eval.search(c) == -1) {
              if (Derivative.derivateConstraints.contains(c)) continue;

              if (!list.contains(c)) list.add(c);
            }
          }
        }

    // if (debug)
    //     System.out.println ("Possible constraints for variable " + v + " are " + list);

    Constraint c;
    if (list.size() == 1) c = list.get(0);
    else c = Derivative.resolveConstraint(v, list);

    return c;
  }
示例#3
0
  @Override
  public void impose(Store store) {

    p.putModelConstraint(this, getConsistencyPruningEvent(p));
    r.putModelConstraint(this, getConsistencyPruningEvent(r));
    store.addChanged(this);
    store.countConstraint();
  }
示例#4
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);
  }
示例#5
0
  @Override
  public void consistency(Store store) {

    do {
      store.propagationHasOccurred = false;

      FloatIntervalDomain pDom = FloatDomain.subBounds(r.min(), r.max(), c, c);
      p.domain.in(store.level, p, pDom.min(), pDom.max());

      FloatIntervalDomain rDom = FloatDomain.addBounds(p.min(), p.max(), c, c);
      r.domain.in(store.level, r, rDom.min(), rDom.max());

    } while (store.propagationHasOccurred);
  }
示例#6
0
  public FloatVar derivative(Store store, FloatVar f, java.util.Set<FloatVar> vars, FloatVar x) {
    if (f.equals(r)) {
      // f = p + c
      // f' = d(p)
      FloatVar v = Derivative.getDerivative(store, p, vars, x);
      return v;

    } else if (f.equals(p)) {
      // f = r - c
      // f' = d(r)
      FloatVar v = Derivative.getDerivative(store, r, vars, x);
      return v;
    }

    return null;
  }
示例#7
0
  @Override
  public boolean satisfied() {

    return (p.singleton()
        && r.singleton()
        && r.value() - p.value() - c < FloatDomain.epsilon(r.value() - p.value() - c));
  }
示例#8
0
文件: XeqP.java 项目: mnmlist/jacop
 @Override
 public boolean satisfied() {
   return x.singleton() && p.singleton() && x.min() <= p.max() && x.max() >= p.min();
 }
示例#9
0
文件: XeqP.java 项目: mnmlist/jacop
 @Override
 public void removeConstraint() {
   x.removeConstraint(this);
   p.removeConstraint(this);
 }
示例#10
0
 @Override
 public boolean notSatisfied() {
   FloatDomain pDom = p.dom(), rDom = r.dom();
   return (pDom.max() + c < rDom.min() || pDom.min() + c > rDom.max());
 }
  boolean contains(FloatVar[] fs, FloatVar r) {

    for (FloatVar f : fs) if (f.equals(r)) return true;

    return false;
  }
  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;
  }