All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.exigen.ie.constrainer.GoalAllSolutions Maven / Gradle / Ivy

package com.exigen.ie.constrainer;
///////////////////////////////////////////////////////////////////////////////
/*
 * Copyright Exigen Group 1998, 1999, 2000
 * 320 Amboy Ave., Metuchen, NJ, 08840, USA, www.exigengroup.com
 *
 * The copyright to the computer program(s) herein
 * is the property of Exigen Group, USA. All rights reserved.
 * The program(s) may be used and/or copied only with
 * the written permission of Exigen Group
 * or in accordance with the terms and conditions
 * stipulated in the agreement/contract under which
 * the program(s) have been supplied.
 */
///////////////////////////////////////////////////////////////////////////////

/**
 * An implementation of a {@link Goal} that finds all solutions using the same search goal.
 * This goal executes the "goal"-parameter to find a solution. If a solution is found,
 * the GoalAllSolutions fails (to mark the found solution as "already tried"), and
 * executes the "goal"-parameter again until the are no pther solutions. It is the
 * responsibility of the "goal"-parameter to save each found solution (if necessary).
 * Example of use:
 * 
 *
 *  Constrainer C = new Constrainer("Constrainer Test");
 *  IntVar x = C.addIntVar(0,10,"x");
 *  IntVar y = C.addIntVar(0,10,"y");
 *  IntVar z = C.addIntVar(0,1000,"z");
 *  x.more(3).post();
 *  x.less(y).post();
 *  z.equals(C.sum(x,y)).post();
 *  IntExpArray vars = new IntExpArray(C, x,y,z);
 *  Goal solution = new GoalAnd(new GoalGenerate(vars),
 *                              new GoalPrintSolutionNumber(C),
 *                              new GoalPrint(vars));
 *  Goal all_solutions = new GoalAllSolutions(solution);
 *  C.execute(all_solutions);
 * 
*/ public class GoalAllSolutions extends GoalImpl { private Goal _search_goal; private Goal _fail_goal; private Goal _execution_goal; /** * Constructor with a given search goal. */ public GoalAllSolutions(Goal search_goal) { super(search_goal.constrainer(), "GenerateAllSolutions"); _search_goal = search_goal; _fail_goal = new GoalFail(constrainer()); _execution_goal = new GoalAnd(_search_goal,_fail_goal); } /** * Executes the goal-parameter and * @return GoalAnd(search_goal,fail_goal). */ public Goal execute() throws Failure { //Goal goal = new GoalAnd(_search_goal,_fail_goal); //return new GoalAnd(goal,this); return _execution_goal; } /** * @return a String representation of this goal. */ public String toString() { return "AllSolutions using "+_search_goal; } } // ~GoalAllSolutions




© 2015 - 2024 Weber Informatics LLC | Privacy Policy