|
Cream version 1.06 Core API Specification |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjp.ac.kobe_u.cs.cream.Solver
public abstract class Solver
An abstract class for constraint solvers. A solver is constructed with a constraint network which is used by the solver to find solutions. Please note that any network can not be simultaneously shared by two different solvers.
Solvers can be used in three typical ways.
findFirst()
, findBest()
, etc.
Solution solution = solver.findFirst();
findAll(SolutionHandler handler)
, etc.
solver.findAll(new SolutionHandler() { public synchronized void solved(Solver solver, Solution solution) { ..... } });
start()
, waitNext()
,
resume()
, stop()
, etc.
for (solver.start(); solver.waitNext(); solver.resume()) { Solution solution = solver.getSolution(); ..... } solver.stop();
Network
,
Solution
,
SolutionHandler
Field Summary | |
---|---|
static int |
BETTER
An option value specifying to return only better solutions |
static int |
DEFAULT
A constant value for the default option |
static int |
MAXIMIZE
An option value specifying to maximize the objective variable |
static int |
MINIMIZE
An option value specifying to minimize the objective variable |
static int |
NONE
A constant value for no options |
Constructor Summary | |
---|---|
Solver(Network network)
Constructs a solver for the given network (for invocation by subclass constructors). |
|
Solver(Network network,
int option)
Constructs a solver for the given network and option (for invocation by subclass constructors). |
|
Solver(Network network,
int option,
String name)
Constructs a solver for the given network, option, and name (for invocation by subclass constructors). |
|
Solver(Network network,
String name)
Constructs a solver for the given network and name (for invocation by subclass constructors). |
Method Summary | |
---|---|
void |
clearBest()
Clears the best solution this solver has been found. |
void |
findAll(SolutionHandler handler)
Invokes the handler for each solution. |
void |
findAll(SolutionHandler handler,
long timeout)
Invokes the handler for each solution with the timeout. |
Solution |
findBest()
Finds the best solution. |
Solution |
findBest(long timeout)
Finds the best solution with the timeout. |
Solution |
findFirst()
Finds the first solution. |
Solution |
findFirst(long timeout)
Finds the first solution with the timeout. |
Solution |
getBestSolution()
Returns the best solution this solver has been found. |
int |
getBestValue()
Returns the best objective value this solver has been found. |
long |
getCount()
Returns the number of solutions. |
long |
getElapsedTime()
Returns the elapsed time in milli seconds. |
int |
getID()
Returns the ID number of this solver. |
Monitor |
getMonitor()
Gets the monitor. |
int |
getOption()
Returns the option value. |
Solution |
getSolution()
Returns the last solution this solver is found. |
boolean |
isAborted()
Returns true if the solver is stopped |
void |
join()
Waits until the solver ends the execution. |
static void |
resetIDCounter()
Resets the ID counter to be 0. |
void |
resume()
Resumes the execution of the solver. |
abstract void |
run()
The body of the solver. |
void |
setMonitor(Monitor monitor)
Sets the monitor. |
void |
start()
Starts the solver in a new thread, and immediately returns to the caller. |
void |
start(long timeout)
Starts the solver in a new thread with the timeout, and immediately returns to the caller. |
void |
start(SolutionHandler handler)
Starts the solver in a new thread, and immediately returns to the caller. |
void |
start(SolutionHandler handler,
long timeout)
Starts the solver in a new thread with the timeout, and immediately returns to the caller. |
void |
stop()
Stops the execution of the solver. |
String |
toString()
Returns the name of this solver. |
boolean |
waitNext()
Waits for the next solution, or the end of the solver execution. |
boolean |
waitNext(long timeout)
Waits for the next solution, or the end of the solver execution with the timeout. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT
public static final int NONE
public static final int MINIMIZE
public static final int MAXIMIZE
public static final int BETTER
Constructor Detail |
---|
public Solver(Network network)
network
- the constraint networkpublic Solver(Network network, int option)
network
- the constraint networkoption
- the option for search strategypublic Solver(Network network, String name)
network
- the constraint networkname
- the name of the solverpublic Solver(Network network, int option, String name)
network
- the constraint networkoption
- the option for search strategy, or DEFAULT for default search
strategyname
- the name of the solver, or null for a default nameMethod Detail |
---|
public void setMonitor(Monitor monitor)
monitor
- monitorpublic Monitor getMonitor()
public static void resetIDCounter()
public int getID()
public void clearBest()
public Solution getSolution()
public Solution getBestSolution()
public int getBestValue()
public int getOption()
public boolean isAborted()
public void start()
waitNext()
and waitNext(long timeout)
methods can
be used to wait the next solution. When a solution is found, the solver
suspends the execution until the resume()
method is called. You
can stop the solver anytime by calling the stop()
method.
public void start(long timeout)
waitNext()
and waitNext(long timeout)
methods can be
used to wait the next solution, or to detect the timeout. When a solution
is found, the solver suspends the execution until the resume()
method is called. You can stop the solver anytime by calling the
stop()
method.
timeout
- timeout in milliseconds (non-positive value means no timeout)public void start(SolutionHandler handler)
stop()
method.
handler
- solution handlerpublic void start(SolutionHandler handler, long timeout)
stop()
method.
handler
- solution handlertimeout
- timeout in milliseconds (non-positive value means no timeout)public boolean waitNext()
public boolean waitNext(long timeout)
timeout
- timeout in milliseconds (non-positive value means no timeout)
public void resume()
public void join()
public void stop()
public long getCount()
public long getElapsedTime()
public abstract void run()
start()
methods.
run
in interface Runnable
public Solution findFirst()
findFirst(0)
.
public Solution findFirst(long timeout)
clearBest(); start(timeout); waitNext(); stop(); return getBestSolution();
timeout
- timeout in milliseconds (non-positive value means no timeout)
public Solution findBest()
findBest(0)
.
public Solution findBest(long timeout)
clearBest(); for (start(timeout); waitNext(); resume()) { ; } stop(); return getBestSolution();
timeout
- timeout in milliseconds (non-positive value means no timeout)
public void findAll(SolutionHandler handler)
findFirst(handler, 0)
.
handler
- solution handlerpublic void findAll(SolutionHandler handler, long timeout)
clearBest(); start(handler, timeout); join();
handler
- solution handlertimeout
- timeout in milliseconds (non-positive value means no timeout)public String toString()
toString
in class Object
|
Cream version 1.06 Core API Specification |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |