bdelespierre / php-kmeans

PHP K-Means
MIT License
91 stars 41 forks source link

Pause algorithm execution #30

Open bdelespierre opened 3 years ago

bdelespierre commented 3 years ago

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?

battlecook commented 3 years ago

Is it serialized when paused?

bdelespierre commented 3 years ago

Is it serialized when paused?

No, only when you serialize($result).

battlecook commented 3 years ago

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