-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
52 lines (39 loc) · 1.22 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* @file
*/
use drupol\phpartition\Algorithm\Greedy;
require "vendor/autoload.php";
$input = [];
foreach (range(1, 10) as $iter) {
$input[] = rand(1, $iter);
}
sort($input);
echo "input = [" . implode(',', $input) . "]\n\n";
/** @var \drupol\phpartition\PartitionAlgorithmInterface[] $algos */
$algos = [
new \drupol\phpartition\Algorithm\Simple(),
new Greedy(),
new \drupol\phpartition\Algorithm\BruteForce(),
new \drupol\phpartition\Algorithm\BruteForceCustomA()
];
foreach ($algos as $algo) {
$start_time = microtime(true);
echo "\n";
echo "******************************************************\n";
echo "* Type: " . get_class($algo) . "\n";
echo "******************************************************\n\n";
$algo->setSize(3);
$algo->setData($input);
$sums = [];
foreach ($algo->getResult() as $subset) {
sort($subset);
$sum = array_sum($subset);
$sums[] = $sum;
echo "[" . implode(',', $subset) . "] = " . $sum . "\n";
}
$stdDev = \Oefenweb\Statistics\Statistics::standardDeviation($sums);
echo "Variance: " . round($stdDev, 1) . "\n";
$end = microtime(true) - $start_time;
echo "\nTime elapsed: " . $end . "\n";
}