Examples of Solver


Examples of solver.Solver

    IntVar total_cost;
    RealVar average;

  @Override
    public void createSolver() {
        solver = new Solver("Santa Claude");
    }
View Full Code Here

Examples of solver.Solver

        new SetUnion().execute(args);
    }

    @Override
    public void createSolver() {
        solver = new Solver("set union sample");
    }
View Full Code Here

Examples of solver.Solver

        new Partition().execute(args);
    }

    @Override
    public void createSolver() {
    solver = new Solver("set union sample");
    }
View Full Code Here

Examples of solver.Solver

    IntVar[] itemCost;
    RealVar[] realitemCost;

    @Override
    public void createSolver() {
        solver = new Solver("Grocery");
    }
View Full Code Here

Examples of solver.Solver


  public static void main(String[] args){

    // solver
    Solver solver = new Solver("Santa Claus");

    // input data
    final int n_kids = 3;
    final int n_gifts = 5;
    final int[] gift_price = new int[]{11,24,5,23,16};
    final int min_price = 5;
    final int max_price = 24;

    // FD variables
    final IntVar[] kid_gift = VariableFactory.enumeratedArray("g2k", n_kids, 0, n_gifts, solver);
    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);
    // free IBEX structures from memory
    solver.getIbex().release();
    }
View Full Code Here

Examples of solver.Solver

    int n = 4;
    IntVar[] vars;

    @Override
    public void createSolver() {
        solver = new Solver("NQueen");
    }
View Full Code Here

Examples of solver.Solver

        LoggerFactory.getLogger("bench").info(st.toString());
    }

    @Override
    public void createSolver() {
        solver = new Solver("CycloHexan");
    }
View Full Code Here

Examples of solver.Solver

        this.horizon = n - 1;
    }

    @Override
    public void createSolver() {
        solver = new Solver("Pert");
    }
View Full Code Here

Examples of solver.Solver

    LoggerFactory.getLogger("bench").info(st.toString());
  }

  @Override
  public void createSolver() {
    solver = new Solver("HybridCycloHexan");
  }
View Full Code Here

Examples of solver.Solver

    Constraint[] heavy = new Constraint[3];

    @Override
    public void createSolver() {
        solver = new Solver("Partition " + N);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.