C# Класс 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();
Наследование: IThreadRunnable
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
bestSolution Solution
bestValue int
count long
debug bool
name String
network Cream.Network
option int
solution Solution
startTime long
totalTimeout long

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
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

Описание методов

ClearBest() публичный Метод

Clears the best solution this solver has been found.
public ClearBest ( ) : void
Результат void

Fail() защищенный Метод

protected Fail ( ) : void
Результат void

FindAll() публичный Метод

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 ///
Результат void

FindAll() публичный Метод

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) ///
Результат void

FindBest() публичный Метод

Finds the best solution. This method is equivalent to {@link #FindBest(long) FindBest(0)}.
public FindBest ( ) : Solution
Результат Solution

FindBest() публичный Метод

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) ///
Результат Solution

FindFirst() публичный Метод

Finds the first solution. This method is equivalent to {@link #FindFirst(long) FindFirst(0)}.
public FindFirst ( ) : Solution
Результат Solution

FindFirst() публичный Метод

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) ///
Результат Solution

GetCount() публичный Метод

public GetCount ( ) : long
Результат long

GetElapsedTime() публичный Метод

public GetElapsedTime ( ) : long
Результат long

GetMonitor() публичный Метод

Gets the monitor.
public GetMonitor ( ) : Monitor
Результат Monitor

GetOption() публичный Метод

Returns the option value.
public GetOption ( ) : int
Результат int

IsBetter() защищенный Метод

protected IsBetter ( int value1, int value2 ) : bool
value1 int
value2 int
Результат bool

IsOption() защищенный Метод

protected IsOption ( int opt ) : bool
opt int
Результат bool

Join() публичный Метод

Waits until the solver ends the execution.
public Join ( ) : void
Результат void

ResetIDCounter() публичный статический Метод

Resets the ID counter to be 0.
public static ResetIDCounter ( ) : void
Результат void

Resume() публичный Метод

Resumes the execution of the solver.
public Resume ( ) : void
Результат void

Run() публичный абстрактный Метод

The body of the solver. This method is called from {@link Solver#Start} methods.
public abstract Run ( ) : void
Результат void

SetMonitor() публичный Метод

Sets the mon.
public SetMonitor ( Monitor mon ) : void
mon Monitor monitor ///
Результат void

Solver() защищенный Метод

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 ///
Результат System

Solver() защищенный Метод

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 ///
Результат System

Solver() защищенный Метод

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 ///
Результат System

Solver() защищенный Метод

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 ///
Результат System

Start() публичный Метод

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
Результат void

Start() публичный Метод

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 ///
Результат void

Start() публичный Метод

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) ///
Результат void

Start() публичный Метод

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) ///
Результат void

Stop() публичный Метод

Stops the execution of the solver.
public Stop ( ) : void
Результат void

Success() защищенный Метод

protected Success ( ) : void
Результат void

ToString() публичный Метод

Returns the name of this solver.
public ToString ( ) : String
Результат String

UpdateBest() защищенный Метод

protected UpdateBest ( ) : bool
Результат bool

WaitNext() публичный Метод

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
Результат bool

WaitNext() публичный Метод

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) ///
Результат bool

Описание свойств

bestSolution защищенное свойство

protected Solution,Cream bestSolution
Результат Solution

bestValue защищенное свойство

protected int bestValue
Результат int

count защищенное свойство

protected long count
Результат long

debug защищенное свойство

protected bool debug
Результат bool

name защищенное свойство

protected String name
Результат String

network защищенное свойство

protected Network,Cream network
Результат Cream.Network

option защищенное свойство

protected int option
Результат int

solution защищенное свойство

protected Solution,Cream solution
Результат Solution

startTime защищенное свойство

protected long startTime
Результат long

totalTimeout защищенное свойство

protected long totalTimeout
Результат long