This commit is contained in:
Dennis Eichhorn 2020-11-30 21:13:06 +01:00
parent 1e19f72fc4
commit 6ac2d4d0e8
2 changed files with 22 additions and 7 deletions

View File

@ -35,6 +35,21 @@ final class Continuous
{ {
} }
/**
* Comparing items
*
* @param Item[] $a Item
* @param Item[] $b Item
*
* @return int
*
* @since 1.0.0
*/
private static function continuousComparator(array $a, array $b) : int
{
return $b['item']->getValue() / $b['item']->getCost() <=> $a['item']->getValue() / $a['item']->getCost();
}
/** /**
* Fill the backpack with items * Fill the backpack with items
* *
@ -47,9 +62,7 @@ final class Continuous
*/ */
public static function solve(array $items, BackpackInterface $backpack) : BackpackInterface public static function solve(array $items, BackpackInterface $backpack) : BackpackInterface
{ {
\usort($items, function($a, $b) { \usort($items, ['self', 'continuousComparator']);
return $a['item']->getValue() / $a['item']->getCost() < $b['item']->getValue() / $b['item']->getCost();
});
$availableSpace = $backpack->getMaxCost(); $availableSpace = $backpack->getMaxCost();

View File

@ -363,11 +363,13 @@ class DataMapperAbstract implements DataMapperInterface
public static function clear() : void public static function clear() : void
{ {
// clear parent and objects // clear parent and objects
if (static::class === self::$parentMapper) { if (static::class !== self::$parentMapper) {
self::$parentMapper = null; return;
self::$conditionals = [];
self::$relations = RelationType::ALL;
} }
self::$parentMapper = null;
self::$conditionals = [];
self::$relations = RelationType::ALL;
} }
/** /**