예제 #1
0
 protected final int getLasVegasCoef(int i) {
   // <hca> I round it to PRECISION because of issues between versions of the jvm on mac and pc
   final double log = MathUtils.roundedLog(i * divFactor + 1, geometricalIntFactor);
   final int k = (int) Math.floor(log);
   if (log == k) {
     return MathUtils.pow(geometricalIntFactor, k - 1);
   } else {
     // recursion
     return getLasVegasCoef(i - geometricalSum(geometricalIntFactor, k));
   }
 }
예제 #2
0
 protected boolean propagateNewUpperBound(int myub) throws ContradictionException {
   Explanation expl = this.explainVariablesUB();
   boolean anyChange = false;
   int nbVars = getNbVars();
   if (myub < 0) {
     AbstractIntSConstraint.logger.finer("ub = " + myub + " < 0 => fail");
     ((ExplainedSolver) this.getProblem()).explainedFail(expl);
   }
   int i;
   for (i = 0; i < nbPosVars; i++) {
     int newInfi = MathUtils.divCeil(-(myub), coeffs[i]) + vars[i].getSup();
     if (((ExplainedIntVar) vars[i]).updateInf(newInfi, cIndices[i], expl)) {
       AbstractIntSConstraint.logger.finer(
           "INF("
               + vars[i].toString()
               + ") >= "
               + -(myub)
               + "/"
               + coeffs[i]
               + " + "
               + vars[i].getSup()
               + " = "
               + newInfi);
       anyChange = true;
     }
   }
   for (i = nbPosVars; i < nbVars; i++) {
     int newSupi = MathUtils.divFloor(myub, -(coeffs[i])) + vars[i].getInf();
     if (((ExplainedIntVar) vars[i]).updateSup(newSupi, cIndices[i], expl)) {
       AbstractIntSConstraint.logger.finer(
           "SUP("
               + vars[i].toString()
               + ") <= "
               + myub
               + "/"
               + -(coeffs[i])
               + " + "
               + vars[i].getInf()
               + " = "
               + newSupi);
       anyChange = true;
     }
   }
   return anyChange;
 }
예제 #3
0
 private static final int geometricalSum(int value, int exponent) {
   return (MathUtils.pow(value, exponent) - 1) / (value - 1);
 }