src/Alg/Parcel/Packer.php
public function calculatePackage( $articleList )
	{
		$this->packetList	= array();																	//  reset Packet List

		foreach( $articleList as $name => $quantity )													//  iterate Article List
			if( !$quantity )																			//  and remove all Articles
				unset( $articleList[$name] );															//  without Quantity
		while( $articleList )																			//  iterate Article List
		{
			//  --  ADD FIRST PACKET  --  //
			$largestArticle	= $this->getLargestArticle( $articleList );									//  get Largest Article in List
			if( !count( $this->packetList ) )															//  no Packets yet in Packet List
			{
				$packetName	= $this->getNameOfSmallestPacketForArticle( $largestArticle );				//  get smallest Packet Type for Article
				$packet		= $this->factory->produce( $packetName, array( $largestArticle => 1 ) );	//  put Article in new Packet
				$this->packetList[]	= $packet;															//  add Packet to Packet List
				$this->removeArticleFromList( $articleList, $largestArticle );							//  remove Article from Article List
				continue;																				//  step to next Article
			}

			//  --  FILL PACKET  --  //
			$found = false;																				//  
			for( $i=0; $i<count( $this->packetList ); $i++ )											//  iterate Packets in Packet List
			{
				$packet	= $this->getPacket( $i );														//  get current Packet
				$articleVolume	= $this->volumes[$packet->getName()][$largestArticle];						//  get Article Volume in this Packet
				if( $packet->hasVolumeLeft( $articleVolume ) )											//  check if Article will fit in Packet
				{
					$packet->addArticle( $largestArticle, $articleVolume );								//  put Article in Packet
					$found	= $this->removeArticleFromList( $articleList, $largestArticle );			//  remove Article From Article List
					break;																				//  break Packet Loop
				}
			}
			if( $found )																				//  Article has been put into a Packet
				continue;																				//  step to next Article

			//  --  RESIZE PACKET  --  //
			for( $i=0; $i<count( $this->packetList ); $i++ )											//  iterate Packets in Packet List
			{
				$packet	= $this->getPacket( $i );														//  get current Packet
				while( $this->hasLargerPacket( $packet->getName() ) )									//  there is a larger Packet Type
				{
					$largerPacketName	= $this->getNameOfLargerPacket( $packet->getName() );	
					$articles			= $packet->getArticles();										//  get larger Packet
					$largerPacket		= $this->factory->produce( $largerPacketName, $articles );		//  produce new Packet and add Articles from old Packet
					$articleVolume		= $this->volumes[$largerPacketName][$largestArticle];			//  get Volume of current Article in this Packet
					if( $largerPacket->hasVolumeLeft( $articleVolume ) )
					{
						$largerPacket->addArticle( $largestArticle, $articleVolume );					//  add Article to Packet
						$this->replacePacket( $i, $largerPacket );										//  replace old Packet with new Packet
						$found	= $this->removeArticleFromList( $articleList, $largestArticle );		//  remove Article from Article List
						break;																			//  break Packet Loop
					}
				}
				if( $found )																			//  Article has been put into a Packet
					continue;																			//  break Packet Loop
			}
			if( $found )																				//  Article has been put into a Packet
				continue;																				//  step to next Article
	
			//  --  ADD NEW PACKET  --  //
			$packetName	= $this->getNameOfSmallestPacketForArticle( $largestArticle );					//  get smallest Packet Type for Article
			$packet		= $this->factory->produce( $packetName, array( $largestArticle => 1 ) );		//  produce new Packet and put Article in
				$this->packetList[]	= $packet;															//  add Packet to Packet List
			$this->removeArticleFromList( $articleList, $largestArticle );								//  remove Article from Article List
		}
		return $this->packetList;																		//  return final Packet List with Articles
	}
public function calculatePackage( $articleList )
	{
		$this->packetList	= array();																	//  reset Packet List

		foreach( $articleList as $name => $quantity )													//  iterate Article List
			if( !$quantity )																			//  and remove all Articles
				unset( $articleList[$name] );															//  without Quantity
		while( $articleList )																			//  iterate Article List
		{
			//  --  ADD FIRST PACKET  --  //
			$largestArticle	= $this->getLargestArticle( $articleList );									//  get Largest Article in List
			if( !count( $this->packetList ) )															//  no Packets yet in Packet List
			{
				$packetName	= $this->getNameOfSmallestPacketForArticle( $largestArticle );				//  get smallest Packet Type for Article
				$packet		= $this->factory->produce( $packetName, array( $largestArticle => 1 ) );	//  put Article in new Packet
				$this->packetList[]	= $packet;															//  add Packet to Packet List
				$this->removeArticleFromList( $articleList, $largestArticle );							//  remove Article from Article List
				continue;																				//  step to next Article
			}

			//  --  FILL PACKET  --  //
			$found = false;																				//  
			for( $i=0; $i<count( $this->packetList ); $i++ )											//  iterate Packets in Packet List
			{
				$packet	= $this->getPacket( $i );														//  get current Packet
				$articleVolume	= $this->volumes[$packet->getName()][$largestArticle];						//  get Article Volume in this Packet
				if( $packet->hasVolumeLeft( $articleVolume ) )											//  check if Article will fit in Packet
				{
					$packet->addArticle( $largestArticle, $articleVolume );								//  put Article in Packet
					$found	= $this->removeArticleFromList( $articleList, $largestArticle );			//  remove Article From Article List
					break;																				//  break Packet Loop
				}
			}
			if( $found )																				//  Article has been put into a Packet
				continue;																				//  step to next Article

			//  --  RESIZE PACKET  --  //
			for( $i=0; $i<count( $this->packetList ); $i++ )											//  iterate Packets in Packet List
			{
				$packet	= $this->getPacket( $i );														//  get current Packet
				while( $this->hasLargerPacket( $packet->getName() ) )									//  there is a larger Packet Type
				{
					$largerPacketName	= $this->getNameOfLargerPacket( $packet->getName() );	
					$articles			= $packet->getArticles();										//  get larger Packet
					$largerPacket		= $this->factory->produce( $largerPacketName, $articles );		//  produce new Packet and add Articles from old Packet
					$articleVolume		= $this->volumes[$largerPacketName][$largestArticle];			//  get Volume of current Article in this Packet
					if( $largerPacket->hasVolumeLeft( $articleVolume ) )
					{
						$largerPacket->addArticle( $largestArticle, $articleVolume );					//  add Article to Packet
						$this->replacePacket( $i, $largerPacket );										//  replace old Packet with new Packet
						$found	= $this->removeArticleFromList( $articleList, $largestArticle );		//  remove Article from Article List
						break;																			//  break Packet Loop
					}
				}
				if( $found )																			//  Article has been put into a Packet
					continue;																			//  break Packet Loop
			}
			if( $found )																				//  Article has been put into a Packet
				continue;																				//  step to next Article
	
			//  --  ADD NEW PACKET  --  //
			$packetName	= $this->getNameOfSmallestPacketForArticle( $largestArticle );					//  get smallest Packet Type for Article
			$packet		= $this->factory->produce( $packetName, array( $largestArticle => 1 ) );		//  produce new Packet and put Article in
				$this->packetList[]	= $packet;															//  add Packet to Packet List
			$this->removeArticleFromList( $articleList, $largestArticle );								//  remove Article from Article List
		}
		return $this->packetList;																		//  return final Packet List with Articles
	}
public function calculatePackage ( $ articleList ) { $ this -> packetList = array ( ) ; //  reset Packet List foreach ( $ articleList as $ name => $ quantity ) //  iterate Article List if ( ! $ quantity ) //  and remove all Articles unset ( $ articleList [ $ name ] ) ; //  without Quantity while ( $ articleList ) //  iterate Article List { //  --  ADD FIRST PACKET  --  // $ largestArticle = $ this -> getLargestArticle ( $ articleList ) ; //  get Largest Article in List if ( ! count ( $ this -> packetList ) ) //  no Packets yet in Packet List { $ packetName = $ this -> getNameOfSmallestPacketForArticle ( $ largestArticle ) ; //  get smallest Packet Type for Article $ packet = $ this -> factory -> produce ( $ packetName , array ( $ largestArticle => 1 ) ) ; //  put Article in new Packet $ this -> packetList [ ] = $ packet ; //  add Packet to Packet List $ this -> removeArticleFromList ( $ articleList , $ largestArticle ) ; //  remove Article from Article List continue ; //  step to next Article } //  --  FILL PACKET  --  // $ found = false ; //   for ( $ i = 0 ; $ i < count ( $ this -> packetList ) ; $ i ++ ) //  iterate Packets in Packet List { $ packet = $ this -> getPacket ( $ i ) ; //  get current Packet $ articleVolume = $ this -> volumes [ $ packet -> getName ( ) ] [ $ largestArticle ] ; //  get Article Volume in this Packet if ( $ packet -> hasVolumeLeft ( $ articleVolume ) ) //  check if Article will fit in Packet { $ packet -> addArticle ( $ largestArticle , $ articleVolume ) ; //  put Article in Packet $ found = $ this -> removeArticleFromList ( $ articleList , $ largestArticle ) ; //  remove Article From Article List break ; //  break Packet Loop } } if ( $ found ) //  Article has been put into a Packet continue ; //  step to next Article //  --  RESIZE PACKET  --  // for ( $ i = 0 ; $ i < count ( $ this -> packetList ) ; $ i ++ ) //  iterate Packets in Packet List { $ packet = $ this -> getPacket ( $ i ) ; //  get current Packet while ( $ this -> hasLargerPacket ( $ packet -> getName ( ) ) ) //  there is a larger Packet Type { $ largerPacketName = $ this -> getNameOfLargerPacket ( $ packet -> getName ( ) ) ; $ articles = $ packet -> getArticles ( ) ; //  get larger Packet $ largerPacket = $ this -> factory -> produce ( $ largerPacketName , $ articles ) ; //  produce new Packet and add Articles from old Packet $ articleVolume = $ this -> volumes [ $ largerPacketName ] [ $ largestArticle ] ; //  get Volume of current Article in this Packet if ( $ largerPacket -> hasVolumeLeft ( $ articleVolume ) ) { $ largerPacket -> addArticle ( $ largestArticle , $ articleVolume ) ; //  add Article to Packet $ this -> replacePacket ( $ i , $ largerPacket ) ; //  replace old Packet with new Packet $ found = $ this -> removeArticleFromList ( $ articleList , $ largestArticle ) ; //  remove Article from Article List break ; //  break Packet Loop } } if ( $ found ) //  Article has been put into a Packet continue ; //  break Packet Loop } if ( $ found ) //  Article has been put into a Packet continue ; //  step to next Article //  --  ADD NEW PACKET  --  // $ packetName = $ this -> getNameOfSmallestPacketForArticle ( $ largestArticle ) ; //  get smallest Packet Type for Article $ packet = $ this -> factory -> produce ( $ packetName , array ( $ largestArticle => 1 ) ) ; //  produce new Packet and put Article in $ this -> packetList [ ] = $ packet ; //  add Packet to Packet List $ this -> removeArticleFromList ( $ articleList , $ largestArticle ) ; //  remove Article from Article List } return $ this -> packetList ; //  return final Packet List with Articles }
Calculates Packages for Articles and returns Packet List.
@access		public
@param		array		$articleList		Array of Articles and their Quantities.
@return		array
Calculates Packages for Articles and returns Packet List .