| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | |
| 5 | 5 | class OptimizationType | 
| 6 | 6 |  { | 
| 7 | - const DISTANCE = 'Distance'; | |
| 8 | - const TIME = 'Time'; | |
| 9 | - const TIME_WITH_TRAFFIC = 'timeWithTraffic'; | |
| 7 | + const DISTANCE = 'Distance'; | |
| 8 | + const TIME = 'Time'; | |
| 9 | + const TIME_WITH_TRAFFIC = 'timeWithTraffic'; | |
| 10 | 10 | } | 
| @@ -4,6 +4,6 @@ | ||
| 4 | 4 | |
| 5 | 5 | class DistanceUnit | 
| 6 | 6 |  { | 
| 7 | - const MILES = 'mi'; | |
| 8 | - const KILOMETERS = 'km'; | |
| 7 | + const MILES = 'mi'; | |
| 8 | + const KILOMETERS = 'km'; | |
| 9 | 9 | } | 
| @@ -4,8 +4,8 @@ | ||
| 4 | 4 | |
| 5 | 5 | class Format | 
| 6 | 6 |  { | 
| 7 | - const SERIALIZED = 'serialized'; | |
| 8 | - const CSV = 'csv'; | |
| 9 | - const XML = 'xml'; | |
| 10 | - const JSON = 'json'; | |
| 7 | + const SERIALIZED = 'serialized'; | |
| 8 | + const CSV = 'csv'; | |
| 9 | + const XML = 'xml'; | |
| 10 | + const JSON = 'json'; | |
| 11 | 11 | } | 
| @@ -20,426 +20,426 @@ | ||
| 20 | 20 | |
| 21 | 21 | class OptimizationProblemUntTests extends \PHPUnit\Framework\TestCase | 
| 22 | 22 |  { | 
| 23 | - public static $problem; | |
| 24 | - | |
| 25 | - public static $createdProblems = []; | |
| 26 | - public static $addresses = []; | |
| 27 | - | |
| 28 | - public static function setUpBeforeClass() | |
| 29 | -    { | |
| 30 | -        if (Constants::API_KEY == Constants::DEMO_API_KEY) { | |
| 31 | -            $className = str_replace('UnitTestFiles\\Test\\','',get_class()); | |
| 32 | - self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); | |
| 33 | - } | |
| 34 | - | |
| 35 | - Route4Me::setApiKey(Constants::API_KEY); | |
| 36 | - | |
| 37 | - //region Prepae Addresses | |
| 38 | - $addresses = []; | |
| 39 | - $addresses[] = Address::fromArray([ | |
| 40 | - 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', | |
| 41 | - 'is_depot' => true, | |
| 42 | - 'lat' => 30.159341812134, | |
| 43 | - 'lng' => -81.538619995117, | |
| 44 | - 'time' => 300, | |
| 45 | - 'time_window_start' => 28800, | |
| 46 | - 'time_window_end' => 32400, | |
| 47 | - ]); | |
| 48 | - | |
| 49 | - $addresses[] = Address::fromArray([ | |
| 50 | - 'address' => '214 Edgewater Branch Drive 32259', | |
| 51 | - 'lat' => 30.103567123413, | |
| 52 | - 'lng' => -81.595352172852, | |
| 53 | - 'time' => 300, | |
| 54 | - 'time_window_start' => 36000, | |
| 55 | - 'time_window_end' => 37200, | |
| 56 | - ]); | |
| 57 | - | |
| 58 | - $addresses[] = Address::fromArray([ | |
| 59 | - 'address' => '756 eagle point dr 32092', | |
| 60 | - 'lat' => 30.046422958374, | |
| 61 | - 'lng' => -81.508758544922, | |
| 62 | - 'time' => 300, | |
| 63 | - 'time_window_start' => 39600, | |
| 64 | - 'time_window_end' => 41400, | |
| 65 | - ]); | |
| 66 | - | |
| 67 | - $addresses[] = Address::fromArray([ | |
| 68 | - 'address' => '63 Stone Creek Cir St Johns, FL 32259, USA', | |
| 69 | - 'lat' => 30.048496, | |
| 70 | - 'lng' => -81.558716, | |
| 71 | - 'time' => 300, | |
| 72 | - 'time_window_start' => 43200, | |
| 73 | - 'time_window_end' => 45000, | |
| 74 | - ]); | |
| 75 | - | |
| 76 | - $addresses[] = Address::fromArray([ | |
| 77 | - 'address' => 'St Johns Florida 32259, USA', | |
| 78 | - 'lat' => 30.099642, | |
| 79 | - 'lng' => -81.547201, | |
| 80 | - 'time' => 300, | |
| 81 | - 'time_window_start' => 46800, | |
| 82 | - 'time_window_end' => 48600, | |
| 83 | - ]); | |
| 84 | - | |
| 85 | - $parameters = RouteParameters::fromArray([ | |
| 86 | - 'device_type' => DeviceType::IPAD, | |
| 87 | - 'disable_optimization' => false, | |
| 88 | -            'route_name'            => 'phpunit test '.date('Y-m-d H:i'), | |
| 89 | - ]); | |
| 90 | - //endregion | |
| 91 | - | |
| 92 | - $optimizationParameters = new OptimizationProblemParams(); | |
| 93 | - $optimizationParameters->setAddresses($addresses); | |
| 94 | - $optimizationParameters->setParameters($parameters); | |
| 95 | - | |
| 96 | - self::$createdProblems[] = OptimizationProblem::optimize($optimizationParameters); | |
| 97 | - | |
| 98 | - //region Extra Testing Addresses | |
| 99 | - $addresses = []; | |
| 100 | - $addresses[] = Address::fromArray([ | |
| 101 | - 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', | |
| 102 | - 'is_depot' => true, | |
| 103 | - 'lat' => 30.159341812134, | |
| 104 | - 'lng' => -81.538619995117, | |
| 105 | - 'time' => 300, | |
| 106 | - 'time_window_start' => 28800, | |
| 107 | - 'time_window_end' => 32400, | |
| 108 | - ]); | |
| 109 | - | |
| 110 | - $addresses[] = Address::fromArray([ | |
| 111 | - 'address' => '214 Edgewater Branch Drive 32259', | |
| 112 | - 'lat' => 30.103567123413, | |
| 113 | - 'lng' => -81.595352172852, | |
| 114 | - 'time' => 300, | |
| 115 | - 'time_window_start' => 36000, | |
| 116 | - 'time_window_end' => 37200, | |
| 117 | - ]); | |
| 118 | - | |
| 119 | - $addresses[] = Address::fromArray([ | |
| 120 | - 'address' => '756 eagle point dr 32092', | |
| 121 | - 'lat' => 30.046422958374, | |
| 122 | - 'lng' => -81.508758544922, | |
| 123 | - 'time' => 300, | |
| 124 | - 'time_window_start' => 39600, | |
| 125 | - 'time_window_end' => 41400, | |
| 126 | - ]); | |
| 127 | - //endregion | |
| 128 | - | |
| 129 | - self::$addresses = $addresses; | |
| 130 | - } | |
| 131 | - | |
| 132 | - public function testFromArray() | |
| 133 | -    { | |
| 134 | - $problem = self::$createdProblems[0]; | |
| 135 | - | |
| 136 | - $this->assertNotNull($problem); | |
| 137 | - $this->assertContainsOnlyInstancesOf(OptimizationProblem::class, [$problem]); | |
| 138 | - | |
| 139 | - $this->assertTrue(isset($problem->parameters)); | |
| 140 | - $this->assertContainsOnlyInstancesOf(RouteParameters::class, [$problem->parameters]); | |
| 141 | - | |
| 142 | - $this->assertTrue(isset($problem->addresses)); | |
| 143 | - $this->assertTrue(sizeof($problem->addresses)>0); | |
| 144 | - | |
| 145 | - $firstAddress = $problem->addresses[0]; | |
| 146 | - $this->assertContainsOnlyInstancesOf(Address::class, [$firstAddress]); | |
| 147 | - | |
| 148 | - $this->assertTrue(isset($problem->routes)); | |
| 149 | - $this->assertTrue(sizeof($problem->routes)>0); | |
| 150 | - | |
| 151 | - $firstRoute = $problem->routes[0]; | |
| 152 | - $this->assertContainsOnlyInstancesOf(Route::class, [$firstRoute]); | |
| 153 | - } | |
| 154 | - | |
| 155 | - public function testOptimize() | |
| 156 | -    { | |
| 157 | - $parameters = RouteParameters::fromArray([ | |
| 158 | - 'algorithm_type' => Algorithmtype::TSP, | |
| 159 | - 'device_type' => DeviceType::WEB, | |
| 160 | - 'distance_unit' => DistanceUnit::MILES, | |
| 161 | - 'optimize' => OptimizationType::DISTANCE, | |
| 162 | - 'route_max_duration' => 86400, | |
| 163 | - 'store_route' => true, | |
| 164 | - 'travel_mode' => TravelMode::DRIVING, | |
| 165 | - 'vehicle_capacity' => 1, | |
| 166 | - 'vehicle_max_distance_mi' => 10000, | |
| 167 | - 'route_name' => 'phpunit testOptimize', | |
| 168 | - ]); | |
| 169 | - | |
| 170 | - $optimizationParameters = new OptimizationProblemParams(); | |
| 171 | - $optimizationParameters->setAddresses(self::$addresses); | |
| 172 | - $optimizationParameters->setParameters($parameters); | |
| 173 | - | |
| 174 | - $problem = OptimizationProblem::optimize($optimizationParameters); | |
| 175 | - | |
| 176 | - self::$createdProblems[] = $problem; | |
| 177 | - | |
| 178 | - $this->assertNotNull($problem); | |
| 179 | -        $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 180 | - $this->assertNotNull($problem->getOptimizationId()); | |
| 181 | - $this->assertNotNull($problem->getRoutes()); | |
| 182 | - } | |
| 183 | - | |
| 184 | - public function testGet() | |
| 185 | -    { | |
| 186 | - $problem = OptimizationProblem::get([ | |
| 187 | - 'optimization_problem_id' => self::$createdProblems[0]->getOptimizationId(), | |
| 188 | - ]); | |
| 189 | - | |
| 190 | - $this->assertNotNull($problem); | |
| 191 | - $this->assertInstanceOf(OptimizationProblem::class, $problem); | |
| 192 | - $this->assertNotNull($problem->getRoutes()); | |
| 193 | - } | |
| 194 | - | |
| 195 | - public function testGetOptizationsByState() | |
| 196 | -    { | |
| 197 | - $problems = OptimizationProblem::get([ | |
| 198 | - 'state' => OptimizationStates::OPTIMIZED, | |
| 199 | - 'limit' => 5, | |
| 200 | - 'offset' => 0, | |
| 201 | - ]); | |
| 202 | - | |
| 203 | - $this->assertNotNull($problems); | |
| 204 | - $this->assertTrue(is_array($problems)); | |
| 205 | - $this->assertTrue(sizeof($problems)>0); | |
| 206 | - $this->assertInstanceOf(OptimizationProblem::class, $problems[0]); | |
| 207 | - | |
| 208 | -        foreach ($problems as $problem) { | |
| 209 | - $this->assertEquals(OptimizationStates::OPTIMIZED, $problem->state); | |
| 210 | - } | |
| 211 | - } | |
| 212 | - | |
| 213 | - public function testGetOptimizationIDsOnly() | |
| 214 | -    { | |
| 215 | -        $this->markTestSkipped('must be revisited.'); | |
| 23 | + public static $problem; | |
| 24 | + | |
| 25 | + public static $createdProblems = []; | |
| 26 | + public static $addresses = []; | |
| 27 | + | |
| 28 | + public static function setUpBeforeClass() | |
| 29 | +	{ | |
| 30 | +		if (Constants::API_KEY == Constants::DEMO_API_KEY) { | |
| 31 | +			$className = str_replace('UnitTestFiles\\Test\\','',get_class()); | |
| 32 | + self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); | |
| 33 | + } | |
| 34 | + | |
| 35 | + Route4Me::setApiKey(Constants::API_KEY); | |
| 36 | + | |
| 37 | + //region Prepae Addresses | |
| 38 | + $addresses = []; | |
| 39 | + $addresses[] = Address::fromArray([ | |
| 40 | + 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', | |
| 41 | + 'is_depot' => true, | |
| 42 | + 'lat' => 30.159341812134, | |
| 43 | + 'lng' => -81.538619995117, | |
| 44 | + 'time' => 300, | |
| 45 | + 'time_window_start' => 28800, | |
| 46 | + 'time_window_end' => 32400, | |
| 47 | + ]); | |
| 48 | + | |
| 49 | + $addresses[] = Address::fromArray([ | |
| 50 | + 'address' => '214 Edgewater Branch Drive 32259', | |
| 51 | + 'lat' => 30.103567123413, | |
| 52 | + 'lng' => -81.595352172852, | |
| 53 | + 'time' => 300, | |
| 54 | + 'time_window_start' => 36000, | |
| 55 | + 'time_window_end' => 37200, | |
| 56 | + ]); | |
| 57 | + | |
| 58 | + $addresses[] = Address::fromArray([ | |
| 59 | + 'address' => '756 eagle point dr 32092', | |
| 60 | + 'lat' => 30.046422958374, | |
| 61 | + 'lng' => -81.508758544922, | |
| 62 | + 'time' => 300, | |
| 63 | + 'time_window_start' => 39600, | |
| 64 | + 'time_window_end' => 41400, | |
| 65 | + ]); | |
| 66 | + | |
| 67 | + $addresses[] = Address::fromArray([ | |
| 68 | + 'address' => '63 Stone Creek Cir St Johns, FL 32259, USA', | |
| 69 | + 'lat' => 30.048496, | |
| 70 | + 'lng' => -81.558716, | |
| 71 | + 'time' => 300, | |
| 72 | + 'time_window_start' => 43200, | |
| 73 | + 'time_window_end' => 45000, | |
| 74 | + ]); | |
| 75 | + | |
| 76 | + $addresses[] = Address::fromArray([ | |
| 77 | + 'address' => 'St Johns Florida 32259, USA', | |
| 78 | + 'lat' => 30.099642, | |
| 79 | + 'lng' => -81.547201, | |
| 80 | + 'time' => 300, | |
| 81 | + 'time_window_start' => 46800, | |
| 82 | + 'time_window_end' => 48600, | |
| 83 | + ]); | |
| 84 | + | |
| 85 | + $parameters = RouteParameters::fromArray([ | |
| 86 | + 'device_type' => DeviceType::IPAD, | |
| 87 | + 'disable_optimization' => false, | |
| 88 | +			'route_name'            => 'phpunit test '.date('Y-m-d H:i'), | |
| 89 | + ]); | |
| 90 | + //endregion | |
| 91 | + | |
| 92 | + $optimizationParameters = new OptimizationProblemParams(); | |
| 93 | + $optimizationParameters->setAddresses($addresses); | |
| 94 | + $optimizationParameters->setParameters($parameters); | |
| 95 | + | |
| 96 | + self::$createdProblems[] = OptimizationProblem::optimize($optimizationParameters); | |
| 97 | + | |
| 98 | + //region Extra Testing Addresses | |
| 99 | + $addresses = []; | |
| 100 | + $addresses[] = Address::fromArray([ | |
| 101 | + 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', | |
| 102 | + 'is_depot' => true, | |
| 103 | + 'lat' => 30.159341812134, | |
| 104 | + 'lng' => -81.538619995117, | |
| 105 | + 'time' => 300, | |
| 106 | + 'time_window_start' => 28800, | |
| 107 | + 'time_window_end' => 32400, | |
| 108 | + ]); | |
| 109 | + | |
| 110 | + $addresses[] = Address::fromArray([ | |
| 111 | + 'address' => '214 Edgewater Branch Drive 32259', | |
| 112 | + 'lat' => 30.103567123413, | |
| 113 | + 'lng' => -81.595352172852, | |
| 114 | + 'time' => 300, | |
| 115 | + 'time_window_start' => 36000, | |
| 116 | + 'time_window_end' => 37200, | |
| 117 | + ]); | |
| 118 | + | |
| 119 | + $addresses[] = Address::fromArray([ | |
| 120 | + 'address' => '756 eagle point dr 32092', | |
| 121 | + 'lat' => 30.046422958374, | |
| 122 | + 'lng' => -81.508758544922, | |
| 123 | + 'time' => 300, | |
| 124 | + 'time_window_start' => 39600, | |
| 125 | + 'time_window_end' => 41400, | |
| 126 | + ]); | |
| 127 | + //endregion | |
| 128 | + | |
| 129 | + self::$addresses = $addresses; | |
| 130 | + } | |
| 131 | + | |
| 132 | + public function testFromArray() | |
| 133 | +	{ | |
| 134 | + $problem = self::$createdProblems[0]; | |
| 135 | + | |
| 136 | + $this->assertNotNull($problem); | |
| 137 | + $this->assertContainsOnlyInstancesOf(OptimizationProblem::class, [$problem]); | |
| 138 | + | |
| 139 | + $this->assertTrue(isset($problem->parameters)); | |
| 140 | + $this->assertContainsOnlyInstancesOf(RouteParameters::class, [$problem->parameters]); | |
| 141 | + | |
| 142 | + $this->assertTrue(isset($problem->addresses)); | |
| 143 | + $this->assertTrue(sizeof($problem->addresses)>0); | |
| 144 | + | |
| 145 | + $firstAddress = $problem->addresses[0]; | |
| 146 | + $this->assertContainsOnlyInstancesOf(Address::class, [$firstAddress]); | |
| 147 | + | |
| 148 | + $this->assertTrue(isset($problem->routes)); | |
| 149 | + $this->assertTrue(sizeof($problem->routes)>0); | |
| 150 | + | |
| 151 | + $firstRoute = $problem->routes[0]; | |
| 152 | + $this->assertContainsOnlyInstancesOf(Route::class, [$firstRoute]); | |
| 153 | + } | |
| 154 | + | |
| 155 | + public function testOptimize() | |
| 156 | +	{ | |
| 157 | + $parameters = RouteParameters::fromArray([ | |
| 158 | + 'algorithm_type' => Algorithmtype::TSP, | |
| 159 | + 'device_type' => DeviceType::WEB, | |
| 160 | + 'distance_unit' => DistanceUnit::MILES, | |
| 161 | + 'optimize' => OptimizationType::DISTANCE, | |
| 162 | + 'route_max_duration' => 86400, | |
| 163 | + 'store_route' => true, | |
| 164 | + 'travel_mode' => TravelMode::DRIVING, | |
| 165 | + 'vehicle_capacity' => 1, | |
| 166 | + 'vehicle_max_distance_mi' => 10000, | |
| 167 | + 'route_name' => 'phpunit testOptimize', | |
| 168 | + ]); | |
| 169 | + | |
| 170 | + $optimizationParameters = new OptimizationProblemParams(); | |
| 171 | + $optimizationParameters->setAddresses(self::$addresses); | |
| 172 | + $optimizationParameters->setParameters($parameters); | |
| 173 | + | |
| 174 | + $problem = OptimizationProblem::optimize($optimizationParameters); | |
| 175 | + | |
| 176 | + self::$createdProblems[] = $problem; | |
| 177 | + | |
| 178 | + $this->assertNotNull($problem); | |
| 179 | +		$this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 180 | + $this->assertNotNull($problem->getOptimizationId()); | |
| 181 | + $this->assertNotNull($problem->getRoutes()); | |
| 182 | + } | |
| 183 | + | |
| 184 | + public function testGet() | |
| 185 | +	{ | |
| 186 | + $problem = OptimizationProblem::get([ | |
| 187 | + 'optimization_problem_id' => self::$createdProblems[0]->getOptimizationId(), | |
| 188 | + ]); | |
| 189 | + | |
| 190 | + $this->assertNotNull($problem); | |
| 191 | + $this->assertInstanceOf(OptimizationProblem::class, $problem); | |
| 192 | + $this->assertNotNull($problem->getRoutes()); | |
| 193 | + } | |
| 194 | + | |
| 195 | + public function testGetOptizationsByState() | |
| 196 | +	{ | |
| 197 | + $problems = OptimizationProblem::get([ | |
| 198 | + 'state' => OptimizationStates::OPTIMIZED, | |
| 199 | + 'limit' => 5, | |
| 200 | + 'offset' => 0, | |
| 201 | + ]); | |
| 202 | + | |
| 203 | + $this->assertNotNull($problems); | |
| 204 | + $this->assertTrue(is_array($problems)); | |
| 205 | + $this->assertTrue(sizeof($problems)>0); | |
| 206 | + $this->assertInstanceOf(OptimizationProblem::class, $problems[0]); | |
| 207 | + | |
| 208 | +		foreach ($problems as $problem) { | |
| 209 | + $this->assertEquals(OptimizationStates::OPTIMIZED, $problem->state); | |
| 210 | + } | |
| 211 | + } | |
| 212 | + | |
| 213 | + public function testGetOptimizationIDsOnly() | |
| 214 | +	{ | |
| 215 | +		$this->markTestSkipped('must be revisited.'); | |
| 216 | 216 | |
| 217 | - $problems = OptimizationProblem::get([ | |
| 218 | - 'id_only' => 1, | |
| 219 | - 'limit' => 5, | |
| 220 | - 'offset' => 0, | |
| 221 | - ]); | |
| 217 | + $problems = OptimizationProblem::get([ | |
| 218 | + 'id_only' => 1, | |
| 219 | + 'limit' => 5, | |
| 220 | + 'offset' => 0, | |
| 221 | + ]); | |
| 222 | 222 | |
| 223 | - $this->assertNotNull($problems); | |
| 224 | - $this->assertTrue(is_array($problems)); | |
| 225 | - $this->assertTrue(sizeof($problems)>0); | |
| 226 | - } | |
| 223 | + $this->assertNotNull($problems); | |
| 224 | + $this->assertTrue(is_array($problems)); | |
| 225 | + $this->assertTrue(sizeof($problems)>0); | |
| 226 | + } | |
| 227 | 227 | |
| 228 | - public function testReoptimize() | |
| 229 | -    { | |
| 230 | - $optimizationProblemId = self::$createdProblems[0]->getOptimizationId(); | |
| 228 | + public function testReoptimize() | |
| 229 | +	{ | |
| 230 | + $optimizationProblemId = self::$createdProblems[0]->getOptimizationId(); | |
| 231 | 231 | |
| 232 | - $optimizationProblem = new OptimizationProblem(); | |
| 232 | + $optimizationProblem = new OptimizationProblem(); | |
| 233 | 233 | |
| 234 | - $problem = $optimizationProblem->reoptimize(['optimization_problem_id' => $optimizationProblemId]); | |
| 234 | + $problem = $optimizationProblem->reoptimize(['optimization_problem_id' => $optimizationProblemId]); | |
| 235 | 235 | |
| 236 | - $this->assertNotNull($problem); | |
| 236 | + $this->assertNotNull($problem); | |
| 237 | 237 | |
| 238 | - $this->assertInstanceOf( | |
| 239 | - OptimizationProblem::class, | |
| 240 | - OptimizationProblem::fromArray($problem)); | |
| 241 | - } | |
| 238 | + $this->assertInstanceOf( | |
| 239 | + OptimizationProblem::class, | |
| 240 | + OptimizationProblem::fromArray($problem)); | |
| 241 | + } | |
| 242 | 242 | |
| 243 | - public function testUpdate() | |
| 244 | -    { | |
| 245 | - $problem = self::$createdProblems[0]; | |
| 243 | + public function testUpdate() | |
| 244 | +	{ | |
| 245 | + $problem = self::$createdProblems[0]; | |
| 246 | 246 | |
| 247 | - $initialAddresses = sizeof($problem->addresses); | |
| 248 | - | |
| 249 | - $extraAddresses = []; | |
| 247 | + $initialAddresses = sizeof($problem->addresses); | |
| 248 | + | |
| 249 | + $extraAddresses = []; | |
| 250 | 250 | |
| 251 | - $extraAddresses[] = self::$addresses[1]->toArray(); | |
| 252 | - $extraAddresses[] = self::$addresses[2]->toArray(); | |
| 251 | + $extraAddresses[] = self::$addresses[1]->toArray(); | |
| 252 | + $extraAddresses[] = self::$addresses[2]->toArray(); | |
| 253 | 253 | |
| 254 | - $OptimizationParameters = OptimizationProblem::fromArray([ | |
| 255 | - 'optimization_problem_id' => $problem->optimization_problem_id, | |
| 256 | - 'addresses' => $extraAddresses, | |
| 257 | - 'reoptimize' => 1, | |
| 258 | - ]); | |
| 254 | + $OptimizationParameters = OptimizationProblem::fromArray([ | |
| 255 | + 'optimization_problem_id' => $problem->optimization_problem_id, | |
| 256 | + 'addresses' => $extraAddresses, | |
| 257 | + 'reoptimize' => 1, | |
| 258 | + ]); | |
| 259 | 259 | |
| 260 | - $result = OptimizationProblem::fromArray( | |
| 261 | - OptimizationProblem::update($OptimizationParameters) | |
| 262 | - ); | |
| 260 | + $result = OptimizationProblem::fromArray( | |
| 261 | + OptimizationProblem::update($OptimizationParameters) | |
| 262 | + ); | |
| 263 | 263 | |
| 264 | - $this->assertNotNull($result); | |
| 265 | - $this->assertTrue($result instanceof OptimizationProblem); | |
| 266 | - $this->assertTrue(sizeof($result->addresses)==$initialAddresses+2); | |
| 267 | - } | |
| 264 | + $this->assertNotNull($result); | |
| 265 | + $this->assertTrue($result instanceof OptimizationProblem); | |
| 266 | + $this->assertTrue(sizeof($result->addresses)==$initialAddresses+2); | |
| 267 | + } | |
| 268 | 268 | |
| 269 | - public function testGetRandomOptimizationId() | |
| 270 | -    { | |
| 269 | + public function testGetRandomOptimizationId() | |
| 270 | +	{ | |
| 271 | 271 | |
| 272 | - $optimization_problem_id = self::$createdProblems[0]->getRandomOptimizationId(0, 10); | |
| 272 | + $optimization_problem_id = self::$createdProblems[0]->getRandomOptimizationId(0, 10); | |
| 273 | 273 | |
| 274 | - $this->assertNotNull($optimization_problem_id); | |
| 275 | - $this->assertTrue(strlen($optimization_problem_id)==32); | |
| 274 | + $this->assertNotNull($optimization_problem_id); | |
| 275 | + $this->assertTrue(strlen($optimization_problem_id)==32); | |
| 276 | 276 | |
| 277 | -        define('R_MD5_MATCH', '/^[a-fA-F0-9]{32}$/i'); | |
| 277 | +		define('R_MD5_MATCH', '/^[a-fA-F0-9]{32}$/i'); | |
| 278 | 278 | |
| 279 | - $this->assertTrue(preg_match(R_MD5_MATCH, $optimization_problem_id)==1); | |
| 280 | - } | |
| 279 | + $this->assertTrue(preg_match(R_MD5_MATCH, $optimization_problem_id)==1); | |
| 280 | + } | |
| 281 | 281 | |
| 282 | - public function testGetAddresses() | |
| 283 | -    { | |
| 284 | - $problem = self::$createdProblems[0]; | |
| 282 | + public function testGetAddresses() | |
| 283 | +	{ | |
| 284 | + $problem = self::$createdProblems[0]; | |
| 285 | 285 | |
| 286 | - $addresses = $problem->getAddresses($problem->optimization_problem_id); | |
| 286 | + $addresses = $problem->getAddresses($problem->optimization_problem_id); | |
| 287 | 287 | |
| 288 | - $this->assertNotNull($addresses); | |
| 289 | - $this->assertTrue(sizeof($addresses)>0); | |
| 288 | + $this->assertNotNull($addresses); | |
| 289 | + $this->assertTrue(sizeof($addresses)>0); | |
| 290 | 290 | |
| 291 | - $this->assertContainsOnlyInstancesOf(Address::class, [$addresses[0]]); | |
| 292 | - } | |
| 291 | + $this->assertContainsOnlyInstancesOf(Address::class, [$addresses[0]]); | |
| 292 | + } | |
| 293 | 293 | |
| 294 | - public function testGetRandomAddressFromOptimization() | |
| 295 | -    { | |
| 296 | - $problem = self::$createdProblems[0]; | |
| 294 | + public function testGetRandomAddressFromOptimization() | |
| 295 | +	{ | |
| 296 | + $problem = self::$createdProblems[0]; | |
| 297 | 297 | |
| 298 | - $address = $problem->getRandomAddressFromOptimization($problem->optimization_problem_id); | |
| 298 | + $address = $problem->getRandomAddressFromOptimization($problem->optimization_problem_id); | |
| 299 | 299 | |
| 300 | - $this->assertNotNull($address); | |
| 301 | - $this->assertContainsOnlyInstancesOf(Address::class, [$address]); | |
| 302 | - } | |
| 300 | + $this->assertNotNull($address); | |
| 301 | + $this->assertContainsOnlyInstancesOf(Address::class, [$address]); | |
| 302 | + } | |
| 303 | 303 | |
| 304 | - public function testRemoveAddress() | |
| 305 | -    { | |
| 306 | - $problem = self::$createdProblems[0]; | |
| 304 | + public function testRemoveAddress() | |
| 305 | +	{ | |
| 306 | + $problem = self::$createdProblems[0]; | |
| 307 | 307 | |
| 308 | - $address = end($problem->addresses); | |
| 308 | + $address = end($problem->addresses); | |
| 309 | 309 | |
| 310 | - $params = [ | |
| 311 | - 'optimization_problem_id' => $problem->optimization_problem_id, | |
| 312 | - 'route_destination_id' => $address->route_destination_id, | |
| 313 | - ]; | |
| 310 | + $params = [ | |
| 311 | + 'optimization_problem_id' => $problem->optimization_problem_id, | |
| 312 | + 'route_destination_id' => $address->route_destination_id, | |
| 313 | + ]; | |
| 314 | 314 | |
| 315 | - $result = $problem->removeAddress($params); | |
| 315 | + $result = $problem->removeAddress($params); | |
| 316 | 316 | |
| 317 | - $this->assertNotNull($result); | |
| 318 | - $this->assertTrue(isset($result['deleted'])); | |
| 319 | - $this->assertTrue(isset($result['route_destination_id'])); | |
| 320 | - $this->assertTrue($result['deleted']); | |
| 321 | - $this->assertEquals($address->route_destination_id, $result['route_destination_id']); | |
| 322 | - } | |
| 317 | + $this->assertNotNull($result); | |
| 318 | + $this->assertTrue(isset($result['deleted'])); | |
| 319 | + $this->assertTrue(isset($result['route_destination_id'])); | |
| 320 | + $this->assertTrue($result['deleted']); | |
| 321 | + $this->assertEquals($address->route_destination_id, $result['route_destination_id']); | |
| 322 | + } | |
| 323 | 323 | |
| 324 | - public function testRemoveOptimization() | |
| 325 | -    { | |
| 326 | - $problem = end(self::$createdProblems); | |
| 324 | + public function testRemoveOptimization() | |
| 325 | +	{ | |
| 326 | + $problem = end(self::$createdProblems); | |
| 327 | 327 | |
| 328 | - $params = [ | |
| 329 | - 'optimization_problem_ids' => [ | |
| 330 | - '0' => $problem->optimization_problem_id, | |
| 331 | - ], | |
| 332 | - 'redirect' => 0, | |
| 333 | - ]; | |
| 328 | + $params = [ | |
| 329 | + 'optimization_problem_ids' => [ | |
| 330 | + '0' => $problem->optimization_problem_id, | |
| 331 | + ], | |
| 332 | + 'redirect' => 0, | |
| 333 | + ]; | |
| 334 | 334 | |
| 335 | - $result = $problem->removeOptimization($params); | |
| 335 | + $result = $problem->removeOptimization($params); | |
| 336 | 336 | |
| 337 | - $this->assertNotNull($result); | |
| 338 | - $this->assertTrue(isset($result['status'])); | |
| 339 | - $this->assertTrue(isset($result['removed'])); | |
| 340 | - $this->assertTrue($result['status']); | |
| 341 | - $this->assertEquals(1, $result['removed']); | |
| 337 | + $this->assertNotNull($result); | |
| 338 | + $this->assertTrue(isset($result['status'])); | |
| 339 | + $this->assertTrue(isset($result['removed'])); | |
| 340 | + $this->assertTrue($result['status']); | |
| 341 | + $this->assertEquals(1, $result['removed']); | |
| 342 | 342 | |
| 343 | - self::$createdProblems[] = array_pop(self::$createdProblems); | |
| 344 | - } | |
| 343 | + self::$createdProblems[] = array_pop(self::$createdProblems); | |
| 344 | + } | |
| 345 | 345 | |
| 346 | - public function testGetHybridOptimization() | |
| 347 | -    { | |
| 348 | -        $this->markTestSkipped('must be revisited.'); | |
| 346 | + public function testGetHybridOptimization() | |
| 347 | +	{ | |
| 348 | +		$this->markTestSkipped('must be revisited.'); | |
| 349 | 349 | |
| 350 | - $ep = time() + 604800; | |
| 351 | -        $scheduleDate = date('Y-m-d', $ep); | |
| 350 | + $ep = time() + 604800; | |
| 351 | +		$scheduleDate = date('Y-m-d', $ep); | |
| 352 | 352 | |
| 353 | - $hybridParams = [ | |
| 354 | - 'target_date_string' => $scheduleDate, | |
| 355 | - 'timezone_offset_minutes' => 480, | |
| 356 | - ]; | |
| 353 | + $hybridParams = [ | |
| 354 | + 'target_date_string' => $scheduleDate, | |
| 355 | + 'timezone_offset_minutes' => 480, | |
| 356 | + ]; | |
| 357 | 357 | |
| 358 | - $optimization = new OptimizationProblem(); | |
| 358 | + $optimization = new OptimizationProblem(); | |
| 359 | 359 | |
| 360 | - $hybridOptimization = OptimizationProblem::fromArray( | |
| 361 | - $optimization->getHybridOptimization($hybridParams) | |
| 362 | - ); | |
| 360 | + $hybridOptimization = OptimizationProblem::fromArray( | |
| 361 | + $optimization->getHybridOptimization($hybridParams) | |
| 362 | + ); | |
| 363 | 363 | |
| 364 | - $this->assertNotNull($hybridOptimization); | |
| 365 | - $this->assertContainsOnlyInstancesOf(OptimizationProblem::class, [$hybridOptimization]); | |
| 364 | + $this->assertNotNull($hybridOptimization); | |
| 365 | + $this->assertContainsOnlyInstancesOf(OptimizationProblem::class, [$hybridOptimization]); | |
| 366 | 366 | |
| 367 | - self::$createdProblems[] = $hybridOptimization; | |
| 368 | - } | |
| 367 | + self::$createdProblems[] = $hybridOptimization; | |
| 368 | + } | |
| 369 | 369 | |
| 370 | - public function testAddDepotsToHybrid() | |
| 371 | -    { | |
| 372 | -        $this->markTestSkipped('must be revisited.'); | |
| 370 | + public function testAddDepotsToHybrid() | |
| 371 | +	{ | |
| 372 | +		$this->markTestSkipped('must be revisited.'); | |
| 373 | 373 | |
| 374 | - $ep = time() + 604800; | |
| 375 | -        $scheduleDate = date('Y-m-d', $ep); | |
| 374 | + $ep = time() + 604800; | |
| 375 | +		$scheduleDate = date('Y-m-d', $ep); | |
| 376 | 376 | |
| 377 | - $hybridParams = [ | |
| 378 | - 'target_date_string' => $scheduleDate, | |
| 379 | - 'timezone_offset_minutes' => 480, | |
| 380 | - ]; | |
| 377 | + $hybridParams = [ | |
| 378 | + 'target_date_string' => $scheduleDate, | |
| 379 | + 'timezone_offset_minutes' => 480, | |
| 380 | + ]; | |
| 381 | 381 | |
| 382 | - $optimization = new OptimizationProblem(); | |
| 382 | + $optimization = new OptimizationProblem(); | |
| 383 | 383 | |
| 384 | - $hybridOptimization = OptimizationProblem::fromArray( | |
| 385 | - $optimization->getHybridOptimization($hybridParams) | |
| 386 | - ); | |
| 384 | + $hybridOptimization = OptimizationProblem::fromArray( | |
| 385 | + $optimization->getHybridOptimization($hybridParams) | |
| 386 | + ); | |
| 387 | 387 | |
| 388 | - $this->assertNotNull($hybridOptimization); | |
| 389 | - $this->assertContainsOnlyInstancesOf(OptimizationProblem::class, [$hybridOptimization]); | |
| 388 | + $this->assertNotNull($hybridOptimization); | |
| 389 | + $this->assertContainsOnlyInstancesOf(OptimizationProblem::class, [$hybridOptimization]); | |
| 390 | 390 | |
| 391 | - self::$createdProblems[] = $hybridOptimization; | |
| 391 | + self::$createdProblems[] = $hybridOptimization; | |
| 392 | 392 | |
| 393 | - $depotAddresses = []; | |
| 393 | + $depotAddresses = []; | |
| 394 | 394 | |
| 395 | - $depotsParams = [ | |
| 396 | - 'optimization_problem_id' => $hybridOptimization->optimization_problem_id, | |
| 397 | - 'delete_old_depots' => true, | |
| 398 | - ]; | |
| 395 | + $depotsParams = [ | |
| 396 | + 'optimization_problem_id' => $hybridOptimization->optimization_problem_id, | |
| 397 | + 'delete_old_depots' => true, | |
| 398 | + ]; | |
| 399 | 399 | |
| 400 | - $depotAddresses[] = self::$addresses[0]; | |
| 401 | - $depotAddresses[] = self::$addresses[1]; | |
| 400 | + $depotAddresses[] = self::$addresses[0]; | |
| 401 | + $depotAddresses[] = self::$addresses[1]; | |
| 402 | 402 | |
| 403 | - $depotsParams['new_depots'] = $depotAddresses; | |
| 403 | + $depotsParams['new_depots'] = $depotAddresses; | |
| 404 | 404 | |
| 405 | - $resultDepots = $hybridOptimization->addDepotsToHybrid($depotsParams); | |
| 406 | - $this->assertNotNull($resultDepots); | |
| 405 | + $resultDepots = $hybridOptimization->addDepotsToHybrid($depotsParams); | |
| 406 | + $this->assertNotNull($resultDepots); | |
| 407 | 407 | |
| 408 | - $problemParams = [ | |
| 409 | - 'optimization_problem_id' => $hybridOptimization->optimization_problem_id, | |
| 410 | - ]; | |
| 408 | + $problemParams = [ | |
| 409 | + 'optimization_problem_id' => $hybridOptimization->optimization_problem_id, | |
| 410 | + ]; | |
| 411 | 411 | |
| 412 | - $problem = OptimizationProblem::fromArray( | |
| 413 | - OptimizationProblem::reoptimize($problemParams) | |
| 414 | - ); | |
| 412 | + $problem = OptimizationProblem::fromArray( | |
| 413 | + OptimizationProblem::reoptimize($problemParams) | |
| 414 | + ); | |
| 415 | 415 | |
| 416 | - $this->assertNotNull($problem); | |
| 417 | - $this->assertContainsOnlyInstancesOf(OptimizationProblem::class, [$problem]); | |
| 418 | - } | |
| 416 | + $this->assertNotNull($problem); | |
| 417 | + $this->assertContainsOnlyInstancesOf(OptimizationProblem::class, [$problem]); | |
| 418 | + } | |
| 419 | 419 | |
| 420 | - public static function tearDownAfterClass() | |
| 421 | -    { | |
| 422 | - $optimizationProblemIDs = []; | |
| 420 | + public static function tearDownAfterClass() | |
| 421 | +	{ | |
| 422 | + $optimizationProblemIDs = []; | |
| 423 | 423 | |
| 424 | -        foreach (self::$createdProblems as $problem) { | |
| 425 | - $optimizationProblemId = $problem->optimization_problem_id; | |
| 424 | +		foreach (self::$createdProblems as $problem) { | |
| 425 | + $optimizationProblemId = $problem->optimization_problem_id; | |
| 426 | 426 | |
| 427 | - $optimizationProblemIDs[] = $optimizationProblemId; | |
| 428 | - } | |
| 427 | + $optimizationProblemIDs[] = $optimizationProblemId; | |
| 428 | + } | |
| 429 | 429 | |
| 430 | - $params = [ | |
| 431 | - 'optimization_problem_ids' => $optimizationProblemIDs, | |
| 432 | - 'redirect' => 0, | |
| 433 | - ]; | |
| 430 | + $params = [ | |
| 431 | + 'optimization_problem_ids' => $optimizationProblemIDs, | |
| 432 | + 'redirect' => 0, | |
| 433 | + ]; | |
| 434 | 434 | |
| 435 | - $optProblem = new OptimizationProblem(); | |
| 435 | + $optProblem = new OptimizationProblem(); | |
| 436 | 436 | |
| 437 | - $result = $optProblem->removeOptimization($params); | |
| 437 | + $result = $optProblem->removeOptimization($params); | |
| 438 | 438 | |
| 439 | -        if ($result!=null && $result['status']==true) { | |
| 440 | - echo "The test optimization was removed <br>"; | |
| 441 | -        } else { | |
| 442 | - echo "Cannot remove the test optimization <br>"; | |
| 443 | - } | |
| 444 | - } | |
| 439 | +		if ($result!=null && $result['status']==true) { | |
| 440 | + echo "The test optimization was removed <br>"; | |
| 441 | +		} else { | |
| 442 | + echo "Cannot remove the test optimization <br>"; | |
| 443 | + } | |
| 444 | + } | |
| 445 | 445 | } | 
| 446 | 446 | \ No newline at end of file | 
| @@ -27,9 +27,9 @@ discard block | ||
| 27 | 27 | |
| 28 | 28 | public static function setUpBeforeClass() | 
| 29 | 29 |      { | 
| 30 | -        if (Constants::API_KEY == Constants::DEMO_API_KEY) { | |
| 31 | -            $className = str_replace('UnitTestFiles\\Test\\','',get_class()); | |
| 32 | - self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); | |
| 30 | +        if (Constants::API_KEY==Constants::DEMO_API_KEY) { | |
| 31 | +            $className = str_replace('UnitTestFiles\\Test\\', '', get_class()); | |
| 32 | +            self::markTestSkipped('PHPUnit will skip '.$className." class - it impossible run with demo API key"); | |
| 33 | 33 | } | 
| 34 | 34 | |
| 35 | 35 | Route4Me::setApiKey(Constants::API_KEY); | 
| @@ -263,7 +263,7 @@ discard block | ||
| 263 | 263 | |
| 264 | 264 | $this->assertNotNull($result); | 
| 265 | 265 | $this->assertTrue($result instanceof OptimizationProblem); | 
| 266 | - $this->assertTrue(sizeof($result->addresses)==$initialAddresses+2); | |
| 266 | + $this->assertTrue(sizeof($result->addresses)==$initialAddresses + 2); | |
| 267 | 267 | } | 
| 268 | 268 | |
| 269 | 269 | public function testGetRandomOptimizationId() | 
| @@ -7,37 +7,37 @@ | ||
| 7 | 7 | |
| 8 | 8 | class CommonUnitTests extends \PHPUnit\Framework\TestCase | 
| 9 | 9 |  { | 
| 10 | - public $address; | |
| 10 | + public $address; | |
| 11 | 11 | |
| 12 | - public function setUp() | |
| 13 | -    { | |
| 14 | - $this->address = [ | |
| 15 | - 'address' => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407', | |
| 16 | - 'lat' => 38.2513427734, | |
| 17 | - 'lng' => -77.5993652344, | |
| 18 | - 'time' => 300, | |
| 19 | - 'time_window_end' => 75600, | |
| 20 | - 'time_window_start' => 28800, | |
| 21 | - ]; | |
| 22 | - } | |
| 12 | + public function setUp() | |
| 13 | +	{ | |
| 14 | + $this->address = [ | |
| 15 | + 'address' => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407', | |
| 16 | + 'lat' => 38.2513427734, | |
| 17 | + 'lng' => -77.5993652344, | |
| 18 | + 'time' => 300, | |
| 19 | + 'time_window_end' => 75600, | |
| 20 | + 'time_window_start' => 28800, | |
| 21 | + ]; | |
| 22 | + } | |
| 23 | 23 | |
| 24 | - public function testCheckValue() | |
| 25 | -    { | |
| 26 | - $addressName = Common::getValue($this->address, 'address'); | |
| 27 | - $this->assertNotNull($addressName); | |
| 28 | - $this->assertEquals($addressName, '10609 Mystic Pointe Dr, Fredericksburg, VA 22407'); | |
| 29 | - } | |
| 24 | + public function testCheckValue() | |
| 25 | +	{ | |
| 26 | + $addressName = Common::getValue($this->address, 'address'); | |
| 27 | + $this->assertNotNull($addressName); | |
| 28 | + $this->assertEquals($addressName, '10609 Mystic Pointe Dr, Fredericksburg, VA 22407'); | |
| 29 | + } | |
| 30 | 30 | |
| 31 | - public function testCheckNonExistsValue() | |
| 32 | -    { | |
| 33 | - $badKey = Common::getValue($this->address, 'badkey'); | |
| 34 | - $this->assertNull($badKey); | |
| 35 | - } | |
| 31 | + public function testCheckNonExistsValue() | |
| 32 | +	{ | |
| 33 | + $badKey = Common::getValue($this->address, 'badkey'); | |
| 34 | + $this->assertNull($badKey); | |
| 35 | + } | |
| 36 | 36 | |
| 37 | - public function testCheckNonExistsValueWithDefaultValue() | |
| 38 | -    { | |
| 39 | - $memberId = Common::getValue($this->address, 'member_id', 1); | |
| 40 | - $this->assertNotNull($memberId); | |
| 41 | - $this->assertEquals($memberId, 1); | |
| 42 | - } | |
| 37 | + public function testCheckNonExistsValueWithDefaultValue() | |
| 38 | +	{ | |
| 39 | + $memberId = Common::getValue($this->address, 'member_id', 1); | |
| 40 | + $this->assertNotNull($memberId); | |
| 41 | + $this->assertEquals($memberId, 1); | |
| 42 | + } | |
| 43 | 43 | } | 
| 44 | 44 | \ No newline at end of file | 
| @@ -8,187 +8,187 @@ | ||
| 8 | 8 | |
| 9 | 9 | class OrderCustomUserFieldsTests extends \PHPUnit\Framework\TestCase | 
| 10 | 10 |  { | 
| 11 | - public static $createdCustomUserFields = []; | |
| 12 | - | |
| 13 | - public static function setUpBeforeClass() | |
| 14 | -    { | |
| 15 | - Route4Me::setApiKey(Constants::API_KEY); | |
| 16 | - | |
| 17 | - $orderCustomField = new OrderCustomField(); | |
| 18 | - | |
| 19 | - $orderCustomFieldParameters = OrderCustomField::fromArray([]); | |
| 20 | - | |
| 21 | - $response = $orderCustomField->getOrderCustomUserFields($orderCustomFieldParameters); | |
| 22 | - | |
| 23 | - $field333Exists = false; | |
| 24 | - $field444Id = null; | |
| 25 | - | |
| 26 | -        foreach ($response as $userCustomField) { | |
| 27 | -            if ($userCustomField['order_custom_field_name']=='CustomField333') { | |
| 28 | - $field333Exists = true; | |
| 29 | - } | |
| 30 | - | |
| 31 | -            if ($userCustomField['order_custom_field_name']=='CustomField444') { | |
| 32 | - $field444Id = $userCustomField['order_custom_field_id']; | |
| 33 | - } | |
| 34 | - } | |
| 35 | - | |
| 36 | -        if (!$field333Exists) { | |
| 37 | - $orderCustomFieldParameters = OrderCustomField::fromArray([ | |
| 38 | - 'order_custom_field_name' => 'CustomField333', | |
| 39 | - 'order_custom_field_label' => 'Custom Field 333', | |
| 40 | - 'order_custom_field_type' => 'checkbox', | |
| 41 | - 'order_custom_field_type_info' => ['short_label' => 'cFl333'] | |
| 42 | - ]); | |
| 43 | - | |
| 44 | - $newField = $orderCustomField->addOrderCustomUserField($orderCustomFieldParameters); | |
| 45 | - | |
| 46 | -            if (!is_null($newField) && isset($newField['result']) && $newField['result']=='OK') { | |
| 47 | - self::$createdCustomUserFields[] = $newField['data']['order_custom_field_id']; | |
| 48 | - } | |
| 49 | - } | |
| 50 | - | |
| 51 | -        if ($field444Id!=null) { | |
| 52 | - $orderCustomFieldParameters = OrderCustomField::fromArray([ | |
| 53 | - 'order_custom_field_id' => $field444Id | |
| 54 | - ]); | |
| 55 | - | |
| 56 | - $response = $orderCustomField->removeOrderCustomUserField($orderCustomFieldParameters); | |
| 57 | - | |
| 58 | - if (!is_null($response) && | |
| 59 | - isset($response['result']) && | |
| 60 | - $response['result']=='OK' && | |
| 61 | -                $response['affected']==1) { | |
| 62 | - echo "The order custom user field $field444Id removed <br>"; | |
| 63 | - } | |
| 64 | - } | |
| 65 | - } | |
| 66 | - | |
| 67 | - public function testFromArray() | |
| 68 | -    { | |
| 69 | - $orderCustomFields = OrderCustomField::fromArray([ | |
| 70 | - 'order_custom_field_name' => 'CustomField4', | |
| 71 | - 'order_custom_field_label' => 'Custom Field 4', | |
| 72 | - 'order_custom_field_type' => 'checkbox', | |
| 73 | - 'order_custom_field_type_info' => ['short_label' => 'cFl4'] | |
| 74 | - ]); | |
| 75 | - | |
| 76 | -        $this->assertEquals('CustomField4', $orderCustomFields->order_custom_field_name); | |
| 77 | -        $this->assertEquals('Custom Field 4', $orderCustomFields->order_custom_field_label); | |
| 78 | -        $this->assertEquals('checkbox', $orderCustomFields->order_custom_field_type); | |
| 79 | - $this->assertEquals(['short_label' => 'cFl4'], $orderCustomFields->order_custom_field_type_info); | |
| 80 | - } | |
| 81 | - | |
| 82 | - public function testToArray() | |
| 83 | -    { | |
| 84 | - $orderCustomFields = OrderCustomField::fromArray([ | |
| 85 | - 'order_custom_field_name' => 'CustomField4', | |
| 86 | - 'order_custom_field_label' => 'Custom Field 4', | |
| 87 | - 'order_custom_field_type' => 'checkbox', | |
| 88 | - 'order_custom_field_type_info' => ['short_label' => 'cFl4'] | |
| 89 | - ]); | |
| 90 | - | |
| 91 | - $this->assertEquals($orderCustomFields->toArray(), | |
| 92 | - [ | |
| 93 | - 'order_custom_field_name' => 'CustomField4', | |
| 94 | - 'order_custom_field_label' => 'Custom Field 4', | |
| 95 | - 'order_custom_field_type' => 'checkbox', | |
| 96 | - 'order_custom_field_type_info' => ['short_label' => 'cFl4'] | |
| 97 | - ] | |
| 98 | - ); | |
| 99 | - } | |
| 100 | - | |
| 101 | - public function testGetOrderCustomUserFields() | |
| 102 | -    { | |
| 103 | - $orderCustomField = new OrderCustomField(); | |
| 104 | - | |
| 105 | - $orderCustomFieldParameters = OrderCustomField::fromArray([]); | |
| 106 | - | |
| 107 | - $response = $orderCustomField->getOrderCustomUserFields($orderCustomFieldParameters); | |
| 108 | - | |
| 109 | - $this->assertNotNull($response); | |
| 110 | - $this->assertTrue(is_array($response)); | |
| 111 | - $this->assertInstanceOf(OrderCustomField::class, OrderCustomField::fromArray($response[0])); | |
| 112 | - } | |
| 113 | - | |
| 114 | - public function testAddOrderCustomUserField() | |
| 115 | -    { | |
| 116 | - $orderCustomField = new OrderCustomField(); | |
| 117 | - | |
| 118 | - $orderCustomFieldParameters = OrderCustomField::fromArray([ | |
| 119 | - 'order_custom_field_name' => 'CustomField444', | |
| 120 | - 'order_custom_field_label' => 'Custom Field 444', | |
| 121 | - 'order_custom_field_type' => 'checkbox', | |
| 122 | - 'order_custom_field_type_info' => ['short_label' => 'cFl444'] | |
| 123 | - ]); | |
| 124 | - | |
| 125 | - $response = $orderCustomField->addOrderCustomUserField($orderCustomFieldParameters); | |
| 126 | - | |
| 127 | - $this->assertNotNull($response); | |
| 128 | - $this->assertTrue(isset($response['result'])); | |
| 129 | -        $this->assertEquals('OK', $response['result']); | |
| 130 | - | |
| 131 | - self::$createdCustomUserFields[] = $response['data']['order_custom_field_id']; | |
| 132 | - } | |
| 133 | - | |
| 134 | - public function testUpdateOrderCustomUserField() | |
| 135 | -    { | |
| 136 | - $orderCustomField = new OrderCustomField(); | |
| 137 | - | |
| 138 | - $orderCustomFieldParameters = OrderCustomField::fromArray([ | |
| 139 | - 'order_custom_field_id' => self::$createdCustomUserFields[0], | |
| 140 | - 'order_custom_field_label' => 'Custom Field 333 Updated', | |
| 141 | - 'order_custom_field_type' => 'checkbox', | |
| 142 | - 'order_custom_field_type_info' => ['short_label' => 'cFl333'] | |
| 143 | - ]); | |
| 144 | - | |
| 145 | - $response = $orderCustomField->updateOrderCustomUserField($orderCustomFieldParameters); | |
| 146 | - | |
| 147 | - $this->assertNotNull($response); | |
| 148 | - $this->assertTrue(isset($response['result'])); | |
| 149 | -        $this->assertEquals('OK', $response['result']); | |
| 150 | - | |
| 151 | -        $this->assertEquals('Custom Field 333 Updated', $response['data']['order_custom_field_label']); | |
| 152 | - } | |
| 153 | - | |
| 154 | - public function testRemoveOrderCustomUserField() | |
| 155 | -    { | |
| 156 | - $orderCustomField = new OrderCustomField(); | |
| 157 | - | |
| 158 | - $orderCustomFieldParameters = OrderCustomField::fromArray([ | |
| 159 | - 'order_custom_field_id' => self::$createdCustomUserFields[0] | |
| 160 | - ]); | |
| 161 | - | |
| 162 | - $response = $orderCustomField->removeOrderCustomUserField($orderCustomFieldParameters); | |
| 163 | - | |
| 164 | - $this->assertNotNull($response); | |
| 165 | - $this->assertTrue(isset($response['result'])); | |
| 166 | -        $this->assertEquals('OK', $response['result']); | |
| 167 | - $this->assertTrue(isset($response['affected'])); | |
| 168 | - $this->assertEquals(1, $response['affected']); | |
| 169 | - | |
| 170 | - array_shift(self::$createdCustomUserFields); | |
| 171 | - } | |
| 172 | - | |
| 173 | - public static function tearDownAfterClass() | |
| 174 | -    { | |
| 175 | -        if (sizeof(self::$createdCustomUserFields)>0) { | |
| 176 | - $orderCustomField = new OrderCustomField(); | |
| 177 | - | |
| 178 | -            foreach (self::$createdCustomUserFields as $customFieldId) { | |
| 179 | - $orderCustomFieldParameters = OrderCustomField::fromArray([ | |
| 180 | - 'order_custom_field_id' => $customFieldId | |
| 181 | - ]); | |
| 182 | - | |
| 183 | - $response = $orderCustomField->removeOrderCustomUserField($orderCustomFieldParameters); | |
| 184 | - | |
| 185 | - if (!is_null($response) && | |
| 186 | - isset($response['result']) && | |
| 187 | - $response['result']=='OK' && | |
| 188 | -                    $response['affected']==1) { | |
| 189 | - echo "The order custom user field $customFieldId removed <br>"; | |
| 190 | - } | |
| 191 | - } | |
| 192 | - } | |
| 193 | - } | |
| 11 | + public static $createdCustomUserFields = []; | |
| 12 | + | |
| 13 | + public static function setUpBeforeClass() | |
| 14 | +	{ | |
| 15 | + Route4Me::setApiKey(Constants::API_KEY); | |
| 16 | + | |
| 17 | + $orderCustomField = new OrderCustomField(); | |
| 18 | + | |
| 19 | + $orderCustomFieldParameters = OrderCustomField::fromArray([]); | |
| 20 | + | |
| 21 | + $response = $orderCustomField->getOrderCustomUserFields($orderCustomFieldParameters); | |
| 22 | + | |
| 23 | + $field333Exists = false; | |
| 24 | + $field444Id = null; | |
| 25 | + | |
| 26 | +		foreach ($response as $userCustomField) { | |
| 27 | +			if ($userCustomField['order_custom_field_name']=='CustomField333') { | |
| 28 | + $field333Exists = true; | |
| 29 | + } | |
| 30 | + | |
| 31 | +			if ($userCustomField['order_custom_field_name']=='CustomField444') { | |
| 32 | + $field444Id = $userCustomField['order_custom_field_id']; | |
| 33 | + } | |
| 34 | + } | |
| 35 | + | |
| 36 | +		if (!$field333Exists) { | |
| 37 | + $orderCustomFieldParameters = OrderCustomField::fromArray([ | |
| 38 | + 'order_custom_field_name' => 'CustomField333', | |
| 39 | + 'order_custom_field_label' => 'Custom Field 333', | |
| 40 | + 'order_custom_field_type' => 'checkbox', | |
| 41 | + 'order_custom_field_type_info' => ['short_label' => 'cFl333'] | |
| 42 | + ]); | |
| 43 | + | |
| 44 | + $newField = $orderCustomField->addOrderCustomUserField($orderCustomFieldParameters); | |
| 45 | + | |
| 46 | +			if (!is_null($newField) && isset($newField['result']) && $newField['result']=='OK') { | |
| 47 | + self::$createdCustomUserFields[] = $newField['data']['order_custom_field_id']; | |
| 48 | + } | |
| 49 | + } | |
| 50 | + | |
| 51 | +		if ($field444Id!=null) { | |
| 52 | + $orderCustomFieldParameters = OrderCustomField::fromArray([ | |
| 53 | + 'order_custom_field_id' => $field444Id | |
| 54 | + ]); | |
| 55 | + | |
| 56 | + $response = $orderCustomField->removeOrderCustomUserField($orderCustomFieldParameters); | |
| 57 | + | |
| 58 | + if (!is_null($response) && | |
| 59 | + isset($response['result']) && | |
| 60 | + $response['result']=='OK' && | |
| 61 | +				$response['affected']==1) { | |
| 62 | + echo "The order custom user field $field444Id removed <br>"; | |
| 63 | + } | |
| 64 | + } | |
| 65 | + } | |
| 66 | + | |
| 67 | + public function testFromArray() | |
| 68 | +	{ | |
| 69 | + $orderCustomFields = OrderCustomField::fromArray([ | |
| 70 | + 'order_custom_field_name' => 'CustomField4', | |
| 71 | + 'order_custom_field_label' => 'Custom Field 4', | |
| 72 | + 'order_custom_field_type' => 'checkbox', | |
| 73 | + 'order_custom_field_type_info' => ['short_label' => 'cFl4'] | |
| 74 | + ]); | |
| 75 | + | |
| 76 | +		$this->assertEquals('CustomField4', $orderCustomFields->order_custom_field_name); | |
| 77 | +		$this->assertEquals('Custom Field 4', $orderCustomFields->order_custom_field_label); | |
| 78 | +		$this->assertEquals('checkbox', $orderCustomFields->order_custom_field_type); | |
| 79 | + $this->assertEquals(['short_label' => 'cFl4'], $orderCustomFields->order_custom_field_type_info); | |
| 80 | + } | |
| 81 | + | |
| 82 | + public function testToArray() | |
| 83 | +	{ | |
| 84 | + $orderCustomFields = OrderCustomField::fromArray([ | |
| 85 | + 'order_custom_field_name' => 'CustomField4', | |
| 86 | + 'order_custom_field_label' => 'Custom Field 4', | |
| 87 | + 'order_custom_field_type' => 'checkbox', | |
| 88 | + 'order_custom_field_type_info' => ['short_label' => 'cFl4'] | |
| 89 | + ]); | |
| 90 | + | |
| 91 | + $this->assertEquals($orderCustomFields->toArray(), | |
| 92 | + [ | |
| 93 | + 'order_custom_field_name' => 'CustomField4', | |
| 94 | + 'order_custom_field_label' => 'Custom Field 4', | |
| 95 | + 'order_custom_field_type' => 'checkbox', | |
| 96 | + 'order_custom_field_type_info' => ['short_label' => 'cFl4'] | |
| 97 | + ] | |
| 98 | + ); | |
| 99 | + } | |
| 100 | + | |
| 101 | + public function testGetOrderCustomUserFields() | |
| 102 | +	{ | |
| 103 | + $orderCustomField = new OrderCustomField(); | |
| 104 | + | |
| 105 | + $orderCustomFieldParameters = OrderCustomField::fromArray([]); | |
| 106 | + | |
| 107 | + $response = $orderCustomField->getOrderCustomUserFields($orderCustomFieldParameters); | |
| 108 | + | |
| 109 | + $this->assertNotNull($response); | |
| 110 | + $this->assertTrue(is_array($response)); | |
| 111 | + $this->assertInstanceOf(OrderCustomField::class, OrderCustomField::fromArray($response[0])); | |
| 112 | + } | |
| 113 | + | |
| 114 | + public function testAddOrderCustomUserField() | |
| 115 | +	{ | |
| 116 | + $orderCustomField = new OrderCustomField(); | |
| 117 | + | |
| 118 | + $orderCustomFieldParameters = OrderCustomField::fromArray([ | |
| 119 | + 'order_custom_field_name' => 'CustomField444', | |
| 120 | + 'order_custom_field_label' => 'Custom Field 444', | |
| 121 | + 'order_custom_field_type' => 'checkbox', | |
| 122 | + 'order_custom_field_type_info' => ['short_label' => 'cFl444'] | |
| 123 | + ]); | |
| 124 | + | |
| 125 | + $response = $orderCustomField->addOrderCustomUserField($orderCustomFieldParameters); | |
| 126 | + | |
| 127 | + $this->assertNotNull($response); | |
| 128 | + $this->assertTrue(isset($response['result'])); | |
| 129 | +		$this->assertEquals('OK', $response['result']); | |
| 130 | + | |
| 131 | + self::$createdCustomUserFields[] = $response['data']['order_custom_field_id']; | |
| 132 | + } | |
| 133 | + | |
| 134 | + public function testUpdateOrderCustomUserField() | |
| 135 | +	{ | |
| 136 | + $orderCustomField = new OrderCustomField(); | |
| 137 | + | |
| 138 | + $orderCustomFieldParameters = OrderCustomField::fromArray([ | |
| 139 | + 'order_custom_field_id' => self::$createdCustomUserFields[0], | |
| 140 | + 'order_custom_field_label' => 'Custom Field 333 Updated', | |
| 141 | + 'order_custom_field_type' => 'checkbox', | |
| 142 | + 'order_custom_field_type_info' => ['short_label' => 'cFl333'] | |
| 143 | + ]); | |
| 144 | + | |
| 145 | + $response = $orderCustomField->updateOrderCustomUserField($orderCustomFieldParameters); | |
| 146 | + | |
| 147 | + $this->assertNotNull($response); | |
| 148 | + $this->assertTrue(isset($response['result'])); | |
| 149 | +		$this->assertEquals('OK', $response['result']); | |
| 150 | + | |
| 151 | +		$this->assertEquals('Custom Field 333 Updated', $response['data']['order_custom_field_label']); | |
| 152 | + } | |
| 153 | + | |
| 154 | + public function testRemoveOrderCustomUserField() | |
| 155 | +	{ | |
| 156 | + $orderCustomField = new OrderCustomField(); | |
| 157 | + | |
| 158 | + $orderCustomFieldParameters = OrderCustomField::fromArray([ | |
| 159 | + 'order_custom_field_id' => self::$createdCustomUserFields[0] | |
| 160 | + ]); | |
| 161 | + | |
| 162 | + $response = $orderCustomField->removeOrderCustomUserField($orderCustomFieldParameters); | |
| 163 | + | |
| 164 | + $this->assertNotNull($response); | |
| 165 | + $this->assertTrue(isset($response['result'])); | |
| 166 | +		$this->assertEquals('OK', $response['result']); | |
| 167 | + $this->assertTrue(isset($response['affected'])); | |
| 168 | + $this->assertEquals(1, $response['affected']); | |
| 169 | + | |
| 170 | + array_shift(self::$createdCustomUserFields); | |
| 171 | + } | |
| 172 | + | |
| 173 | + public static function tearDownAfterClass() | |
| 174 | +	{ | |
| 175 | +		if (sizeof(self::$createdCustomUserFields)>0) { | |
| 176 | + $orderCustomField = new OrderCustomField(); | |
| 177 | + | |
| 178 | +			foreach (self::$createdCustomUserFields as $customFieldId) { | |
| 179 | + $orderCustomFieldParameters = OrderCustomField::fromArray([ | |
| 180 | + 'order_custom_field_id' => $customFieldId | |
| 181 | + ]); | |
| 182 | + | |
| 183 | + $response = $orderCustomField->removeOrderCustomUserField($orderCustomFieldParameters); | |
| 184 | + | |
| 185 | + if (!is_null($response) && | |
| 186 | + isset($response['result']) && | |
| 187 | + $response['result']=='OK' && | |
| 188 | +					$response['affected']==1) { | |
| 189 | + echo "The order custom user field $customFieldId removed <br>"; | |
| 190 | + } | |
| 191 | + } | |
| 192 | + } | |
| 193 | + } | |
| 194 | 194 | } | 
| 195 | 195 | \ No newline at end of file | 
| @@ -24,848 +24,848 @@ | ||
| 24 | 24 | |
| 25 | 25 | class RouteExampleTests extends \PHPUnit\Framework\TestCase | 
| 26 | 26 |  { | 
| 27 | - public static $problem; | |
| 28 | - | |
| 29 | - public static $createdProblems = []; | |
| 30 | - public static $testRoutes = []; | |
| 31 | - public static $addresses = []; | |
| 32 | - | |
| 33 | - public static $removedOptimizationIDs = []; | |
| 34 | - public static $removedRouteIDs = []; | |
| 35 | - public static $removedVehicle; | |
| 36 | - | |
| 37 | - public static function setUpBeforeClass() | |
| 38 | -    { | |
| 39 | -        if (Constants::API_KEY == Constants::DEMO_API_KEY) { | |
| 40 | -            $className = str_replace('UnitTestFiles\\Test\\','',get_class()); | |
| 41 | - self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); | |
| 42 | - } | |
| 43 | - | |
| 44 | - Route4Me::setApiKey(Constants::API_KEY); | |
| 45 | - | |
| 46 | - //region Prepae Addresses | |
| 47 | - $addresses = []; | |
| 48 | - $addresses[] = Address::fromArray([ | |
| 49 | - 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', | |
| 50 | - 'is_depot' => true, | |
| 51 | - 'lat' => 30.159341812134, | |
| 52 | - 'lng' => -81.538619995117, | |
| 53 | - 'time' => 300, | |
| 54 | - 'time_window_start' => 28800, | |
| 55 | - 'time_window_end' => 32400, | |
| 56 | - ]); | |
| 57 | - | |
| 58 | - $addresses[] = Address::fromArray([ | |
| 59 | - 'address' => '214 Edgewater Branch Drive 32259', | |
| 60 | - 'lat' => 30.103567123413, | |
| 61 | - 'lng' => -81.595352172852, | |
| 62 | - 'time' => 300, | |
| 63 | - 'time_window_start' => 36000, | |
| 64 | - 'time_window_end' => 37200, | |
| 65 | - ]); | |
| 66 | - | |
| 67 | - $addresses[] = Address::fromArray([ | |
| 68 | - 'address' => '756 eagle point dr 32092', | |
| 69 | - 'lat' => 30.046422958374, | |
| 70 | - 'lng' => -81.508758544922, | |
| 71 | - 'time' => 300, | |
| 72 | - 'time_window_start' => 39600, | |
| 73 | - 'time_window_end' => 41400, | |
| 74 | - ]); | |
| 75 | - | |
| 76 | - $addresses[] = Address::fromArray([ | |
| 77 | - 'address' => '63 Stone Creek Cir St Johns, FL 32259, USA', | |
| 78 | - 'lat' => 30.048496, | |
| 79 | - 'lng' => -81.558716, | |
| 80 | - 'time' => 300, | |
| 81 | - 'time_window_start' => 43200, | |
| 82 | - 'time_window_end' => 45000, | |
| 83 | - ]); | |
| 84 | - | |
| 85 | - $addresses[] = Address::fromArray([ | |
| 86 | - 'address' => 'St Johns Florida 32259, USA', | |
| 87 | - 'lat' => 30.099642, | |
| 88 | - 'lng' => -81.547201, | |
| 89 | - 'time' => 300, | |
| 90 | - 'time_window_start' => 46800, | |
| 91 | - 'time_window_end' => 48600, | |
| 92 | - ]); | |
| 93 | - | |
| 94 | - $parameters = RouteParameters::fromArray([ | |
| 95 | - 'device_type' => DeviceType::IPAD, | |
| 96 | - 'disable_optimization' => false, | |
| 97 | -            'route_name'            => 'phpunit test '.date('Y-m-d H:i'), | |
| 98 | - ]); | |
| 99 | - //endregion | |
| 100 | - | |
| 101 | - $optimizationParameters = new OptimizationProblemParams(); | |
| 102 | - $optimizationParameters->setAddresses($addresses); | |
| 103 | - $optimizationParameters->setParameters($parameters); | |
| 104 | - | |
| 105 | - self::$createdProblems[] = OptimizationProblem::optimize($optimizationParameters); | |
| 106 | - | |
| 107 | - self::$testRoutes = self::$createdProblems[0]->routes; | |
| 108 | - | |
| 109 | - //region Extra Testing Addresses | |
| 110 | - $addresses = []; | |
| 111 | - $addresses[] = Address::fromArray([ | |
| 112 | - 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', | |
| 113 | - 'is_depot' => true, | |
| 114 | - 'lat' => 30.159341812134, | |
| 115 | - 'lng' => -81.538619995117, | |
| 116 | - 'time' => 300, | |
| 117 | - 'time_window_start' => 28800, | |
| 118 | - 'time_window_end' => 32400, | |
| 119 | - ]); | |
| 120 | - | |
| 121 | - $addresses[] = Address::fromArray([ | |
| 122 | - 'address' => '214 Edgewater Branch Drive 32259', | |
| 123 | - 'lat' => 30.103567123413, | |
| 124 | - 'lng' => -81.595352172852, | |
| 125 | - 'time' => 300, | |
| 126 | - 'time_window_start' => 36000, | |
| 127 | - 'time_window_end' => 37200, | |
| 128 | - ]); | |
| 129 | - | |
| 130 | - $addresses[] = Address::fromArray([ | |
| 131 | - 'address' => '756 eagle point dr 32092', | |
| 132 | - 'lat' => 30.046422958374, | |
| 133 | - 'lng' => -81.508758544922, | |
| 134 | - 'time' => 300, | |
| 135 | - 'time_window_start' => 39600, | |
| 136 | - 'time_window_end' => 41400, | |
| 137 | - ]); | |
| 138 | - //endregion | |
| 139 | - | |
| 140 | - self::$addresses = $addresses; | |
| 141 | - } | |
| 142 | - | |
| 143 | - public function testOptimizationWithBundledAddresses() | |
| 144 | -    { | |
| 145 | -        $this->markTestSkipped('The test requires special permission to use the address bundling feature.'); | |
| 146 | - | |
| 147 | - // Huge list of addresses | |
| 148 | - $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true); | |
| 149 | - | |
| 150 | - $addresses = []; | |
| 151 | -        foreach ($json as $address) { | |
| 152 | - $addresses[] = Address::fromArray($address); | |
| 153 | - } | |
| 154 | - | |
| 155 | - $bundling = new AddressBundling(); | |
| 156 | - | |
| 157 | - $bundling->mode = AddressBundlingModes\Mode::ADDRESS; | |
| 158 | - $bundling->merge_mode = AddressBundlingModes\FirstItemMode::KEEP_ORIGINAL; | |
| 159 | - $bundling->service_time_rules->first_item_mode = AddressBundlingModes\FirstItemMode::KEEP_ORIGINAL; | |
| 160 | - $bundling->service_time_rules->additional_items_mode = AddressBundlingModes\AdditionalItemsMode::KEEP_ORIGINAL; | |
| 161 | - | |
| 162 | - $parameters = RouteParameters::fromArray([ | |
| 163 | - 'algorithm_type' => Algorithmtype::TSP, | |
| 164 | - 'route_name' => 'Single Driver Multiple TimeWindows 50 Stops', | |
| 165 | - 'route_date' => time() + 24 * 60 * 60, | |
| 166 | - 'route_time' => 5 * 3600 + 30 * 60, | |
| 167 | - 'distance_unit' => DistanceUnit::MILES, | |
| 168 | - 'device_type' => DeviceType::WEB, | |
| 169 | - 'optimize' => OptimizationType::DISTANCE, | |
| 170 | - 'metric' => Metric::GEODESIC, | |
| 171 | - 'bundling' => $bundling, | |
| 172 | - ]); | |
| 173 | - | |
| 174 | - $optimizationParams = new OptimizationProblemParams(); | |
| 175 | - $optimizationParams->setAddresses($addresses); | |
| 176 | - $optimizationParams->setParameters($parameters); | |
| 177 | - | |
| 178 | - $problem = OptimizationProblem::optimize($optimizationParams); | |
| 179 | - | |
| 180 | - self::$createdProblems[] = $problem; | |
| 181 | - | |
| 182 | - $this->assertNotNull($problem); | |
| 183 | -        $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 184 | - $this->assertNotNull($problem->getOptimizationId()); | |
| 185 | - $this->assertNotNull($problem->getRoutes()); | |
| 186 | - } | |
| 187 | - | |
| 188 | - public function testGetScheduleCalendar() | |
| 189 | -    { | |
| 190 | - $now = new \DateTime(); | |
| 191 | - | |
| 192 | - $schedCalendarParams = new ScheduleCalendarParameters(); | |
| 193 | - | |
| 194 | - $schedCalendarParams->date_from_string = $now | |
| 195 | -            ->add(\DateInterval::createFromDateString('-5 days')) | |
| 196 | -            ->format('Y-m-d'); | |
| 197 | - $schedCalendarParams->date_to_string = $now | |
| 198 | -            ->add(\DateInterval::createFromDateString('5 days')) | |
| 199 | -            ->format('Y-m-d'); | |
| 200 | - $schedCalendarParams->orders = true; | |
| 201 | - $schedCalendarParams->ab = true; | |
| 202 | - $schedCalendarParams->routes_count = true; | |
| 203 | - | |
| 204 | - $scheduleCalendar = ScheduleCalendarResponse::fromArray( | |
| 205 | - $schedCalendarParams->getScheduleCalendar($schedCalendarParams) | |
| 206 | - ); | |
| 207 | - | |
| 208 | - $this->assertNotNull($scheduleCalendar); | |
| 209 | -        $this->assertInstanceOf('Route4Me\ScheduleCalendarResponse', $scheduleCalendar); | |
| 210 | - } | |
| 211 | - | |
| 212 | - public function testMergeRoutes() | |
| 213 | -    { | |
| 214 | - $route = new Route(); | |
| 215 | - | |
| 216 | - $routeIDs = [self::$testRoutes[0]->route_id]; | |
| 217 | - | |
| 218 | - $routeDuplicate = $route->duplicateRoute($routeIDs); | |
| 219 | - | |
| 220 | - $this->assertTrue(isset($routeDuplicate['status']), "Cannot created duplicate route"); | |
| 221 | - $this->assertTrue($routeDuplicate['status'], "Cannot created duplicate route"); | |
| 222 | - | |
| 223 | - $duplicatedRouteId = $routeDuplicate['route_ids'][0]; | |
| 224 | - | |
| 225 | - self::$removedRouteIDs[] = $duplicatedRouteId; | |
| 226 | - | |
| 227 | - $depot = self::$testRoutes[0]->addresses[0]; | |
| 228 | - | |
| 229 | - // Merge the selected routes | |
| 230 | - $params = [ | |
| 231 | - 'route_ids' => $routeIDs[0].','.$duplicatedRouteId, | |
| 232 | - 'depot_address' => $depot->address, | |
| 233 | - 'remove_origin' => false, | |
| 234 | - 'depot_lat' => $depot->lat, | |
| 235 | - 'depot_lng' => $depot->lng, | |
| 236 | - ]; | |
| 237 | - | |
| 238 | - $result = $route->mergeRoutes($params); | |
| 239 | - | |
| 240 | - $this->assertNotNull($result); | |
| 241 | - $this->assertTrue(isset($result['status']), "Cannot merge the routes"); | |
| 242 | - $this->assertTrue($result['status'], "Cannot merge the routes"); | |
| 243 | - $this->assertTrue(isset($result['optimization_problem_id']), "Cannot merge the routes"); | |
| 244 | - $this->assertEquals(32,strlen($result['optimization_problem_id']), "Cannot merge the routes"); | |
| 245 | - | |
| 246 | - self::$removedOptimizationIDs[] = $result['optimization_problem_id']; | |
| 247 | - } | |
| 248 | - | |
| 249 | - public function testMultipleDepotMultipleDriverFineTuning() | |
| 250 | -    { | |
| 251 | - // Huge list of addresses | |
| 252 | - $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_md_tw.json'), true); | |
| 253 | - $json = array_slice($json, 0, 19); | |
| 254 | - | |
| 255 | - $addresses = []; | |
| 256 | - | |
| 257 | -        foreach ($json as $address) { | |
| 258 | - $addresses[] = Address::fromArray($address); | |
| 259 | - } | |
| 260 | - | |
| 261 | - //region Optimization With Duration Priority FineTuning | |
| 262 | - $parameters = RouteParameters::fromArray([ | |
| 263 | -            'route_name'        => 'Optimization With Duration Priority FineTuning. '.date('Y-m-d H:i'), | |
| 264 | - 'algorithm_type' => AlgorithmType::CVRP_TW_MD, | |
| 265 | - 'route_time' => 23200, | |
| 266 | - 'optimize' => OptimizationType::TIME, | |
| 267 | - 'device_type' => DeviceType::WEB, | |
| 268 | - 'udu_distance_unit' => 'km', | |
| 269 | - 'route_max_duration' => 86400, | |
| 270 | - 'travel_mode' => TravelMode::DRIVING, | |
| 271 | - 'vehicle_capacity' => 30, | |
| 272 | - 'vehicle_max_distance_mi' => 10000, | |
| 273 | - 'rt' => true, | |
| 274 | - 'target_duration' => 100, | |
| 275 | - 'target_distance' => 0, | |
| 276 | - 'target_wait_by_tail_size' => 0 | |
| 277 | - | |
| 278 | - ]); | |
| 279 | - | |
| 280 | - $optimizationParams = new OptimizationProblemParams(); | |
| 281 | - $optimizationParams->setAddresses($addresses); | |
| 282 | - $optimizationParams->setParameters($parameters); | |
| 283 | - | |
| 284 | - $problems = OptimizationProblem::optimize($optimizationParams); | |
| 285 | - $this->assertTrue(!is_null($problems), "Cannot generate an optimization with duration priority fine-tuning"); | |
| 286 | - | |
| 287 | - self::$createdProblems[] = $problems; | |
| 288 | - | |
| 289 | - $routes=$problems->getRoutes(); | |
| 290 | - $this->assertTrue(sizeof($routes)==2, "The generated optimization hasn't two routes"); | |
| 291 | - | |
| 292 | - $totalTripDistanceByDuration = $routes[0]->trip_distance + $routes[1]->trip_distance; | |
| 293 | - $totalTripDurationByDuration = $routes[0]->route_duration_sec + $routes[1]->route_duration_sec; | |
| 294 | - $totalTripWaitingTimeByDuration = $routes[0]->total_wait_time + $routes[1]->total_wait_time; | |
| 295 | - | |
| 296 | - echo "Generated an optimization with the <b>duration</b> priority fine-tuning:<br>"; | |
| 297 | - echo " Total Trip Distance: $totalTripDistanceByDuration <br>"; | |
| 298 | - echo " Total Trip Duration: $totalTripDurationByDuration <br>"; | |
| 299 | - echo " Total Trip Waiting Time: $totalTripWaitingTimeByDuration <br><br><br>"; | |
| 300 | - | |
| 301 | - //endregion | |
| 302 | - | |
| 303 | - //region Optimization With Distance Priority FineTuning | |
| 304 | - $parameters = RouteParameters::fromArray([ | |
| 305 | -            'route_name'        => 'Optimization With Distance Priority FineTuning. '.date('Y-m-d H:i'), | |
| 306 | - 'algorithm_type' => AlgorithmType::CVRP_TW_SD, | |
| 307 | - 'route_time' => 23200, | |
| 308 | - 'optimize' => OptimizationType::TIME, | |
| 309 | - 'device_type' => DeviceType::WEB, | |
| 310 | - 'udu_distance_unit' => 'km', | |
| 311 | - 'route_max_duration' => 86400, | |
| 312 | - 'travel_mode' => TravelMode::DRIVING, | |
| 313 | - 'vehicle_capacity' => 30, | |
| 314 | - 'vehicle_max_distance_mi' => 10000, | |
| 315 | - 'rt' => true, | |
| 316 | - 'target_duration' => 0, | |
| 317 | - 'target_distance' => 100, | |
| 318 | - 'target_wait_by_tail_size' => 0 | |
| 319 | - ]); | |
| 320 | - | |
| 321 | - $optimizationParams = new OptimizationProblemParams(); | |
| 322 | - $optimizationParams->setAddresses($addresses); | |
| 323 | - $optimizationParams->setParameters($parameters); | |
| 324 | - | |
| 325 | - $problems = OptimizationProblem::optimize($optimizationParams); | |
| 326 | - $this->assertTrue(!is_null($problems), "Cannot generate an optimization with the distance priority fine-tuning"); | |
| 327 | - | |
| 328 | - self::$createdProblems[]=$problems; | |
| 329 | - | |
| 330 | - $routes=$problems->getRoutes(); | |
| 331 | - $this->assertTrue(sizeof($routes)==2, "The generated optimization hasn't two routes"); | |
| 332 | - | |
| 333 | - $totalTripDistanceByDistance = $routes[0]->trip_distance + $routes[1]->trip_distance; | |
| 334 | - $totalTripDurationByDistance = $routes[0]->route_duration_sec + $routes[1]->route_duration_sec; | |
| 335 | - $totalTripWaitingTimeByDistance = $routes[0]->total_wait_time + $routes[1]->total_wait_time; | |
| 336 | - | |
| 337 | - $this->assertTrue($totalTripDistanceByDistance>0); | |
| 338 | - $this->assertTrue($totalTripDurationByDistance>0); | |
| 339 | - $this->assertTrue($totalTripWaitingTimeByDistance>0); | |
| 340 | - } | |
| 341 | - | |
| 342 | - public function testMultipleDepotMultipleDriver() | |
| 343 | -    { | |
| 344 | - // Huge list of addresses | |
| 345 | - $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_md_tw.json'), true); | |
| 346 | - | |
| 347 | - $addresses = []; | |
| 348 | -        foreach ($json as $address) { | |
| 349 | - $addresses[] = Address::fromArray($address); | |
| 350 | - } | |
| 351 | - | |
| 352 | - $parameters = RouteParameters::fromArray([ | |
| 353 | - 'algorithm_type' => AlgorithmType::CVRP_TW_MD, | |
| 354 | - 'distance_unit' => DistanceUnit::MILES, | |
| 355 | - 'device_type' => DeviceType::WEB, | |
| 356 | - 'optimize' => OptimizationType::TIME, | |
| 357 | - 'metric' => Metric::MATRIX, | |
| 358 | - 'route_max_duration' => 86400 , | |
| 359 | - 'travel_mode' => TravelMode::DRIVING, | |
| 360 | - 'vehicle_capacity' => 50, | |
| 361 | - 'vehicle_max_distance_mi' => 10000, | |
| 362 | - ]); | |
| 363 | - | |
| 364 | - $optimizationParams = new OptimizationProblemParams(); | |
| 365 | - $optimizationParams->setAddresses($addresses); | |
| 366 | - $optimizationParams->setParameters($parameters); | |
| 367 | - | |
| 368 | - $problem = OptimizationProblem::optimize($optimizationParams); | |
| 369 | - | |
| 370 | - self::$createdProblems[] = $problem; | |
| 371 | - | |
| 372 | - $this->assertNotNull($problem); | |
| 373 | -        $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 374 | - $this->assertNotNull($problem->getOptimizationId()); | |
| 375 | - $this->assertNotNull($problem->getRoutes()); | |
| 376 | - $this->assertTrue(sizeof($problem->getRoutes())>1); | |
| 377 | - } | |
| 378 | - | |
| 379 | - public function testMultipleDepotMultipleDriverTimeWindow() | |
| 380 | -    { | |
| 381 | - $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_md_tw.json'), true); | |
| 382 | - | |
| 383 | - $addresses = []; | |
| 384 | - | |
| 385 | -        foreach ($json as $address) { | |
| 386 | - $addresses[] = Address::fromArray($address); | |
| 387 | - } | |
| 388 | - | |
| 389 | - $parameters = RouteParameters::fromArray([ | |
| 390 | - 'algorithm_type' => Algorithmtype::CVRP_TW_MD, | |
| 391 | - 'route_name' => 'Multiple Depot, Multiple Driver, Time Window', | |
| 392 | - 'route_date' => time() + 24 * 60 * 60, | |
| 393 | - 'route_time' => 60 * 60 * 7, | |
| 394 | - 'rt' => true, | |
| 395 | - 'distance_unit' => DistanceUnit::MILES, | |
| 396 | - 'device_type' => DeviceType::WEB, | |
| 397 | - 'optimize' => OptimizationType::TIME, | |
| 398 | - 'metric' => Metric::GEODESIC, | |
| 399 | - 'route_max_duration' => 86400 * 3, | |
| 400 | - 'travel_mode' => TravelMode::DRIVING, | |
| 401 | - 'vehicle_capacity' => 99, | |
| 402 | - 'vehicle_max_distance_mi' => 99999, | |
| 403 | - ]); | |
| 404 | - | |
| 405 | - $optimizationParams = new OptimizationProblemParams(); | |
| 406 | - $optimizationParams->setAddresses($addresses); | |
| 407 | - $optimizationParams->setParameters($parameters); | |
| 408 | - | |
| 409 | - $problem = OptimizationProblem::optimize($optimizationParams); | |
| 410 | - | |
| 411 | - self::$createdProblems[] = $problem; | |
| 412 | - | |
| 413 | - $this->assertNotNull($problem); | |
| 414 | -        $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 415 | - $this->assertNotNull($problem->getOptimizationId()); | |
| 416 | - $this->assertNotNull($problem->getRoutes()); | |
| 417 | - } | |
| 418 | - | |
| 419 | - public function testMultipleDepotMultipleDriverWith24StopsTimeWindow() | |
| 420 | -    { | |
| 421 | - // Huge list of addresses | |
| 422 | - $json = json_decode(file_get_contents(dirname(__FILE__).'/data/mdp_mdr_24stops_tw.json'), true); | |
| 423 | - | |
| 424 | - $addresses = []; | |
| 425 | -        foreach ($json as $address) { | |
| 426 | - $addresses[] = Address::fromArray($address); | |
| 427 | - } | |
| 428 | - | |
| 429 | - $addresses[7]->is_depot = true; | |
| 430 | - | |
| 431 | - $parameters = RouteParameters::fromArray([ | |
| 432 | - 'algorithm_type' => Algorithmtype::CVRP_TW_MD, | |
| 433 | - 'route_name' => 'Multiple Depot, Multiple Driver with 24 Stops, Time Window', | |
| 434 | - 'route_date' => time() + 24 * 60 * 60, | |
| 435 | - 'route_time' => 60 * 60 * 7, | |
| 436 | - 'distance_unit' => DistanceUnit::MILES, | |
| 437 | - 'device_type' => DeviceType::WEB, | |
| 438 | - 'optimize' => OptimizationType::TIME, | |
| 439 | - 'metric' => Metric::MATRIX, | |
| 440 | - 'route_max_duration' => 86400, | |
| 441 | - 'travel_mode' => TravelMode::DRIVING, | |
| 442 | - 'vehicle_capacity' => 5, | |
| 443 | - 'vehicle_max_distance_mi' => 10000, | |
| 444 | - ]); | |
| 445 | - | |
| 446 | - $optimizationParams = new OptimizationProblemParams(); | |
| 447 | - $optimizationParams->setAddresses($addresses); | |
| 448 | - $optimizationParams->setParameters($parameters); | |
| 449 | - | |
| 450 | - $problem = OptimizationProblem::optimize($optimizationParams); | |
| 451 | - | |
| 452 | - self::$createdProblems[] = $problem; | |
| 453 | - | |
| 454 | - $this->assertNotNull($problem); | |
| 455 | -        $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 456 | - $this->assertNotNull($problem->getOptimizationId()); | |
| 457 | - $this->assertNotNull($problem->getRoutes()); | |
| 458 | - $this->assertTrue(sizeof($problem->getRoutes())>1); | |
| 459 | - } | |
| 460 | - | |
| 461 | - public function testMultipleSeparateDepostMultipleDriver() | |
| 462 | -    { | |
| 463 | - // List of addresses | |
| 464 | - $jsonAddresses = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_only.json'), true); | |
| 465 | - | |
| 466 | - $addresses = []; | |
| 467 | -        foreach ($jsonAddresses as $address) { | |
| 468 | - $addresses[] = Address::fromArray($address); | |
| 469 | - } | |
| 470 | - | |
| 471 | - $jsonDepots = json_decode(file_get_contents(dirname(__FILE__).'/data/depots.json'), true); | |
| 472 | - | |
| 473 | - // List of depots | |
| 474 | - $depots = []; | |
| 475 | -        foreach ($jsonDepots as $depot) { | |
| 476 | - $depots[] = Address::fromArray($depot); | |
| 477 | - } | |
| 478 | - | |
| 479 | - $parameters = RouteParameters::fromArray([ | |
| 480 | -            'route_name'                => 'Multiple Depots Seprate Section '.date('Y-m-d H:i'), | |
| 481 | - 'algorithm_type' => AlgorithmType::CVRP_TW_MD, | |
| 482 | - 'distance_unit' => DistanceUnit::MILES, | |
| 483 | - 'device_type' => DeviceType::WEB, | |
| 484 | - 'optimize' => OptimizationType::TIME, | |
| 485 | - 'metric' => Metric::GEODESIC, | |
| 486 | - 'route_max_duration' => 86400 * 2, | |
| 487 | - 'travel_mode' => TravelMode::DRIVING, | |
| 488 | - 'vehicle_capacity' => 50, | |
| 489 | - 'vehicle_max_distance_mi' => 10000, | |
| 490 | - 'parts' => 50, | |
| 491 | - ]); | |
| 492 | - | |
| 493 | - $optimizationParams = new OptimizationProblemParams(); | |
| 494 | - $optimizationParams->setAddresses($addresses); | |
| 495 | - $optimizationParams->setDepots($depots); | |
| 496 | - $optimizationParams->setParameters($parameters); | |
| 497 | - | |
| 498 | - $problem = OptimizationProblem::optimize($optimizationParams); | |
| 499 | - | |
| 500 | - self::$createdProblems[] = $problem; | |
| 501 | - | |
| 502 | - $this->assertNotNull($problem); | |
| 503 | -        $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 504 | - $this->assertNotNull($problem->getOptimizationId()); | |
| 505 | - $this->assertNotNull($problem->getRoutes()); | |
| 506 | - } | |
| 507 | - | |
| 508 | - public function testOptimizationSingleDriverRoute10Stops() | |
| 509 | -    { | |
| 510 | - // Huge list of addresses | |
| 511 | - $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true); | |
| 512 | - $json = array_slice($json, 0, 10); | |
| 513 | - | |
| 514 | - $addresses = []; | |
| 515 | -        foreach ($json as $address) { | |
| 516 | - $addresses[] = Address::fromArray($address); | |
| 517 | - } | |
| 518 | - | |
| 519 | - $parameters = RouteParameters::fromArray([ | |
| 520 | - 'algorithm_type' => AlgorithmType::TSP, | |
| 521 | - 'distance_unit' => DistanceUnit::MILES, | |
| 522 | - 'device_type' => DeviceType::WEB, | |
| 523 | - 'optimize' => OptimizationType::DISTANCE, | |
| 524 | - 'travel_mode' => TravelMode::DRIVING, | |
| 525 | - 'route_max_duration' => 86400, | |
| 526 | - 'vehicle_capacity' => 1, | |
| 527 | - 'vehicle_max_distance_mi' => 10000, | |
| 528 | - ]); | |
| 529 | - | |
| 530 | - $optimizationParams = new OptimizationProblemParams(); | |
| 531 | - $optimizationParams->setAddresses($addresses); | |
| 532 | - $optimizationParams->setParameters($parameters); | |
| 533 | - | |
| 534 | - $problem = OptimizationProblem::optimize($optimizationParams); | |
| 535 | - | |
| 536 | - self::$createdProblems[] = $problem; | |
| 537 | - | |
| 538 | - $this->assertNotNull($problem); | |
| 539 | -        $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 540 | - $this->assertNotNull($problem->getOptimizationId()); | |
| 541 | - $this->assertNotNull($problem->getRoutes()); | |
| 542 | - } | |
| 543 | - | |
| 544 | - public function testRouteSlowDown() | |
| 545 | -    { | |
| 546 | - // Huge list of addresses | |
| 547 | - $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true); | |
| 548 | - $json = array_slice($json, 0, 10); | |
| 549 | - | |
| 550 | - $addresses = []; | |
| 551 | -        foreach ($json as $address) { | |
| 552 | - $addresses[] = Address::fromArray($address); | |
| 553 | - } | |
| 554 | - | |
| 555 | - $parameters = RouteParameters::fromArray([ | |
| 556 | - 'algorithm_type' => AlgorithmType::TSP, | |
| 557 | - 'distance_unit' => DistanceUnit::MILES, | |
| 558 | - 'device_type' => DeviceType::WEB, | |
| 559 | - 'optimize' => OptimizationType::DISTANCE, | |
| 560 | - 'travel_mode' => TravelMode::DRIVING, | |
| 561 | -            'route_name'                => 'SD 10 stops slowdown route '.date('Y-m-d H:i'), | |
| 562 | - 'route_max_duration' => 86400, | |
| 563 | - 'vehicle_capacity' => 1, | |
| 564 | - 'vehicle_max_distance_mi' => 10000, | |
| 565 | - 'slowdowns' => [ | |
| 566 | - 'service_time' => 15, | |
| 567 | - 'travel_time' => 20 | |
| 568 | - ], | |
| 569 | - ]); | |
| 570 | - | |
| 571 | - $optimizationParams = new OptimizationProblemParams(); | |
| 572 | - $optimizationParams->setAddresses($addresses); | |
| 573 | - $optimizationParams->setParameters($parameters); | |
| 574 | - | |
| 575 | - $problem = OptimizationProblem::optimize($optimizationParams); | |
| 576 | - | |
| 577 | - self::$createdProblems[] = $problem; | |
| 578 | - | |
| 579 | - $this->assertNotNull($problem); | |
| 580 | -        $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 581 | - $this->assertNotNull($problem->getOptimizationId()); | |
| 582 | - $this->assertNotNull($problem->parameters); | |
| 583 | - | |
| 584 | - $this->assertNotNull($problem->parameters->route_time_multiplier); | |
| 585 | - $this->assertNotNull($problem->parameters->route_service_time_multiplier); | |
| 586 | - $this->assertEquals(15, $problem->parameters->route_service_time_multiplier); | |
| 587 | - $this->assertEquals(20, $problem->parameters->route_time_multiplier); | |
| 588 | - } | |
| 589 | - | |
| 590 | - public function testSingleDriverRoundTrip() | |
| 591 | -    { | |
| 592 | - // Huge list of addresses | |
| 593 | - $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true); | |
| 594 | - $json = array_slice($json, 0, 16); | |
| 595 | - | |
| 596 | - $addresses = []; | |
| 597 | - | |
| 598 | -        foreach ($json as $address) { | |
| 599 | - $addresses[] = Address::fromArray($address); | |
| 600 | - } | |
| 601 | - | |
| 602 | - $parameters = RouteParameters::fromArray([ | |
| 603 | - 'algorithm_type' => AlgorithmType::TSP, | |
| 604 | - 'distance_unit' => DistanceUnit::MILES, | |
| 605 | - 'device_type' => DeviceType::WEB, | |
| 606 | - 'optimize' => OptimizationType::DISTANCE, | |
| 607 | - 'travel_mode' => TravelMode::DRIVING, | |
| 608 | - 'route_max_duration' => 86400, | |
| 609 | - 'vehicle_capacity' => 1, | |
| 610 | - 'vehicle_max_distance_mi' => 10000, | |
| 611 | - 'rt' => true, | |
| 612 | - ]); | |
| 613 | - | |
| 614 | - $optimizationParams = new OptimizationProblemParams(); | |
| 615 | - $optimizationParams->setAddresses($addresses); | |
| 616 | - $optimizationParams->setParameters($parameters); | |
| 617 | - | |
| 618 | - $problem = OptimizationProblem::optimize($optimizationParams); | |
| 619 | - | |
| 620 | - self::$createdProblems[] = $problem; | |
| 621 | - | |
| 622 | - $this->assertNotNull($problem); | |
| 623 | -        $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 624 | - $this->assertNotNull($problem->getOptimizationId()); | |
| 625 | - $this->assertNotNull($problem->getRoutes()); | |
| 626 | - $this->assertNotNull($problem->addresses); | |
| 627 | - | |
| 628 | - $firstAddress = $problem->routes[0]->addresses[0]; | |
| 629 | - $lastAddress = $problem->routes[0]->addresses[sizeof($problem->routes[0]->addresses)-1]; | |
| 630 | - | |
| 631 | - $this->assertEquals($firstAddress->route_destination_id, $lastAddress->route_destination_id); | |
| 632 | - } | |
| 633 | - | |
| 634 | - public function testSingleDepotMultipleDriverNoTimeWindow() | |
| 635 | -    { | |
| 636 | - // Huge list of addresses | |
| 637 | - $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true); | |
| 638 | - | |
| 639 | - $addresses = []; | |
| 640 | -        foreach ($json as $address) { | |
| 641 | - $addresses[] = Address::fromArray($address); | |
| 642 | - } | |
| 643 | - | |
| 644 | - $parameters = RouteParameters::fromArray([ | |
| 645 | - 'algorithm_type' => Algorithmtype::CVRP_TW_SD, | |
| 646 | - 'route_name' => 'Single Depot, Multiple Driver, No Time Window', | |
| 647 | - 'route_date' => time() + 24 * 60 * 60, | |
| 648 | - 'route_time' => 60 * 60 * 7, | |
| 649 | - 'rt' => true, | |
| 650 | - 'distance_unit' => DistanceUnit::MILES, | |
| 651 | - 'device_type' => DeviceType::WEB, | |
| 652 | - 'optimize' => OptimizationType::TIME, | |
| 653 | - 'metric' => Metric::GEODESIC, | |
| 654 | - 'route_max_duration' => 86400, | |
| 655 | - 'travel_mode' => TravelMode::DRIVING, | |
| 656 | - 'vehicle_capacity' => 20, | |
| 657 | - 'vehicle_max_distance_mi' => 99999, | |
| 658 | - 'parts' => 4, | |
| 659 | - ]); | |
| 660 | - | |
| 661 | - $optimizationParams = new OptimizationProblemParams(); | |
| 662 | - $optimizationParams->setAddresses($addresses); | |
| 663 | - $optimizationParams->setParameters($parameters); | |
| 664 | - | |
| 665 | - $problem = OptimizationProblem::optimize($optimizationParams); | |
| 666 | - | |
| 667 | - self::$createdProblems[] = $problem; | |
| 668 | - | |
| 669 | - $this->assertNotNull($problem); | |
| 670 | -        $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 671 | - $this->assertNotNull($problem->getOptimizationId()); | |
| 672 | - $this->assertNotNull($problem->getRoutes()); | |
| 673 | - | |
| 674 | - $this->assertNotNull(sizeof($problem->routes)>1); | |
| 675 | - } | |
| 676 | - | |
| 677 | - public function testSingleDriverMultipleTimeWindows() | |
| 678 | -    { | |
| 679 | - // Huge list of addresses | |
| 680 | - $json = json_decode(file_get_contents(dirname(__FILE__).'/data/mdp_mdr_24stops_tw.json'), true); | |
| 681 | - $json = array_slice($json, 0, 20); | |
| 682 | - | |
| 683 | - $addresses = []; | |
| 684 | -        foreach ($json as $address) { | |
| 685 | - $addresses[] = Address::fromArray($address); | |
| 686 | - } | |
| 687 | - | |
| 688 | - $parameters = RouteParameters::fromArray([ | |
| 689 | - 'algorithm_type' => Algorithmtype::TSP, | |
| 690 | -            'route_name'        => 'Single Driver Multiple TimeWindows 20 Stops '.date('Y-m-d H:i'), | |
| 691 | - 'route_date' => time() + 24 * 60 * 60, | |
| 692 | - 'route_time' => 5 * 3600 + 30 * 60, | |
| 693 | - 'distance_unit' => DistanceUnit::MILES, | |
| 694 | - 'device_type' => DeviceType::WEB, | |
| 695 | - 'optimize' => OptimizationType::TIME, | |
| 696 | - 'metric' => Metric::MATRIX, | |
| 697 | - ]); | |
| 698 | - | |
| 699 | - $optimizationParams = new OptimizationProblemParams(); | |
| 700 | - $optimizationParams->setAddresses($addresses); | |
| 701 | - $optimizationParams->setParameters($parameters); | |
| 702 | - | |
| 703 | - $problem = OptimizationProblem::optimize($optimizationParams); | |
| 704 | - | |
| 705 | - self::$createdProblems[] = $problem; | |
| 706 | - | |
| 707 | - $this->assertNotNull($problem); | |
| 708 | -        $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 709 | - $this->assertNotNull($problem->getOptimizationId()); | |
| 710 | - $this->assertNotNull($problem->getRoutes()); | |
| 711 | - | |
| 712 | - $this->assertNotNull(sizeof($problem->routes)>1); | |
| 713 | - } | |
| 714 | - | |
| 715 | - public function testTruckingSingleDriverMultipleTimeWindows() | |
| 716 | -    { | |
| 717 | - #region Create Medium Truck | |
| 718 | - | |
| 719 | - $vehicle = new Vehicle(); | |
| 720 | - | |
| 721 | - $vehicleParameters = Vehicle::fromArray([ | |
| 722 | - 'vehicle_name' => 'GMC TopKick C5500 Medium', | |
| 723 | - 'vehicle_alias' => 'GMC TopKick C5500 Medium', | |
| 724 | - 'vehicle_vin' => 'SAJXA01A06FN08012', | |
| 725 | - 'vehicle_license_plate' => 'CVH4561', | |
| 726 | - 'vehicle_model' => 'TopKick C5500', | |
| 727 | - 'vehicle_model_year' => 1995, | |
| 728 | - 'vehicle_year_acquired' => 2008, | |
| 729 | - 'vehicle_reg_country_id' => '223', | |
| 730 | - 'vehicle_make' => 'GMC', | |
| 731 | - 'vehicle_type_id' => 'pickup_truck', | |
| 732 | - 'vehicle_axle_count' => 2, | |
| 733 | - 'mpg_city' => 7, | |
| 734 | - 'mpg_highway' => 14, | |
| 735 | - 'fuel_type' => 'diesel', | |
| 736 | - 'height_inches' => 97, | |
| 737 | - 'height_metric' => 243, | |
| 738 | - 'weight_lb' => 19000, | |
| 739 | - 'maxWeightPerAxleGroupInPounds' => 9500, | |
| 740 | - 'max_weight_per_axle_group_metric' => 4300, | |
| 741 | - 'widthInInches' => 96, | |
| 742 | - 'width_metric' => 240, | |
| 743 | - 'lengthInInches' => 244, | |
| 744 | - 'length_metric' => 610, | |
| 745 | - 'Use53FootTrailerRouting' => 'YES', | |
| 746 | - 'UseTruckRestrictions' => 'YES', | |
| 747 | - 'DividedHighwayAvoidPreference' => 'NEUTRAL', | |
| 748 | - 'FreewayAvoidPreference' => 'NEUTRAL', | |
| 749 | - 'truck_config' => 'FULLSIZEVAN', | |
| 750 | - ]); | |
| 751 | - | |
| 752 | - $result = $vehicle->createVehicle($vehicleParameters); | |
| 753 | - | |
| 754 | - $this->assertNotNull($result); | |
| 755 | - $this->assertTrue(isset($result['status'])); | |
| 756 | - $this->assertTrue($result['status']); | |
| 757 | - $this->assertTrue(isset($result['vehicle_guid'])); | |
| 758 | - $vehicleId = $result['vehicle_guid']; | |
| 759 | - | |
| 760 | - self::$removedVehicle = $vehicleId; | |
| 761 | - | |
| 762 | - #endregion | |
| 763 | - // Huge list of addresses | |
| 764 | - $json = json_decode(file_get_contents(dirname(__FILE__).'/data/mdp_mdr_24stops_tw.json'), true); | |
| 765 | - $json = array_slice($json, 0, 18); | |
| 766 | - | |
| 767 | - $addresses = []; | |
| 768 | -        foreach ($json as $address) { | |
| 769 | - $addresses[] = Address::fromArray($address); | |
| 770 | - } | |
| 771 | - | |
| 772 | - $parameters = RouteParameters::fromArray([ | |
| 773 | - 'algorithm_type' => Algorithmtype::CVRP_TW_SD, | |
| 774 | -            'route_name'                => 'Trucking SD Multiple TW 18 Stops '.date('Y-m-d H:i'), | |
| 775 | - 'route_date' => time() + 24 * 60 * 60, | |
| 776 | - 'route_time' => 5 * 3600 + 30 * 60, | |
| 777 | - 'distance_unit' => DistanceUnit::MILES, | |
| 778 | - 'device_type' => DeviceType::WEB, | |
| 779 | - 'optimize' => OptimizationType::TIME_WITH_TRAFFIC, | |
| 780 | - 'metric' => Metric::MATRIX, | |
| 781 | - 'route_max_duration' => 8 * 3600 + 30 * 60, | |
| 782 | - 'vehicle_id' => $vehicleId, | |
| 783 | - 'travel_mode' => TravelMode::DRIVING, | |
| 784 | - 'vehicle_max_cargo_weight' => 30, | |
| 785 | - 'vehicle_capacity' => 10, | |
| 786 | - 'vehicle_max_distance_mi' => 10000, | |
| 787 | - 'trailer_weight_t' => 10, | |
| 788 | - 'weight_per_axle_t' => 10, | |
| 789 | - 'limited_weight_t' => 20, | |
| 790 | - 'rt' => true | |
| 791 | - ]); | |
| 792 | - | |
| 793 | - $optimizationParams = new OptimizationProblemParams(); | |
| 794 | - $optimizationParams->setAddresses($addresses); | |
| 795 | - $optimizationParams->setParameters($parameters); | |
| 796 | - | |
| 797 | - $problem = OptimizationProblem::optimize($optimizationParams); | |
| 798 | - | |
| 799 | - self::$createdProblems[] = $problem; | |
| 800 | - | |
| 801 | - $this->assertNotNull($problem); | |
| 802 | -        $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 803 | - $this->assertNotNull($problem->getOptimizationId()); | |
| 804 | - $this->assertNotNull($problem->getRoutes()); | |
| 805 | - | |
| 806 | - $this->assertNotNull(sizeof($problem->routes)>1); | |
| 807 | - } | |
| 808 | - | |
| 809 | - public static function tearDownAfterClass() | |
| 810 | -    { | |
| 811 | -        if (sizeof(self::$createdProblems)>0) { | |
| 812 | - $optimizationProblemIDs = []; | |
| 813 | - | |
| 814 | -            foreach (self::$createdProblems as $problem) { | |
| 815 | - $optimizationProblemId = $problem->optimization_problem_id; | |
| 816 | - | |
| 817 | - $optimizationProblemIDs[] = $optimizationProblemId; | |
| 818 | - } | |
| 819 | - | |
| 820 | -            if (sizeof(self::$removedOptimizationIDs)>0) { | |
| 821 | - $optimizationProblemIDs = array_merge($optimizationProblemIDs,self::$removedOptimizationIDs); | |
| 822 | - } | |
| 823 | - | |
| 824 | - $params = [ | |
| 825 | - 'optimization_problem_ids' => $optimizationProblemIDs, | |
| 826 | - 'redirect' => 0, | |
| 827 | - ]; | |
| 828 | - | |
| 829 | - $problem = new OptimizationProblem(); | |
| 830 | - $result = $problem->removeOptimization($params); | |
| 831 | - | |
| 832 | -            if ($result!=null && $result['status']==true) { | |
| 833 | - echo "The test optimizations were removed <br>"; | |
| 834 | -            } else { | |
| 835 | - echo "Cannot remove the test optimizations <br>"; | |
| 836 | - } | |
| 837 | - } | |
| 838 | - | |
| 839 | -        if (sizeof(self::$removedRouteIDs)>0) { | |
| 840 | - $route = new Route(); | |
| 841 | - | |
| 842 | -            $route_ids = join(',', self::$removedRouteIDs); | |
| 843 | - | |
| 844 | - $result = $route->deleteRoutes($route_ids); | |
| 845 | - | |
| 846 | -            if ($result!=null && $result['deleted']==true) { | |
| 847 | - echo "The test routes were removed <br>"; | |
| 848 | -            } else { | |
| 849 | - echo "Cannot remove the test routes <br>"; | |
| 850 | - } | |
| 851 | - } | |
| 852 | - | |
| 853 | -        if (!is_null(self::$removedVehicle!=null) && strlen(self::$removedVehicle)==32) { | |
| 854 | - | |
| 855 | - $vehicle = new Vehicle(); | |
| 856 | - | |
| 857 | - $vehicleParameters = Vehicle::fromArray([ | |
| 858 | - 'vehicle_id' => self::$removedVehicle, | |
| 859 | - ]); | |
| 860 | - | |
| 861 | - $result = $vehicle->removeVehicle($vehicleParameters); | |
| 862 | - | |
| 863 | -            if (!is_null($result)) { | |
| 864 | - echo "The vehicle ".$result['vehicle_id']." removed <br>"; | |
| 865 | -            } else { | |
| 866 | - echo "Cannot remove the vehicle ".$vehicle['vehicle_id']."<br>"; | |
| 867 | - } | |
| 868 | - | |
| 869 | - } | |
| 870 | - } | |
| 27 | + public static $problem; | |
| 28 | + | |
| 29 | + public static $createdProblems = []; | |
| 30 | + public static $testRoutes = []; | |
| 31 | + public static $addresses = []; | |
| 32 | + | |
| 33 | + public static $removedOptimizationIDs = []; | |
| 34 | + public static $removedRouteIDs = []; | |
| 35 | + public static $removedVehicle; | |
| 36 | + | |
| 37 | + public static function setUpBeforeClass() | |
| 38 | +	{ | |
| 39 | +		if (Constants::API_KEY == Constants::DEMO_API_KEY) { | |
| 40 | +			$className = str_replace('UnitTestFiles\\Test\\','',get_class()); | |
| 41 | + self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); | |
| 42 | + } | |
| 43 | + | |
| 44 | + Route4Me::setApiKey(Constants::API_KEY); | |
| 45 | + | |
| 46 | + //region Prepae Addresses | |
| 47 | + $addresses = []; | |
| 48 | + $addresses[] = Address::fromArray([ | |
| 49 | + 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', | |
| 50 | + 'is_depot' => true, | |
| 51 | + 'lat' => 30.159341812134, | |
| 52 | + 'lng' => -81.538619995117, | |
| 53 | + 'time' => 300, | |
| 54 | + 'time_window_start' => 28800, | |
| 55 | + 'time_window_end' => 32400, | |
| 56 | + ]); | |
| 57 | + | |
| 58 | + $addresses[] = Address::fromArray([ | |
| 59 | + 'address' => '214 Edgewater Branch Drive 32259', | |
| 60 | + 'lat' => 30.103567123413, | |
| 61 | + 'lng' => -81.595352172852, | |
| 62 | + 'time' => 300, | |
| 63 | + 'time_window_start' => 36000, | |
| 64 | + 'time_window_end' => 37200, | |
| 65 | + ]); | |
| 66 | + | |
| 67 | + $addresses[] = Address::fromArray([ | |
| 68 | + 'address' => '756 eagle point dr 32092', | |
| 69 | + 'lat' => 30.046422958374, | |
| 70 | + 'lng' => -81.508758544922, | |
| 71 | + 'time' => 300, | |
| 72 | + 'time_window_start' => 39600, | |
| 73 | + 'time_window_end' => 41400, | |
| 74 | + ]); | |
| 75 | + | |
| 76 | + $addresses[] = Address::fromArray([ | |
| 77 | + 'address' => '63 Stone Creek Cir St Johns, FL 32259, USA', | |
| 78 | + 'lat' => 30.048496, | |
| 79 | + 'lng' => -81.558716, | |
| 80 | + 'time' => 300, | |
| 81 | + 'time_window_start' => 43200, | |
| 82 | + 'time_window_end' => 45000, | |
| 83 | + ]); | |
| 84 | + | |
| 85 | + $addresses[] = Address::fromArray([ | |
| 86 | + 'address' => 'St Johns Florida 32259, USA', | |
| 87 | + 'lat' => 30.099642, | |
| 88 | + 'lng' => -81.547201, | |
| 89 | + 'time' => 300, | |
| 90 | + 'time_window_start' => 46800, | |
| 91 | + 'time_window_end' => 48600, | |
| 92 | + ]); | |
| 93 | + | |
| 94 | + $parameters = RouteParameters::fromArray([ | |
| 95 | + 'device_type' => DeviceType::IPAD, | |
| 96 | + 'disable_optimization' => false, | |
| 97 | +			'route_name'            => 'phpunit test '.date('Y-m-d H:i'), | |
| 98 | + ]); | |
| 99 | + //endregion | |
| 100 | + | |
| 101 | + $optimizationParameters = new OptimizationProblemParams(); | |
| 102 | + $optimizationParameters->setAddresses($addresses); | |
| 103 | + $optimizationParameters->setParameters($parameters); | |
| 104 | + | |
| 105 | + self::$createdProblems[] = OptimizationProblem::optimize($optimizationParameters); | |
| 106 | + | |
| 107 | + self::$testRoutes = self::$createdProblems[0]->routes; | |
| 108 | + | |
| 109 | + //region Extra Testing Addresses | |
| 110 | + $addresses = []; | |
| 111 | + $addresses[] = Address::fromArray([ | |
| 112 | + 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', | |
| 113 | + 'is_depot' => true, | |
| 114 | + 'lat' => 30.159341812134, | |
| 115 | + 'lng' => -81.538619995117, | |
| 116 | + 'time' => 300, | |
| 117 | + 'time_window_start' => 28800, | |
| 118 | + 'time_window_end' => 32400, | |
| 119 | + ]); | |
| 120 | + | |
| 121 | + $addresses[] = Address::fromArray([ | |
| 122 | + 'address' => '214 Edgewater Branch Drive 32259', | |
| 123 | + 'lat' => 30.103567123413, | |
| 124 | + 'lng' => -81.595352172852, | |
| 125 | + 'time' => 300, | |
| 126 | + 'time_window_start' => 36000, | |
| 127 | + 'time_window_end' => 37200, | |
| 128 | + ]); | |
| 129 | + | |
| 130 | + $addresses[] = Address::fromArray([ | |
| 131 | + 'address' => '756 eagle point dr 32092', | |
| 132 | + 'lat' => 30.046422958374, | |
| 133 | + 'lng' => -81.508758544922, | |
| 134 | + 'time' => 300, | |
| 135 | + 'time_window_start' => 39600, | |
| 136 | + 'time_window_end' => 41400, | |
| 137 | + ]); | |
| 138 | + //endregion | |
| 139 | + | |
| 140 | + self::$addresses = $addresses; | |
| 141 | + } | |
| 142 | + | |
| 143 | + public function testOptimizationWithBundledAddresses() | |
| 144 | +	{ | |
| 145 | +		$this->markTestSkipped('The test requires special permission to use the address bundling feature.'); | |
| 146 | + | |
| 147 | + // Huge list of addresses | |
| 148 | + $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true); | |
| 149 | + | |
| 150 | + $addresses = []; | |
| 151 | +		foreach ($json as $address) { | |
| 152 | + $addresses[] = Address::fromArray($address); | |
| 153 | + } | |
| 154 | + | |
| 155 | + $bundling = new AddressBundling(); | |
| 156 | + | |
| 157 | + $bundling->mode = AddressBundlingModes\Mode::ADDRESS; | |
| 158 | + $bundling->merge_mode = AddressBundlingModes\FirstItemMode::KEEP_ORIGINAL; | |
| 159 | + $bundling->service_time_rules->first_item_mode = AddressBundlingModes\FirstItemMode::KEEP_ORIGINAL; | |
| 160 | + $bundling->service_time_rules->additional_items_mode = AddressBundlingModes\AdditionalItemsMode::KEEP_ORIGINAL; | |
| 161 | + | |
| 162 | + $parameters = RouteParameters::fromArray([ | |
| 163 | + 'algorithm_type' => Algorithmtype::TSP, | |
| 164 | + 'route_name' => 'Single Driver Multiple TimeWindows 50 Stops', | |
| 165 | + 'route_date' => time() + 24 * 60 * 60, | |
| 166 | + 'route_time' => 5 * 3600 + 30 * 60, | |
| 167 | + 'distance_unit' => DistanceUnit::MILES, | |
| 168 | + 'device_type' => DeviceType::WEB, | |
| 169 | + 'optimize' => OptimizationType::DISTANCE, | |
| 170 | + 'metric' => Metric::GEODESIC, | |
| 171 | + 'bundling' => $bundling, | |
| 172 | + ]); | |
| 173 | + | |
| 174 | + $optimizationParams = new OptimizationProblemParams(); | |
| 175 | + $optimizationParams->setAddresses($addresses); | |
| 176 | + $optimizationParams->setParameters($parameters); | |
| 177 | + | |
| 178 | + $problem = OptimizationProblem::optimize($optimizationParams); | |
| 179 | + | |
| 180 | + self::$createdProblems[] = $problem; | |
| 181 | + | |
| 182 | + $this->assertNotNull($problem); | |
| 183 | +		$this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 184 | + $this->assertNotNull($problem->getOptimizationId()); | |
| 185 | + $this->assertNotNull($problem->getRoutes()); | |
| 186 | + } | |
| 187 | + | |
| 188 | + public function testGetScheduleCalendar() | |
| 189 | +	{ | |
| 190 | + $now = new \DateTime(); | |
| 191 | + | |
| 192 | + $schedCalendarParams = new ScheduleCalendarParameters(); | |
| 193 | + | |
| 194 | + $schedCalendarParams->date_from_string = $now | |
| 195 | +			->add(\DateInterval::createFromDateString('-5 days')) | |
| 196 | +			->format('Y-m-d'); | |
| 197 | + $schedCalendarParams->date_to_string = $now | |
| 198 | +			->add(\DateInterval::createFromDateString('5 days')) | |
| 199 | +			->format('Y-m-d'); | |
| 200 | + $schedCalendarParams->orders = true; | |
| 201 | + $schedCalendarParams->ab = true; | |
| 202 | + $schedCalendarParams->routes_count = true; | |
| 203 | + | |
| 204 | + $scheduleCalendar = ScheduleCalendarResponse::fromArray( | |
| 205 | + $schedCalendarParams->getScheduleCalendar($schedCalendarParams) | |
| 206 | + ); | |
| 207 | + | |
| 208 | + $this->assertNotNull($scheduleCalendar); | |
| 209 | +		$this->assertInstanceOf('Route4Me\ScheduleCalendarResponse', $scheduleCalendar); | |
| 210 | + } | |
| 211 | + | |
| 212 | + public function testMergeRoutes() | |
| 213 | +	{ | |
| 214 | + $route = new Route(); | |
| 215 | + | |
| 216 | + $routeIDs = [self::$testRoutes[0]->route_id]; | |
| 217 | + | |
| 218 | + $routeDuplicate = $route->duplicateRoute($routeIDs); | |
| 219 | + | |
| 220 | + $this->assertTrue(isset($routeDuplicate['status']), "Cannot created duplicate route"); | |
| 221 | + $this->assertTrue($routeDuplicate['status'], "Cannot created duplicate route"); | |
| 222 | + | |
| 223 | + $duplicatedRouteId = $routeDuplicate['route_ids'][0]; | |
| 224 | + | |
| 225 | + self::$removedRouteIDs[] = $duplicatedRouteId; | |
| 226 | + | |
| 227 | + $depot = self::$testRoutes[0]->addresses[0]; | |
| 228 | + | |
| 229 | + // Merge the selected routes | |
| 230 | + $params = [ | |
| 231 | + 'route_ids' => $routeIDs[0].','.$duplicatedRouteId, | |
| 232 | + 'depot_address' => $depot->address, | |
| 233 | + 'remove_origin' => false, | |
| 234 | + 'depot_lat' => $depot->lat, | |
| 235 | + 'depot_lng' => $depot->lng, | |
| 236 | + ]; | |
| 237 | + | |
| 238 | + $result = $route->mergeRoutes($params); | |
| 239 | + | |
| 240 | + $this->assertNotNull($result); | |
| 241 | + $this->assertTrue(isset($result['status']), "Cannot merge the routes"); | |
| 242 | + $this->assertTrue($result['status'], "Cannot merge the routes"); | |
| 243 | + $this->assertTrue(isset($result['optimization_problem_id']), "Cannot merge the routes"); | |
| 244 | + $this->assertEquals(32,strlen($result['optimization_problem_id']), "Cannot merge the routes"); | |
| 245 | + | |
| 246 | + self::$removedOptimizationIDs[] = $result['optimization_problem_id']; | |
| 247 | + } | |
| 248 | + | |
| 249 | + public function testMultipleDepotMultipleDriverFineTuning() | |
| 250 | +	{ | |
| 251 | + // Huge list of addresses | |
| 252 | + $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_md_tw.json'), true); | |
| 253 | + $json = array_slice($json, 0, 19); | |
| 254 | + | |
| 255 | + $addresses = []; | |
| 256 | + | |
| 257 | +		foreach ($json as $address) { | |
| 258 | + $addresses[] = Address::fromArray($address); | |
| 259 | + } | |
| 260 | + | |
| 261 | + //region Optimization With Duration Priority FineTuning | |
| 262 | + $parameters = RouteParameters::fromArray([ | |
| 263 | +			'route_name'        => 'Optimization With Duration Priority FineTuning. '.date('Y-m-d H:i'), | |
| 264 | + 'algorithm_type' => AlgorithmType::CVRP_TW_MD, | |
| 265 | + 'route_time' => 23200, | |
| 266 | + 'optimize' => OptimizationType::TIME, | |
| 267 | + 'device_type' => DeviceType::WEB, | |
| 268 | + 'udu_distance_unit' => 'km', | |
| 269 | + 'route_max_duration' => 86400, | |
| 270 | + 'travel_mode' => TravelMode::DRIVING, | |
| 271 | + 'vehicle_capacity' => 30, | |
| 272 | + 'vehicle_max_distance_mi' => 10000, | |
| 273 | + 'rt' => true, | |
| 274 | + 'target_duration' => 100, | |
| 275 | + 'target_distance' => 0, | |
| 276 | + 'target_wait_by_tail_size' => 0 | |
| 277 | + | |
| 278 | + ]); | |
| 279 | + | |
| 280 | + $optimizationParams = new OptimizationProblemParams(); | |
| 281 | + $optimizationParams->setAddresses($addresses); | |
| 282 | + $optimizationParams->setParameters($parameters); | |
| 283 | + | |
| 284 | + $problems = OptimizationProblem::optimize($optimizationParams); | |
| 285 | + $this->assertTrue(!is_null($problems), "Cannot generate an optimization with duration priority fine-tuning"); | |
| 286 | + | |
| 287 | + self::$createdProblems[] = $problems; | |
| 288 | + | |
| 289 | + $routes=$problems->getRoutes(); | |
| 290 | + $this->assertTrue(sizeof($routes)==2, "The generated optimization hasn't two routes"); | |
| 291 | + | |
| 292 | + $totalTripDistanceByDuration = $routes[0]->trip_distance + $routes[1]->trip_distance; | |
| 293 | + $totalTripDurationByDuration = $routes[0]->route_duration_sec + $routes[1]->route_duration_sec; | |
| 294 | + $totalTripWaitingTimeByDuration = $routes[0]->total_wait_time + $routes[1]->total_wait_time; | |
| 295 | + | |
| 296 | + echo "Generated an optimization with the <b>duration</b> priority fine-tuning:<br>"; | |
| 297 | + echo " Total Trip Distance: $totalTripDistanceByDuration <br>"; | |
| 298 | + echo " Total Trip Duration: $totalTripDurationByDuration <br>"; | |
| 299 | + echo " Total Trip Waiting Time: $totalTripWaitingTimeByDuration <br><br><br>"; | |
| 300 | + | |
| 301 | + //endregion | |
| 302 | + | |
| 303 | + //region Optimization With Distance Priority FineTuning | |
| 304 | + $parameters = RouteParameters::fromArray([ | |
| 305 | +			'route_name'        => 'Optimization With Distance Priority FineTuning. '.date('Y-m-d H:i'), | |
| 306 | + 'algorithm_type' => AlgorithmType::CVRP_TW_SD, | |
| 307 | + 'route_time' => 23200, | |
| 308 | + 'optimize' => OptimizationType::TIME, | |
| 309 | + 'device_type' => DeviceType::WEB, | |
| 310 | + 'udu_distance_unit' => 'km', | |
| 311 | + 'route_max_duration' => 86400, | |
| 312 | + 'travel_mode' => TravelMode::DRIVING, | |
| 313 | + 'vehicle_capacity' => 30, | |
| 314 | + 'vehicle_max_distance_mi' => 10000, | |
| 315 | + 'rt' => true, | |
| 316 | + 'target_duration' => 0, | |
| 317 | + 'target_distance' => 100, | |
| 318 | + 'target_wait_by_tail_size' => 0 | |
| 319 | + ]); | |
| 320 | + | |
| 321 | + $optimizationParams = new OptimizationProblemParams(); | |
| 322 | + $optimizationParams->setAddresses($addresses); | |
| 323 | + $optimizationParams->setParameters($parameters); | |
| 324 | + | |
| 325 | + $problems = OptimizationProblem::optimize($optimizationParams); | |
| 326 | + $this->assertTrue(!is_null($problems), "Cannot generate an optimization with the distance priority fine-tuning"); | |
| 327 | + | |
| 328 | + self::$createdProblems[]=$problems; | |
| 329 | + | |
| 330 | + $routes=$problems->getRoutes(); | |
| 331 | + $this->assertTrue(sizeof($routes)==2, "The generated optimization hasn't two routes"); | |
| 332 | + | |
| 333 | + $totalTripDistanceByDistance = $routes[0]->trip_distance + $routes[1]->trip_distance; | |
| 334 | + $totalTripDurationByDistance = $routes[0]->route_duration_sec + $routes[1]->route_duration_sec; | |
| 335 | + $totalTripWaitingTimeByDistance = $routes[0]->total_wait_time + $routes[1]->total_wait_time; | |
| 336 | + | |
| 337 | + $this->assertTrue($totalTripDistanceByDistance>0); | |
| 338 | + $this->assertTrue($totalTripDurationByDistance>0); | |
| 339 | + $this->assertTrue($totalTripWaitingTimeByDistance>0); | |
| 340 | + } | |
| 341 | + | |
| 342 | + public function testMultipleDepotMultipleDriver() | |
| 343 | +	{ | |
| 344 | + // Huge list of addresses | |
| 345 | + $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_md_tw.json'), true); | |
| 346 | + | |
| 347 | + $addresses = []; | |
| 348 | +		foreach ($json as $address) { | |
| 349 | + $addresses[] = Address::fromArray($address); | |
| 350 | + } | |
| 351 | + | |
| 352 | + $parameters = RouteParameters::fromArray([ | |
| 353 | + 'algorithm_type' => AlgorithmType::CVRP_TW_MD, | |
| 354 | + 'distance_unit' => DistanceUnit::MILES, | |
| 355 | + 'device_type' => DeviceType::WEB, | |
| 356 | + 'optimize' => OptimizationType::TIME, | |
| 357 | + 'metric' => Metric::MATRIX, | |
| 358 | + 'route_max_duration' => 86400 , | |
| 359 | + 'travel_mode' => TravelMode::DRIVING, | |
| 360 | + 'vehicle_capacity' => 50, | |
| 361 | + 'vehicle_max_distance_mi' => 10000, | |
| 362 | + ]); | |
| 363 | + | |
| 364 | + $optimizationParams = new OptimizationProblemParams(); | |
| 365 | + $optimizationParams->setAddresses($addresses); | |
| 366 | + $optimizationParams->setParameters($parameters); | |
| 367 | + | |
| 368 | + $problem = OptimizationProblem::optimize($optimizationParams); | |
| 369 | + | |
| 370 | + self::$createdProblems[] = $problem; | |
| 371 | + | |
| 372 | + $this->assertNotNull($problem); | |
| 373 | +		$this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 374 | + $this->assertNotNull($problem->getOptimizationId()); | |
| 375 | + $this->assertNotNull($problem->getRoutes()); | |
| 376 | + $this->assertTrue(sizeof($problem->getRoutes())>1); | |
| 377 | + } | |
| 378 | + | |
| 379 | + public function testMultipleDepotMultipleDriverTimeWindow() | |
| 380 | +	{ | |
| 381 | + $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_md_tw.json'), true); | |
| 382 | + | |
| 383 | + $addresses = []; | |
| 384 | + | |
| 385 | +		foreach ($json as $address) { | |
| 386 | + $addresses[] = Address::fromArray($address); | |
| 387 | + } | |
| 388 | + | |
| 389 | + $parameters = RouteParameters::fromArray([ | |
| 390 | + 'algorithm_type' => Algorithmtype::CVRP_TW_MD, | |
| 391 | + 'route_name' => 'Multiple Depot, Multiple Driver, Time Window', | |
| 392 | + 'route_date' => time() + 24 * 60 * 60, | |
| 393 | + 'route_time' => 60 * 60 * 7, | |
| 394 | + 'rt' => true, | |
| 395 | + 'distance_unit' => DistanceUnit::MILES, | |
| 396 | + 'device_type' => DeviceType::WEB, | |
| 397 | + 'optimize' => OptimizationType::TIME, | |
| 398 | + 'metric' => Metric::GEODESIC, | |
| 399 | + 'route_max_duration' => 86400 * 3, | |
| 400 | + 'travel_mode' => TravelMode::DRIVING, | |
| 401 | + 'vehicle_capacity' => 99, | |
| 402 | + 'vehicle_max_distance_mi' => 99999, | |
| 403 | + ]); | |
| 404 | + | |
| 405 | + $optimizationParams = new OptimizationProblemParams(); | |
| 406 | + $optimizationParams->setAddresses($addresses); | |
| 407 | + $optimizationParams->setParameters($parameters); | |
| 408 | + | |
| 409 | + $problem = OptimizationProblem::optimize($optimizationParams); | |
| 410 | + | |
| 411 | + self::$createdProblems[] = $problem; | |
| 412 | + | |
| 413 | + $this->assertNotNull($problem); | |
| 414 | +		$this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 415 | + $this->assertNotNull($problem->getOptimizationId()); | |
| 416 | + $this->assertNotNull($problem->getRoutes()); | |
| 417 | + } | |
| 418 | + | |
| 419 | + public function testMultipleDepotMultipleDriverWith24StopsTimeWindow() | |
| 420 | +	{ | |
| 421 | + // Huge list of addresses | |
| 422 | + $json = json_decode(file_get_contents(dirname(__FILE__).'/data/mdp_mdr_24stops_tw.json'), true); | |
| 423 | + | |
| 424 | + $addresses = []; | |
| 425 | +		foreach ($json as $address) { | |
| 426 | + $addresses[] = Address::fromArray($address); | |
| 427 | + } | |
| 428 | + | |
| 429 | + $addresses[7]->is_depot = true; | |
| 430 | + | |
| 431 | + $parameters = RouteParameters::fromArray([ | |
| 432 | + 'algorithm_type' => Algorithmtype::CVRP_TW_MD, | |
| 433 | + 'route_name' => 'Multiple Depot, Multiple Driver with 24 Stops, Time Window', | |
| 434 | + 'route_date' => time() + 24 * 60 * 60, | |
| 435 | + 'route_time' => 60 * 60 * 7, | |
| 436 | + 'distance_unit' => DistanceUnit::MILES, | |
| 437 | + 'device_type' => DeviceType::WEB, | |
| 438 | + 'optimize' => OptimizationType::TIME, | |
| 439 | + 'metric' => Metric::MATRIX, | |
| 440 | + 'route_max_duration' => 86400, | |
| 441 | + 'travel_mode' => TravelMode::DRIVING, | |
| 442 | + 'vehicle_capacity' => 5, | |
| 443 | + 'vehicle_max_distance_mi' => 10000, | |
| 444 | + ]); | |
| 445 | + | |
| 446 | + $optimizationParams = new OptimizationProblemParams(); | |
| 447 | + $optimizationParams->setAddresses($addresses); | |
| 448 | + $optimizationParams->setParameters($parameters); | |
| 449 | + | |
| 450 | + $problem = OptimizationProblem::optimize($optimizationParams); | |
| 451 | + | |
| 452 | + self::$createdProblems[] = $problem; | |
| 453 | + | |
| 454 | + $this->assertNotNull($problem); | |
| 455 | +		$this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 456 | + $this->assertNotNull($problem->getOptimizationId()); | |
| 457 | + $this->assertNotNull($problem->getRoutes()); | |
| 458 | + $this->assertTrue(sizeof($problem->getRoutes())>1); | |
| 459 | + } | |
| 460 | + | |
| 461 | + public function testMultipleSeparateDepostMultipleDriver() | |
| 462 | +	{ | |
| 463 | + // List of addresses | |
| 464 | + $jsonAddresses = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_only.json'), true); | |
| 465 | + | |
| 466 | + $addresses = []; | |
| 467 | +		foreach ($jsonAddresses as $address) { | |
| 468 | + $addresses[] = Address::fromArray($address); | |
| 469 | + } | |
| 470 | + | |
| 471 | + $jsonDepots = json_decode(file_get_contents(dirname(__FILE__).'/data/depots.json'), true); | |
| 472 | + | |
| 473 | + // List of depots | |
| 474 | + $depots = []; | |
| 475 | +		foreach ($jsonDepots as $depot) { | |
| 476 | + $depots[] = Address::fromArray($depot); | |
| 477 | + } | |
| 478 | + | |
| 479 | + $parameters = RouteParameters::fromArray([ | |
| 480 | +			'route_name'                => 'Multiple Depots Seprate Section '.date('Y-m-d H:i'), | |
| 481 | + 'algorithm_type' => AlgorithmType::CVRP_TW_MD, | |
| 482 | + 'distance_unit' => DistanceUnit::MILES, | |
| 483 | + 'device_type' => DeviceType::WEB, | |
| 484 | + 'optimize' => OptimizationType::TIME, | |
| 485 | + 'metric' => Metric::GEODESIC, | |
| 486 | + 'route_max_duration' => 86400 * 2, | |
| 487 | + 'travel_mode' => TravelMode::DRIVING, | |
| 488 | + 'vehicle_capacity' => 50, | |
| 489 | + 'vehicle_max_distance_mi' => 10000, | |
| 490 | + 'parts' => 50, | |
| 491 | + ]); | |
| 492 | + | |
| 493 | + $optimizationParams = new OptimizationProblemParams(); | |
| 494 | + $optimizationParams->setAddresses($addresses); | |
| 495 | + $optimizationParams->setDepots($depots); | |
| 496 | + $optimizationParams->setParameters($parameters); | |
| 497 | + | |
| 498 | + $problem = OptimizationProblem::optimize($optimizationParams); | |
| 499 | + | |
| 500 | + self::$createdProblems[] = $problem; | |
| 501 | + | |
| 502 | + $this->assertNotNull($problem); | |
| 503 | +		$this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 504 | + $this->assertNotNull($problem->getOptimizationId()); | |
| 505 | + $this->assertNotNull($problem->getRoutes()); | |
| 506 | + } | |
| 507 | + | |
| 508 | + public function testOptimizationSingleDriverRoute10Stops() | |
| 509 | +	{ | |
| 510 | + // Huge list of addresses | |
| 511 | + $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true); | |
| 512 | + $json = array_slice($json, 0, 10); | |
| 513 | + | |
| 514 | + $addresses = []; | |
| 515 | +		foreach ($json as $address) { | |
| 516 | + $addresses[] = Address::fromArray($address); | |
| 517 | + } | |
| 518 | + | |
| 519 | + $parameters = RouteParameters::fromArray([ | |
| 520 | + 'algorithm_type' => AlgorithmType::TSP, | |
| 521 | + 'distance_unit' => DistanceUnit::MILES, | |
| 522 | + 'device_type' => DeviceType::WEB, | |
| 523 | + 'optimize' => OptimizationType::DISTANCE, | |
| 524 | + 'travel_mode' => TravelMode::DRIVING, | |
| 525 | + 'route_max_duration' => 86400, | |
| 526 | + 'vehicle_capacity' => 1, | |
| 527 | + 'vehicle_max_distance_mi' => 10000, | |
| 528 | + ]); | |
| 529 | + | |
| 530 | + $optimizationParams = new OptimizationProblemParams(); | |
| 531 | + $optimizationParams->setAddresses($addresses); | |
| 532 | + $optimizationParams->setParameters($parameters); | |
| 533 | + | |
| 534 | + $problem = OptimizationProblem::optimize($optimizationParams); | |
| 535 | + | |
| 536 | + self::$createdProblems[] = $problem; | |
| 537 | + | |
| 538 | + $this->assertNotNull($problem); | |
| 539 | +		$this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 540 | + $this->assertNotNull($problem->getOptimizationId()); | |
| 541 | + $this->assertNotNull($problem->getRoutes()); | |
| 542 | + } | |
| 543 | + | |
| 544 | + public function testRouteSlowDown() | |
| 545 | +	{ | |
| 546 | + // Huge list of addresses | |
| 547 | + $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true); | |
| 548 | + $json = array_slice($json, 0, 10); | |
| 549 | + | |
| 550 | + $addresses = []; | |
| 551 | +		foreach ($json as $address) { | |
| 552 | + $addresses[] = Address::fromArray($address); | |
| 553 | + } | |
| 554 | + | |
| 555 | + $parameters = RouteParameters::fromArray([ | |
| 556 | + 'algorithm_type' => AlgorithmType::TSP, | |
| 557 | + 'distance_unit' => DistanceUnit::MILES, | |
| 558 | + 'device_type' => DeviceType::WEB, | |
| 559 | + 'optimize' => OptimizationType::DISTANCE, | |
| 560 | + 'travel_mode' => TravelMode::DRIVING, | |
| 561 | +			'route_name'                => 'SD 10 stops slowdown route '.date('Y-m-d H:i'), | |
| 562 | + 'route_max_duration' => 86400, | |
| 563 | + 'vehicle_capacity' => 1, | |
| 564 | + 'vehicle_max_distance_mi' => 10000, | |
| 565 | + 'slowdowns' => [ | |
| 566 | + 'service_time' => 15, | |
| 567 | + 'travel_time' => 20 | |
| 568 | + ], | |
| 569 | + ]); | |
| 570 | + | |
| 571 | + $optimizationParams = new OptimizationProblemParams(); | |
| 572 | + $optimizationParams->setAddresses($addresses); | |
| 573 | + $optimizationParams->setParameters($parameters); | |
| 574 | + | |
| 575 | + $problem = OptimizationProblem::optimize($optimizationParams); | |
| 576 | + | |
| 577 | + self::$createdProblems[] = $problem; | |
| 578 | + | |
| 579 | + $this->assertNotNull($problem); | |
| 580 | +		$this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 581 | + $this->assertNotNull($problem->getOptimizationId()); | |
| 582 | + $this->assertNotNull($problem->parameters); | |
| 583 | + | |
| 584 | + $this->assertNotNull($problem->parameters->route_time_multiplier); | |
| 585 | + $this->assertNotNull($problem->parameters->route_service_time_multiplier); | |
| 586 | + $this->assertEquals(15, $problem->parameters->route_service_time_multiplier); | |
| 587 | + $this->assertEquals(20, $problem->parameters->route_time_multiplier); | |
| 588 | + } | |
| 589 | + | |
| 590 | + public function testSingleDriverRoundTrip() | |
| 591 | +	{ | |
| 592 | + // Huge list of addresses | |
| 593 | + $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true); | |
| 594 | + $json = array_slice($json, 0, 16); | |
| 595 | + | |
| 596 | + $addresses = []; | |
| 597 | + | |
| 598 | +		foreach ($json as $address) { | |
| 599 | + $addresses[] = Address::fromArray($address); | |
| 600 | + } | |
| 601 | + | |
| 602 | + $parameters = RouteParameters::fromArray([ | |
| 603 | + 'algorithm_type' => AlgorithmType::TSP, | |
| 604 | + 'distance_unit' => DistanceUnit::MILES, | |
| 605 | + 'device_type' => DeviceType::WEB, | |
| 606 | + 'optimize' => OptimizationType::DISTANCE, | |
| 607 | + 'travel_mode' => TravelMode::DRIVING, | |
| 608 | + 'route_max_duration' => 86400, | |
| 609 | + 'vehicle_capacity' => 1, | |
| 610 | + 'vehicle_max_distance_mi' => 10000, | |
| 611 | + 'rt' => true, | |
| 612 | + ]); | |
| 613 | + | |
| 614 | + $optimizationParams = new OptimizationProblemParams(); | |
| 615 | + $optimizationParams->setAddresses($addresses); | |
| 616 | + $optimizationParams->setParameters($parameters); | |
| 617 | + | |
| 618 | + $problem = OptimizationProblem::optimize($optimizationParams); | |
| 619 | + | |
| 620 | + self::$createdProblems[] = $problem; | |
| 621 | + | |
| 622 | + $this->assertNotNull($problem); | |
| 623 | +		$this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 624 | + $this->assertNotNull($problem->getOptimizationId()); | |
| 625 | + $this->assertNotNull($problem->getRoutes()); | |
| 626 | + $this->assertNotNull($problem->addresses); | |
| 627 | + | |
| 628 | + $firstAddress = $problem->routes[0]->addresses[0]; | |
| 629 | + $lastAddress = $problem->routes[0]->addresses[sizeof($problem->routes[0]->addresses)-1]; | |
| 630 | + | |
| 631 | + $this->assertEquals($firstAddress->route_destination_id, $lastAddress->route_destination_id); | |
| 632 | + } | |
| 633 | + | |
| 634 | + public function testSingleDepotMultipleDriverNoTimeWindow() | |
| 635 | +	{ | |
| 636 | + // Huge list of addresses | |
| 637 | + $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true); | |
| 638 | + | |
| 639 | + $addresses = []; | |
| 640 | +		foreach ($json as $address) { | |
| 641 | + $addresses[] = Address::fromArray($address); | |
| 642 | + } | |
| 643 | + | |
| 644 | + $parameters = RouteParameters::fromArray([ | |
| 645 | + 'algorithm_type' => Algorithmtype::CVRP_TW_SD, | |
| 646 | + 'route_name' => 'Single Depot, Multiple Driver, No Time Window', | |
| 647 | + 'route_date' => time() + 24 * 60 * 60, | |
| 648 | + 'route_time' => 60 * 60 * 7, | |
| 649 | + 'rt' => true, | |
| 650 | + 'distance_unit' => DistanceUnit::MILES, | |
| 651 | + 'device_type' => DeviceType::WEB, | |
| 652 | + 'optimize' => OptimizationType::TIME, | |
| 653 | + 'metric' => Metric::GEODESIC, | |
| 654 | + 'route_max_duration' => 86400, | |
| 655 | + 'travel_mode' => TravelMode::DRIVING, | |
| 656 | + 'vehicle_capacity' => 20, | |
| 657 | + 'vehicle_max_distance_mi' => 99999, | |
| 658 | + 'parts' => 4, | |
| 659 | + ]); | |
| 660 | + | |
| 661 | + $optimizationParams = new OptimizationProblemParams(); | |
| 662 | + $optimizationParams->setAddresses($addresses); | |
| 663 | + $optimizationParams->setParameters($parameters); | |
| 664 | + | |
| 665 | + $problem = OptimizationProblem::optimize($optimizationParams); | |
| 666 | + | |
| 667 | + self::$createdProblems[] = $problem; | |
| 668 | + | |
| 669 | + $this->assertNotNull($problem); | |
| 670 | +		$this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 671 | + $this->assertNotNull($problem->getOptimizationId()); | |
| 672 | + $this->assertNotNull($problem->getRoutes()); | |
| 673 | + | |
| 674 | + $this->assertNotNull(sizeof($problem->routes)>1); | |
| 675 | + } | |
| 676 | + | |
| 677 | + public function testSingleDriverMultipleTimeWindows() | |
| 678 | +	{ | |
| 679 | + // Huge list of addresses | |
| 680 | + $json = json_decode(file_get_contents(dirname(__FILE__).'/data/mdp_mdr_24stops_tw.json'), true); | |
| 681 | + $json = array_slice($json, 0, 20); | |
| 682 | + | |
| 683 | + $addresses = []; | |
| 684 | +		foreach ($json as $address) { | |
| 685 | + $addresses[] = Address::fromArray($address); | |
| 686 | + } | |
| 687 | + | |
| 688 | + $parameters = RouteParameters::fromArray([ | |
| 689 | + 'algorithm_type' => Algorithmtype::TSP, | |
| 690 | +			'route_name'        => 'Single Driver Multiple TimeWindows 20 Stops '.date('Y-m-d H:i'), | |
| 691 | + 'route_date' => time() + 24 * 60 * 60, | |
| 692 | + 'route_time' => 5 * 3600 + 30 * 60, | |
| 693 | + 'distance_unit' => DistanceUnit::MILES, | |
| 694 | + 'device_type' => DeviceType::WEB, | |
| 695 | + 'optimize' => OptimizationType::TIME, | |
| 696 | + 'metric' => Metric::MATRIX, | |
| 697 | + ]); | |
| 698 | + | |
| 699 | + $optimizationParams = new OptimizationProblemParams(); | |
| 700 | + $optimizationParams->setAddresses($addresses); | |
| 701 | + $optimizationParams->setParameters($parameters); | |
| 702 | + | |
| 703 | + $problem = OptimizationProblem::optimize($optimizationParams); | |
| 704 | + | |
| 705 | + self::$createdProblems[] = $problem; | |
| 706 | + | |
| 707 | + $this->assertNotNull($problem); | |
| 708 | +		$this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 709 | + $this->assertNotNull($problem->getOptimizationId()); | |
| 710 | + $this->assertNotNull($problem->getRoutes()); | |
| 711 | + | |
| 712 | + $this->assertNotNull(sizeof($problem->routes)>1); | |
| 713 | + } | |
| 714 | + | |
| 715 | + public function testTruckingSingleDriverMultipleTimeWindows() | |
| 716 | +	{ | |
| 717 | + #region Create Medium Truck | |
| 718 | + | |
| 719 | + $vehicle = new Vehicle(); | |
| 720 | + | |
| 721 | + $vehicleParameters = Vehicle::fromArray([ | |
| 722 | + 'vehicle_name' => 'GMC TopKick C5500 Medium', | |
| 723 | + 'vehicle_alias' => 'GMC TopKick C5500 Medium', | |
| 724 | + 'vehicle_vin' => 'SAJXA01A06FN08012', | |
| 725 | + 'vehicle_license_plate' => 'CVH4561', | |
| 726 | + 'vehicle_model' => 'TopKick C5500', | |
| 727 | + 'vehicle_model_year' => 1995, | |
| 728 | + 'vehicle_year_acquired' => 2008, | |
| 729 | + 'vehicle_reg_country_id' => '223', | |
| 730 | + 'vehicle_make' => 'GMC', | |
| 731 | + 'vehicle_type_id' => 'pickup_truck', | |
| 732 | + 'vehicle_axle_count' => 2, | |
| 733 | + 'mpg_city' => 7, | |
| 734 | + 'mpg_highway' => 14, | |
| 735 | + 'fuel_type' => 'diesel', | |
| 736 | + 'height_inches' => 97, | |
| 737 | + 'height_metric' => 243, | |
| 738 | + 'weight_lb' => 19000, | |
| 739 | + 'maxWeightPerAxleGroupInPounds' => 9500, | |
| 740 | + 'max_weight_per_axle_group_metric' => 4300, | |
| 741 | + 'widthInInches' => 96, | |
| 742 | + 'width_metric' => 240, | |
| 743 | + 'lengthInInches' => 244, | |
| 744 | + 'length_metric' => 610, | |
| 745 | + 'Use53FootTrailerRouting' => 'YES', | |
| 746 | + 'UseTruckRestrictions' => 'YES', | |
| 747 | + 'DividedHighwayAvoidPreference' => 'NEUTRAL', | |
| 748 | + 'FreewayAvoidPreference' => 'NEUTRAL', | |
| 749 | + 'truck_config' => 'FULLSIZEVAN', | |
| 750 | + ]); | |
| 751 | + | |
| 752 | + $result = $vehicle->createVehicle($vehicleParameters); | |
| 753 | + | |
| 754 | + $this->assertNotNull($result); | |
| 755 | + $this->assertTrue(isset($result['status'])); | |
| 756 | + $this->assertTrue($result['status']); | |
| 757 | + $this->assertTrue(isset($result['vehicle_guid'])); | |
| 758 | + $vehicleId = $result['vehicle_guid']; | |
| 759 | + | |
| 760 | + self::$removedVehicle = $vehicleId; | |
| 761 | + | |
| 762 | + #endregion | |
| 763 | + // Huge list of addresses | |
| 764 | + $json = json_decode(file_get_contents(dirname(__FILE__).'/data/mdp_mdr_24stops_tw.json'), true); | |
| 765 | + $json = array_slice($json, 0, 18); | |
| 766 | + | |
| 767 | + $addresses = []; | |
| 768 | +		foreach ($json as $address) { | |
| 769 | + $addresses[] = Address::fromArray($address); | |
| 770 | + } | |
| 771 | + | |
| 772 | + $parameters = RouteParameters::fromArray([ | |
| 773 | + 'algorithm_type' => Algorithmtype::CVRP_TW_SD, | |
| 774 | +			'route_name'                => 'Trucking SD Multiple TW 18 Stops '.date('Y-m-d H:i'), | |
| 775 | + 'route_date' => time() + 24 * 60 * 60, | |
| 776 | + 'route_time' => 5 * 3600 + 30 * 60, | |
| 777 | + 'distance_unit' => DistanceUnit::MILES, | |
| 778 | + 'device_type' => DeviceType::WEB, | |
| 779 | + 'optimize' => OptimizationType::TIME_WITH_TRAFFIC, | |
| 780 | + 'metric' => Metric::MATRIX, | |
| 781 | + 'route_max_duration' => 8 * 3600 + 30 * 60, | |
| 782 | + 'vehicle_id' => $vehicleId, | |
| 783 | + 'travel_mode' => TravelMode::DRIVING, | |
| 784 | + 'vehicle_max_cargo_weight' => 30, | |
| 785 | + 'vehicle_capacity' => 10, | |
| 786 | + 'vehicle_max_distance_mi' => 10000, | |
| 787 | + 'trailer_weight_t' => 10, | |
| 788 | + 'weight_per_axle_t' => 10, | |
| 789 | + 'limited_weight_t' => 20, | |
| 790 | + 'rt' => true | |
| 791 | + ]); | |
| 792 | + | |
| 793 | + $optimizationParams = new OptimizationProblemParams(); | |
| 794 | + $optimizationParams->setAddresses($addresses); | |
| 795 | + $optimizationParams->setParameters($parameters); | |
| 796 | + | |
| 797 | + $problem = OptimizationProblem::optimize($optimizationParams); | |
| 798 | + | |
| 799 | + self::$createdProblems[] = $problem; | |
| 800 | + | |
| 801 | + $this->assertNotNull($problem); | |
| 802 | +		$this->assertInstanceOf('Route4Me\OptimizationProblem', $problem); | |
| 803 | + $this->assertNotNull($problem->getOptimizationId()); | |
| 804 | + $this->assertNotNull($problem->getRoutes()); | |
| 805 | + | |
| 806 | + $this->assertNotNull(sizeof($problem->routes)>1); | |
| 807 | + } | |
| 808 | + | |
| 809 | + public static function tearDownAfterClass() | |
| 810 | +	{ | |
| 811 | +		if (sizeof(self::$createdProblems)>0) { | |
| 812 | + $optimizationProblemIDs = []; | |
| 813 | + | |
| 814 | +			foreach (self::$createdProblems as $problem) { | |
| 815 | + $optimizationProblemId = $problem->optimization_problem_id; | |
| 816 | + | |
| 817 | + $optimizationProblemIDs[] = $optimizationProblemId; | |
| 818 | + } | |
| 819 | + | |
| 820 | +			if (sizeof(self::$removedOptimizationIDs)>0) { | |
| 821 | + $optimizationProblemIDs = array_merge($optimizationProblemIDs,self::$removedOptimizationIDs); | |
| 822 | + } | |
| 823 | + | |
| 824 | + $params = [ | |
| 825 | + 'optimization_problem_ids' => $optimizationProblemIDs, | |
| 826 | + 'redirect' => 0, | |
| 827 | + ]; | |
| 828 | + | |
| 829 | + $problem = new OptimizationProblem(); | |
| 830 | + $result = $problem->removeOptimization($params); | |
| 831 | + | |
| 832 | +			if ($result!=null && $result['status']==true) { | |
| 833 | + echo "The test optimizations were removed <br>"; | |
| 834 | +			} else { | |
| 835 | + echo "Cannot remove the test optimizations <br>"; | |
| 836 | + } | |
| 837 | + } | |
| 838 | + | |
| 839 | +		if (sizeof(self::$removedRouteIDs)>0) { | |
| 840 | + $route = new Route(); | |
| 841 | + | |
| 842 | +			$route_ids = join(',', self::$removedRouteIDs); | |
| 843 | + | |
| 844 | + $result = $route->deleteRoutes($route_ids); | |
| 845 | + | |
| 846 | +			if ($result!=null && $result['deleted']==true) { | |
| 847 | + echo "The test routes were removed <br>"; | |
| 848 | +			} else { | |
| 849 | + echo "Cannot remove the test routes <br>"; | |
| 850 | + } | |
| 851 | + } | |
| 852 | + | |
| 853 | +		if (!is_null(self::$removedVehicle!=null) && strlen(self::$removedVehicle)==32) { | |
| 854 | + | |
| 855 | + $vehicle = new Vehicle(); | |
| 856 | + | |
| 857 | + $vehicleParameters = Vehicle::fromArray([ | |
| 858 | + 'vehicle_id' => self::$removedVehicle, | |
| 859 | + ]); | |
| 860 | + | |
| 861 | + $result = $vehicle->removeVehicle($vehicleParameters); | |
| 862 | + | |
| 863 | +			if (!is_null($result)) { | |
| 864 | + echo "The vehicle ".$result['vehicle_id']." removed <br>"; | |
| 865 | +			} else { | |
| 866 | + echo "Cannot remove the vehicle ".$vehicle['vehicle_id']."<br>"; | |
| 867 | + } | |
| 868 | + | |
| 869 | + } | |
| 870 | + } | |
| 871 | 871 | } | 
| 872 | 872 | \ No newline at end of file | 
| @@ -36,9 +36,9 @@ discard block | ||
| 36 | 36 | |
| 37 | 37 | public static function setUpBeforeClass() | 
| 38 | 38 |      { | 
| 39 | -        if (Constants::API_KEY == Constants::DEMO_API_KEY) { | |
| 40 | -            $className = str_replace('UnitTestFiles\\Test\\','',get_class()); | |
| 41 | - self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); | |
| 39 | +        if (Constants::API_KEY==Constants::DEMO_API_KEY) { | |
| 40 | +            $className = str_replace('UnitTestFiles\\Test\\', '', get_class()); | |
| 41 | +            self::markTestSkipped('PHPUnit will skip '.$className." class - it impossible run with demo API key"); | |
| 42 | 42 | } | 
| 43 | 43 | |
| 44 | 44 | Route4Me::setApiKey(Constants::API_KEY); | 
| @@ -187,7 +187,7 @@ discard block | ||
| 187 | 187 | |
| 188 | 188 | public function testGetScheduleCalendar() | 
| 189 | 189 |      { | 
| 190 | - $now = new \DateTime(); | |
| 190 | + $now = new \DateTime(); | |
| 191 | 191 | |
| 192 | 192 | $schedCalendarParams = new ScheduleCalendarParameters(); | 
| 193 | 193 | |
| @@ -241,7 +241,7 @@ discard block | ||
| 241 | 241 | $this->assertTrue(isset($result['status']), "Cannot merge the routes"); | 
| 242 | 242 | $this->assertTrue($result['status'], "Cannot merge the routes"); | 
| 243 | 243 | $this->assertTrue(isset($result['optimization_problem_id']), "Cannot merge the routes"); | 
| 244 | - $this->assertEquals(32,strlen($result['optimization_problem_id']), "Cannot merge the routes"); | |
| 244 | + $this->assertEquals(32, strlen($result['optimization_problem_id']), "Cannot merge the routes"); | |
| 245 | 245 | |
| 246 | 246 | self::$removedOptimizationIDs[] = $result['optimization_problem_id']; | 
| 247 | 247 | } | 
| @@ -286,7 +286,7 @@ discard block | ||
| 286 | 286 | |
| 287 | 287 | self::$createdProblems[] = $problems; | 
| 288 | 288 | |
| 289 | - $routes=$problems->getRoutes(); | |
| 289 | + $routes = $problems->getRoutes(); | |
| 290 | 290 | $this->assertTrue(sizeof($routes)==2, "The generated optimization hasn't two routes"); | 
| 291 | 291 | |
| 292 | 292 | $totalTripDistanceByDuration = $routes[0]->trip_distance + $routes[1]->trip_distance; | 
| @@ -325,9 +325,9 @@ discard block | ||
| 325 | 325 | $problems = OptimizationProblem::optimize($optimizationParams); | 
| 326 | 326 | $this->assertTrue(!is_null($problems), "Cannot generate an optimization with the distance priority fine-tuning"); | 
| 327 | 327 | |
| 328 | - self::$createdProblems[]=$problems; | |
| 328 | + self::$createdProblems[] = $problems; | |
| 329 | 329 | |
| 330 | - $routes=$problems->getRoutes(); | |
| 330 | + $routes = $problems->getRoutes(); | |
| 331 | 331 | $this->assertTrue(sizeof($routes)==2, "The generated optimization hasn't two routes"); | 
| 332 | 332 | |
| 333 | 333 | $totalTripDistanceByDistance = $routes[0]->trip_distance + $routes[1]->trip_distance; | 
| @@ -355,7 +355,7 @@ discard block | ||
| 355 | 355 | 'device_type' => DeviceType::WEB, | 
| 356 | 356 | 'optimize' => OptimizationType::TIME, | 
| 357 | 357 | 'metric' => Metric::MATRIX, | 
| 358 | - 'route_max_duration' => 86400 , | |
| 358 | + 'route_max_duration' => 86400, | |
| 359 | 359 | 'travel_mode' => TravelMode::DRIVING, | 
| 360 | 360 | 'vehicle_capacity' => 50, | 
| 361 | 361 | 'vehicle_max_distance_mi' => 10000, | 
| @@ -626,7 +626,7 @@ discard block | ||
| 626 | 626 | $this->assertNotNull($problem->addresses); | 
| 627 | 627 | |
| 628 | 628 | $firstAddress = $problem->routes[0]->addresses[0]; | 
| 629 | - $lastAddress = $problem->routes[0]->addresses[sizeof($problem->routes[0]->addresses)-1]; | |
| 629 | + $lastAddress = $problem->routes[0]->addresses[sizeof($problem->routes[0]->addresses) - 1]; | |
| 630 | 630 | |
| 631 | 631 | $this->assertEquals($firstAddress->route_destination_id, $lastAddress->route_destination_id); | 
| 632 | 632 | } | 
| @@ -818,7 +818,7 @@ discard block | ||
| 818 | 818 | } | 
| 819 | 819 | |
| 820 | 820 |              if (sizeof(self::$removedOptimizationIDs)>0) { | 
| 821 | - $optimizationProblemIDs = array_merge($optimizationProblemIDs,self::$removedOptimizationIDs); | |
| 821 | + $optimizationProblemIDs = array_merge($optimizationProblemIDs, self::$removedOptimizationIDs); | |
| 822 | 822 | } | 
| 823 | 823 | |
| 824 | 824 | $params = [ | 
| @@ -22,800 +22,800 @@ | ||
| 22 | 22 | |
| 23 | 23 | class RouteTests extends \PHPUnit\Framework\TestCase | 
| 24 | 24 |  { | 
| 25 | - public static $createdProblems = []; | |
| 26 | - public static $testRoutes = []; | |
| 27 | - public static $addresses = []; | |
| 28 | - | |
| 29 | - public static $removedOptimizationIDs = []; | |
| 30 | - public static $removedRouteIDs = []; | |
| 31 | - public static $removedVehicleIDs = []; | |
| 32 | - | |
| 33 | - public static function setUpBeforeClass() | |
| 34 | -    { | |
| 35 | - Route4Me::setApiKey(Constants::API_KEY); | |
| 36 | - | |
| 37 | - //region -- Prepae Addresses -- | |
| 38 | - $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_md_tw.json'), true); | |
| 39 | - | |
| 40 | - $addresses = []; | |
| 41 | -        foreach ($json as $address) { | |
| 42 | - $addresses[] = Address::fromArray($address); | |
| 43 | - } | |
| 44 | - | |
| 45 | - $parameters = RouteParameters::fromArray([ | |
| 46 | - 'algorithm_type' => AlgorithmType::CVRP_TW_MD, | |
| 47 | - 'distance_unit' => DistanceUnit::MILES, | |
| 48 | - 'device_type' => DeviceType::WEB, | |
| 49 | - 'optimize' => OptimizationType::DISTANCE, | |
| 50 | - 'metric' => Metric::GEODESIC, | |
| 51 | - 'route_max_duration' => 86400 * 2, | |
| 52 | - 'travel_mode' => TravelMode::DRIVING, | |
| 53 | - 'vehicle_capacity' => 50, | |
| 54 | - 'vehicle_max_distance_mi' => 10000, | |
| 55 | - 'parts' => 50, | |
| 56 | - ]); | |
| 57 | - //endregion | |
| 58 | - | |
| 59 | - $optimizationParameters = new OptimizationProblemParams(); | |
| 60 | - $optimizationParameters->setAddresses($addresses); | |
| 61 | - $optimizationParameters->setParameters($parameters); | |
| 62 | - | |
| 63 | - self::$createdProblems[] = OptimizationProblem::optimize($optimizationParameters); | |
| 64 | - | |
| 65 | - self::$testRoutes = self::$createdProblems[0]->routes; | |
| 66 | - | |
| 67 | - //region -- Extra Testing Addresses -- | |
| 68 | - $addresses = []; | |
| 69 | - $addresses[] = Address::fromArray([ | |
| 70 | - 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', | |
| 71 | - 'is_depot' => true, | |
| 72 | - 'lat' => 30.159341812134, | |
| 73 | - 'lng' => -81.538619995117, | |
| 74 | - 'time' => 300, | |
| 75 | - 'time_window_start' => 28800, | |
| 76 | - 'time_window_end' => 32400, | |
| 77 | - ]); | |
| 78 | - | |
| 79 | - $addresses[] = Address::fromArray([ | |
| 80 | - 'address' => '214 Edgewater Branch Drive 32259', | |
| 81 | - 'lat' => 30.103567123413, | |
| 82 | - 'lng' => -81.595352172852, | |
| 83 | - 'time' => 300, | |
| 84 | - 'time_window_start' => 36000, | |
| 85 | - 'time_window_end' => 37200, | |
| 86 | - ]); | |
| 87 | - | |
| 88 | - $addresses[] = Address::fromArray([ | |
| 89 | - 'address' => '756 eagle point dr 32092', | |
| 90 | - 'lat' => 30.046422958374, | |
| 91 | - 'lng' => -81.508758544922, | |
| 92 | - 'time' => 300, | |
| 93 | - 'time_window_start' => 39600, | |
| 94 | - 'time_window_end' => 41400, | |
| 95 | - ]); | |
| 96 | - //endregion | |
| 97 | - | |
| 98 | - self::$addresses = $addresses; | |
| 99 | - | |
| 100 | - //region -- Create Test Order -- | |
| 101 | - | |
| 102 | - | |
| 103 | - | |
| 104 | - //endregion | |
| 105 | - } | |
| 106 | - | |
| 107 | - public function testFromArray() | |
| 108 | -    { | |
| 109 | - //region -- Prepare Addresses -- | |
| 110 | - | |
| 111 | - $addresses = []; | |
| 112 | - $addresses[] = [ | |
| 113 | - 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', | |
| 114 | - 'is_depot' => true, | |
| 115 | - 'lat' => 30.159341812134, | |
| 116 | - 'lng' => -81.538619995117, | |
| 117 | - 'time' => 300, | |
| 118 | - 'time_window_start' => 28800, | |
| 119 | - 'time_window_end' => 32400, | |
| 120 | - ]; | |
| 121 | - | |
| 122 | - $addresses[] = [ | |
| 123 | - 'address' => '214 Edgewater Branch Drive 32259', | |
| 124 | - 'lat' => 30.103567123413, | |
| 125 | - 'lng' => -81.595352172852, | |
| 126 | - 'time' => 300, | |
| 127 | - 'time_window_start' => 36000, | |
| 128 | - 'time_window_end' => 37200, | |
| 129 | - ]; | |
| 130 | - | |
| 131 | - $addresses[] = [ | |
| 132 | - 'address' => '756 eagle point dr 32092', | |
| 133 | - 'lat' => 30.046422958374, | |
| 134 | - 'lng' => -81.508758544922, | |
| 135 | - 'time' => 300, | |
| 136 | - 'time_window_start' => 39600, | |
| 137 | - 'time_window_end' => 41400, | |
| 138 | - ]; | |
| 139 | - | |
| 140 | - $addresses[] = [ | |
| 141 | - 'address' => '63 Stone Creek Cir St Johns, FL 32259, USA', | |
| 142 | - 'lat' => 30.048496, | |
| 143 | - 'lng' => -81.558716, | |
| 144 | - 'time' => 300, | |
| 145 | - 'time_window_start' => 43200, | |
| 146 | - 'time_window_end' => 45000, | |
| 147 | - ]; | |
| 148 | - | |
| 149 | - $addresses[] = [ | |
| 150 | - 'address' => 'St Johns Florida 32259, USA', | |
| 151 | - 'lat' => 30.099642, | |
| 152 | - 'lng' => -81.547201, | |
| 153 | - 'time' => 300, | |
| 154 | - 'time_window_start' => 46800, | |
| 155 | - 'time_window_end' => 48600, | |
| 156 | - ]; | |
| 25 | + public static $createdProblems = []; | |
| 26 | + public static $testRoutes = []; | |
| 27 | + public static $addresses = []; | |
| 28 | + | |
| 29 | + public static $removedOptimizationIDs = []; | |
| 30 | + public static $removedRouteIDs = []; | |
| 31 | + public static $removedVehicleIDs = []; | |
| 32 | + | |
| 33 | + public static function setUpBeforeClass() | |
| 34 | +	{ | |
| 35 | + Route4Me::setApiKey(Constants::API_KEY); | |
| 36 | + | |
| 37 | + //region -- Prepae Addresses -- | |
| 38 | + $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_md_tw.json'), true); | |
| 39 | + | |
| 40 | + $addresses = []; | |
| 41 | +		foreach ($json as $address) { | |
| 42 | + $addresses[] = Address::fromArray($address); | |
| 43 | + } | |
| 44 | + | |
| 45 | + $parameters = RouteParameters::fromArray([ | |
| 46 | + 'algorithm_type' => AlgorithmType::CVRP_TW_MD, | |
| 47 | + 'distance_unit' => DistanceUnit::MILES, | |
| 48 | + 'device_type' => DeviceType::WEB, | |
| 49 | + 'optimize' => OptimizationType::DISTANCE, | |
| 50 | + 'metric' => Metric::GEODESIC, | |
| 51 | + 'route_max_duration' => 86400 * 2, | |
| 52 | + 'travel_mode' => TravelMode::DRIVING, | |
| 53 | + 'vehicle_capacity' => 50, | |
| 54 | + 'vehicle_max_distance_mi' => 10000, | |
| 55 | + 'parts' => 50, | |
| 56 | + ]); | |
| 57 | + //endregion | |
| 58 | + | |
| 59 | + $optimizationParameters = new OptimizationProblemParams(); | |
| 60 | + $optimizationParameters->setAddresses($addresses); | |
| 61 | + $optimizationParameters->setParameters($parameters); | |
| 62 | + | |
| 63 | + self::$createdProblems[] = OptimizationProblem::optimize($optimizationParameters); | |
| 64 | + | |
| 65 | + self::$testRoutes = self::$createdProblems[0]->routes; | |
| 66 | + | |
| 67 | + //region -- Extra Testing Addresses -- | |
| 68 | + $addresses = []; | |
| 69 | + $addresses[] = Address::fromArray([ | |
| 70 | + 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', | |
| 71 | + 'is_depot' => true, | |
| 72 | + 'lat' => 30.159341812134, | |
| 73 | + 'lng' => -81.538619995117, | |
| 74 | + 'time' => 300, | |
| 75 | + 'time_window_start' => 28800, | |
| 76 | + 'time_window_end' => 32400, | |
| 77 | + ]); | |
| 78 | + | |
| 79 | + $addresses[] = Address::fromArray([ | |
| 80 | + 'address' => '214 Edgewater Branch Drive 32259', | |
| 81 | + 'lat' => 30.103567123413, | |
| 82 | + 'lng' => -81.595352172852, | |
| 83 | + 'time' => 300, | |
| 84 | + 'time_window_start' => 36000, | |
| 85 | + 'time_window_end' => 37200, | |
| 86 | + ]); | |
| 87 | + | |
| 88 | + $addresses[] = Address::fromArray([ | |
| 89 | + 'address' => '756 eagle point dr 32092', | |
| 90 | + 'lat' => 30.046422958374, | |
| 91 | + 'lng' => -81.508758544922, | |
| 92 | + 'time' => 300, | |
| 93 | + 'time_window_start' => 39600, | |
| 94 | + 'time_window_end' => 41400, | |
| 95 | + ]); | |
| 96 | + //endregion | |
| 97 | + | |
| 98 | + self::$addresses = $addresses; | |
| 99 | + | |
| 100 | + //region -- Create Test Order -- | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + //endregion | |
| 105 | + } | |
| 106 | + | |
| 107 | + public function testFromArray() | |
| 108 | +	{ | |
| 109 | + //region -- Prepare Addresses -- | |
| 110 | + | |
| 111 | + $addresses = []; | |
| 112 | + $addresses[] = [ | |
| 113 | + 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', | |
| 114 | + 'is_depot' => true, | |
| 115 | + 'lat' => 30.159341812134, | |
| 116 | + 'lng' => -81.538619995117, | |
| 117 | + 'time' => 300, | |
| 118 | + 'time_window_start' => 28800, | |
| 119 | + 'time_window_end' => 32400, | |
| 120 | + ]; | |
| 121 | + | |
| 122 | + $addresses[] = [ | |
| 123 | + 'address' => '214 Edgewater Branch Drive 32259', | |
| 124 | + 'lat' => 30.103567123413, | |
| 125 | + 'lng' => -81.595352172852, | |
| 126 | + 'time' => 300, | |
| 127 | + 'time_window_start' => 36000, | |
| 128 | + 'time_window_end' => 37200, | |
| 129 | + ]; | |
| 130 | + | |
| 131 | + $addresses[] = [ | |
| 132 | + 'address' => '756 eagle point dr 32092', | |
| 133 | + 'lat' => 30.046422958374, | |
| 134 | + 'lng' => -81.508758544922, | |
| 135 | + 'time' => 300, | |
| 136 | + 'time_window_start' => 39600, | |
| 137 | + 'time_window_end' => 41400, | |
| 138 | + ]; | |
| 139 | + | |
| 140 | + $addresses[] = [ | |
| 141 | + 'address' => '63 Stone Creek Cir St Johns, FL 32259, USA', | |
| 142 | + 'lat' => 30.048496, | |
| 143 | + 'lng' => -81.558716, | |
| 144 | + 'time' => 300, | |
| 145 | + 'time_window_start' => 43200, | |
| 146 | + 'time_window_end' => 45000, | |
| 147 | + ]; | |
| 148 | + | |
| 149 | + $addresses[] = [ | |
| 150 | + 'address' => 'St Johns Florida 32259, USA', | |
| 151 | + 'lat' => 30.099642, | |
| 152 | + 'lng' => -81.547201, | |
| 153 | + 'time' => 300, | |
| 154 | + 'time_window_start' => 46800, | |
| 155 | + 'time_window_end' => 48600, | |
| 156 | + ]; | |
| 157 | 157 | |
| 158 | - //endregion | |
| 159 | - | |
| 160 | - $parameters = [ | |
| 161 | - 'device_type' => DeviceType::IPAD, | |
| 162 | - 'disable_optimization' => false, | |
| 163 | -            'route_name'            => 'phpunit test '.date('Y-m-d H:i'), | |
| 164 | - ]; | |
| 165 | - | |
| 166 | - $routeParameters = Route::fromArray([ | |
| 167 | - 'parameters' => $parameters, | |
| 168 | - 'addresses' => $addresses | |
| 169 | - ]); | |
| 170 | - | |
| 171 | - $this->assertEquals(RouteParameters::fromArray($parameters), $routeParameters->parameters); | |
| 172 | - } | |
| 173 | - | |
| 174 | - public function testAssignMemberToRoute() | |
| 175 | -    { | |
| 176 | - //region -- Get Random Member -- | |
| 158 | + //endregion | |
| 159 | + | |
| 160 | + $parameters = [ | |
| 161 | + 'device_type' => DeviceType::IPAD, | |
| 162 | + 'disable_optimization' => false, | |
| 163 | +			'route_name'            => 'phpunit test '.date('Y-m-d H:i'), | |
| 164 | + ]; | |
| 165 | + | |
| 166 | + $routeParameters = Route::fromArray([ | |
| 167 | + 'parameters' => $parameters, | |
| 168 | + 'addresses' => $addresses | |
| 169 | + ]); | |
| 170 | + | |
| 171 | + $this->assertEquals(RouteParameters::fromArray($parameters), $routeParameters->parameters); | |
| 172 | + } | |
| 173 | + | |
| 174 | + public function testAssignMemberToRoute() | |
| 175 | +	{ | |
| 176 | + //region -- Get Random Member -- | |
| 177 | 177 | |
| 178 | - $member = new Member(); | |
| 178 | + $member = new Member(); | |
| 179 | 179 | |
| 180 | - $users = $member->getUsers(); | |
| 180 | + $users = $member->getUsers(); | |
| 181 | 181 | |
| 182 | - assert(!is_null($users), 'Cannot retrieve list of the users'); | |
| 183 | - assert(2 == sizeof($users), 'Cannot retrieve list of the users'); | |
| 184 | - assert(isset($users['results']), 'Cannot retrieve list of the users'); | |
| 185 | - assert(isset($users['total']), 'Cannot retrieve list of the users'); | |
| 182 | + assert(!is_null($users), 'Cannot retrieve list of the users'); | |
| 183 | + assert(2 == sizeof($users), 'Cannot retrieve list of the users'); | |
| 184 | + assert(isset($users['results']), 'Cannot retrieve list of the users'); | |
| 185 | + assert(isset($users['total']), 'Cannot retrieve list of the users'); | |
| 186 | 186 | |
| 187 | - $randIndex = rand(0, $users['total'] - 1); | |
| 187 | + $randIndex = rand(0, $users['total'] - 1); | |
| 188 | 188 | |
| 189 | - $randomUserID = $users['results'][$randIndex]['member_id']; | |
| 189 | + $randomUserID = $users['results'][$randIndex]['member_id']; | |
| 190 | 190 | |
| 191 | - //endregion | |
| 191 | + //endregion | |
| 192 | 192 | |
| 193 | - //region -- Assign Member To Route | |
| 193 | + //region -- Assign Member To Route | |
| 194 | 194 | |
| 195 | - $route = new Route(); | |
| 195 | + $route = new Route(); | |
| 196 | 196 | |
| 197 | - $routeId = self::$createdProblems[0] | |
| 198 | - ->routes[sizeof(self::$createdProblems[0]->routes) - 1] | |
| 199 | - ->route_id; | |
| 197 | + $routeId = self::$createdProblems[0] | |
| 198 | + ->routes[sizeof(self::$createdProblems[0]->routes) - 1] | |
| 199 | + ->route_id; | |
| 200 | 200 | |
| 201 | - $route->route_id = $routeId; | |
| 201 | + $route->route_id = $routeId; | |
| 202 | 202 | |
| 203 | - $route->parameters = new \stdClass(); | |
| 203 | + $route->parameters = new \stdClass(); | |
| 204 | 204 | |
| 205 | - $route->parameters = [ | |
| 206 | - 'member_id' => $randomUserID, | |
| 207 | - ]; | |
| 205 | + $route->parameters = [ | |
| 206 | + 'member_id' => $randomUserID, | |
| 207 | + ]; | |
| 208 | 208 | |
| 209 | - $route->httpheaders = 'Content-type: application/json'; | |
| 209 | + $route->httpheaders = 'Content-type: application/json'; | |
| 210 | 210 | |
| 211 | - $route->update(); | |
| 211 | + $route->update(); | |
| 212 | 212 | |
| 213 | - $this->assertNotNull($route); | |
| 214 | - $this->assertInstanceOf(Route::class,$route); | |
| 213 | + $this->assertNotNull($route); | |
| 214 | + $this->assertInstanceOf(Route::class,$route); | |
| 215 | 215 | |
| 216 | - //endregion | |
| 216 | + //endregion | |
| 217 | 217 | |
| 218 | - //region -- Check the Route Assigned -- | |
| 218 | + //region -- Check the Route Assigned -- | |
| 219 | 219 | |
| 220 | - $route = new Route(); | |
| 220 | + $route = new Route(); | |
| 221 | 221 | |
| 222 | - $assignedRoute= $route->getRoutes(['route_id' => $routeId]); | |
| 222 | + $assignedRoute= $route->getRoutes(['route_id' => $routeId]); | |
| 223 | 223 | |
| 224 | - $this->assertNotNull($assignedRoute); | |
| 225 | - $this->assertInstanceOf(Route::class,$assignedRoute); | |
| 226 | - $this->assertEquals($randomUserID, $assignedRoute->parameters->member_id); | |
| 224 | + $this->assertNotNull($assignedRoute); | |
| 225 | + $this->assertInstanceOf(Route::class,$assignedRoute); | |
| 226 | + $this->assertEquals($randomUserID, $assignedRoute->parameters->member_id); | |
| 227 | 227 | |
| 228 | - //endregion | |
| 229 | - } | |
| 228 | + //endregion | |
| 229 | + } | |
| 230 | 230 | |
| 231 | - public function testAssignVehicleToRoute() | |
| 232 | -    { | |
| 233 | - //region -- Get Random Vehicle -- | |
| 231 | + public function testAssignVehicleToRoute() | |
| 232 | +	{ | |
| 233 | + //region -- Get Random Vehicle -- | |
| 234 | 234 | |
| 235 | - $vehicle = new Vehicle(); | |
| 235 | + $vehicle = new Vehicle(); | |
| 236 | 236 | |
| 237 | - $vehicleParameters = [ | |
| 238 | - 'with_pagination' => true, | |
| 239 | - 'page' => 1, | |
| 240 | - 'perPage' => 10, | |
| 241 | - ]; | |
| 237 | + $vehicleParameters = [ | |
| 238 | + 'with_pagination' => true, | |
| 239 | + 'page' => 1, | |
| 240 | + 'perPage' => 10, | |
| 241 | + ]; | |
| 242 | 242 | |
| 243 | - $response = $vehicle->getVehicles($vehicleParameters); | |
| 243 | + $response = $vehicle->getVehicles($vehicleParameters); | |
| 244 | 244 | |
| 245 | - $this->assertNotNull($response); | |
| 246 | - $this->assertTrue(is_array($response)); | |
| 245 | + $this->assertNotNull($response); | |
| 246 | + $this->assertTrue(is_array($response)); | |
| 247 | 247 | |
| 248 | -        if (sizeof($response)<1) { | |
| 249 | - $vehicle = new VehicleV4(); | |
| 248 | +		if (sizeof($response)<1) { | |
| 249 | + $vehicle = new VehicleV4(); | |
| 250 | 250 | |
| 251 | - $vehicleParameters = Vehicle::fromArray([ | |
| 252 | - 'vehicle_name' => 'Ford Transit Test 5', | |
| 253 | - 'vehicle_alias' => 'Ford Transit Test 5', | |
| 254 | - 'vehicle_vin' => 'JS3TD62V1Y4107898', | |
| 255 | - 'vehicle_reg_country_id' => '223', | |
| 256 | - 'vehicle_make' => 'Ford', | |
| 257 | - 'vehicle_model_year' => 2013, | |
| 258 | - 'vehicle_axle_count' => 2, | |
| 259 | - 'mpg_city' => 8, | |
| 260 | - 'mpg_highway' => 14, | |
| 261 | - 'fuel_type' => 'unleaded 93', | |
| 262 | - 'height_inches' => 72, | |
| 263 | - 'weight_lb' => 2000, | |
| 264 | - ]); | |
| 251 | + $vehicleParameters = Vehicle::fromArray([ | |
| 252 | + 'vehicle_name' => 'Ford Transit Test 5', | |
| 253 | + 'vehicle_alias' => 'Ford Transit Test 5', | |
| 254 | + 'vehicle_vin' => 'JS3TD62V1Y4107898', | |
| 255 | + 'vehicle_reg_country_id' => '223', | |
| 256 | + 'vehicle_make' => 'Ford', | |
| 257 | + 'vehicle_model_year' => 2013, | |
| 258 | + 'vehicle_axle_count' => 2, | |
| 259 | + 'mpg_city' => 8, | |
| 260 | + 'mpg_highway' => 14, | |
| 261 | + 'fuel_type' => 'unleaded 93', | |
| 262 | + 'height_inches' => 72, | |
| 263 | + 'weight_lb' => 2000, | |
| 264 | + ]); | |
| 265 | 265 | |
| 266 | - $result = $vehicle->createVehicle($vehicleParameters); | |
| 266 | + $result = $vehicle->createVehicle($vehicleParameters); | |
| 267 | 267 | |
| 268 | - self::assertNotNull($result); | |
| 269 | - self::assertInstanceOf( | |
| 270 | - VehicleV4::class, | |
| 271 | - VehicleV4::fromArray($result) | |
| 272 | - ); | |
| 268 | + self::assertNotNull($result); | |
| 269 | + self::assertInstanceOf( | |
| 270 | + VehicleV4::class, | |
| 271 | + VehicleV4::fromArray($result) | |
| 272 | + ); | |
| 273 | 273 | |
| 274 | - $response[] = $result; | |
| 274 | + $response[] = $result; | |
| 275 | 275 | |
| 276 | - $removedVehicleIDs[] = $result['vehicle_id']; | |
| 277 | - } | |
| 276 | + $removedVehicleIDs[] = $result['vehicle_id']; | |
| 277 | + } | |
| 278 | 278 | |
| 279 | - $randomIndex = rand(0, sizeof($response)-1); | |
| 280 | - $vehicleId = $response[$randomIndex]['vehicle_id']; | |
| 279 | + $randomIndex = rand(0, sizeof($response)-1); | |
| 280 | + $vehicleId = $response[$randomIndex]['vehicle_id']; | |
| 281 | 281 | |
| 282 | - //endregion | |
| 282 | + //endregion | |
| 283 | 283 | |
| 284 | - //region -- Assign Vehicle To Route | |
| 284 | + //region -- Assign Vehicle To Route | |
| 285 | 285 | |
| 286 | - $route = new Route(); | |
| 286 | + $route = new Route(); | |
| 287 | 287 | |
| 288 | - $routeId = self::$createdProblems[0] | |
| 289 | - ->routes[sizeof(self::$createdProblems[0]->routes) - 1] | |
| 290 | - ->route_id; | |
| 288 | + $routeId = self::$createdProblems[0] | |
| 289 | + ->routes[sizeof(self::$createdProblems[0]->routes) - 1] | |
| 290 | + ->route_id; | |
| 291 | 291 | |
| 292 | - $route->route_id = $routeId; | |
| 292 | + $route->route_id = $routeId; | |
| 293 | 293 | |
| 294 | - $route->parameters = new \stdClass(); | |
| 294 | + $route->parameters = new \stdClass(); | |
| 295 | 295 | |
| 296 | - $route->parameters = [ | |
| 297 | - 'vehicle_id' => $vehicleId, | |
| 298 | - ]; | |
| 296 | + $route->parameters = [ | |
| 297 | + 'vehicle_id' => $vehicleId, | |
| 298 | + ]; | |
| 299 | 299 | |
| 300 | - $route->httpheaders = 'Content-type: application/json'; | |
| 300 | + $route->httpheaders = 'Content-type: application/json'; | |
| 301 | 301 | |
| 302 | - $route->update(); | |
| 302 | + $route->update(); | |
| 303 | 303 | |
| 304 | - $this->assertNotNull($route); | |
| 305 | - $this->assertInstanceOf(Route::class,$route); | |
| 304 | + $this->assertNotNull($route); | |
| 305 | + $this->assertInstanceOf(Route::class,$route); | |
| 306 | 306 | |
| 307 | - //endregion | |
| 307 | + //endregion | |
| 308 | 308 | |
| 309 | - //region -- Check the Route Assigned -- | |
| 309 | + //region -- Check the Route Assigned -- | |
| 310 | 310 | |
| 311 | - $route = new Route(); | |
| 311 | + $route = new Route(); | |
| 312 | 312 | |
| 313 | - $assignedRoute= $route->getRoutes(['route_id' => $routeId]); | |
| 313 | + $assignedRoute= $route->getRoutes(['route_id' => $routeId]); | |
| 314 | 314 | |
| 315 | - $this->assertNotNull($assignedRoute); | |
| 316 | - $this->assertInstanceOf(Route::class,$assignedRoute); | |
| 317 | - $this->assertEquals($vehicleId, $assignedRoute->parameters->vehicle_id); | |
| 315 | + $this->assertNotNull($assignedRoute); | |
| 316 | + $this->assertInstanceOf(Route::class,$assignedRoute); | |
| 317 | + $this->assertEquals($vehicleId, $assignedRoute->parameters->vehicle_id); | |
| 318 | 318 | |
| 319 | - //endregion | |
| 320 | - } | |
| 319 | + //endregion | |
| 320 | + } | |
| 321 | 321 | |
| 322 | - public function testDuplicateRoute() | |
| 323 | -    { | |
| 324 | - $route = new Route(); | |
| 322 | + public function testDuplicateRoute() | |
| 323 | +	{ | |
| 324 | + $route = new Route(); | |
| 325 | 325 | |
| 326 | - $routeIDs = [self::$testRoutes[0]->route_id]; | |
| 326 | + $routeIDs = [self::$testRoutes[0]->route_id]; | |
| 327 | 327 | |
| 328 | - $routeDuplicate = $route->duplicateRoute($routeIDs); | |
| 328 | + $routeDuplicate = $route->duplicateRoute($routeIDs); | |
| 329 | 329 | |
| 330 | - $this->assertTrue(isset($routeDuplicate['status']), "Cannot created duplicate route"); | |
| 331 | - $this->assertTrue($routeDuplicate['status'], "Cannot created duplicate route"); | |
| 330 | + $this->assertTrue(isset($routeDuplicate['status']), "Cannot created duplicate route"); | |
| 331 | + $this->assertTrue($routeDuplicate['status'], "Cannot created duplicate route"); | |
| 332 | 332 | |
| 333 | - $duplicatedRouteId = $routeDuplicate['route_ids'][0]; | |
| 333 | + $duplicatedRouteId = $routeDuplicate['route_ids'][0]; | |
| 334 | 334 | |
| 335 | - self::$removedRouteIDs[] = $duplicatedRouteId; | |
| 336 | - } | |
| 335 | + self::$removedRouteIDs[] = $duplicatedRouteId; | |
| 336 | + } | |
| 337 | 337 | |
| 338 | - public function testGetRouteDirections() | |
| 339 | -    { | |
| 340 | - $route = new Route(); | |
| 338 | + public function testGetRouteDirections() | |
| 339 | +	{ | |
| 340 | + $route = new Route(); | |
| 341 | 341 | |
| 342 | - $route_id = self::$testRoutes[0]->route_id; | |
| 342 | + $route_id = self::$testRoutes[0]->route_id; | |
| 343 | 343 | |
| 344 | - // Note: not every optimization includes information about directions, | |
| 345 | - // only thus, which was generated with the parameter directions = 1 | |
| 344 | + // Note: not every optimization includes information about directions, | |
| 345 | + // only thus, which was generated with the parameter directions = 1 | |
| 346 | 346 | |
| 347 | - // Get a route with the directions | |
| 348 | - $params = new RouteParametersQuery(); | |
| 347 | + // Get a route with the directions | |
| 348 | + $params = new RouteParametersQuery(); | |
| 349 | 349 | |
| 350 | - $params->route_id = $route_id; | |
| 351 | - $params->directions = true; | |
| 350 | + $params->route_id = $route_id; | |
| 351 | + $params->directions = true; | |
| 352 | 352 | |
| 353 | - $routeResult = (array)$route->getRoutePoints($params->toArray()); | |
| 353 | + $routeResult = (array)$route->getRoutePoints($params->toArray()); | |
| 354 | 354 | |
| 355 | - $this->assertNotNull($routeResult); | |
| 356 | - $this->assertTrue(is_array($routeResult)); | |
| 357 | - $this->assertTrue(sizeof($routeResult)>0); | |
| 358 | - $this->assertInstanceOf(Route::class, Route::fromArray($routeResult)); | |
| 359 | - $this->assertTrue(isset($routeResult['directions'])); | |
| 360 | - $this->assertTrue(sizeof($routeResult['directions'])>0); | |
| 361 | - } | |
| 355 | + $this->assertNotNull($routeResult); | |
| 356 | + $this->assertTrue(is_array($routeResult)); | |
| 357 | + $this->assertTrue(sizeof($routeResult)>0); | |
| 358 | + $this->assertInstanceOf(Route::class, Route::fromArray($routeResult)); | |
| 359 | + $this->assertTrue(isset($routeResult['directions'])); | |
| 360 | + $this->assertTrue(sizeof($routeResult['directions'])>0); | |
| 361 | + } | |
| 362 | 362 | |
| 363 | - public function testGetRoutePathPoints() | |
| 364 | -    { | |
| 365 | - $route = new Route(); | |
| 363 | + public function testGetRoutePathPoints() | |
| 364 | +	{ | |
| 365 | + $route = new Route(); | |
| 366 | 366 | |
| 367 | - $route_id = self::$testRoutes[0]->route_id; | |
| 367 | + $route_id = self::$testRoutes[0]->route_id; | |
| 368 | 368 | |
| 369 | - // Note: not every optimization includes information about path points, only thus, | |
| 370 | - // which was generated with the parameter route_path_output = "Points" | |
| 369 | + // Note: not every optimization includes information about path points, only thus, | |
| 370 | + // which was generated with the parameter route_path_output = "Points" | |
| 371 | 371 | |
| 372 | - // Get a route with the path points | |
| 372 | + // Get a route with the path points | |
| 373 | 373 | |
| 374 | - $params = new RouteParametersQuery(); | |
| 374 | + $params = new RouteParametersQuery(); | |
| 375 | 375 | |
| 376 | - $params->route_id = $route_id; | |
| 377 | - $params->route_path_output = 'Points'; | |
| 376 | + $params->route_id = $route_id; | |
| 377 | + $params->route_path_output = 'Points'; | |
| 378 | 378 | |
| 379 | - $routeResult = (array) $route->getRoutePoints($params->toArray()); | |
| 379 | + $routeResult = (array) $route->getRoutePoints($params->toArray()); | |
| 380 | 380 | |
| 381 | - $this->assertNotNull($routeResult); | |
| 382 | - $this->assertTrue(is_array($routeResult)); | |
| 383 | - $this->assertTrue(sizeof($routeResult)>0); | |
| 384 | - $this->assertInstanceOf(Route::class, Route::fromArray($routeResult)); | |
| 385 | - $this->assertTrue(isset($routeResult['path'])); | |
| 386 | - $this->assertTrue(sizeof($routeResult['path'])>0); | |
| 387 | - } | |
| 381 | + $this->assertNotNull($routeResult); | |
| 382 | + $this->assertTrue(is_array($routeResult)); | |
| 383 | + $this->assertTrue(sizeof($routeResult)>0); | |
| 384 | + $this->assertInstanceOf(Route::class, Route::fromArray($routeResult)); | |
| 385 | + $this->assertTrue(isset($routeResult['path'])); | |
| 386 | + $this->assertTrue(sizeof($routeResult['path'])>0); | |
| 387 | + } | |
| 388 | 388 | |
| 389 | - public function testGetRoute() | |
| 390 | -    { | |
| 391 | - $route = new Route(); | |
| 389 | + public function testGetRoute() | |
| 390 | +	{ | |
| 391 | + $route = new Route(); | |
| 392 | 392 | |
| 393 | - $route_id = self::$testRoutes[0]->route_id; | |
| 393 | + $route_id = self::$testRoutes[0]->route_id; | |
| 394 | 394 | |
| 395 | - // get a route by ID | |
| 396 | - $routeResult = $route->getRoutes(['route_id' => $route_id]); | |
| 395 | + // get a route by ID | |
| 396 | + $routeResult = $route->getRoutes(['route_id' => $route_id]); | |
| 397 | 397 | |
| 398 | - $this->assertNotNull($routeResult); | |
| 399 | - $this->assertInstanceOf(Route::class, $routeResult); | |
| 400 | - $this->assertEquals($route_id, $routeResult->route_id); | |
| 401 | - } | |
| 398 | + $this->assertNotNull($routeResult); | |
| 399 | + $this->assertInstanceOf(Route::class, $routeResult); | |
| 400 | + $this->assertEquals($route_id, $routeResult->route_id); | |
| 401 | + } | |
| 402 | 402 | |
| 403 | - public function testGetRoutesByIDs() | |
| 404 | -    { | |
| 405 | - $params = new RouteParametersQuery(); | |
| 403 | + public function testGetRoutesByIDs() | |
| 404 | +	{ | |
| 405 | + $params = new RouteParametersQuery(); | |
| 406 | 406 | |
| 407 | - $params->limit = 5; | |
| 408 | - $params->offset = 0; | |
| 407 | + $params->limit = 5; | |
| 408 | + $params->offset = 0; | |
| 409 | 409 | |
| 410 | - $route = new Route(); | |
| 410 | + $route = new Route(); | |
| 411 | 411 | |
| 412 | - $routeResults = $route->getRoutes($params->toArray()); | |
| 412 | + $routeResults = $route->getRoutes($params->toArray()); | |
| 413 | 413 | |
| 414 | - $routeId1 = $routeResults[0]->route_id; | |
| 415 | - $routeId2 = $routeResults[1]->route_id; | |
| 414 | + $routeId1 = $routeResults[0]->route_id; | |
| 415 | + $routeId2 = $routeResults[1]->route_id; | |
| 416 | 416 | |
| 417 | - $routesResult = $route->getRoutes(['route_id' => $routeId1.','.$routeId2]); | |
| 417 | + $routesResult = $route->getRoutes(['route_id' => $routeId1.','.$routeId2]); | |
| 418 | 418 | |
| 419 | - $this->assertNotNull($routesResult); | |
| 420 | - $this->assertTrue(is_array($routesResult)); | |
| 421 | - $this->assertTrue(sizeof($routesResult)==2); | |
| 422 | - $this->assertInstanceOf( | |
| 423 | - Route::class, | |
| 424 | - Route::fromArray($routesResult[0]) | |
| 425 | - ); | |
| 426 | - } | |
| 419 | + $this->assertNotNull($routesResult); | |
| 420 | + $this->assertTrue(is_array($routesResult)); | |
| 421 | + $this->assertTrue(sizeof($routesResult)==2); | |
| 422 | + $this->assertInstanceOf( | |
| 423 | + Route::class, | |
| 424 | + Route::fromArray($routesResult[0]) | |
| 425 | + ); | |
| 426 | + } | |
| 427 | 427 | |
| 428 | - public function testGetRoutesFromDateRange() | |
| 429 | -    { | |
| 430 | - $params = new RouteParametersQuery(); | |
| 428 | + public function testGetRoutesFromDateRange() | |
| 429 | +	{ | |
| 430 | + $params = new RouteParametersQuery(); | |
| 431 | 431 | |
| 432 | -        $params->start_date = date('Y-m-d', strtotime('-1 days')); | |
| 433 | -        $params->end_date   = date('Y-m-d', strtotime('+1 days')); | |
| 432 | +		$params->start_date = date('Y-m-d', strtotime('-1 days')); | |
| 433 | +		$params->end_date   = date('Y-m-d', strtotime('+1 days')); | |
| 434 | 434 | |
| 435 | - $route = new Route(); | |
| 435 | + $route = new Route(); | |
| 436 | 436 | |
| 437 | - $routeResults = $route->getRoutes($params->toArray()); | |
| 437 | + $routeResults = $route->getRoutes($params->toArray()); | |
| 438 | 438 | |
| 439 | - $this->assertNotNull($routeResults); | |
| 440 | - $this->assertTrue(is_array($routeResults)); | |
| 441 | - $this->assertTrue(sizeof($routeResults)>0); | |
| 442 | - $this->assertInstanceOf(Route::class, Route::fromArray($routeResults)); | |
| 439 | + $this->assertNotNull($routeResults); | |
| 440 | + $this->assertTrue(is_array($routeResults)); | |
| 441 | + $this->assertTrue(sizeof($routeResults)>0); | |
| 442 | + $this->assertInstanceOf(Route::class, Route::fromArray($routeResults)); | |
| 443 | 443 | |
| 444 | -        $startDateUnix = date_create($params->start_date)->format('U'); | |
| 445 | -        $endtDateUnix = date_create($params->end_date)->format('U'); | |
| 444 | +		$startDateUnix = date_create($params->start_date)->format('U'); | |
| 445 | +		$endtDateUnix = date_create($params->end_date)->format('U'); | |
| 446 | 446 | |
| 447 | -        $tz = date('Z'); | |
| 447 | +		$tz = date('Z'); | |
| 448 | 448 | |
| 449 | -        foreach ($routeResults as $routeResult) { | |
| 449 | +		foreach ($routeResults as $routeResult) { | |
| 450 | 450 | |
| 451 | - $this->assertTrue( | |
| 452 | - $routeResult->parameters->route_date - $tz >= $startDateUnix && | |
| 453 | - $routeResult->parameters->route_date - $tz <= $endtDateUnix | |
| 454 | - ); | |
| 455 | - } | |
| 456 | - } | |
| 451 | + $this->assertTrue( | |
| 452 | + $routeResult->parameters->route_date - $tz >= $startDateUnix && | |
| 453 | + $routeResult->parameters->route_date - $tz <= $endtDateUnix | |
| 454 | + ); | |
| 455 | + } | |
| 456 | + } | |
| 457 | 457 | |
| 458 | - public function testGetRoutes() | |
| 459 | -    { | |
| 460 | - $params = new RouteParametersQuery(); | |
| 458 | + public function testGetRoutes() | |
| 459 | +	{ | |
| 460 | + $params = new RouteParametersQuery(); | |
| 461 | 461 | |
| 462 | - $params->limit = 10; | |
| 463 | - $params->offset = 0; | |
| 462 | + $params->limit = 10; | |
| 463 | + $params->offset = 0; | |
| 464 | 464 | |
| 465 | - $route = new Route(); | |
| 465 | + $route = new Route(); | |
| 466 | 466 | |
| 467 | - $routeResults = $route->getRoutes($params->toArray()); | |
| 467 | + $routeResults = $route->getRoutes($params->toArray()); | |
| 468 | 468 | |
| 469 | - $this->assertNotNull($routeResults); | |
| 470 | - $this->assertTrue(is_array($routeResults)); | |
| 471 | - $this->assertTrue(sizeof($routeResults)>0); | |
| 472 | - $this->assertInstanceOf(Route::class, Route::fromArray($routeResults)); | |
| 473 | - } | |
| 469 | + $this->assertNotNull($routeResults); | |
| 470 | + $this->assertTrue(is_array($routeResults)); | |
| 471 | + $this->assertTrue(sizeof($routeResults)>0); | |
| 472 | + $this->assertInstanceOf(Route::class, Route::fromArray($routeResults)); | |
| 473 | + } | |
| 474 | 474 | |
| 475 | - public function testReoptimizeRoute() | |
| 476 | -    { | |
| 477 | - $route = new Route(); | |
| 475 | + public function testReoptimizeRoute() | |
| 476 | +	{ | |
| 477 | + $route = new Route(); | |
| 478 | 478 | |
| 479 | - $route_id = self::$testRoutes[0]->route_id; | |
| 479 | + $route_id = self::$testRoutes[0]->route_id; | |
| 480 | 480 | |
| 481 | - // Re-sequence all addresses | |
| 482 | - $params = new RouteParametersQuery(); | |
| 481 | + // Re-sequence all addresses | |
| 482 | + $params = new RouteParametersQuery(); | |
| 483 | 483 | |
| 484 | - $params->route_id = $route_id; | |
| 485 | - $params->reoptimize = true; | |
| 484 | + $params->route_id = $route_id; | |
| 485 | + $params->reoptimize = true; | |
| 486 | 486 | |
| 487 | - $routeResult = $route->updateRoute($params->toArray()); | |
| 487 | + $routeResult = $route->updateRoute($params->toArray()); | |
| 488 | 488 | |
| 489 | - $this->assertNotNull($routeResult); | |
| 490 | - $this->assertTrue(is_array($routeResult)); | |
| 491 | - $this->assertTrue(sizeof($routeResult)>0); | |
| 492 | - $this->assertInstanceOf(Route::class, Route::fromArray($routeResult)); | |
| 493 | - } | |
| 489 | + $this->assertNotNull($routeResult); | |
| 490 | + $this->assertTrue(is_array($routeResult)); | |
| 491 | + $this->assertTrue(sizeof($routeResult)>0); | |
| 492 | + $this->assertInstanceOf(Route::class, Route::fromArray($routeResult)); | |
| 493 | + } | |
| 494 | 494 | |
| 495 | - public function testResequenceReoptimizeRoute() | |
| 496 | -    { | |
| 497 | - $route = new Route(); | |
| 495 | + public function testResequenceReoptimizeRoute() | |
| 496 | +	{ | |
| 497 | + $route = new Route(); | |
| 498 | 498 | |
| 499 | - $selectedRoute = null; | |
| 499 | + $selectedRoute = null; | |
| 500 | 500 | |
| 501 | -        foreach (self::$testRoutes as $route1) { | |
| 502 | -            if (isset($route1->destination_count)) { | |
| 503 | -                if ($route1->destination_count > 4) { | |
| 504 | - $selectedRoute = $route->getRoutes(['route_id' => $route1->route_id]); | |
| 505 | - break; | |
| 506 | - } | |
| 507 | - } | |
| 508 | - } | |
| 501 | +		foreach (self::$testRoutes as $route1) { | |
| 502 | +			if (isset($route1->destination_count)) { | |
| 503 | +				if ($route1->destination_count > 4) { | |
| 504 | + $selectedRoute = $route->getRoutes(['route_id' => $route1->route_id]); | |
| 505 | + break; | |
| 506 | + } | |
| 507 | + } | |
| 508 | + } | |
| 509 | 509 | |
| 510 | - $this->assertNotNull( | |
| 511 | - $selectedRoute, | |
| 512 | - "Cannot select a route with more than 4 addresses"); | |
| 510 | + $this->assertNotNull( | |
| 511 | + $selectedRoute, | |
| 512 | + "Cannot select a route with more than 4 addresses"); | |
| 513 | 513 | |
| 514 | - // Resequence a route destination | |
| 515 | - $routeID = $selectedRoute->route_id; | |
| 516 | - $routeDestinationID = $selectedRoute->addresses[2]->route_destination_id; | |
| 514 | + // Resequence a route destination | |
| 515 | + $routeID = $selectedRoute->route_id; | |
| 516 | + $routeDestinationID = $selectedRoute->addresses[2]->route_destination_id; | |
| 517 | 517 | |
| 518 | - echo "Route ID-> $routeID, Route destination ID -> $routeDestinationID <br>"; | |
| 518 | + echo "Route ID-> $routeID, Route destination ID -> $routeDestinationID <br>"; | |
| 519 | 519 | |
| 520 | - $params = [ | |
| 521 | - 'route_id' => $routeID, | |
| 522 | - 'route_destination_id' => $routeDestinationID, | |
| 523 | - 'addresses' => [ | |
| 524 | - '0' => [ | |
| 525 | - 'route_destination_id' => $routeDestinationID, | |
| 526 | - 'sequence_no' => 3, | |
| 527 | - ], | |
| 528 | - ], | |
| 529 | - ]; | |
| 520 | + $params = [ | |
| 521 | + 'route_id' => $routeID, | |
| 522 | + 'route_destination_id' => $routeDestinationID, | |
| 523 | + 'addresses' => [ | |
| 524 | + '0' => [ | |
| 525 | + 'route_destination_id' => $routeDestinationID, | |
| 526 | + 'sequence_no' => 3, | |
| 527 | + ], | |
| 528 | + ], | |
| 529 | + ]; | |
| 530 | 530 | |
| 531 | - $response = $route->resequenceRoute($params); | |
| 531 | + $response = $route->resequenceRoute($params); | |
| 532 | 532 | |
| 533 | - $this->assertNotNull($response); | |
| 534 | - $this->assertTrue(is_array($response)); | |
| 535 | - $this->assertTrue(sizeof($response)>0); | |
| 536 | - $this->assertInstanceOf(Route::class, Route::fromArray($response)); | |
| 537 | - } | |
| 533 | + $this->assertNotNull($response); | |
| 534 | + $this->assertTrue(is_array($response)); | |
| 535 | + $this->assertTrue(sizeof($response)>0); | |
| 536 | + $this->assertInstanceOf(Route::class, Route::fromArray($response)); | |
| 537 | + } | |
| 538 | 538 | |
| 539 | - public function testResequenceRouteDestinations() | |
| 540 | -    { | |
| 541 | - $route = new Route(); | |
| 542 | - $address = new Address(); | |
| 539 | + public function testResequenceRouteDestinations() | |
| 540 | +	{ | |
| 541 | + $route = new Route(); | |
| 542 | + $address = new Address(); | |
| 543 | 543 | |
| 544 | - $routeID = self::$testRoutes[0]->route_id; | |
| 545 | - $routeDestinationID = self::$testRoutes[0]->addresses[2]->route_destination_id; | |
| 544 | + $routeID = self::$testRoutes[0]->route_id; | |
| 545 | + $routeDestinationID = self::$testRoutes[0]->addresses[2]->route_destination_id; | |
| 546 | 546 | |
| 547 | - $this->assertNotNull($routeID); | |
| 548 | - $this->assertNotNull($routeDestinationID); | |
| 547 | + $this->assertNotNull($routeID); | |
| 548 | + $this->assertNotNull($routeDestinationID); | |
| 549 | 549 | |
| 550 | - //region -- Re-sequence a route destination -- | |
| 550 | + //region -- Re-sequence a route destination -- | |
| 551 | 551 | |
| 552 | - $params = [ | |
| 553 | - 'route_id' => $routeID, | |
| 554 | - 'route_destination_id' => $routeDestinationID, | |
| 555 | - 'addresses' => [ | |
| 556 | - '0' => [ | |
| 557 | - 'route_destination_id' => $routeDestinationID, | |
| 558 | - 'sequence_no' => 3, | |
| 559 | - ], | |
| 560 | - ], | |
| 561 | - ]; | |
| 552 | + $params = [ | |
| 553 | + 'route_id' => $routeID, | |
| 554 | + 'route_destination_id' => $routeDestinationID, | |
| 555 | + 'addresses' => [ | |
| 556 | + '0' => [ | |
| 557 | + 'route_destination_id' => $routeDestinationID, | |
| 558 | + 'sequence_no' => 3, | |
| 559 | + ], | |
| 560 | + ], | |
| 561 | + ]; | |
| 562 | 562 | |
| 563 | - $response = $route->resequenceRoute($params); | |
| 563 | + $response = $route->resequenceRoute($params); | |
| 564 | 564 | |
| 565 | - $this->assertNotNull($response); | |
| 566 | - $this->assertTrue(is_array($response)); | |
| 567 | - $this->assertTrue(sizeof($response)>0); | |
| 568 | - $this->assertInstanceOf(Route::class, Route::fromArray($response)); | |
| 565 | + $this->assertNotNull($response); | |
| 566 | + $this->assertTrue(is_array($response)); | |
| 567 | + $this->assertTrue(sizeof($response)>0); | |
| 568 | + $this->assertInstanceOf(Route::class, Route::fromArray($response)); | |
| 569 | 569 | |
| 570 | - //endregion | |
| 570 | + //endregion | |
| 571 | 571 | |
| 572 | - //region -- Check the Address re-sequenced -- | |
| 572 | + //region -- Check the Address re-sequenced -- | |
| 573 | 573 | |
| 574 | - $addressRetrieved = $address->getAddress($routeID, $routeDestinationID); | |
| 574 | + $addressRetrieved = $address->getAddress($routeID, $routeDestinationID); | |
| 575 | 575 | |
| 576 | - $this->assertEquals(3, $addressRetrieved->sequence_no); | |
| 576 | + $this->assertEquals(3, $addressRetrieved->sequence_no); | |
| 577 | 577 | |
| 578 | - //endregion | |
| 579 | - } | |
| 578 | + //endregion | |
| 579 | + } | |
| 580 | 580 | |
| 581 | - public function testRouteOriginParameter() | |
| 582 | -    { | |
| 583 | - $route = new Route(); | |
| 581 | + public function testRouteOriginParameter() | |
| 582 | +	{ | |
| 583 | + $route = new Route(); | |
| 584 | 584 | |
| 585 | - $routeID = self::$testRoutes[0]->route_id; | |
| 585 | + $routeID = self::$testRoutes[0]->route_id; | |
| 586 | 586 | |
| 587 | - //region -- Re-sequence the route -- | |
| 587 | + //region -- Re-sequence the route -- | |
| 588 | 588 | |
| 589 | - $params = new RouteParametersQuery(); | |
| 590 | - $params->route_id = $routeID; | |
| 589 | + $params = new RouteParametersQuery(); | |
| 590 | + $params->route_id = $routeID; | |
| 591 | 591 | |
| 592 | - $result = $route->reoptimizeRoute($params); | |
| 592 | + $result = $route->reoptimizeRoute($params); | |
| 593 | 593 | |
| 594 | - $this->assertNotNull($result); | |
| 595 | - $this->assertInstanceOf(Route::class, Route::fromArray($result)); | |
| 594 | + $this->assertNotNull($result); | |
| 595 | + $this->assertInstanceOf(Route::class, Route::fromArray($result)); | |
| 596 | 596 | |
| 597 | - $params = new RouteParametersQuery(); | |
| 597 | + $params = new RouteParametersQuery(); | |
| 598 | 598 | |
| 599 | - $params->route_id = $routeID; | |
| 600 | - $params->original = true; | |
| 599 | + $params->route_id = $routeID; | |
| 600 | + $params->original = true; | |
| 601 | 601 | |
| 602 | - $routeWithOriginRoute = $route->getRoutes($params->toArray()); | |
| 602 | + $routeWithOriginRoute = $route->getRoutes($params->toArray()); | |
| 603 | 603 | |
| 604 | - //endregion | |
| 604 | + //endregion | |
| 605 | 605 | |
| 606 | - $this->assertNotNull($routeWithOriginRoute); | |
| 607 | - $this->assertInstanceOf(Route::class, $routeWithOriginRoute); | |
| 606 | + $this->assertNotNull($routeWithOriginRoute); | |
| 607 | + $this->assertInstanceOf(Route::class, $routeWithOriginRoute); | |
| 608 | 608 | |
| 609 | - $this->assertNotNull($routeWithOriginRoute->original_route); | |
| 610 | - $this->assertInstanceOf(Route::class, $routeWithOriginRoute->original_route); | |
| 611 | - } | |
| 609 | + $this->assertNotNull($routeWithOriginRoute->original_route); | |
| 610 | + $this->assertInstanceOf(Route::class, $routeWithOriginRoute->original_route); | |
| 611 | + } | |
| 612 | 612 | |
| 613 | - public function testShareRoute() | |
| 614 | -    { | |
| 615 | - $route = new Route(); | |
| 613 | + public function testShareRoute() | |
| 614 | +	{ | |
| 615 | + $route = new Route(); | |
| 616 | 616 | |
| 617 | - $routeID = self::$testRoutes[0]->route_id; | |
| 617 | + $routeID = self::$testRoutes[0]->route_id; | |
| 618 | 618 | |
| 619 | - // Share a route with an email | |
| 620 | - $params = [ | |
| 621 | - 'route_id' => $routeID, | |
| 622 | - 'response_format' => 'json', | |
| 623 | - 'recipient_email' => '[email protected]', | |
| 624 | - ]; | |
| 619 | + // Share a route with an email | |
| 620 | + $params = [ | |
| 621 | + 'route_id' => $routeID, | |
| 622 | + 'response_format' => 'json', | |
| 623 | + 'recipient_email' => '[email protected]', | |
| 624 | + ]; | |
| 625 | 625 | |
| 626 | - $result = $route->shareRoute($params); | |
| 626 | + $result = $route->shareRoute($params); | |
| 627 | 627 | |
| 628 | - $this->assertNotNull($result); | |
| 629 | - $this->assertTrue(isset($result['status'])); | |
| 630 | - $this->assertTrue($result['status']); | |
| 631 | - } | |
| 628 | + $this->assertNotNull($result); | |
| 629 | + $this->assertTrue(isset($result['status'])); | |
| 630 | + $this->assertTrue($result['status']); | |
| 631 | + } | |
| 632 | 632 | |
| 633 | - public function testUnlinkRouteFromOptimization() | |
| 634 | -    { | |
| 635 | - $route = new Route(); | |
| 633 | + public function testUnlinkRouteFromOptimization() | |
| 634 | +	{ | |
| 635 | + $route = new Route(); | |
| 636 | 636 | |
| 637 | - $routeID = self::$testRoutes[0]->route_id; | |
| 637 | + $routeID = self::$testRoutes[0]->route_id; | |
| 638 | 638 | |
| 639 | - //region -- Unlink a route from master destination -- | |
| 639 | + //region -- Unlink a route from master destination -- | |
| 640 | 640 | |
| 641 | - $route->route_id = $routeID; | |
| 642 | - $route->parameters = new \stdClass(); | |
| 641 | + $route->route_id = $routeID; | |
| 642 | + $route->parameters = new \stdClass(); | |
| 643 | 643 | |
| 644 | - $parameters = [ | |
| 645 | - 'route_id' => $routeID, | |
| 646 | - 'unlink_from_master_optimization' => true, | |
| 647 | - ]; | |
| 644 | + $parameters = [ | |
| 645 | + 'route_id' => $routeID, | |
| 646 | + 'unlink_from_master_optimization' => true, | |
| 647 | + ]; | |
| 648 | 648 | |
| 649 | - $route->httpheaders = 'Content-type: application/json'; | |
| 649 | + $route->httpheaders = 'Content-type: application/json'; | |
| 650 | 650 | |
| 651 | - $result = $route->updateRoute($parameters); | |
| 651 | + $result = $route->updateRoute($parameters); | |
| 652 | 652 | |
| 653 | - //endregion | |
| 653 | + //endregion | |
| 654 | 654 | |
| 655 | - $this->assertNotNull($result); | |
| 656 | - $this->assertInstanceOf(Route::class, Route::fromArray($result)); | |
| 657 | - $this->assertNull($result['optimization_problem_id']); | |
| 655 | + $this->assertNotNull($result); | |
| 656 | + $this->assertInstanceOf(Route::class, Route::fromArray($result)); | |
| 657 | + $this->assertNull($result['optimization_problem_id']); | |
| 658 | 658 | |
| 659 | - $removedRouteIDs[]= $result['route_id']; | |
| 660 | - } | |
| 659 | + $removedRouteIDs[]= $result['route_id']; | |
| 660 | + } | |
| 661 | 661 | |
| 662 | - public function testUpdateRouteAvoidanceZone() | |
| 663 | -    { | |
| 664 | - $route = new Route(); | |
| 662 | + public function testUpdateRouteAvoidanceZone() | |
| 663 | +	{ | |
| 664 | + $route = new Route(); | |
| 665 | 665 | |
| 666 | - $routeID = self::$testRoutes[0]->route_id; | |
| 666 | + $routeID = self::$testRoutes[0]->route_id; | |
| 667 | 667 | |
| 668 | - $parameters = [ | |
| 669 | - 'route_id' => $routeID, | |
| 670 | - 'parameters' => [ | |
| 671 | - 'avoidance_zones' => [ | |
| 672 | - 'FAA49711A0F1144CE4E203DC18ABDFFB', | |
| 673 | - '9C48E8008E9865006336B99D3595E66A' | |
| 674 | - ] | |
| 675 | - ] | |
| 676 | - ]; | |
| 668 | + $parameters = [ | |
| 669 | + 'route_id' => $routeID, | |
| 670 | + 'parameters' => [ | |
| 671 | + 'avoidance_zones' => [ | |
| 672 | + 'FAA49711A0F1144CE4E203DC18ABDFFB', | |
| 673 | + '9C48E8008E9865006336B99D3595E66A' | |
| 674 | + ] | |
| 675 | + ] | |
| 676 | + ]; | |
| 677 | 677 | |
| 678 | - $route->httpheaders = 'Content-type: application/json'; | |
| 678 | + $route->httpheaders = 'Content-type: application/json'; | |
| 679 | 679 | |
| 680 | - $result = $route->updateRoute($parameters); | |
| 680 | + $result = $route->updateRoute($parameters); | |
| 681 | 681 | |
| 682 | - $this->assertNotNull($result); | |
| 683 | - $this->assertInstanceOf(Route::class, Route::fromArray($result)); | |
| 682 | + $this->assertNotNull($result); | |
| 683 | + $this->assertInstanceOf(Route::class, Route::fromArray($result)); | |
| 684 | 684 | |
| 685 | - $this->assertNotNull($result['parameters']['avoidance_zones']); | |
| 686 | - $this->assertTrue(is_array($result['parameters']['avoidance_zones'])); | |
| 687 | - $this->assertEquals(2, sizeof($result['parameters']['avoidance_zones'])); | |
| 688 | - } | |
| 685 | + $this->assertNotNull($result['parameters']['avoidance_zones']); | |
| 686 | + $this->assertTrue(is_array($result['parameters']['avoidance_zones'])); | |
| 687 | + $this->assertEquals(2, sizeof($result['parameters']['avoidance_zones'])); | |
| 688 | + } | |
| 689 | 689 | |
| 690 | - public function testUpdateRouteCustomData() | |
| 691 | -    { | |
| 692 | - $route = new Route(); | |
| 690 | + public function testUpdateRouteCustomData() | |
| 691 | +	{ | |
| 692 | + $route = new Route(); | |
| 693 | 693 | |
| 694 | - $routeID = self::$testRoutes[0]->route_id; | |
| 694 | + $routeID = self::$testRoutes[0]->route_id; | |
| 695 | 695 | |
| 696 | - // Get a random address ID from selected route above | |
| 697 | - $addressRand = (array)$route->GetRandomAddressFromRoute($routeID); | |
| 696 | + // Get a random address ID from selected route above | |
| 697 | + $addressRand = (array)$route->GetRandomAddressFromRoute($routeID); | |
| 698 | 698 | |
| 699 | - $route->route_id = $routeID; | |
| 700 | - $route->route_destination_id = $addressRand['route_destination_id']; | |
| 699 | + $route->route_id = $routeID; | |
| 700 | + $route->route_destination_id = $addressRand['route_destination_id']; | |
| 701 | 701 | |
| 702 | - // Update destination custom data | |
| 703 | - $route->parameters = new \stdClass(); | |
| 702 | + // Update destination custom data | |
| 703 | + $route->parameters = new \stdClass(); | |
| 704 | 704 | |
| 705 | - $route->parameters->custom_fields = [ | |
| 706 | - 'animal' => 'tiger', | |
| 707 | - 'bird' => 'canary', | |
| 708 | - ]; | |
| 705 | + $route->parameters->custom_fields = [ | |
| 706 | + 'animal' => 'tiger', | |
| 707 | + 'bird' => 'canary', | |
| 708 | + ]; | |
| 709 | 709 | |
| 710 | - $route->httpheaders = 'Content-type: application/json'; | |
| 710 | + $route->httpheaders = 'Content-type: application/json'; | |
| 711 | 711 | |
| 712 | - $result = $route->updateAddress(); | |
| 712 | + $result = $route->updateAddress(); | |
| 713 | 713 | |
| 714 | - $this->assertNotNull($result); | |
| 715 | - $this->assertInstanceOf(Address::class, Address::fromArray($result)); | |
| 714 | + $this->assertNotNull($result); | |
| 715 | + $this->assertInstanceOf(Address::class, Address::fromArray($result)); | |
| 716 | 716 | |
| 717 | - $this->assertTrue(isset($result['custom_fields'])); | |
| 718 | - $this->assertTrue(is_array($result['custom_fields'])); | |
| 719 | -        $this->assertEquals('tiger', $result['custom_fields']['animal']); | |
| 720 | -        $this->assertEquals('canary', $result['custom_fields']['bird']); | |
| 721 | - } | |
| 717 | + $this->assertTrue(isset($result['custom_fields'])); | |
| 718 | + $this->assertTrue(is_array($result['custom_fields'])); | |
| 719 | +		$this->assertEquals('tiger', $result['custom_fields']['animal']); | |
| 720 | +		$this->assertEquals('canary', $result['custom_fields']['bird']); | |
| 721 | + } | |
| 722 | 722 | |
| 723 | - public function testUpdateRoute() | |
| 724 | -    { | |
| 725 | - $route = new Route(); | |
| 723 | + public function testUpdateRoute() | |
| 724 | +	{ | |
| 725 | + $route = new Route(); | |
| 726 | 726 | |
| 727 | - $routeID = self::$testRoutes[0]->route_id; | |
| 727 | + $routeID = self::$testRoutes[0]->route_id; | |
| 728 | 728 | |
| 729 | - $initialRoute = self::$testRoutes[0]; | |
| 729 | + $initialRoute = self::$testRoutes[0]; | |
| 730 | 730 | |
| 731 | - // Update the route parameters | |
| 732 | - $route->route_id = $routeID; | |
| 731 | + // Update the route parameters | |
| 732 | + $route->route_id = $routeID; | |
| 733 | 733 | |
| 734 | - $route->parameters = new \stdClass(); | |
| 734 | + $route->parameters = new \stdClass(); | |
| 735 | 735 | |
| 736 | - $route->parameters = [ | |
| 737 | - 'member_id' => $initialRoute->member_id, | |
| 738 | - 'optimize' => 'Distance', | |
| 739 | - 'route_max_duration' => '82400', | |
| 740 | -            'route_name'            => 'updated '.date('m-d-Y'), | |
| 741 | - ]; | |
| 736 | + $route->parameters = [ | |
| 737 | + 'member_id' => $initialRoute->member_id, | |
| 738 | + 'optimize' => 'Distance', | |
| 739 | + 'route_max_duration' => '82400', | |
| 740 | +			'route_name'            => 'updated '.date('m-d-Y'), | |
| 741 | + ]; | |
| 742 | 742 | |
| 743 | - $route->httpheaders = 'Content-type: application/json'; | |
| 743 | + $route->httpheaders = 'Content-type: application/json'; | |
| 744 | 744 | |
| 745 | - $result = $route->update(); | |
| 745 | + $result = $route->update(); | |
| 746 | 746 | |
| 747 | - $this->assertNotNull($result); | |
| 748 | - $this->assertInstanceOf(Route::class, $result); | |
| 749 | - } | |
| 747 | + $this->assertNotNull($result); | |
| 748 | + $this->assertInstanceOf(Route::class, $result); | |
| 749 | + } | |
| 750 | 750 | |
| 751 | - public function testDeleteRoutes() | |
| 752 | -    { | |
| 753 | - $route = new Route(); | |
| 751 | + public function testDeleteRoutes() | |
| 752 | +	{ | |
| 753 | + $route = new Route(); | |
| 754 | 754 | |
| 755 | -        $route_ids = join(',', [self::$createdProblems[0]->routes[0]->route_id]); | |
| 755 | +		$route_ids = join(',', [self::$createdProblems[0]->routes[0]->route_id]); | |
| 756 | 756 | |
| 757 | - $result = $route->deleteRoutes($route_ids); | |
| 757 | + $result = $route->deleteRoutes($route_ids); | |
| 758 | 758 | |
| 759 | - $this->assertNotNull($result); | |
| 760 | - $this->assertTrue(isset($result['deleted'])); | |
| 761 | - $this->assertTrue($result['deleted']); | |
| 762 | - } | |
| 759 | + $this->assertNotNull($result); | |
| 760 | + $this->assertTrue(isset($result['deleted'])); | |
| 761 | + $this->assertTrue($result['deleted']); | |
| 762 | + } | |
| 763 | 763 | |
| 764 | - public static function tearDownAfterClass() | |
| 765 | -    { | |
| 766 | -        if (sizeof(self::$createdProblems)>0) { | |
| 767 | - $optimizationProblemIDs = []; | |
| 764 | + public static function tearDownAfterClass() | |
| 765 | +	{ | |
| 766 | +		if (sizeof(self::$createdProblems)>0) { | |
| 767 | + $optimizationProblemIDs = []; | |
| 768 | 768 | |
| 769 | -            foreach (self::$createdProblems as $problem) { | |
| 770 | - $optimizationProblemId = $problem->optimization_problem_id; | |
| 769 | +			foreach (self::$createdProblems as $problem) { | |
| 770 | + $optimizationProblemId = $problem->optimization_problem_id; | |
| 771 | 771 | |
| 772 | - $optimizationProblemIDs[] = $optimizationProblemId; | |
| 773 | - } | |
| 772 | + $optimizationProblemIDs[] = $optimizationProblemId; | |
| 773 | + } | |
| 774 | 774 | |
| 775 | -            if (sizeof(self::$removedOptimizationIDs)>0) { | |
| 776 | - $optimizationProblemIDs = array_merge($optimizationProblemIDs,self::$removedOptimizationIDs); | |
| 777 | - } | |
| 775 | +			if (sizeof(self::$removedOptimizationIDs)>0) { | |
| 776 | + $optimizationProblemIDs = array_merge($optimizationProblemIDs,self::$removedOptimizationIDs); | |
| 777 | + } | |
| 778 | 778 | |
| 779 | - $params = [ | |
| 780 | - 'optimization_problem_ids' => $optimizationProblemIDs, | |
| 781 | - 'redirect' => 0, | |
| 782 | - ]; | |
| 779 | + $params = [ | |
| 780 | + 'optimization_problem_ids' => $optimizationProblemIDs, | |
| 781 | + 'redirect' => 0, | |
| 782 | + ]; | |
| 783 | 783 | |
| 784 | - $problem = new OptimizationProblem(); | |
| 785 | - $result = $problem->removeOptimization($params); | |
| 784 | + $problem = new OptimizationProblem(); | |
| 785 | + $result = $problem->removeOptimization($params); | |
| 786 | 786 | |
| 787 | -            if ($result!=null && $result['status']==true) { | |
| 788 | - echo "The test optimizations were removed <br>"; | |
| 789 | -            } else { | |
| 790 | - echo "Cannot remove the test optimizations <br>"; | |
| 791 | - } | |
| 792 | - } | |
| 787 | +			if ($result!=null && $result['status']==true) { | |
| 788 | + echo "The test optimizations were removed <br>"; | |
| 789 | +			} else { | |
| 790 | + echo "Cannot remove the test optimizations <br>"; | |
| 791 | + } | |
| 792 | + } | |
| 793 | 793 | |
| 794 | -        if (sizeof(self::$removedRouteIDs)>0) { | |
| 795 | - $route = new Route(); | |
| 794 | +		if (sizeof(self::$removedRouteIDs)>0) { | |
| 795 | + $route = new Route(); | |
| 796 | 796 | |
| 797 | -            $route_ids = join(',', self::$removedRouteIDs); | |
| 797 | +			$route_ids = join(',', self::$removedRouteIDs); | |
| 798 | 798 | |
| 799 | - $result = $route->deleteRoutes($route_ids); | |
| 799 | + $result = $route->deleteRoutes($route_ids); | |
| 800 | 800 | |
| 801 | -            if ($result!=null && $result['deleted']==true) { | |
| 802 | - echo "The test routes were removed <br>"; | |
| 803 | -            } else { | |
| 804 | - echo "Cannot remove the test routes <br>"; | |
| 805 | - } | |
| 806 | - } | |
| 801 | +			if ($result!=null && $result['deleted']==true) { | |
| 802 | + echo "The test routes were removed <br>"; | |
| 803 | +			} else { | |
| 804 | + echo "Cannot remove the test routes <br>"; | |
| 805 | + } | |
| 806 | + } | |
| 807 | 807 | |
| 808 | -        if (sizeof(self::$removedVehicleIDs)>0) { | |
| 809 | - $vehicle = new VehicleV4(); | |
| 808 | +		if (sizeof(self::$removedVehicleIDs)>0) { | |
| 809 | + $vehicle = new VehicleV4(); | |
| 810 | 810 | |
| 811 | -            foreach (self::$removedVehicleIDs as $vehicleID) { | |
| 812 | - $vehicleParameters = VehicleV4::fromArray([ | |
| 813 | - 'vehicle_id' => $vehicleID, | |
| 814 | - ]); | |
| 811 | +			foreach (self::$removedVehicleIDs as $vehicleID) { | |
| 812 | + $vehicleParameters = VehicleV4::fromArray([ | |
| 813 | + 'vehicle_id' => $vehicleID, | |
| 814 | + ]); | |
| 815 | 815 | |
| 816 | - $result = $vehicle->removeVehicle($vehicleParameters); | |
| 817 | - } | |
| 818 | - } | |
| 819 | - } | |
| 816 | + $result = $vehicle->removeVehicle($vehicleParameters); | |
| 817 | + } | |
| 818 | + } | |
| 819 | + } | |
| 820 | 820 | |
| 821 | 821 | } | 
| 822 | 822 | \ No newline at end of file | 
| @@ -180,7 +180,7 @@ discard block | ||
| 180 | 180 | $users = $member->getUsers(); | 
| 181 | 181 | |
| 182 | 182 | assert(!is_null($users), 'Cannot retrieve list of the users'); | 
| 183 | - assert(2 == sizeof($users), 'Cannot retrieve list of the users'); | |
| 183 | + assert(2==sizeof($users), 'Cannot retrieve list of the users'); | |
| 184 | 184 | assert(isset($users['results']), 'Cannot retrieve list of the users'); | 
| 185 | 185 | assert(isset($users['total']), 'Cannot retrieve list of the users'); | 
| 186 | 186 | |
| @@ -211,7 +211,7 @@ discard block | ||
| 211 | 211 | $route->update(); | 
| 212 | 212 | |
| 213 | 213 | $this->assertNotNull($route); | 
| 214 | - $this->assertInstanceOf(Route::class,$route); | |
| 214 | + $this->assertInstanceOf(Route::class, $route); | |
| 215 | 215 | |
| 216 | 216 | //endregion | 
| 217 | 217 | |
| @@ -219,10 +219,10 @@ discard block | ||
| 219 | 219 | |
| 220 | 220 | $route = new Route(); | 
| 221 | 221 | |
| 222 | - $assignedRoute= $route->getRoutes(['route_id' => $routeId]); | |
| 222 | + $assignedRoute = $route->getRoutes(['route_id' => $routeId]); | |
| 223 | 223 | |
| 224 | 224 | $this->assertNotNull($assignedRoute); | 
| 225 | - $this->assertInstanceOf(Route::class,$assignedRoute); | |
| 225 | + $this->assertInstanceOf(Route::class, $assignedRoute); | |
| 226 | 226 | $this->assertEquals($randomUserID, $assignedRoute->parameters->member_id); | 
| 227 | 227 | |
| 228 | 228 | //endregion | 
| @@ -276,7 +276,7 @@ discard block | ||
| 276 | 276 | $removedVehicleIDs[] = $result['vehicle_id']; | 
| 277 | 277 | } | 
| 278 | 278 | |
| 279 | - $randomIndex = rand(0, sizeof($response)-1); | |
| 279 | + $randomIndex = rand(0, sizeof($response) - 1); | |
| 280 | 280 | $vehicleId = $response[$randomIndex]['vehicle_id']; | 
| 281 | 281 | |
| 282 | 282 | //endregion | 
| @@ -302,7 +302,7 @@ discard block | ||
| 302 | 302 | $route->update(); | 
| 303 | 303 | |
| 304 | 304 | $this->assertNotNull($route); | 
| 305 | - $this->assertInstanceOf(Route::class,$route); | |
| 305 | + $this->assertInstanceOf(Route::class, $route); | |
| 306 | 306 | |
| 307 | 307 | //endregion | 
| 308 | 308 | |
| @@ -310,10 +310,10 @@ discard block | ||
| 310 | 310 | |
| 311 | 311 | $route = new Route(); | 
| 312 | 312 | |
| 313 | - $assignedRoute= $route->getRoutes(['route_id' => $routeId]); | |
| 313 | + $assignedRoute = $route->getRoutes(['route_id' => $routeId]); | |
| 314 | 314 | |
| 315 | 315 | $this->assertNotNull($assignedRoute); | 
| 316 | - $this->assertInstanceOf(Route::class,$assignedRoute); | |
| 316 | + $this->assertInstanceOf(Route::class, $assignedRoute); | |
| 317 | 317 | $this->assertEquals($vehicleId, $assignedRoute->parameters->vehicle_id); | 
| 318 | 318 | |
| 319 | 319 | //endregion | 
| @@ -376,7 +376,7 @@ discard block | ||
| 376 | 376 | $params->route_id = $route_id; | 
| 377 | 377 | $params->route_path_output = 'Points'; | 
| 378 | 378 | |
| 379 | - $routeResult = (array) $route->getRoutePoints($params->toArray()); | |
| 379 | + $routeResult = (array)$route->getRoutePoints($params->toArray()); | |
| 380 | 380 | |
| 381 | 381 | $this->assertNotNull($routeResult); | 
| 382 | 382 | $this->assertTrue(is_array($routeResult)); | 
| @@ -449,8 +449,8 @@ discard block | ||
| 449 | 449 |          foreach ($routeResults as $routeResult) { | 
| 450 | 450 | |
| 451 | 451 | $this->assertTrue( | 
| 452 | - $routeResult->parameters->route_date - $tz >= $startDateUnix && | |
| 453 | - $routeResult->parameters->route_date - $tz <= $endtDateUnix | |
| 452 | + $routeResult->parameters->route_date - $tz>=$startDateUnix && | |
| 453 | + $routeResult->parameters->route_date - $tz<=$endtDateUnix | |
| 454 | 454 | ); | 
| 455 | 455 | } | 
| 456 | 456 | } | 
| @@ -500,7 +500,7 @@ discard block | ||
| 500 | 500 | |
| 501 | 501 |          foreach (self::$testRoutes as $route1) { | 
| 502 | 502 |              if (isset($route1->destination_count)) { | 
| 503 | -                if ($route1->destination_count > 4) { | |
| 503 | +                if ($route1->destination_count>4) { | |
| 504 | 504 | $selectedRoute = $route->getRoutes(['route_id' => $route1->route_id]); | 
| 505 | 505 | break; | 
| 506 | 506 | } | 
| @@ -656,7 +656,7 @@ discard block | ||
| 656 | 656 | $this->assertInstanceOf(Route::class, Route::fromArray($result)); | 
| 657 | 657 | $this->assertNull($result['optimization_problem_id']); | 
| 658 | 658 | |
| 659 | - $removedRouteIDs[]= $result['route_id']; | |
| 659 | + $removedRouteIDs[] = $result['route_id']; | |
| 660 | 660 | } | 
| 661 | 661 | |
| 662 | 662 | public function testUpdateRouteAvoidanceZone() | 
| @@ -773,7 +773,7 @@ discard block | ||
| 773 | 773 | } | 
| 774 | 774 | |
| 775 | 775 |              if (sizeof(self::$removedOptimizationIDs)>0) { | 
| 776 | - $optimizationProblemIDs = array_merge($optimizationProblemIDs,self::$removedOptimizationIDs); | |
| 776 | + $optimizationProblemIDs = array_merge($optimizationProblemIDs, self::$removedOptimizationIDs); | |
| 777 | 777 | } | 
| 778 | 778 | |
| 779 | 779 | $params = [ | 
| @@ -11,18 +11,18 @@ | ||
| 11 | 11 | use Route4Me\AvoidanceZone; | 
| 12 | 12 | |
| 13 | 13 |  class Route4MeUnitTests extends \PHPUnit\Framework\TestCase { | 
| 14 | - protected $AvoidanceZone; | |
| 14 | + protected $AvoidanceZone; | |
| 15 | 15 | |
| 16 | - public function setUp() | |
| 17 | -    { | |
| 18 | - $this->AvoidanceZone = new AvoidanceZone(); | |
| 19 | - } | |
| 16 | + public function setUp() | |
| 17 | +	{ | |
| 18 | + $this->AvoidanceZone = new AvoidanceZone(); | |
| 19 | + } | |
| 20 | 20 | |
| 21 | - public function testgetAvoidanceZones() | |
| 22 | -    { | |
| 23 | - echo "This Is Route4MeUnitTests <br>"; | |
| 24 | - $condition = true; | |
| 25 | - $this->assertTrue($condition); | |
| 26 | - } | |
| 21 | + public function testgetAvoidanceZones() | |
| 22 | +	{ | |
| 23 | + echo "This Is Route4MeUnitTests <br>"; | |
| 24 | + $condition = true; | |
| 25 | + $this->assertTrue($condition); | |
| 26 | + } | |
| 27 | 27 | } | 
| 28 | 28 | |
| 29 | 29 | \ No newline at end of file |