for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace drupol\phpartition\Algorithm;
use drupol\phpartition\BasePartitionAlgorithm;
use drupol\phpartition\PartitionAlgorithmInterface;
use drupol\phpartition\Subset;
/**
* Class Greedy.
*
* @package drupol\phpartition\Algorithm
*/
class Greedy extends BasePartitionAlgorithm implements PartitionAlgorithmInterface {
* The greedy algorithm needs the input data to be sorted (desc).
* @return array
public function getResult() {
$this->dataset->sortByValue('DESC');
return parent::getResult();
}
* @param \drupol\phpartition\Subset $subset
* @return int|mixed
public function getSubsetWeight(Subset $subset) {
$sum = 0;
foreach($subset->getItems() as $item) {
$sum += $item->getValue();
return $sum;