From 5522cf06fc370d57c2508240fa19421de4fe030b Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 13 Nov 2016 20:00:09 +0100 Subject: [PATCH] Algorithm placeholder --- Algorithm/AlgorithmType.php | 0 Algorithm/Knappsack/Backpack.php | 90 +++++++++++++++++++++++++++ Algorithm/Knappsack/ItemInterface.php | 0 3 files changed, 90 insertions(+) create mode 100644 Algorithm/AlgorithmType.php create mode 100644 Algorithm/Knappsack/Backpack.php create mode 100644 Algorithm/Knappsack/ItemInterface.php diff --git a/Algorithm/AlgorithmType.php b/Algorithm/AlgorithmType.php new file mode 100644 index 000000000..e69de29bb diff --git a/Algorithm/Knappsack/Backpack.php b/Algorithm/Knappsack/Backpack.php new file mode 100644 index 000000000..0e7f3f4a3 --- /dev/null +++ b/Algorithm/Knappsack/Backpack.php @@ -0,0 +1,90 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace phpOMS\Algorithm\Knappsack; + +/** + * Knappsack algorithm implementations + * + * @category Framework + * @package phpOMS\Auth + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Backpack +{ + private $costMaximum = 0; + + private $value = 0; + + private $cost = 0; + + private $items = []; + + private $population = []; + + public function __construct(float $costMaximum) + { + $this->costMaximum = $costMaximum; + } + + public function addPopulationItem(ItemInterface $item) : bool + { + if(isset($this->population[$item->getId()])) { + return false; + } + + $this->population[$item->getId()] = $item; + + return true; + } + + public function setPopulationItem(ItemInterface $item) + { + $this->population[$item->getId()] = $item; + } + + public function setCostCalculation(\Closure $callback) + { + + } + + public function setValueCalculation(\Closure $callback) + { + + } + + public function setTestPopulationBuilder(\Closure $callback) + { + + } + + public function pack(int $type) + { + switch($type) { + case AlgorithmType::BRUTEFORCE: + return $this->bruteforce(); + default: + throw new \Exception('Invalid algorithm type'); + } + } + + public function bruteforce() + { + } +} \ No newline at end of file diff --git a/Algorithm/Knappsack/ItemInterface.php b/Algorithm/Knappsack/ItemInterface.php new file mode 100644 index 000000000..e69de29bb