private function find_routes($org, $dest, &$flights) { $result = array(); $queue = new SplPriorityQueue(); foreach ($flights as $flight) { if ($flight['org_id'] == $org) { $route = new Route($this->route_opts); $num_seats = Flight::get_open_seats_on_flight($flight['flight_id'], $this->user); $route->add_flight($flight, $num_seats); $queue->insert($route, $route->get_joy()); } } //BFS to find all routes that take < 10 hours $count = 0; while ($queue->count() > 0 && $count < $this->opts['max_results']) { $cur_route = $queue->extract(); if ($cur_route->get_dest() == $dest) { $result[] = $cur_route; $count++; continue; } foreach ($flights as $flight) { if (!array_key_exists($flight['dest_id'], $cur_route->visited) && $flight['org_id'] == $cur_route->get_dest() && $flight['e_depart_time'] > 30 * 60 + $cur_route->get_arrival_time()) { $new_route = $cur_route->copy(); $num_seats = Flight::get_open_seats_on_flight($flight['flight_id'], $this->user); $new_route->add_flight($flight, $num_seats); if ($new_route->get_trip_time() < 24 * 60 * 60 && $new_route->seats >= $this->opts['passengers']) { $queue->insert($new_route, $new_route->get_joy()); } } } } return $result; }
private function find_routes($org, $dest, &$flights) { $result = array(); $queue = new SplPriorityQueue(); foreach ($flights as $flight) { if ($flight['org_id'] == $org) { $route = new Route($this->route_opts); $route->add_flight($flight); array_push($this->id, $flight['flight_id']); $queue->insert($route, $route->get_joy()); } } //BFS to find all routes that take < 10 hours $count = 0; while ($queue->count() > 0 && $count < $this->opts['max_results']) { $cur_route = $queue->extract(); if ($cur_route->get_dest() == $dest) { $result[] = $cur_route; $count++; continue; } foreach ($flights as $flight) { if ($flight['org_id'] == $cur_route->get_dest() && $flight['e_depart_time'] > 30 * 60 + $cur_route->get_arrival_time()) { $new_route = $cur_route->copy(); $new_route->add_flight($flight); array_push($this->id, $flight['flight_id']); if ($new_route->get_trip_time() < 24 * 60 * 60) { $queue->insert($new_route, $new_route->get_joy()); } } } } return $result; }
public function copy() { $copy = new Route($this->opts); foreach ($this->flights as $flight) { $copy->add_flight($flight); } return $copy; }