C# Class Cream.Solver

An abstract class for constraint solvers. A solver is constructed with a {@linkplain Network 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. As a subroutine: {@link #FindFirst()}, {@link #FindBest()}, etc.
Solution solution = solver.FindFirst();
As a handler caller: {@link #FindAll(ISolutionHandler handler)}, etc.
solver.FindAll(new ISolutionHandler() { public synchronized void Solved(Solver solver, Solution solution) { ..... } });
As a coroutine: {@link #Start()}, {@link #WaitNext()}, {@link #Resume()}, {@link #Stop()}, etc.
for (solver.Start(); solver.WaitNext(); solver.Resume()) { Solution solution = solver.getSolution(); ..... } solver.Stop();
Inheritance: IThreadRunnable
Afficher le fichier Open project: kikoanis/CSharpCream Class Usage Examples

Protected Properties

Свойство Type Description
bestSolution Solution
bestValue int
count long
debug bool
name String
network Cream.Network
option int
solution Solution
startTime long
totalTimeout long

Méthodes publiques

Méthode Description
ClearBest ( ) : void

Clears the best solution this solver has been found.

FindAll ( ISolutionHandler handler ) : void

Invokes the handler for each solution. This method is equivalent to {@link #FindAll(ISolutionHandler, long) FindFirst(handler, 0)}.

FindAll ( ISolutionHandler handler, long timeout ) : void

Invokes the handler for each solution with the timeout. This method is implemented as follows:

 ClearBest(); Start(handler, timeout); Join(); 

FindBest ( ) : Solution

Finds the best solution. This method is equivalent to {@link #FindBest(long) FindBest(0)}.

FindBest ( long timeout ) : Solution

Finds the best solution with the timeout. This method is implemented as follows:

 ClearBest(); for (Start(timeout); WaitNext(); Resume()) { ; } Stop(); return getBestSolution(); 

FindFirst ( ) : Solution

Finds the first solution. This method is equivalent to {@link #FindFirst(long) FindFirst(0)}.

FindFirst ( long timeout ) : Solution

Finds the first solution with the timeout. This method is implemented as follows:

 ClearBest(); Start(timeout); WaitNext(); Stop(); return getBestSolution(); 

GetCount ( ) : long
GetElapsedTime ( ) : long
GetMonitor ( ) : Monitor

Gets the monitor.

GetOption ( ) : int

Returns the option value.

Join ( ) : void

Waits until the solver ends the execution.

ResetIDCounter ( ) : void

Resets the ID counter to be 0.

Resume ( ) : void

Resumes the execution of the solver.

Run ( ) : void

The body of the solver. This method is called from {@link Solver#Start} methods.

SetMonitor ( Monitor mon ) : void

Sets the mon.

Start ( ) : void

Starts the solver in a new thread, and immediately returns to the caller. The {@link #WaitNext()} and {@link #WaitNext(long timeout)} methods can be used to wait the next solution. When a solution is found, the solver suspends the execution until the {@link #Resume()} method is called. You can Stop the solver anytime by calling the {@link #Stop()} method.

Start ( ISolutionHandler handler ) : void

Starts the solver in a new thread, and immediately returns to the caller. The handler is called for each solution and at the end of the solver execution. You can Stop the solver anytime by calling the {@link #Stop()} method.

Start ( ISolutionHandler handler, long timeout ) : void

Starts the solver in a new thread with the timeout, and immediately returns to the caller. When the timeout milliseconds have been elapsed since the Start of the solver, it stops the execution. The handler is called for each solution and at the end of the solver execution. You can Stop the solver anytime by calling the {@link #Stop()} method.

Start ( long timeout ) : void

Starts the solver in a new thread with the timeout, and immediately returns to the caller. When the timeout milliseconds have been elapsed since the Start of the solver, it stops the execution. The {@link #WaitNext()} and {@link #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 {@link #Resume()} method is called. You can Stop the solver anytime by calling the {@link #Stop()} method.

Stop ( ) : void

Stops the execution of the solver.

ToString ( ) : String

Returns the name of this solver.

WaitNext ( ) : bool

Waits for the next solution, or the end of the solver execution. It returns true if the next solution is available, false if the solver ends the execution.

WaitNext ( long timeout ) : bool

Waits for the next solution, or the end of the solver execution with the timeout. It returns true if the next solution is available within the timeout milliseconds, false if the solver ends the execution or the timeout milliseconds have been elapsed since the Start of this method.

Méthodes protégées

Méthode Description
Fail ( ) : void
IsBetter ( int value1, int value2 ) : bool
IsOption ( int opt ) : bool
Solver ( Cream.Network network ) : System

Constructs a solver for the given network (for invocation by subclass constructors). This constructor is equivalent to Solver(network, Default, null).

Solver ( Cream.Network network, String name ) : System

Constructs a solver for the given network and name (for invocation by subclass constructors). This constructor is equivalent to Solver(network, Default, name).

Solver ( Cream.Network network, int option ) : System

Constructs a solver for the given network and option (for invocation by subclass constructors). This constructor is equivalent to Solver(network, option, null).

Solver ( Cream.Network network, int option, String name ) : System

Constructs a solver for the given network, option, and name (for invocation by subclass constructors). When option is Default, None is used if the network has no objective variable, or else Minimize is used. Solvers and subclasses have their ID number starting from 0.

Success ( ) : void
UpdateBest ( ) : bool

Method Details

ClearBest() public méthode

Clears the best solution this solver has been found.
public ClearBest ( ) : void
Résultat void

Fail() protected méthode

protected Fail ( ) : void
Résultat void

FindAll() public méthode

Invokes the handler for each solution. This method is equivalent to {@link #FindAll(ISolutionHandler, long) FindFirst(handler, 0)}.
public FindAll ( ISolutionHandler handler ) : void
handler ISolutionHandler solution handler ///
Résultat void

FindAll() public méthode

Invokes the handler for each solution with the timeout. This method is implemented as follows:
 ClearBest(); Start(handler, timeout); Join(); 
public FindAll ( ISolutionHandler handler, long timeout ) : void
handler ISolutionHandler solution handler ///
timeout long timeout in milliseconds (non-positive value means no timeout) ///
Résultat void

FindBest() public méthode

Finds the best solution. This method is equivalent to {@link #FindBest(long) FindBest(0)}.
public FindBest ( ) : Solution
Résultat Solution

FindBest() public méthode

Finds the best solution with the timeout. This method is implemented as follows:
 ClearBest(); for (Start(timeout); WaitNext(); Resume()) { ; } Stop(); return getBestSolution(); 
public FindBest ( long timeout ) : Solution
timeout long timeout in milliseconds (non-positive value means no timeout) ///
Résultat Solution

FindFirst() public méthode

Finds the first solution. This method is equivalent to {@link #FindFirst(long) FindFirst(0)}.
public FindFirst ( ) : Solution
Résultat Solution

FindFirst() public méthode

Finds the first solution with the timeout. This method is implemented as follows:
 ClearBest(); Start(timeout); WaitNext(); Stop(); return getBestSolution(); 
public FindFirst ( long timeout ) : Solution
timeout long timeout in milliseconds (non-positive value means no timeout) ///
Résultat Solution

GetCount() public méthode

public GetCount ( ) : long
Résultat long

GetElapsedTime() public méthode

public GetElapsedTime ( ) : long
Résultat long

GetMonitor() public méthode

Gets the monitor.
public GetMonitor ( ) : Monitor
Résultat Monitor

GetOption() public méthode

Returns the option value.
public GetOption ( ) : int
Résultat int

IsBetter() protected méthode

protected IsBetter ( int value1, int value2 ) : bool
value1 int
value2 int
Résultat bool

IsOption() protected méthode

protected IsOption ( int opt ) : bool
opt int
Résultat bool

Join() public méthode

Waits until the solver ends the execution.
public Join ( ) : void
Résultat void

ResetIDCounter() public static méthode

Resets the ID counter to be 0.
public static ResetIDCounter ( ) : void
Résultat void

Resume() public méthode

Resumes the execution of the solver.
public Resume ( ) : void
Résultat void

Run() public abstract méthode

The body of the solver. This method is called from {@link Solver#Start} methods.
public abstract Run ( ) : void
Résultat void

SetMonitor() public méthode

Sets the mon.
public SetMonitor ( Monitor mon ) : void
mon Monitor monitor ///
Résultat void

Solver() protected méthode

Constructs a solver for the given network (for invocation by subclass constructors). This constructor is equivalent to Solver(network, Default, null).
protected Solver ( Cream.Network network ) : System
network Cream.Network the constraint network ///
Résultat System

Solver() protected méthode

Constructs a solver for the given network and name (for invocation by subclass constructors). This constructor is equivalent to Solver(network, Default, name).
protected Solver ( Cream.Network network, String name ) : System
network Cream.Network the constraint network ///
name String the name of the solver ///
Résultat System

Solver() protected méthode

Constructs a solver for the given network and option (for invocation by subclass constructors). This constructor is equivalent to Solver(network, option, null).
protected Solver ( Cream.Network network, int option ) : System
network Cream.Network the constraint network ///
option int the option for search strategy ///
Résultat System

Solver() protected méthode

Constructs a solver for the given network, option, and name (for invocation by subclass constructors). When option is Default, None is used if the network has no objective variable, or else Minimize is used. Solvers and subclasses have their ID number starting from 0.
protected Solver ( Cream.Network network, int option, String name ) : System
network Cream.Network the constraint network ///
option int the option for search strategy, or Default for default search strategy ///
name String the name of the solver, or null for a default name ///
Résultat System

Start() public méthode

Starts the solver in a new thread, and immediately returns to the caller. The {@link #WaitNext()} and {@link #WaitNext(long timeout)} methods can be used to wait the next solution. When a solution is found, the solver suspends the execution until the {@link #Resume()} method is called. You can Stop the solver anytime by calling the {@link #Stop()} method.
public Start ( ) : void
Résultat void

Start() public méthode

Starts the solver in a new thread, and immediately returns to the caller. The handler is called for each solution and at the end of the solver execution. You can Stop the solver anytime by calling the {@link #Stop()} method.
public Start ( ISolutionHandler handler ) : void
handler ISolutionHandler solution handler ///
Résultat void

Start() public méthode

Starts the solver in a new thread with the timeout, and immediately returns to the caller. When the timeout milliseconds have been elapsed since the Start of the solver, it stops the execution. The handler is called for each solution and at the end of the solver execution. You can Stop the solver anytime by calling the {@link #Stop()} method.
public Start ( ISolutionHandler handler, long timeout ) : void
handler ISolutionHandler solution handler ///
timeout long timeout in milliseconds (non-positive value means no timeout) ///
Résultat void

Start() public méthode

Starts the solver in a new thread with the timeout, and immediately returns to the caller. When the timeout milliseconds have been elapsed since the Start of the solver, it stops the execution. The {@link #WaitNext()} and {@link #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 {@link #Resume()} method is called. You can Stop the solver anytime by calling the {@link #Stop()} method.
public Start ( long timeout ) : void
timeout long timeout in milliseconds (non-positive value means no timeout) ///
Résultat void

Stop() public méthode

Stops the execution of the solver.
public Stop ( ) : void
Résultat void

Success() protected méthode

protected Success ( ) : void
Résultat void

ToString() public méthode

Returns the name of this solver.
public ToString ( ) : String
Résultat String

UpdateBest() protected méthode

protected UpdateBest ( ) : bool
Résultat bool

WaitNext() public méthode

Waits for the next solution, or the end of the solver execution. It returns true if the next solution is available, false if the solver ends the execution.
public WaitNext ( ) : bool
Résultat bool

WaitNext() public méthode

Waits for the next solution, or the end of the solver execution with the timeout. It returns true if the next solution is available within the timeout milliseconds, false if the solver ends the execution or the timeout milliseconds have been elapsed since the Start of this method.
public WaitNext ( long timeout ) : bool
timeout long timeout in milliseconds (non-positive value means no timeout) ///
Résultat bool

Property Details

bestSolution protected_oe property

protected Solution,Cream bestSolution
Résultat Solution

bestValue protected_oe property

protected int bestValue
Résultat int

count protected_oe property

protected long count
Résultat long

debug protected_oe property

protected bool debug
Résultat bool

name protected_oe property

protected String name
Résultat String

network protected_oe property

protected Network,Cream network
Résultat Cream.Network

option protected_oe property

protected int option
Résultat int

solution protected_oe property

protected Solution,Cream solution
Résultat Solution

startTime protected_oe property

protected long startTime
Résultat long

totalTimeout protected_oe property

protected long totalTimeout
Résultat long