php-kmeans icon indicating copy to clipboard operation
php-kmeans copied to clipboard

Pause algorithm execution

Open bdelespierre opened this issue 2 years ago • 3 comments

Since resuming the algorithm is possible (see #28), why not give the user the ability to pause it as well?

Here's an implementation target:

$algo = new Kmeans\Algorithm(new Kmeans\RandomInitialization());

$aglo->registerIterationCallback(function ($algo) {
    if ($algo->getStatus()->startedAt() > new \DateTime('1 hour ago')) {
        return $algo->pause();
    }
});

$result = $algo->clusterize($points, $nbClusters);

if ($result->getStatus()->isPaused()) {
    echo "Clusterization ran for more than 1h and had to be paused.";
}

What do you think?

bdelespierre avatar Sep 06 '21 11:09 bdelespierre

Is it serialized when paused?

battlecook avatar Sep 08 '21 14:09 battlecook

Is it serialized when paused?

No, only when you serialize($result).

bdelespierre avatar Sep 09 '21 11:09 bdelespierre

I think it's okay to provide a pause function to the user.

battlecook avatar Sep 10 '21 15:09 battlecook