PHP code example of ggggino / warehouse-path

1. Go to this page and download the library: Download ggggino/warehouse-path library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ggggino / warehouse-path example snippets


use GGGGino\WarehousePath\Warehouse;

public static function getSampleData()
{
    return array(
        array(array('weight' => 2), array('weight' => 1), array('weight' => 100), array('weight' => 1), array('weight' => 2), array('weight' => 1)),
        array(array('weight' => 2), array('weight' => 1), array('weight' => 100), array('weight' => 1), array('weight' => 2), array('weight' => 1)),
        array(array('weight' => 2), array('weight' => 1), array('weight' => 100), array('weight' => 1), array('weight' => 2), array('weight' => 1)),
        array(array('weight' => 2), array('weight' => 2), array('weight' =>   2), array('weight' => 2), array('weight' => 2), array('weight' => 1))
    );
}

/** @var Warehouse $warehouse */
$warehouse = Warehouse::createFromMatrix(self::getSampleData());

use GGGGino\WarehousePath\Warehouse;
        
$loc1 = new Location('L1');
$loc2 = new Location('L2');
$loc3 = new Location('L3');
$corridor1 = new Location('C1');

$loc1->setBottomRef($loc2);
$loc1->setRightRef($loc3);

$loc3->setBottomRef($loc3);

$arrayPlaces = array($loc1, $loc2, $loc3, $corridor1);
        
/** @var Warehouse $warehouse */
$warehouse = Warehouse::createFromTree($arrayPlaces);

use GGGGino\WarehousePath\Warehouse;

/** @var Warehouse $warehouse */
$warehouse = Warehouse::createFromJson(getcwd() . "/resources/simpleWarehouse.json")

// Instantiate a place collector that contain the type of available places
$placesCollector = new PlacesCollector();

// optionally add the baseplace types (Location, Corridor, Wall)
$placesCollector->addBasePlaceTypes();

// Istantiate the Parser to prepare the places in an array
$wm = new MatrixParser($param, $placesCollector);

// Istantiate a customizable Breadcrumb buider 
$breadcrumbBuilder = new BreadthFirstBreadcrumb($placesCollector);

$instance = new Warehouse($placesCollector, $wm, $breadcrumbBuilder);
$instance->setPlaces($wm->parse());

/** @var Place $nodeStart */
$nodeStart = $calculatedArray[4];
$warehouse->getPath($nodeStart);

/** @var Place[] $arrayNodes array of the places to touch */
$arrayNodes = [...]

$matrix = $warehouse->getMultiplePath($arrayNodes);

/** @var Place[] $arrayNodes array of the places to touch */
$arrayNodes = [...]

$arrayNodeSorted = $warehouse->calculate($arrayNodes, $matrix);