Skip to content

Commit

Permalink
Make available space info available (issue #7)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed May 31, 2014
1 parent a8f1546 commit 1cc377b
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 9 deletions.
75 changes: 73 additions & 2 deletions PackedBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,34 @@ class PackedBox {

/**
* Total weight of box
* @var float
* @var int
*/
protected $weight;

/**
* Remaining width inside box for another item
* @var int
*/
protected $remainingWidth;

/**
* Remaining length inside box for another item
* @var int
*/
protected $remainingLength;

/**
* Remaining depth inside box for another item
* @var int
*/
protected $remainingDepth;

/**
* Remaining weight inside box for another item
* @var int
*/
protected $remainingWeight;

/**
* Get box used
* @return Box
Expand Down Expand Up @@ -65,9 +89,56 @@ public function getWeight() {
return $this->weight;
}

public function __construct(Box $aBox, ItemList $aItemList) {
/**
* Get remaining width inside box for another item
* @return int
*/
public function getRemainingWidth() {
return $this->remainingWidth;
}

/**
* Get remaining length inside box for another item
* @return int
*/
public function getRemainingLength() {
return $this->remainingLength;
}

/**
* Get remaining depth inside box for another item
* @return int
*/
public function getRemainingDepth() {
return $this->remainingDepth;
}

/**
* Get remaining weight inside box for another item
* @return int
*/
public function getRemainingWeight() {
return $this->remainingWeight;
}



/**
* Constructor
* @param Box $aBox
* @param ItemList $aItemList
* @param int $aRemainingWidth
* @param int $aRemainingLength
* @param int $aRemainingDepth
* @param int $aRemainingWeight
*/
public function __construct(Box $aBox, ItemList $aItemList, $aRemainingWidth, $aRemainingLength, $aRemainingDepth, $aRemainingWeight) {
$this->box = $aBox;
$this->items = $aItemList;
$this->remainingWidth = $aRemainingWidth;
$this->remainingLength = $aRemainingLength;
$this->remainingDepth = $aRemainingDepth;
$this->remainingWeight = $aRemainingWeight;
}

}
26 changes: 19 additions & 7 deletions Packer.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ public function doVolumePacking() {
//Loop through boxes starting with smallest, see what happens
while (!$boxesToEvaluate->isEmpty()) {
$box = $boxesToEvaluate->extract();
$packedItems = $this->packBox($box, clone $this->items);
if ($packedItems->count()) {
$packedBoxesIteration->insert(new PackedBox($box, $packedItems));
$packedBox = $this->packIntoBox($box, clone $this->items);
if ($packedBox->getItems()->count()) {
$packedBoxesIteration->insert($packedBox);

//Have we found a single box that contains everything?
if ($packedItems->count() === $this->items->count()) {
if ($packedBox->getItems()->count() === $this->items->count()) {
break;
}
}
Expand Down Expand Up @@ -234,9 +234,9 @@ public function redistributeWeight(PackedBoxList $aPackedBoxes) {
* Pack as many items as possible into specific given box
* @param Box $aBox
* @param ItemList $aItems
* @return ItemList items packed into box
* @return PackedBox packed box
*/
public function packBox(Box $aBox, ItemList $aItems) {
public function packIntoBox(Box $aBox, ItemList $aItems) {
$this->logger->log(LogLevel::DEBUG, "evaluating box {$aBox->getReference()}");

$packedItems = new ItemList;
Expand Down Expand Up @@ -300,6 +300,18 @@ public function packBox(Box $aBox, ItemList $aItems) {
}
}
$this->logger->log(LogLevel::DEBUG, "done with this box");
return $packedItems;
return new PackedBox($aBox, $packedItems, $remainingWidth, $remainingLength, $remainingDepth, $remainingWeight);
}

/**
* Pack as many items as possible into specific given box
* @deprecated
* @param Box $aBox
* @param ItemList $aItems
* @return ItemList items packed into box
*/
public function packBox(Box $aBox, ItemList $aItems) {
$packedBox = $this->packIntoBox($aBox, $aItems);
return $packedBox->getItems();
}
}

0 comments on commit 1cc377b

Please sign in to comment.