Package solver.variables

Examples of solver.variables.RealVar


    final IntVar[] kid_price = VariableFactory.boundedArray("p2k", n_kids, min_price, max_price, solver);
    final IntVar total_cost = VariableFactory.bounded("total cost", min_price*n_kids, max_price * n_kids, solver);

    // CD variable
    double precision = 1.e-4;
    final RealVar average = VariableFactory.real("average", min_price, max_price, precision, solver);
    final RealVar average_deviation = VariableFactory.real("average_deviation", 0, max_price, precision, solver);

    // continuous views of FD variables
    RealVar[] realViews = VariableFactory.real(kid_price, precision);

    // kids must have different gifts
        solver.post(IntConstraintFactory.alldifferent(kid_gift, "AC"));
    // associate each kid with his gift cost
        for (int i = 0; i < n_kids; i++) {
            solver.post(IntConstraintFactory.element(kid_price[i], gift_price, kid_gift[i]));
        }
    // compute total cost
        solver.post(IntConstraintFactory.sum(kid_price, total_cost));

    // compute average cost (i.e. average gift cost per kid)
    RealVar[] allRV = ArrayUtils.append(realViews,new RealVar[]{average,average_deviation});
    solver.post(new RealConstraint(
        "Avg/AvgDev",
        "({0}+{1}+{2})/3={3};(abs({0}-{3})+abs({1}-{3})+abs({2}-{3}))/3={4}",
        allRV)
    );

    // set search strategy (ABS)
    solver.set(IntStrategyFactory.minDom_LB(kid_gift));
    // displays resolution statistics
    SearchMonitorFactory.log(solver,true,false);
    // print each solution
        solver.plugMonitor(new IMonitorSolution() {
            @Override
            public void onSolution() {
                if (LoggerFactory.getLogger("solver").isInfoEnabled()) {
                    LoggerFactory.getLogger("solver").info("*******************");
                    for (int i = 0; i < n_kids; i++) {
                        LoggerFactory.getLogger("solver").info("Kids #{} has received the gift #{} at a cost of {} euros",
                                new Object[]{i, kid_gift[i].getValue(), kid_price[i].getValue()});
                    }
                    LoggerFactory.getLogger("solver").info("Total cost: {} euros", total_cost.getValue());
          LoggerFactory.getLogger("solver").info("Average: {} euros per kid", average.getLB());
          LoggerFactory.getLogger("solver").info("Average deviation: {} ", average_deviation.getLB());
                }
            }
        });
    // find optimal solution (Santa Claus is stingy)
    solver.findOptimalSolution(ResolutionPolicy.MINIMIZE,average_deviation, precision);
View Full Code Here


      } else {
        double offset = 0;
        if (objective.getSolver().getMeasures().getSolutionCount() > 0 && strict) {
          offset = precision;
        }
        RealVar io = (RealVar) objective;
        if (policy == ResolutionPolicy.MINIMIZE) {
          io.updateUpperBound(bestProvedUB.doubleValue() - offset, this);
          io.updateLowerBound(bestProvedLB.doubleValue(), this);
        } else {
          io.updateUpperBound(bestProvedUB.doubleValue(), this);
          io.updateLowerBound(bestProvedLB.doubleValue() + offset, this);
        }
      }
    }
  }
View Full Code Here

    }

    @SuppressWarnings({"unchecked"})
    @Override
    public Decision getDecision() {
        RealVar variable = varselector.getVariable(vars);
        return computeDecision(variable);
    }
View Full Code Here

                case Variable.BOOL:
                    IntVar v = (IntVar) vars[i];
                    intmap.put(v, v.getValue());
                    break;
                case Variable.REAL:
                    RealVar r = (RealVar) vars[i];
                    realmap.put(r, new double[]{r.getLB(), r.getUB()});
                    break;
                case Variable.SET:
                    SetVar s = (SetVar) vars[i];
                    setmap.put(s, s.getValues());
                    break;
View Full Code Here

      @Override
      public void propagate(int evtmask) throws ContradictionException {
        assert n==realVars.length;
        for(int i=0;i<n;i++) {
          IntVar intVar = intVars[i];
          RealVar realVar = realVars[i];
          realVar.updateBounds((double) intVar.getLB() - epsilon, (double) intVar.getUB() + epsilon, aCause);
          intVar.updateLowerBound((int) Math.ceil(realVar.getLB() - epsilon), aCause);
          intVar.updateUpperBound((int) Math.floor(realVar.getUB() + epsilon), aCause);
          if (intVar.hasEnumeratedDomain()) {
            realVar.updateBounds((double) intVar.getLB() - epsilon, (double) intVar.getUB() + epsilon, aCause);
          }
        }
      }
      @Override
      public ESat isEntailed() {
        assert intVars.length==realVars.length;
        boolean allInst = true;
        for(int i=0;i<n;i++) {
          IntVar intVar = intVars[i];
          RealVar realVar = realVars[i];
          if ((realVar.getLB() < (double) intVar.getLB() - epsilon) || (realVar.getUB() > (double) intVar.getUB() + epsilon)) {
            return ESat.FALSE;
          }
          if (!(intVar.isInstantiated() && realVar.isInstantiated())) {
            allInst = false;
          }
        }
        return allInst?ESat.TRUE:ESat.UNDEFINED;
      }
View Full Code Here

    @Test(groups = "1s")
    public void testreal() {
        Solver solver = new Solver();
        double PREC = 0.01d; // precision
        RealVar x = VariableFactory.real("x", -1.0d, 1.0d, PREC, solver);
        RealVar y = VariableFactory.real("y", -1.0d, 1.0d, PREC, solver);
        RealConstraint rc = new RealConstraint(
                "my fct",
                "({0}*{1})+sin({0})=1.0;ln({0}+[-0.1,0.1])>=2.6",
                Ibex.HC4,
                x, y);
View Full Code Here

TOP

Related Classes of solver.variables.RealVar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.