Skip to content

Commit

Permalink
Eliminate duplicate permutations up front
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Dec 15, 2018
1 parent fa71e45 commit ab7b4a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/OrientatedItem.php
Expand Up @@ -150,4 +150,12 @@ public function jsonSerialize()
'depth' => $this->depth,
];
}

/**
* @return string
*/
public function __toString(): string
{
return $this->width . '|' . $this->length . '|' . $this->depth;
}
}
4 changes: 4 additions & 0 deletions src/OrientatedItemFactory.php
Expand Up @@ -152,6 +152,8 @@ public function getPossibleOrientations(
}
}

$orientations = array_unique($orientations);

//remove any that simply don't fit
return array_filter($orientations, function (OrientatedItem $i) use ($widthLeft, $lengthLeft, $depthLeft) {
return $i->getWidth() <= $widthLeft && $i->getLength() <= $lengthLeft && $i->getDepth() <= $depthLeft;
Expand Down Expand Up @@ -323,6 +325,8 @@ protected function calculateAdditionalItemsPackedWithThisOrientation(
}
}

$this->logger->debug('Lookahead with orientation', ['packedCount' => $packedCount, 'orientatedItem' => $prevItem]);

return $packedCount; // this isn't scientific, but is a reasonable proxy for success from an actual forward packing
}
}

0 comments on commit ab7b4a5

Please sign in to comment.