Example #1
0
  /**
   * It conducts master-slave search. Both of them use input order variable ordering.
   *
   * @param masterVars it specifies the search variables used in master search.
   * @param slaveVars it specifies the search variables used in slave search.
   * @return true if the solution exists, false otherwise.
   */
  public boolean searchMasterSlave(ArrayList<Var> masterVars, ArrayList<Var> slaveVars) {

    long T1 = System.currentTimeMillis();

    boolean result = false;

    Search<SetVar> labelSlave = new DepthFirstSearch<SetVar>();
    SelectChoicePoint<SetVar> selectSlave =
        new SimpleSelect<SetVar>(
            slaveVars.toArray(new SetVar[0]), null, new IndomainSetMin<SetVar>());
    labelSlave.setSelectChoicePoint(selectSlave);

    Search<SetVar> labelMaster = new DepthFirstSearch<SetVar>();
    SelectChoicePoint<SetVar> selectMaster =
        new SimpleSelect<SetVar>(
            masterVars.toArray(new SetVar[0]), null, new IndomainSetMin<SetVar>());

    labelMaster.addChildSearch(labelSlave);

    search = labelMaster;

    result = labelMaster.labeling(store, selectMaster);

    if (result) System.out.println("Solution found");

    if (result) store.print();

    long T2 = System.currentTimeMillis();

    System.out.println("\n\t*** Execution time = " + (T2 - T1) + " ms");

    return result;
  }
Example #2
0
  /**
   * It specifies simple search method based on input order and lexigraphical ordering of values.
   *
   * @return true if there is a solution, false otherwise.
   */
  public boolean search() {

    long T1, T2;
    T1 = System.currentTimeMillis();

    SelectChoicePoint<SetVar> select =
        new SimpleSelect<SetVar>(vars.toArray(new SetVar[1]), null, new IndomainSetMin<SetVar>());

    search = new DepthFirstSearch<SetVar>();

    boolean result = search.labeling(store, select);

    if (result) store.print();

    T2 = System.currentTimeMillis();

    System.out.println("\n\t*** Execution time = " + (T2 - T1) + " ms");

    System.out.println();
    System.out.print(search.getNodes() + "\t");
    System.out.print(search.getDecisions() + "\t");
    System.out.print(search.getWrongDecisions() + "\t");
    System.out.print(search.getBacktracks() + "\t");
    System.out.print(search.getMaximumDepth() + "\t");

    return result;
  }
Example #3
0
  /**
   * It specifies simple search method based on input order and lexigraphical ordering of values. It
   * optimizes the solution by minimizing the cost function.
   *
   * @return true if there is a solution, false otherwise.
   */
  public boolean searchOptimal() {

    long T1, T2;
    T1 = System.currentTimeMillis();

    SelectChoicePoint<SetVar> select =
        new SimpleSelect<SetVar>(vars.toArray(new SetVar[1]), null, new IndomainSetMin<SetVar>());

    search = new DepthFirstSearch<SetVar>();

    boolean result = search.labeling(store, select, cost);

    if (result) store.print();

    T2 = System.currentTimeMillis();

    System.out.println("\n\t*** Execution time = " + (T2 - T1) + " ms");

    return result;
  }