Struct abc::Hive
[−]
[src]
pub struct Hive<Ctx: Context> { // some fields omitted }
Runs the ABC algorithm, maintaining any necessary state.
Methods
impl<Ctx: Context> Hive<Ctx>
fn get(&self) -> AbcResult<MutexGuard<Candidate<Ctx::Solution>>>
Returns a guard for the current best solution found by the hive.
If the hive is running, you should drop the guard returned by this
function as soon as convenient, since the logic of the hive can block
on the availability of the associated mutex. If you plan on performing
expensive computations, you should drop
the guard as soon as
possible, or acquire and clone it within a small block.
fn run_for_rounds(&self, rounds: usize) -> AbcResult<Candidate<Ctx::Solution>>
Runs for a fixed number of rounds, then return the best solution found.
If one of the worker threads panics while working, this will return
Err(abc::Error)
. Otherwise, it will return Ok
with a Candidate
.
fn run_forever(&self) -> AbcResult<()>
Run indefinitely.
If one of the worker threads panics while working, this will return
Err(abc::Error)
. Otherwise, it will return Ok(())
.
fn stop(&self) -> AbcResult<()>
Stops a running hive.
If a worker thread has panicked, this returns Err(abc::Error)
.
fn set_sender(&mut self, sender: Sender<Candidate<Ctx::Solution>>)
Each new best candidate will be sent to sender
.
This is kept in a separate function so that the hive can be borrowed while running.
fn get_round(&self) -> AbcResult<Option<usize>>
Returns the current round of a running hive.
If a worker thread has panicked and poisoned the task generator lock,
get_round
will return Err(abc::Error)
. If the hive has not been
run, get_round
will return Ok(None)
.
If the hive is running, this will return Ok(Some(n))
. n
will start
at 0, and increment each time every task in the round has been claimed
(though not necessarily completed) by a worker thread.
fn context(&self) -> &Ctx
Get a reference to the hive's context.
impl<Ctx: Context + 'static> Hive<Ctx>
fn stream(self) -> Receiver<Candidate<Ctx::Solution>>
Runs indefinitely in the background, providing a stream of results.
This method consumes the hive, which will run until the HiveBuilder
object is dropped. It returns an mpsc::Receiver
, which receives a
Candidate
each time the hive improves on its best solution.