Package com.exigen.ie.constrainer

Examples of com.exigen.ie.constrainer.Constrainer


  } // end of execute

  // TEST
  static void test1(String args[]) throws Exception
  {
    Constrainer C = new Constrainer("Test");

    IntExp x = C.addIntVar(0,10,"x",IntVar.DOMAIN_DEFAULT);
    IntExp y = C.addIntVar(2,10,"y",IntVar.DOMAIN_DEFAULT);
    IntExp z = C.addIntVar(0,10,"z",IntVar.DOMAIN_DEFAULT);

    int size = 3;
    IntExpArray vars = new IntExpArray(C, size);
    vars.set(x, 0);
    vars.set(y, 1);
    vars.set(z, 2);

    Constraint constraintAllDiff2 = new ConstraintAllDiff2(vars);
    constraintAllDiff2.execute();

    //IntExp cost = C.addIntVar(0,20,"cost");
    //Constraint sum = new ConstraintAddVector(vars,cost);
    //sum.execute();
    IntExp cost = C.sum(vars); cost.name("cost");

    //x.lessOrEqual(y).execute();
    x.mul(2).sub(cost).more(y).execute();

    C.traceChoicePoints(vars);
    //C.displayOnBacktrack(vars);
    C.traceFailures(vars);

    IntValueSelector value_selector = new IntValueSelectorMin();
    IntVarSelector var_selector = new IntVarSelectorMinSize(vars);
    Goal print = new GoalAnd(new GoalPrint(vars),new GoalPrintObject(C,cost));
    Goal solution = new GoalAnd(print,
                                new GoalGenerate(vars,var_selector,value_selector),
                                print);

    //if (!C.execute(new GoalMinimize(solution,cost)))
    if (!C.execute(solution))
      System.out.println("No solutions");
    System.out.println(x + " " + y + " " + " " + z + cost);
  }
View Full Code Here


  } // end of execute

  // TEST
  static void test1(String args[]) throws Exception
  {
    Constrainer C = new Constrainer("Test");

    IntExp x = C.addIntVar(0,10,"x",IntVar.DOMAIN_DEFAULT);
    IntExp y = C.addIntVar(2,10,"y",IntVar.DOMAIN_DEFAULT);
    IntExp z = C.addIntVar(0,10,"z",IntVar.DOMAIN_DEFAULT);

    int size = 3;
    IntExpArray vars = new IntExpArray(C, size);
    vars.set(x, 0);
    vars.set(y, 1);
    vars.set(z, 2);

    Constraint constraintAllDiff2 = new ConstraintAllDiff2(vars);
    constraintAllDiff2.execute();

    //IntExp cost = C.addIntVar(0,20,"cost");
    //Constraint sum = new ConstraintAddVector(vars,cost);
    //sum.execute();
    IntExp cost = C.sum(vars); cost.name("cost");

    //x.lessOrEqual(y).execute();
    x.mul(2).sub(cost).more(y).execute();

    C.traceChoicePoints(vars);
    //C.displayOnBacktrack(vars);
    C.traceFailures(vars);

    IntValueSelector value_selector = new IntValueSelectorMin();
    IntVarSelector var_selector = new IntVarSelectorMinSize(vars);
    Goal print = new GoalAnd(new GoalPrint(vars),new GoalPrintObject(C,cost));
    Goal solution = new GoalAnd(print,
                                new GoalGenerate(vars,var_selector,value_selector),
                                print);

    //if (!C.execute(new GoalMinimize(solution,cost)))
    if (!C.execute(solution))
      System.out.println("No solutions");
    System.out.println(x + " " + y + " " + " " + z + cost);
  }
View Full Code Here

  com.exigen.ie.constrainer.Goal nativeGoal;
 
  public GoalAssignValuesNative(Solver solver, Var[] vars) {
    super(solver,"generate");
    this.vars = vars;
    Constrainer constrainer = getConstrainer();
    IntExpArray intvars = new IntExpArray(constrainer,vars.length);
    for(int i=0; i<vars.length; i++) {
      IntExp var = (IntExp)vars[i].getImpl();
      intvars.set(var, i);
    }
View Full Code Here

   *         null if there are no solutions.
   */
  public Solution findOptimalSolution(Objective objective, Var objectiveVar) {
    addObjective(objectiveVar);
    javax.constraints.impl.Problem p = (javax.constraints.impl.Problem)getProblem();
    Constrainer constrainer = p.getConstrainer();
   
    SearchStrategy searchStrategy = getSearchStrategy();
    if (isTraceSolutions()) {
      addSearchStrategy(new StrategyLogVar("Found a solution with ", objectiveVar));
    }
   
    Goal strategy = makeGoal(searchStrategy);
    com.exigen.ie.constrainer.Goal goal = (com.exigen.ie.constrainer.Goal)strategy.getImpl();
    for (int i = 1; i < getSearchStrategies().size(); i++) {
      strategy = makeGoal(getSearchStrategies().elementAt(i));
      com.exigen.ie.constrainer.Goal nextGoal = (com.exigen.ie.constrainer.Goal)strategy.getImpl();
      goal = new GoalAnd(goal,nextGoal);
    }
   
    //clearSolutions();
    com.exigen.ie.constrainer.Goal saveGoal = new GoalSaveSolution(this);
    com.exigen.ie.constrainer.Goal totalGoal = new GoalAnd(goal,saveGoal);
   
    IntExp cObj = (IntExp)objectiveVar.getImpl();
    if ( objective.equals(Objective.MAXIMIZE) ) {
      cObj = cObj.mul(-1);
    }
//    if (solver.getMaxNumberOfSolutions() > 0)
//      constrainer.set
    boolean trace = false;
    boolean goal_saves_solution = true;
    GoalFastMinimize optimizationGoal = new GoalFastMinimize(totalGoal, cObj, trace, goal_saves_solution);
    Solution solution = null;
    try {
      if (constrainer.execute(optimizationGoal)) {
//        solution = new BasicSolution(this,1);
//        solution.setSolutionNumber(optimizationGoal.numberOfSolutions());
        solution = this.getSolution();
      }
    } catch (Exception e) {
View Full Code Here

    return solution;
  }
 
  public IntExpArray createConstrainerVars(Var[] vars) {
    javax.constraints.impl.Problem p = (javax.constraints.impl.Problem)getProblem();
    Constrainer constrainer = p.getConstrainer();
    IntExpArray intvars = new IntExpArray(constrainer,vars.length);
    for(int i=0; i<vars.length; i++) {
      IntExp var = (IntExp)vars[i].getImpl();
      intvars.set(var, i);
    }
View Full Code Here

    for (int i = 0; i < vars.length; i++) {
      trace(vars[i],event);
    }
   
    Problem p = (Problem)getProblem();
    Constrainer constrainer = p.getConstrainer();
    IntExpArray intvars = new IntExpArray(constrainer,vars.length);
    for(int i=0; i<vars.length; i++) {
      IntExp var = (IntExp)vars[i].getImpl();
      intvars.set(var, i);
    }
    constrainer.trace(intvars);
  }
View Full Code Here

public class AllDifferent extends Constraint {

  public AllDifferent(Var[] vars) {
    super(vars[0].getProblem(),"AllDiff");
    Problem problem = (Problem) getProblem();
    Constrainer constrainer = problem.getConstrainer();
    IntExpArray intvars = new IntExpArray(constrainer,vars.length);
    for(int i=0; i<vars.length; i++) {
      IntExp var = (IntExp)vars[i].getImpl();
      intvars.set(var, i);
    }

    com.exigen.ie.constrainer.Constraint allDiff =
      new com.exigen.ie.constrainer.impl.ConstraintAllDiff(intvars);
    setImpl(constrainer.addConstraint(allDiff));
  }
View Full Code Here

   * Example: cardinality(vars,cardValue) < var
   */
  public Cardinality(Var[] vars, int cardValue, String oper, Var var) {
    super(vars[0].getProblem(),name);
    Problem problem = (Problem) vars[0].getProblem();
    Constrainer constrainer = problem.getConstrainer();
    IntExpArray cVars = problem.getExpArray(vars);
    try {
      IntExp cardinality = constrainer.cardinality(cVars,cardValue);
      problem.defineConstraintImpl(this, cardinality, oper, var);
    } catch (Exception f) {
      throw new RuntimeException(
          "Failure to create constraint "+name);
    }
View Full Code Here

   * Example: cardinality(vars,cardVar) < var
   */
  public Cardinality(Var[] vars, Var cardVar, String oper, Var var) {
    super(vars[0].getProblem(),name);
    Problem problem = (Problem) vars[0].getProblem();
    Constrainer constrainer = problem.getConstrainer();
    IntExpArray cVars = problem.getExpArray(vars);
    try {
      IntExp cVar = (IntExp) cardVar.getImpl();
      IntExp cardinality = constrainer.cardinality(cVars,cVar);
      problem.defineConstraintImpl(this, cardinality, oper, var);
    } catch (Exception f) {
      throw new RuntimeException(
          "Failure to create constraint "+name);
    }
View Full Code Here

   * Example: cardinality(vars,cardValue) < value
   */
  public Cardinality(Var[] vars, int cardValue, String oper, int value) {
    super(vars[0].getProblem(),name);
    Problem problem = (Problem) vars[0].getProblem();
    Constrainer constrainer = problem.getConstrainer();
    IntExpArray cVars = problem.getExpArray(vars);
    try {
      IntExp cardinality = constrainer.cardinality(cVars,cardValue);
      problem.defineConstraintImpl(this, cardinality, oper, value);
    } catch (Exception f) {
      throw new RuntimeException(
          "Failure to create constraint "+name);
    }
View Full Code Here

TOP

Related Classes of com.exigen.ie.constrainer.Constrainer

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.