From 27035d8be7d9f725bedd52f5a8c5e7ecec49e95a Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 6 Sep 2019 21:25:09 +0200 Subject: [PATCH] prepare for more algorithms --- Account/AccountManager.php | 4 +- Algorithm/CoinMatching/MinimumCoinProblem.php | 76 +++++++++++++++++++ Algorithm/JobScheduling/Job.php | 0 Algorithm/JobScheduling/Weighted.php | 0 Algorithm/Knappsack/Backpack.php | 63 +++++++++++++++ Algorithm/Knappsack/Bounded.php | 0 Algorithm/Knappsack/Continuous.php | 0 Algorithm/Knappsack/Item.php | 40 ++++++++++ Algorithm/Knappsack/Unbounded.php | 0 .../CoinMatching/MinimumCoinProblemTest.php | 40 ++++++++++ .../PathFinding/JumpPointSearchTest.php | 2 +- 11 files changed, 222 insertions(+), 3 deletions(-) create mode 100644 Algorithm/CoinMatching/MinimumCoinProblem.php create mode 100644 Algorithm/JobScheduling/Job.php create mode 100644 Algorithm/JobScheduling/Weighted.php create mode 100644 Algorithm/Knappsack/Backpack.php create mode 100644 Algorithm/Knappsack/Bounded.php create mode 100644 Algorithm/Knappsack/Continuous.php create mode 100644 Algorithm/Knappsack/Item.php create mode 100644 Algorithm/Knappsack/Unbounded.php create mode 100644 tests/Algorithm/CoinMatching/MinimumCoinProblemTest.php diff --git a/Account/AccountManager.php b/Account/AccountManager.php index c743978f9..41aec18ed 100644 --- a/Account/AccountManager.php +++ b/Account/AccountManager.php @@ -41,10 +41,10 @@ final class AccountManager implements \Countable /** * Session. * - * @var null|SessionInterface + * @var SessionInterface * @since 1.0.0 */ - private ?SessionInterface $session = null; + private SessionInterface $session; /** * Constructor. diff --git a/Algorithm/CoinMatching/MinimumCoinProblem.php b/Algorithm/CoinMatching/MinimumCoinProblem.php new file mode 100644 index 000000000..036c01cfe --- /dev/null +++ b/Algorithm/CoinMatching/MinimumCoinProblem.php @@ -0,0 +1,76 @@ +maxCost = $maxCost; + } + + public function getValue() + { + return $this->value; + } + + public function getCost() + { + return $this->cost; + } + + public function getItems() : array + { + return $this->items; + } + + public function addItem(Item $item) : void + { + $this->items[] = $item; + $this->value += $item->getValue(); + $this->cost += $item->getCost(); + } +} diff --git a/Algorithm/Knappsack/Bounded.php b/Algorithm/Knappsack/Bounded.php new file mode 100644 index 000000000..e69de29bb diff --git a/Algorithm/Knappsack/Continuous.php b/Algorithm/Knappsack/Continuous.php new file mode 100644 index 000000000..e69de29bb diff --git a/Algorithm/Knappsack/Item.php b/Algorithm/Knappsack/Item.php new file mode 100644 index 000000000..79e93472a --- /dev/null +++ b/Algorithm/Knappsack/Item.php @@ -0,0 +1,40 @@ +value; + } + + public function getCost() + { + return $this->cost; + } +} diff --git a/Algorithm/Knappsack/Unbounded.php b/Algorithm/Knappsack/Unbounded.php new file mode 100644 index 000000000..e69de29bb diff --git a/tests/Algorithm/CoinMatching/MinimumCoinProblemTest.php b/tests/Algorithm/CoinMatching/MinimumCoinProblemTest.php new file mode 100644 index 000000000..0f4eb13d4 --- /dev/null +++ b/tests/Algorithm/CoinMatching/MinimumCoinProblemTest.php @@ -0,0 +1,40 @@ +