Exemple #1
0
function getData($startStop, $endStop, $startDistance, $endDistance)
{
    $showOnlyIndirectRoutes = 1;
    // find out the buses that pass through these stops
    $checkString = findDistanceBetweenSourceDestination($startStop, $endStop);
    $arr = array();
    $arr = split(":", $checkString);
    $strRoute1 = '';
    $strRoute2 = '';
    $strRoute3 = '';
    $strRoute4 = '';
    $minimalDistanceOption7 = 10000;
    $minimalDistanceOption8 = 10000;
    //print_r($arr);
    if ($arr[4] < 0.7) {
        $strRoute = '';
        $routeDetails = htmlentities($startStop) . ":" . $arr[0] . ":" . $arr[1] . ":" . htmlentities($endStop) . ":" . $arr[2] . ":" . $arr[3] . ":" . $arr[4];
        //$st='sdsd';
        $strRoute = '<Routes>';
        $strRoute = $strRoute . '<Route>';
        $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
        $strRoute = $strRoute . '<ErrorCode>5</ErrorCode>';
        $strRoute = $strRoute . '<RouteDetails>' . $routeDetails . '</RouteDetails>';
        $strRoute = $strRoute . '</Route>';
        $strRoute = $strRoute . '</Routes>';
        return $strRoute;
        //echo "The distance is walkable";
    } else {
        $startBuses = explode(",", getBusesForStopWithFrequency($startStop));
        $endBuses = explode(",", getBusesForStopWithFrequency($endStop));
        //print_r($startBuses);
        //print_r($endBuses);
        // for now pick the first entry as the bus number but we need to do some optimization on choosing the buses based on their frequency, the stop number etc
        //$arrCommonBuses=getCommonBuses($startBuses,$endBuses,$showOnlyIndirectRoutes);
        // print_r($arrCommonBuses);
        //echo getJunctionsForIndirectBuses($arrCommonBuses,$startStop,$endStop,$startDistance,$endDistance);
        $status = getJunctionsForIndirectBusesRevamp3($startStop, $endStop, $startBuses, $endBuses, $startDistance, $endDistance, 0);
        //echo "normal status".$status."<br/>";
        // this should not be the case now but just for the sake of eror handling
        if ($status == "404" || $status == "405") {
            list($endStopDepotName, $endStopDepotDistance) = explode(":", getDepotName($endStop));
            list($startStopDepotName, $startStopDepotDistance) = explode(":", getDepotName($startStop));
            $startStopStartDepotDistance = $startStopDepotDistance;
            $endDepotEndStopDistance = $endStopDepotDistance;
            // echo "StartStop=>".$startStop.":".$startStopDepotName.",".$startStopDepotDistance."<br/>EndStop=>".$endStop.":".$endStopDepotName.",".$endStopDepotDistance;
            $totalDistanceForCase1 = 10000;
            $totalDistanceForCase2 = 10000;
            // intension is that it is possible to take only one detour, starting from the start depot
            if ($startStopDepotDistance < (double) 7) {
                //get the direct buses between the startStop and depot
                //echo "first case";
                //find direct bus between start stop and start depot + distance
                $startStopStartDepotCommonBuses = getBusesCommonBetweenTwoStops($startStop, $startStopDepotName);
                if (sizeof($startStopStartDepotCommonBuses) > 0) {
                    $startStopStartDepotDistance = $startStopDepotDistance;
                    $startDepotEndStopCommonBuses = getBusesCommonBetweenTwoStops($startStopDepotName, $endStop);
                    //print_r($startDepotEndStopCommonBuses);
                    //echo sizeof($startDepotEndStopCommonBuses);
                    if (sizeof($startDepotEndStopCommonBuses) > 0) {
                        $startDepotEndStopDistance = distanceBetweenStops($startStopDepotName, $endStop);
                        $totalDistanceForCase1 = $startDistance + $startStopStartDepotDistance + $startDepotEndStopDistance + $endDistance;
                        $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . " We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
                        $strRoute1 = '<Routes>';
                        $strRoute1 = $strRoute1 . '<Route>';
                        $strRoute1 = $strRoute1 . '<IsDirectRoute>N</IsDirectRoute>';
                        $strRoute1 = $strRoute1 . '<ErrorCode>7</ErrorCode>';
                        $strRoute1 = $strRoute1 . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                        $routeDetail = "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                        $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                        $routeDetail = $routeDetail . "<Depot>" . htmlentities($startStopDepotName) . ":" . getLatitudeLongitude($startStopDepotName) . ":" . getBusesForStop($startStopDepotName) . "</Depot>";
                        $routeDetail = $routeDetail . "<BusesStartStopAndDepot>" . implode(",", $startStopStartDepotCommonBuses) . "</BusesStartStopAndDepot>";
                        $routeDetail = $routeDetail . "<BusesEndStopAndDepot>" . implode(",", $startDepotEndStopCommonBuses) . "</BusesEndStopAndDepot>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndStartStop>" . $startStopStartDepotDistance . "</DistanceBetweenDepotAndStartStop>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndEndStop>" . $startDepotEndStopDistance . "</DistanceBetweenDepotAndEndStop>";
                        $routeDetail = $routeDetail . "<TotalRouteDistance>" . $totalDistanceForCase1 . "</TotalRouteDistance>";
                        $routeDetail = $routeDetail . "<UseDepot>1</UseDepot>";
                        $strRoute1 = $strRoute1 . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        $strRoute1 = $strRoute1 . '</Route>';
                        $strRoute1 = $strRoute1 . '</Routes>';
                        // echo $strRoute1;
                    }
                }
            }
            // check if the detour is from the endpoint side
            //2. possible to have startStop->EndDepot->endpoint using Bus1, Bus2
            if ($endStopDepotDistance < (double) 7) {
                //echo "second case";
                //find the direct bus between start stop and end depot +distance
                $startStopEndDepotCommonBuses = getBusesCommonBetweenTwoStops($startStop, $endStopDepotName);
                //print_r($startStopEndDepotCommonBuses);
                if (sizeof($startStopEndDepotCommonBuses) > 0) {
                    //echo "first condifition";
                    $startStopEndDepotDistance = distanceBetweenStops($startStop, $endStopDepotName);
                    $endDepotEndStopCommonBuses = getBusesCommonBetweenTwoStops($endStopDepotName, $endStop);
                    if (sizeof($endDepotEndStopCommonBuses) > 0) {
                        //find the direct bus between end depot and the end stop + distnace
                        $endDepotEndStopDistance = $endStopDepotDistance;
                        $totalDistanceForCase2 = $startDistance + $startStopEndDepotDistance + $endDepotEndStopDistance + $endDistance;
                        $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . ". We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
                        $strRoute2 = '<Routes>';
                        $strRoute2 = $strRoute2 . '<Route>';
                        $strRoute2 = $strRoute2 . '<IsDirectRoute>N</IsDirectRoute>';
                        $strRoute2 = $strRoute2 . '<ErrorCode>8</ErrorCode>';
                        $strRoute2 = $strRoute2 . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                        $routeDetail = "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                        $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                        $routeDetail = $routeDetail . "<Depot>" . htmlentities($endStopDepotName) . ":" . getLatitudeLongitude($endStopDepotName) . ":" . getBusesForStop($endStopDepotName) . "</Depot>";
                        $routeDetail = $routeDetail . "<BusesStartStopAndDepot>" . implode(",", $startStopEndDepotCommonBuses) . "</BusesStartStopAndDepot>";
                        $routeDetail = $routeDetail . "<BusesEndStopAndDepot>" . implode(",", $endDepotEndStopCommonBuses) . "</BusesEndStopAndDepot>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndStartStop>" . $startStopEndDepotDistance . "</DistanceBetweenDepotAndStartStop>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndEndStop>" . $endDepotEndStopDistance . "</DistanceBetweenDepotAndEndStop>";
                        $routeDetail = $routeDetail . "<TotalRouteDistance>" . $totalDistanceForCase2 . "</TotalRouteDistance>";
                        $routeDetail = $routeDetail . "<UseDepot>1</UseDepot>";
                        $strRoute2 = $strRoute2 . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        $strRoute2 = $strRoute2 . '</Route>';
                        $strRoute2 = $strRoute2 . '</Routes>';
                    }
                }
            }
            //echo "tt".$totalDistanceForCase1.",".$totalDistanceForCase2;
            if ($totalDistanceForCase1 > $totalDistanceForCase2) {
                return $strRoute2;
            } else {
                if ($totalDistanceForCase1 < $totalDistanceForCase2) {
                    return $strRoute1;
                }
            }
            // if both the start poit detour and the endpoint detour failed that means you dont have the buses either from the
            // detour to the endpoint or between the start point and the detour
            if ($totalDistanceForCase1 == 10000 && $totalDistanceForCase2 == 10000) {
                if ($startStopDepotDistance < (double) 7) {
                    //echo "hi";
                    $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . ". We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
                    $startStopStartDepotCommonBuses = getBusesCommonBetweenTwoStops($startStop, $startStopDepotName);
                    $strRoute3 = '<Routes>';
                    //$strRoute2=$strRoute2.'<Route>';
                    $strRoute3 = $strRoute3 . '<IsDirectRoute>N</IsDirectRoute>';
                    $strRoute3 = $strRoute3 . '<ErrorCode>9</ErrorCode>';
                    $strRoute3 = $strRoute3 . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                    $routeDetail = "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                    $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                    $routeDetail = $routeDetail . "<Depot>" . htmlentities($startStopDepotName) . ":" . getLatitudeLongitude($startStopDepotName) . ":" . getBusesForStop($startStopDepotName) . "</Depot>";
                    $routeDetail = $routeDetail . "<BusesBetweenStopAndDepot>" . implode(",", $startStopStartDepotCommonBuses) . "</BusesBetweenStopAndDepot>";
                    $routeDetail = $routeDetail . "<DistanceBetweenDepotAndStop>" . $startStopStartDepotDistance . "</DistanceBetweenDepotAndStop>";
                    //  echo "==================";
                    $startDepotBuses = explode(",", getBusesForStopWithFrequency($startStopDepotName));
                    $totalDistanceBeforeReachingToDepot = $startDistance + $startStopStartDepotDistance;
                    $indirectRoutesDetails = getJunctionsForIndirectBusesRevamp3($startStopDepotName, $endStop, $startDepotBuses, $endBuses, 0, $endDistance, $showOnlyIndirectRoutes, 1, $totalDistanceBeforeReachingToDepot);
                    if ($indirectRoutesDetails != "404" && $indirectRoutesDetails != "405") {
                        list($indirectBusesBetweenDepotAndEndpoint, $minimalDistanceOption7) = explode("^", $indirectRoutesDetails);
                        $routeDetail = $routeDetail . "<indirectRoutes>" . $indirectBusesBetweenDepotAndEndpoint . "</indirectRoutes>";
                        //$routeDetail=$routeDetail."<UseDepot>1</UseDepot>";
                        $strRoute3 = $strRoute3 . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        //$strRoute2=$strRoute2.'</Route>';
                        $strRoute3 = $strRoute3 . '</Routes>';
                        //echo $strRoute3;
                    } else {
                        $minimalDistanceOption7 = 10000;
                    }
                }
                if ($endStopDepotDistance < (double) 7) {
                    $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . ". We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
                    $strRoute4 = '<Routes>';
                    $strRoute4 = $strRoute4 . '<IsDirectRoute>N</IsDirectRoute>';
                    $strRoute4 = $strRoute4 . '<ErrorCode>10</ErrorCode>';
                    $strRoute4 = $strRoute4 . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                    $routeDetail = "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                    $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                    $endDepotEndStopCommonBuses = getBusesCommonBetweenTwoStops($endStopDepotName, $endStop);
                    $routeDetail = $routeDetail . "<Depot>" . htmlentities($endStopDepotName) . ":" . getLatitudeLongitude($endStopDepotName) . ":" . getBusesForStop($endStopDepotName) . "</Depot>";
                    $routeDetail = $routeDetail . "<BusesBetweenStopAndDepot>" . implode(",", $endDepotEndStopCommonBuses) . "</BusesBetweenStopAndDepot>";
                    $routeDetail = $routeDetail . "<DistanceBetweenDepotAndStop>" . $endDepotEndStopDistance . "</DistanceBetweenDepotAndStop>";
                    //  echo "==================";
                    $endDepotBuses = explode(",", getBusesForStopWithFrequency($endStopDepotName));
                    $totalDistanceBeforeReachingToDepot = $endDistance + $endDepotEndStopDistance;
                    $indirectRoutesDetails = getJunctionsForIndirectBusesRevamp3($startStop, $endStopDepotName, $startBuses, $endDepotBuses, $startDistance, 0, $showOnlyIndirectRoutes, 1, $totalDistanceBeforeReachingToDepot);
                    if ($indirectRoutesDetails != "404" && $indirectRoutesDetails != "405") {
                        list($indirectBusesBetweenDepotAndEndpoint, $minimalDistanceOption8) = explode("^", $indirectRoutesDetails);
                        $routeDetail = $routeDetail . "<indirectRoutes>" . $indirectBusesBetweenDepotAndEndpoint . "</indirectRoutes>";
                        //$routeDetail=$routeDetail."<UseDepot>1</UseDepot>";
                        $strRoute4 = $strRoute4 . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        //$strRoute2=$strRoute2.'</Route>';
                        $strRoute4 = $strRoute4 . '</Routes>';
                        //echo $strRoute3;
                    } else {
                        $minimalDistanceOption8 = 10000;
                    }
                } else {
                    $minimalDistanceOption7 = 10000;
                    $minimalDistanceOption8 = 10000;
                }
            }
            //echo $minimalDistanceOption7.",".$minimalDistanceOption8;
            if ($minimalDistanceOption7 == 10000 && $minimalDistanceOption8 == 10000) {
                //the depots are too far away
                $strRoute = '<Routes>';
                $strRoute = $strRoute . '<Route>';
                $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
                $strRoute = $strRoute . '<ErrorCode>411</ErrorCode>';
                $strRoute = $strRoute . '<StartStop>' . $startStop . '</StartStop>';
                $strRoute = $strRoute . '<EndStop>' . $endStop . '</EndStop>';
                $strRoute = $strRoute . '</Route>';
                $strRoute = $strRoute . '</Routes>';
                return $strRoute;
            } else {
                if ($minimalDistanceOption7 < $minimalDistanceOption8) {
                    return $strRoute3;
                } else {
                    return $strRoute4;
                }
            }
        } else {
            $strRoute = '<Routes>' . $status . '</Routes>';
            return $strRoute;
        }
    }
    //echo "<sample>hhhh</sample>";
}
/**
This is the correct one
*/
function getJunctionsForIndirectBusesRevamp2($log, $startStop, $endStop, $startBuses, $endBuses, $startOffsetDistance, $endOffsetDistance, $showOnlyIndirectBuses, $useDepot = "0")
{
    //get the buses that are direct
    // actually the arrays have the last entry as null so 1 less
    $arrSameBus = array();
    //  print_r($startBuses);
    $numStartBuses = sizeof($startBuses);
    //print_r($endBuses);
    for ($ii = 0; $ii < $numStartBuses; $ii++) {
        $tempStart = $startBuses[$ii];
        // this checks is the same bus is available in the start buses and end buses.
        if (in_array($tempStart, $endBuses)) {
            $element = $tempStart . ":" . $tempStart;
            array_push($arrSameBus, $element);
        }
    }
    // print_r($arrSameBus);
    $sortedDirectBuses = array();
    //sort all the direct buses on the basis of frequency and distance of the route. Also see if the direct bus is not a BIAs
    if (sizeof($arrSameBus) > 0 && $showOnlyIndirectBuses == 0) {
        /*echo "before sort <br/>";
          print_r($arrSameBus);
          echo "after sorting <br/>";
          $sortedArray= sortBasedOnBusFrequency($arrSameBus);
          print_r($sortedArray);*/
        $directDistance = getDirectBusDistance($startStop, $endStop, $startOffsetDistance, $endOffsetDistance);
        // $sortedDirectBuses=sortBusesBasedOnDistanceToDestination($arrSameBus);
        $sortedDirectBuses = sortBasedOnBusFrequency($arrSameBus);
        // at this point we can sort it out based on the frequency of the buses and also let the know the meaning of the frequency
        $sortedDirectBuses = applyBIAFilter($sortedDirectBuses);
        //echo "found the direct buses";
        $log->LogDebug("[STATUS] result status is DIRECT between " . $startStop . " and " . $endStop);
        return displayDirectBuses($sortedDirectBuses, $directDistance);
    } else {
        $arrFirstJunctions = array();
        $arrSecondJunctions = array();
        $arrFirstBuses = array();
        $arrSecondBuses = array();
        $numEndBuses = sizeof($endBuses);
        $displayJunctionsDataArray = array();
        //print_r($displayJunctionsDataArray);
        // print_r($startBuses);
        //print_r($endBuses);
        if ($numStartBuses > 10) {
            $numStartBuses = 10;
        }
        if ($numEndBuses > 10) {
            $numEndBuses = 10;
        }
        // echo "numstart".$numStartBuses;
        //echo "numEnd".$numEndBuses;
        for ($i = 0; $i < $numStartBuses; $i++) {
            $firstBus = $startBuses[$i];
            $minimum = 10000;
            for ($j = 0; $j < $numEndBuses; $j++) {
                $secondBus = $endBuses[$j];
                //avoiud the direct bus combination
                if ($firstBus == $secondBus) {
                    continue;
                }
                //echo "secondBus".$secondBus;
                // i think when the first bus is same as the second bus this fails
                //find the entry from the table.
                list($firstBusNumber, $firstBusFrequency, $firstBusStartPoint, $secondBusNumber, $secondBusFrequency, $firstBusLowerJunction, $secondBusLowerJunction, $distLower, $lowerJunctionFrequency, $firstBusHigherJunction, $secondBusHigherJunction, $distHigher, $higherJunctionFrequency) = explode(":", getIntermediateStopsAndDistanceWithFrequency($firstBus, $secondBus));
                //echo "firstBusLowerJunction".$firstBusLowerJunction."firstBusHigherJunction".$firstBusHigherJunction;
                //return;
                //need to find which junction is valid for the source stop
                if ($firstBusLowerJunction != $firstBusHigherJunction) {
                    //echo "<b>hhh</b>";
                    if (distanceBetweenStops($firstBusStartPoint, $firstBusLowerJunction) < distanceBetweenStops($firstBusStartPoint, $firstBusHigherJunction)) {
                        // echo "inside lower <br/>";
                        $junction1 = $firstBusLowerJunction;
                        $junction2 = $secondBusLowerJunction;
                        $junctionFrequency = $lowerJunctionFrequency;
                        $dist = $distLower;
                        $totalRouteDistance = getTotalRouteDistance($startStop, $junction1, $junction2, $dist, $endStop, $startOffsetDistance, $endOffsetDistance);
                        //echo $totalRouteDistance."<br/>";
                    } else {
                        // echo "inside higher <br/>";
                        $junction1 = $firstBusHigherJunction;
                        $junction2 = $secondBusHigherJunction;
                        $junctionFrequency = $higherJunctionFrequency;
                        $dist = $distHigher;
                        $totalRouteDistance = getTotalRouteDistance($startStop, $junction1, $junction2, $dist, $endStop, $startOffsetDistance, $endOffsetDistance);
                    }
                } else {
                    //echo "inside common <br/>";
                    $junction1 = $firstBusLowerJunction;
                    $junction2 = $secondBusLowerJunction;
                    //echo $junction1;
                    $junctionFrequency = $lowerJunctionFrequency;
                    $dist = $distLower;
                    $totalRouteDistance = getTotalRouteDistance($startStop, $junction1, $junction2, $dist, $endStop, $startOffsetDistance, $endOffsetDistance);
                }
                //echo $dist."<br/>";
                //collective frequency= sum(firstbus frequency, second bus frequency)
                //may be buses are high frequency but the junction are seperataed
                //&& $firstBusFrequency >0 && $secondBusFrequency >0
                if ($dist < (double) 0.8) {
                    // echo "hh".$junction1.",".$junction2."<br/>";
                    //print_r($displayJunctionsDataArray);
                    //echo "<br/>";
                    if (checkUniqueJunctions($displayJunctionsDataArray, $junction1, $junction2, $dist) == 0) {
                        /* echo "jnc1".$junction1."start stop".$startStop."jnc2".$junction2."end stop".$endStop."<br/>";
                           // also chekc that the endstop or the start stop is not same as the juntion as in case of marathahalli bridge and multiplex
                           if(strcmp($junction1,$startStop)==0 ||
                               strcmp($junction1,$endStop)==0 ||
                               strcmp($junction2,$startStop)==0 ||
                               strcmp($junction2,$endStop)==0)
                           {
                               // this is the case that is removing the case 2
                               echo "in the pit";
                               continue;
                           }
                           else
                           {*/
                        $junctionString = $junction1 . ":" . $junction2 . ":" . $dist;
                        //echo "distashdg".$dist;
                        //$junctionString,$totalDistance,$startStop,$endStop,$junction1,$junction2,$junctionDistance
                        $element = new DisplaySortedJunctionsData($junctionString, $totalRouteDistance, $startStop, $endStop, $junction1, $junction2, $dist);
                        //echo "element".$i.",".$j."<br/>";
                        //	print_r($element);
                        array_push($displayJunctionsDataArray, $element);
                        //array_push($arrayUniqueJunctions,$element);
                        //}
                    }
                    /* if($dist<=(float)0.05)
                            $distPenalty=0;
                        else if($dist>(float)0.05 && $dist<=(float)0.2)
                            $distPenalty=0.5;
                        else if($dist>(float)0.2 && $dist<=(float)0.5)
                            $distPenalty=1;
                        else
                            $distPenalty=1.5;
                        echo "penalty".$distPenalty;
                        $collectiveFreq=$firstBusFrequency+$secondBusFrequency-($distPenalty);
                        $element=new IndirectBusStructureWithFrequency($firstBusNumber,$firstBusFrequency,
                            $secondBusNumber,$secondBusFrequency,$junction1,$junction2,$junctionFrequency,$dist,$collectiveFreq,$totalRouteDistance);
                        array_push($arrIndirectBuses,$element);
                       }*/
                }
            }
        }
        //	echo "<br/>";
        // print_r($displayJunctionsDataArray);
        $SortedJunctionsDataArray = sortBasedOnTotalRouteDistance($displayJunctionsDataArray);
        //echo "after sorting <br/>";
        //print_r($SortedJunctionsDataArray);
        //echo "sdsd";
        // display the results
        $strRoute = '';
        if (sizeof($SortedJunctionsDataArray) == 0 || strlen($SortedJunctionsDataArray[0]->getFirstJunction()) == 0) {
            /*$strRoute='<Routes>';
              $strRoute=$strRoute.'<Route>';
              $strRoute=$strRoute.'<IsDirectRoute>N</IsDirectRoute>';
              $strRoute=$strRoute.'<ErrorCode>4</ErrorCode>';
              $strRoute=$strRoute.'</Route>';
              $strRoute=$strRoute.'</Routes>';
              */
            return "404";
        } else {
            $strRoute = '<Routes>';
            $routeDetail = '';
            // there can be chances that when we are filling the xml all the details are not properly found. In that case we need to
            // remove that entry. If at the end this check counter becomes equals to the sizeof($SortedJunctionsDataArray). It means every entry had a problem
            // and we will return the error code 4
            $FalseAlarmCounter = 0;
            $sizeofSortedJunctions = sizeof($SortedJunctionsDataArray);
            //populate a datastructure
            for ($i = 0; $i < $sizeofSortedJunctions; $i++) {
                list($firstJnName, $secondJnName, $distanceJn) = explode(":", $SortedJunctionsDataArray[$i]->getJunctionString());
                $getCommonBusesForFirstJunctionArray = getBusesCommonBetweenTwoStops($startStop, $firstJnName);
                $getCommonBusesForSecondJunctionArray = getBusesCommonBetweenTwoStops($secondJnName, $endStop);
                $junction1Frequency = sizeof($getCommonBusesForFirstJunctionArray);
                $junction2Frequency = sizeof($getCommonBusesForSecondJunctionArray);
                $getCommonBusesForFirstJunction = implode(",", $getCommonBusesForFirstJunctionArray);
                $getCommonBusesForSecondJunction = implode(",", $getCommonBusesForSecondJunctionArray);
                $SortedJunctionsDataArray[$i]->setFirstJunctionFrequency($junction1Frequency);
                $SortedJunctionsDataArray[$i]->setSecondJunctionFrequency($junction2Frequency);
                $SortedJunctionsDataArray[$i]->setStartBusString($getCommonBusesForFirstJunction);
                $SortedJunctionsDataArray[$i]->setEndBusString($getCommonBusesForSecondJunction);
            }
            // print_r($SortedJunctionsDataArray);
            //echo "Raw";
            //print_r($SortedJunctionsDataArray);
            //echo "<br/><hr/>";
            //sorting on the baseis of the collective
            //$SortedJunctionsDataArray= sortBasedOnJunctionFrequency($SortedJunctionsDataArray);
            $SortedJunctionsDataArray = prioritizeAndSortJunctionArray($SortedJunctionsDataArray);
            //echo "final";
            //print_r($SortedJunctionsDataArray);
            $sizeofSortedJunctions = sizeof($SortedJunctionsDataArray);
            //print_r($SortedJunctionsDataArray);
            //need to see how to create this xml. If needed we can break the bus into seperate sml tags, every element as
            //speerate xml tag
            for ($i = 0; $i < $sizeofSortedJunctions; $i++) {
                $isCorrectEntry = 1;
                // check if this particular entry is correct. Since the node need to be removed otherwise
                if ($i > 2) {
                    // this will restrict the indirect results to 3
                    break;
                }
                //list($firstJnName,$secondJnName,$distanceJn)=explode(":",$SortedJunctionsDataArray[$i]->getJunctionString());
                $firstJnName = $SortedJunctionsDataArray[$i]->getFirstJunction();
                $secondJnName = $SortedJunctionsDataArray[$i]->getSecondJunction();
                $distanceJn = $SortedJunctionsDataArray[$i]->getJunctionDistance();
                $junction1Frequency = $SortedJunctionsDataArray[$i]->getFirstJunctionFrequency();
                $junction2Frequency = $SortedJunctionsDataArray[$i]->getSecondJunctionFrequency();
                //get all the buses for firstJn
                $strRoute = $strRoute . '<Route>';
                $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
                //echo "<h1>data firstJnName->".$firstJnName." secondJunctionName->".$secondJnName. " endpoint->".$endStop."</h1>";
                /**
                 *We have the following conditions now
                 * if(J1==J2) && (A!=J1) && (B!=J2) ...then this is error code 1
                 * If(J1!=J2)
                 *    if(A==J1) && (B!=J2) ..then this is error code 4
                 *    if(A!=J1) && (B==J2) ..then this is error code 2
                 *    if(A!=J1) && (B!=J2) ..then this is error code 3
                 *
                 *
                 * */
                if ($junction1Frequency > 0 && $junction2Frequency > 0) {
                    $getCommonBusesForFirstJunction = $SortedJunctionsDataArray[$i]->getStartBusString();
                    //getBusesCommonBetweenTwoStops($startStop,$firstJnName);
                    $getCommonBusesForSecondJunction = $SortedJunctionsDataArray[$i]->getEndBusString();
                    //getBusesCommonBetweenTwoStops($secondJnName,$endStop);
                    //condition exists in magestic okalipuran. basically sometimes there is no valid indirect route
                    //it means that there is only a single junction and also the junction is same as the stop
                    if ($distanceJn == 0 && strcmp($firstJnName, $startStop) == 0 || $distanceJn == 0 && strcmp($secondJnName, $endStop) == 0) {
                        return exceptionalConditionForIndirectRoute($startStop, $endStop);
                    }
                    if ($distanceJn == 0 && strcmp($firstJnName, $startStop) != 0 && strcmp($secondJnName, $endStop) != 0) {
                        $strRoute = $strRoute . '<ErrorCode>1</ErrorCode>';
                        $log->LogDebug("[STATUS] result status is 1 between " . $startStop . " and " . $endStop);
                    } else {
                        //echo intval($distanceJn).",".$startStop.",".$endStop.",".$firstJnName.",".$secondJnName."<br/>";
                        if ($distanceJn != 0) {
                            if (strcmp($firstJnName, $startStop) == 0 && strcmp($secondJnName, $endStop) != 0) {
                                // this is more or less like error code 1.
                                $strRoute = $strRoute . '<ErrorCode>4</ErrorCode>';
                                $log->LogDebug("[STATUS] result status is 4 between " . $startStop . " and " . $endStop);
                            } else {
                                if (strcmp($firstJnName, $startStop) != 0 && strcmp($secondJnName, $endStop) == 0) {
                                    //echo "dss2";
                                    $strRoute = $strRoute . '<ErrorCode>2</ErrorCode>';
                                    $log->LogDebug("[STATUS] result status is 2 between " . $startStop . " and " . $endStop);
                                } else {
                                    if (strcmp($firstJnName, $startStop) != 0 && strcmp($secondJnName, $endStop) != 0) {
                                        $strRoute = $strRoute . '<ErrorCode>3</ErrorCode>';
                                        $log->LogDebug("[STATUS] result status is 3 between " . $startStop . " and " . $endStop);
                                    } else {
                                        return exceptionalConditionForIndirectRoute($startStop, $endStop);
                                        //not sure what has happened
                                    }
                                }
                            }
                        }
                    }
                    $routeDetail = "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                    $routeDetail = $routeDetail . "<StartBuses>" . $getCommonBusesForFirstJunction . "</StartBuses>";
                    $routeDetail = $routeDetail . "<FirstJunction>" . htmlentities($firstJnName) . ":" . getLatitudeLongitude($firstJnName) . "</FirstJunction>";
                    $routeDetail = $routeDetail . "<DistanceBetweenJunction>" . $distanceJn . "</DistanceBetweenJunction>";
                    $routeDetail = $routeDetail . "<SecondJunction>" . htmlentities($secondJnName) . ":" . getLatitudeLongitude($secondJnName) . "</SecondJunction>";
                    $routeDetail = $routeDetail . "<EndBuses>" . $getCommonBusesForSecondJunction . "</EndBuses>";
                    $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                } else {
                    $FalseAlarmCounter++;
                }
                /*
                                if(strcmp($secondJnName,$endStop)==0)
                                {
                
                                    if($junction1Frequency>0 && $junction2Frequency>0)
                                    {
                                        $getCommonBusesForFirstJunction=$SortedJunctionsDataArray[$i]->getStartBusString();//getBusesCommonBetweenTwoStops($startStop,$firstJnName);
                                        $getCommonBusesForSecondJunction=$SortedJunctionsDataArray[$i]->getEndBusString();//getBusesCommonBetweenTwoStops($secondJnName,$endStop);
                                        $strRoute=$strRoute.'<ErrorCode>2</ErrorCode>';
                                        $routeDetail="<StartStop>".htmlentities($startStop)."</StartStop>";
                                        $routeDetail=$routeDetail."<StartBuses>".$getCommonBusesForFirstJunction."</StartBuses>";
                                        $routeDetail=$routeDetail."<FirstJunction>".htmlentities($firstJnName).":".getLatitudeLongitude($firstJnName)."</FirstJunction>";
                                        $routeDetail=$routeDetail."<DistanceBetweenJunction>".$distanceJn."</DistanceBetweenJunction>";
                                        $routeDetail=$routeDetail."<SecondJunction>".htmlentities($secondJnName).":".getLatitudeLongitude($secondJnName)."</SecondJunction>";
                                        $routeDetail=$routeDetail."<EndBuses>".$getCommonBusesForSecondJunction."</EndBuses>";
                                        $routeDetail=$routeDetail."<EndStop>".htmlentities($endStop)."</EndStop>";
                                    }
                                    else
                                    {
                                        $FalseAlarmCounter++;
                                    }
                                }
                                else
                                {
                                    if($distanceJn==0 && strcmp($firstJnName,$startStop)!=0)
                                    {
                                        $getCommonBusesForFirstJunction=$SortedJunctionsDataArray[$i]->getStartBusString();//getBusesCommonBetweenTwoStops($startStop,$firstJnName);
                                        $getCommonBusesForSecondJunction=$SortedJunctionsDataArray[$i]->getEndBusString();//getBusesCommonBetweenTwoStops($secondJnName,$endStop);
                                        if($junction1Frequency>0 && $junction2Frequency>0)
                                        {
                                            $strRoute=$strRoute.'<ErrorCode>1</ErrorCode>';
                                            $routeDetail="<StartStop>".htmlentities($startStop)."</StartStop>";
                                            $routeDetail=$routeDetail."<StartBuses>".$getCommonBusesForFirstJunction."</StartBuses>";
                                            $routeDetail=$routeDetail."<FirstJunction>".htmlentities($firstJnName).":".getLatitudeLongitude($firstJnName)."</FirstJunction>";
                                            $routeDetail=$routeDetail."<DistanceBetweenJunction>0</DistanceBetweenJunction>";
                                            $routeDetail=$routeDetail."<SecondJunction>".htmlentities($secondJnName).":".getLatitudeLongitude($secondJnName)."</SecondJunction>";
                                            $routeDetail=$routeDetail."<EndBuses>".$getCommonBusesForSecondJunction."</EndBuses>";
                                            $routeDetail=$routeDetail."<EndStop>".htmlentities($endStop)."</EndStop>";
                                        }
                                        else
                                        {
                                            $FalseAlarmCounter++;
                                        }
                
                                    }
                                    else
                                    {
                                        $getCommonBusesForFirstJunction=$SortedJunctionsDataArray[$i]->getStartBusString();//getBusesCommonBetweenTwoStops($startStop,$firstJnName);
                                        $getCommonBusesForSecondJunction=$SortedJunctionsDataArray[$i]->getEndBusString();
                                        if($junction1Frequency>0 && $junction2Frequency>0)
                                        {
                                            $strRoute=$strRoute.'<ErrorCode>3</ErrorCode>';
                                            $routeDetail="<StartStop>".htmlentities($startStop)."</StartStop>";
                                            $routeDetail=$routeDetail."<StartBuses>".$getCommonBusesForFirstJunction."</StartBuses>";
                                            $routeDetail=$routeDetail."<FirstJunction>".htmlentities($firstJnName).":".getLatitudeLongitude($firstJnName)."</FirstJunction>";
                                            $routeDetail=$routeDetail."<DistanceBetweenJunction>".$distanceJn."</DistanceBetweenJunction>";
                                            $routeDetail=$routeDetail."<SecondJunction>".htmlentities($secondJnName).":".getLatitudeLongitude($secondJnName)."</SecondJunction>";
                                            $routeDetail=$routeDetail."<EndBuses>".$getCommonBusesForSecondJunction."</EndBuses>";
                                            $routeDetail=$routeDetail."<EndStop>".htmlentities($endStop)."</EndStop>";
                                        }
                                        else
                                        {
                                            $FalseAlarmCounter++;
                                        }
                
                                    }
                                }*/
                $routeDetail = $routeDetail . "<TotalRouteDistance>" . $SortedJunctionsDataArray[$i]->getTotalRouteDistance() . "</TotalRouteDistance>";
                $routeDetail = $routeDetail . "<UseDepot>" . $useDepot . "</UseDepot>";
                $strRoute = $strRoute . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                $strRoute = $strRoute . '</Route>';
            }
            $strRoute = $strRoute . '</Routes>';
            // check if every thing was wrong that means we need to send the erro codes.
            if ($FalseAlarmCounter == sizeof($SortedJunctionsDataArray)) {
                return "405";
            }
        }
        // echo "---------------------------------<br/>";
        // echo $strRoute;
        return $strRoute;
    }
}
					}

				}
				
				// check if the detour is from the endpoint side
				//2. possible to have startStop->EndDepot->endpoint using Bus1, Bus2
				if($endStopDepotDistance < (float) 7)
				{
					//echo "second case";
					//find the direct bus between start stop and end depot +distance
					$startStopEndDepotCommonBuses=getBusesCommonBetweenTwoStops($startStop,$endStopDepotName);
					//print_r($startStopEndDepotCommonBuses);
					if(sizeof($startStopEndDepotCommonBuses)>0)
					{	
						//echo "first condifition";
						$startStopEndDepotDistance=distanceBetweenStops($startStop,$endStopDepotName);
						$endDepotEndStopCommonBuses=getBusesCommonBetweenTwoStops($endStopDepotName,$endStop);
						
						if(sizeof($endDepotEndStopCommonBuses)>0)
						{
							//find the direct bus between end depot and the end stop + distnace
							$endDepotEndStopDistance=$endStopDepotDistance;
							$totalDistanceForCase2=$startDistance+$startStopEndDepotDistance+$endDepotEndStopDistance+$endDistance;
							$routeInfoString="There is no direct or indirect bus availalble between ".$startStop." and ".$endStop.". We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
							
							$strRoute2='<Routes>';
							 $strRoute2=$strRoute2.'<Route>';
							 $strRoute2=$strRoute2.'<IsDirectRoute>N</IsDirectRoute>';
							 $strRoute2=$strRoute2.'<ErrorCode>8</ErrorCode>';
							 $strRoute2=$strRoute2."<RouteInfo>".$routeInfoString."</RouteInfo>";							
							 $routeDetail="<StartStop>".htmlentities($startStop)."</StartStop>";
         $routes = parse_array($str, "<Route>", "</Route>");
         $numRouteCount = 0;
         foreach ($routes as $route) {
             $numRouteCount++;
             $indirectRouteErrorCodeArray = parse_array($str, "<ErrorCode>", "</ErrorCode>");
             $indirectStartStopsArray = parse_array($str, "<StartStop>", "</StartStop>");
             $indirectStartBusesArray = parse_array($str, "<StartBuses>", "</StartBuses>");
             $indirectDepotArray = parse_array($str, "<FirstJunction>", "</FirstJunction>");
             $indirectEndBusesArray = parse_array($str, "<EndBuses>", "</EndBuses>");
             $indirectEndStopsArray = parse_array($str, "<EndStop>", "</EndStop>");
         }
         for ($i = 0; $i < $numRouteCount; $i++) {
             $depotNameString = return_between($indirectDepotArray[$i], "<FirstJunction>", "</FirstJunction>", EXCL);
             list($depotName, $lat, $lon) = explode(":", $depotNameString);
             $distanceBetweenDepotAndStartStop = distanceBetweenStops($startStop, $depotName);
             $distanceBetweenDepotAndEndStop = distanceBetweenStops($endStop, $depotName);
             $totalRouteDistance = floatval($distanceBetweenDepotAndStartStop) + floatval($distanceBetweenDepotAndEndStop);
             $sql = "INSERT INTO directdepotbusroutes (DepotErrorCode,\r\n\t\t\t\t\t\t\t\t\t\t\t\t  StartStop,\r\n\t\t\t\t\t\t\t\t\t\t\t\t  EndStop,\r\n\t\t\t\t\t\t\t\t\t\t\t\t  DepotNameString,\r\n\t\t\t\t\t\t\t\t\t\t\t\t  BusesBetweenStartStopAndDepot,\r\n\t\t\t\t\t\t\t\t\t\t\t\t  BusesBetweenEndStopAndDepot,\r\n\t\t\t\t\t\t\t\t\t\t\t\t  DistanceBetweenDepotAndStartStop,\r\n\t\t\t\t\t\t\t\t\t\t\t\t  DistanceBetweenDepotAndEndStop,\r\n\t\t\t\t\t\t\t\t\t\t\t\t  TotalRouteDistance) Values('" . intval(return_between($indirectRouteErrorCodeArray[$i], "<ErrorCode>", "</ErrorCode>", EXCL)) . "','" . $startStop . "','" . $endStop . "','" . $depotNameString . "','" . return_between($indirectStartBusesArray[$i], "<StartBuses>", "</StartBuses>", EXCL) . "','" . return_between($indirectEndBusesArray[$i], "<EndBuses>", "</EndBuses>", EXCL) . "','" . floatval($distanceBetweenDepotAndStartStop) . "','" . floatval($distanceBetweenDepotAndEndStop) . "','" . floatval($totalRouteDistance) . "')";
             echo $sql;
             /*$result=mysql_query($sql);
             		if($result)
             			echo "insert is successful";
             		else
             			echo "<b>INSERT ERROR: ".mysql_error()."</b>". $sql."<br/>";
             		*/
         }
     }
 } else {
     echo "StartStop:" . $startStop . "," . "EndStop:" . $endStop . ",depotErrorCode:" . $depotErrorCode . "n";
     $sql = "INSERT INTO depotbusroutes (DepotErrorCode,SourceStartStop,DestinationEndStop)\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tValues('" . intval($depotErrorCode) . "','" . $startStop . "','" . $endStop . "')";
     echo $sql;
/**
* This is a special function for the depots.
* This needs to return the direct or indirect buses between the two depots
* Important thing is to finalize on the structure of the xml that will be returned.
* This will return only a subpart of the xml
* the structure in case of direct bus found between the depots the structure will be
*<Routes>
	<Route>
		<IsDirectRoute />
		<ErrorCode>9</ErrorCode>
		<IsDirectBusesBwDepots>Y</IsDirectBusesBwDepots>
		<RouteInfo />
		<StartStop/>
		<EndStop/>
		<FirstDepotNames />
		<SecondDepotName />
		<BusesStartStopAndDepot />
		<BusesInterDepot />
		<BusesEndStopAndDepot />
		<DistanceBetweenStartStopAndFirstDepot />
		<DistanceBetweenDepots />
		<DistanceBetweenEndStopAndLastDepot />
		<TotalRouteDistance />
		<UseDepot />
	</Route>
</Routes>
*
* In this case the user will be given 3 buses 
*the structure in case of indirect buses found the structure will be
*<Routes>
	<Route>
		<IsDirectRoute />
		<ErrorCode>10</ErrorCode>
		<IsDirectBusesBwDepots>N</IsDirectBusesBwDepots>
		<RouteInfo />
		<StartStop/>
		<EndStop/>
		<FirstDepotNames />
		<SecondDepotName />
		<BusesStartStopAndDepot />
		<BusesInterDepot> {for loop..we need to remove the cases where there are two junctions}
		   <BusesFirstDepotAndJunction></BusesFirstDepotAndJunction>
		   <JunctionName></JunctionName>
		   <BusesSecondDepotAndJunction></BusesSecondDepotAndJunction>
		   <DistanceBetweenFirstDepotAndJunction />
		   <DistanceBetweenSecondDepotAndJunction />		
		</BusesInterDepot>
		<BusesEndStopAndDepot />
		<DistanceBetweenStartStopAndFirstDepot />
		<DistanceBetweenEndStopAndLastDepot />
		<StartStopOffset />
		<EndSopOffset/>
		<UseDepot />
	</Route>
</Routes>
* Note: in this case we will end up in 4 buses. I think that is too much but will show this
* The errror condition and invealid search will give 407 & 408 respectively we will display the errorr that nothing could be found
* startDepotStop : this is the first depot
* endDepotStop: This is the second depot
* startDepotBuses : this is the set of buses which goes to first depot
* endDepotBuses: this is the set of buses that goes to the second depot
* startStopStartDepotCommonBusesString: these are the buses that goes between the start stop and the startdepot
* endDepotEndStopCommonBusesString : these are the buses that are common between the end stop and the end depot
* startOffsetDistance: This is the offest distacne between the source and the start stop. Here used to calculate the total distance
* endOffsetDistance: This is the offset distance between the end point and the destnatiuon. here used to calculate the total distance
* distanceBetweenStartStopAndFirstDepot: The distance between the start stop an dthe first depot
* distanceBetweenEndStopAndLastDepot : The distcnae between the end point and the last depot
*/
function getJunctionsForInterDepotTravel($startStop, $endStop, $startDepotStop, $endDepotStop, $startDepotBuses, $endDepotBuses, $startOffsetDistance, $endOffsetDistance, $startStopStartDepotCommonBusesString, $endDepotEndStopCommonBusesString, $distanceBetweenStartStopAndFirstDepot, $distanceBetweenEndStopAndLastDepot, $showOnlyIndirectBuses)
{
    //echo "ddd";
    //get the buses that are direct
    // actually the arrays have the last entry as null so 1 less
    $arrSameBus = array();
    //  print_r($startBuses);
    $numStartBuses = sizeof($startDepotBuses);
    //print_r($endBuses);
    for ($ii = 0; $ii < $numStartBuses; $ii++) {
        $tempStart = $startDepotBuses[$ii];
        // this checks is the same bus is available in the start buses and end buses.
        if (in_array($tempStart, $endDepotBuses)) {
            $element = $tempStart . ":" . $tempStart;
            array_push($arrSameBus, $element);
        }
    }
    // print_r($arrSameBus);
    $sortedDirectBuses = array();
    //sort all the direct buses on the basis of frequency and distance of the route. Also see if the direct bus is not a BIAs
    if (sizeof($arrSameBus) > 0 && $showOnlyIndirectBuses == 0) {
        $directDistance = getDirectBusDistance($startDepotStop, $endDepotStop, 0, 0);
        // $sortedDirectBuses=sortBusesBasedOnDistanceToDestination($arrSameBus);
        $sortedDirectBuses = sortBasedOnBusFrequency($arrSameBus);
        // at this point we can sort it out based on the frequency of the buses and also let the know the meaning of the frequency
        $sortedDirectBuses = applyBIAFilter($sortedDirectBuses);
        //echo "found the direct buses";
        //return displayDirectBuses($sortedDirectBuses,$directDistance);
        //need to return a sub xml in this place.
        $distanceBetweenDepots = distanceBetweenStops($startDepotStop, $endDepotStop);
        $totalRouteDistance = $startOffsetDistance + $distanceBetweenStartStopAndFirstDepot + $distanceBetweenDepots + $distanceBetweenEndStopAndLastDepot + $endOffsetDistance;
        $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . ". We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
        $routeDetails = "<Routes>";
        $routeDetails = $routeDetails . "<Route>";
        $routeDetails = $routeDetails . "<IsDirectRoute>N</IsDirectRoute>";
        $routeDetails = $routeDetails . "<ErrorCode>9</ErrorCode>";
        //$routeDetails=$routeDetails."<IsDirectBusesBwDepots>Y</IsDirectBusesBwDepots>";
        $routeDetails = $routeDetails . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
        $routeDetails = $routeDetails . "<RouteDetails>";
        $routeDetails = $routeDetails . "<StartStop>" . htmlentities($startStop) . "</StartStop>";
        $routeDetails = $routeDetails . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
        $routeDetails = $routeDetails . "<FirstDepotName>" . htmlentities($startDepotStop) . ":" . getLatitudeLongitude($startDepotStop) . ":" . getBusesForStop($startDepotStop) . "</FirstDepotName>";
        $routeDetails = $routeDetails . "<SecondDepotName>" . htmlentities($endDepotStop) . ":" . getLatitudeLongitude($endDepotStop) . ":" . getBusesForStop($endDepotStop) . "</SecondDepotName>";
        $routeDetails = $routeDetails . "<BusesStartStopAndDepot>" . $startStopStartDepotCommonBusesString . "</BusesStartStopAndDepot>";
        $routeDetails = $routeDetails . "<BusesInterDepot>" . implode(",", $sortedDirectBuses) . "</BusesInterDepot>";
        $routeDetails = $routeDetails . "<BusesEndStopAndDepot>" . $endDepotEndStopCommonBusesString . "</BusesEndStopAndDepot>";
        $routeDetails = $routeDetails . "<DistanceBetweenStartStopAndFirstDepot>" . $distanceBetweenStartStopAndFirstDepot . "</DistanceBetweenStartStopAndFirstDepot>";
        $routeDetails = $routeDetails . "<DistanceBetweenEndStopAndLastDepot>" . $distanceBetweenEndStopAndLastDepot . "</DistanceBetweenEndStopAndLastDepot>";
        $routeDetails = $routeDetails . "<DistanceBetweenDepots>" . $distanceBetweenDepots . "</DistanceBetweenDepots>";
        $routeDetails = $routeDetails . "<TotalRouteDistance>" . $totalRouteDistance . "</TotalRouteDistance>";
        $routeDetails = $routeDetails . "</RouteDetails>";
        $routeDetails = $routeDetails . "</Route>";
        $routeDetails = $routeDetails . "</Routes>";
        return $routeDetails;
    } else {
        $arrFirstJunctions = array();
        $arrSecondJunctions = array();
        $arrFirstBuses = array();
        $arrSecondBuses = array();
        $numEndBuses = sizeof($endDepotBuses);
        $displayJunctionsDataArray = array();
        if ($numStartBuses > 10) {
            $numStartBuses = 10;
        }
        if ($numEndBuses > 10) {
            $numEndBuses = 10;
        }
        for ($i = 0; $i < $numStartBuses; $i++) {
            $firstBus = $startDepotBuses[$i];
            $minimum = 10000;
            for ($j = 0; $j < $numEndBuses; $j++) {
                $secondBus = $endDepotBuses[$j];
                //avoiud the direct bus combination
                if ($firstBus == $secondBus) {
                    continue;
                }
                //echo "secondBus".$secondBus;
                // i think when the first bus is same as the second bus this fails
                //find the entry from the table.
                list($firstBusNumber, $firstBusFrequency, $firstBusStartPoint, $secondBusNumber, $secondBusFrequency, $firstBusLowerJunction, $secondBusLowerJunction, $distLower, $lowerJunctionFrequency, $firstBusHigherJunction, $secondBusHigherJunction, $distHigher, $higherJunctionFrequency) = explode(":", getIntermediateStopsAndDistanceWithFrequency($firstBus, $secondBus));
                //return;
                //need to find which junction is valid for the source stop
                if ($firstBusLowerJunction != $firstBusHigherJunction) {
                    if (distanceBetweenStops($firstBusStartPoint, $firstBusLowerJunction) < distanceBetweenStops($firstBusStartPoint, $firstBusHigherJunction)) {
                        // echo "inside lower <br/>";
                        $junction1 = $firstBusLowerJunction;
                        $junction2 = $secondBusLowerJunction;
                        $junctionFrequency = $lowerJunctionFrequency;
                        $dist = $distLower;
                        $totalRouteDistance = getTotalRouteDistance($startDepotStop, $junction1, $junction2, $dist, $endDepotStop, 0, 0);
                        //echo $totalRouteDistance."<br/>";
                    } else {
                        //echo "inside higher <br/>";
                        $junction1 = $firstBusHigherJunction;
                        $junction2 = $secondBusHigherJunction;
                        $junctionFrequency = $higherJunctionFrequency;
                        $dist = $distHigher;
                        $totalRouteDistance = getTotalRouteDistance($startDepotStop, $junction1, $junction2, $dist, $endDepotStop, 0, 0);
                    }
                } else {
                    //echo "inside common <br/>";
                    $junction1 = $firstBusLowerJunction;
                    $junction2 = $secondBusLowerJunction;
                    $junctionFrequency = $lowerJunctionFrequency;
                    $dist = $distLower;
                    $totalRouteDistance = getTotalRouteDistance($startDepotStop, $junction1, $junction2, $dist, $endDepotStop, 0, 0);
                }
                //echo $dist."<br/>";
                //collective frequency= sum(firstbus frequency, second bus frequency)
                //may be buses are high frequency but the junction are seperataed
                //&& $firstBusFrequency >0 && $secondBusFrequency >0
                if ($dist < (double) 0.8) {
                    // echo "hh".$junction1.",".$junction2."<br/>";
                    //print_r($displayJunctionsDataArray);
                    //echo "<br/>";
                    if (checkUniqueJunctions($displayJunctionsDataArray, $junction1, $junction2, $dist) == 0) {
                        // also chekc that the endstop or the start stop is not same as the juntion as in case of marathahalli bridge and multiplex
                        if (strcmp($junction1, $startDepotStop) == 0 || strcmp($junction1, $endDepotStop) == 0 || strcmp($junction2, $startDepotStop) == 0 || strcmp($junction2, $endDepotStop) == 0) {
                            //echo "in the pit";
                            continue;
                        } else {
                            $junctionString = $junction1 . ":" . $junction2 . ":" . $dist;
                            //echo "distashdg".$dist;
                            //$junctionString,$totalDistance,$startStop,$endStop,$junction1,$junction2,$junctionDistance
                            $element = new DisplaySortedJunctionsData($junctionString, $totalRouteDistance, $startStop, $endStop, $junction1, $junction2, $dist);
                            //echo "element".$i.",".$j."<br/>";
                            //	print_r($element);
                            array_push($displayJunctionsDataArray, $element);
                            //array_push($arrayUniqueJunctions,$element);
                        }
                    }
                }
            }
        }
        $SortedJunctionsDataArray = sortBasedOnTotalRouteDistance($displayJunctionsDataArray);
        // display the results
        $strRoute = '';
        if (sizeof($SortedJunctionsDataArray) == 0 || strlen($SortedJunctionsDataArray[0]->getFirstJunction()) == 0) {
            //echo "inside 409";
            return "409";
        } else {
            $strRoute = '<Routes>';
            // there can be chances that when we are filling the xml all the details are not properly found. In that case we need to
            // remove that entry. If at the end this check counter becomes equals to the sizeof($SortedJunctionsDataArray). It means every entry had a problem
            // and we will return the error code 4
            $FalseAlarmCounter = 0;
            $sizeofSortedJunctions = sizeof($SortedJunctionsDataArray);
            //populate a datastructure
            for ($i = 0; $i < $sizeofSortedJunctions; $i++) {
                list($firstJnName, $secondJnName, $distanceJn) = explode(":", $SortedJunctionsDataArray[$i]->getJunctionString());
                $getCommonBusesForFirstJunctionArray = getBusesCommonBetweenTwoStops($startDepotStop, $firstJnName);
                $getCommonBusesForSecondJunctionArray = getBusesCommonBetweenTwoStops($secondJnName, $endDepotStop);
                $junction1Frequency = sizeof($getCommonBusesForFirstJunctionArray);
                $junction2Frequency = sizeof($getCommonBusesForSecondJunctionArray);
                $getCommonBusesForFirstJunction = implode(",", $getCommonBusesForFirstJunctionArray);
                $getCommonBusesForSecondJunction = implode(",", $getCommonBusesForSecondJunctionArray);
                $SortedJunctionsDataArray[$i]->setFirstJunctionFrequency($junction1Frequency);
                $SortedJunctionsDataArray[$i]->setSecondJunctionFrequency($junction2Frequency);
                $SortedJunctionsDataArray[$i]->setStartBusString($getCommonBusesForFirstJunction);
                $SortedJunctionsDataArray[$i]->setEndBusString($getCommonBusesForSecondJunction);
            }
            $SortedJunctionsDataArray = prioritizeAndSortJunctionArray($SortedJunctionsDataArray);
            $sizeofSortedJunctions = sizeof($SortedJunctionsDataArray);
            $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . ". We have tried to find a route that " . "takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
            //need to see how to create this xml. If needed we can break the bus into seperate sml tags, every element as
            //speerate xml tag
            for ($i = 0; $i < $sizeofSortedJunctions; $i++) {
                $isCorrectEntry = 1;
                // check if this particular entry is correct. Since the node need to be removed otherwise
                if ($i > 2) {
                    // this will restrict the indirect results to 3
                    break;
                }
                //list($firstJnName,$secondJnName,$distanceJn)=explode(":",$SortedJunctionsDataArray[$i]->getJunctionString());
                $firstJnName = $SortedJunctionsDataArray[$i]->getFirstJunction();
                $secondJnName = $SortedJunctionsDataArray[$i]->getSecondJunction();
                $distanceJn = $SortedJunctionsDataArray[$i]->getJunctionDistance();
                $junction1Frequency = $SortedJunctionsDataArray[$i]->getFirstJunctionFrequency();
                $junction2Frequency = $SortedJunctionsDataArray[$i]->getSecondJunctionFrequency();
                //get all the buses for firstJn
                //get all the buses for second jun..
                // if the distance between the two junctions is 0
                if ($distanceJn == 0 && strcmp($firstJnName, $startDepotStop) != 0) {
                    $getCommonBusesForFirstJunction = $SortedJunctionsDataArray[$i]->getStartBusString();
                    //getBusesCommonBetweenTwoStops($startStop,$firstJnName);
                    $getCommonBusesForSecondJunction = $SortedJunctionsDataArray[$i]->getEndBusString();
                    //getBusesCommonBetweenTwoStops($secondJnName,$endStop);
                    if ($junction1Frequency > 0 && $junction2Frequency > 0) {
                        $strRoute = $strRoute . '<Route>';
                        $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
                        $strRoute = $strRoute . '<ErrorCode>10</ErrorCode>';
                        //$strRoute=$strRoute.'<IsDirectBusesBwDepots>N</IsDirectBusesBwDepots>';
                        $strRoute = $strRoute . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                        $routeDetail = '';
                        $routeDetail = $routeDetail . "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                        $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                        $routeDetail = $routeDetail . "<FirstDepotName>" . htmlentities($startDepotStop) . ":" . getLatitudeLongitude($startDepotStop) . ":" . getBusesForStop($startDepotStop) . "</FirstDepotName>";
                        $routeDetail = $routeDetail . "<SecondDepotName>" . htmlentities($endDepotStop) . ":" . getLatitudeLongitude($endDepotStop) . ":" . getBusesForStop($endDepotStop) . "</SecondDepotName>";
                        $routeDetail = $routeDetail . "<BusesStartStopAndDepot>" . $startStopStartDepotCommonBusesString . "</BusesStartStopAndDepot>";
                        $routeDetail = $routeDetail . "<FirstJunction>" . htmlentities($firstJnName) . ":" . getLatitudeLongitude($firstJnName) . ":" . getBusesForStop($firstJnName) . "</FirstJunction>";
                        $routeDetail = $routeDetail . "<DistanceBetweenJunction>0</DistanceBetweenJunction>";
                        $routeDetail = $routeDetail . "<SecondJunction>" . htmlentities($secondJnName) . ":" . getLatitudeLongitude($secondJnName) . ":" . getBusesForStop($secondJnName) . "</SecondJunction>";
                        $routeDetail = $routeDetail . "<BusesStartDepotAndJunction>" . $getCommonBusesForFirstJunction . "</BusesStartDepotAndJunction>";
                        $routeDetail = $routeDetail . "<BusesEndDepotAndJunction>" . $getCommonBusesForSecondJunction . "</BusesEndDepotAndJunction>";
                        $routeDetail = $routeDetail . "<BusesEndStopAndDepot>" . $endDepotEndStopCommonBusesString . "</BusesEndStopAndDepot>";
                        $routeDetail = $routeDetail . "<DistanceBetweenStartStopAndFirstDepot>" . $distanceBetweenStartStopAndFirstDepot . "</DistanceBetweenStartStopAndFirstDepot>";
                        $routeDetail = $routeDetail . "<DistanceBetweenEndStopAndLastDepot>" . $distanceBetweenEndStopAndLastDepot . "</DistanceBetweenEndStopAndLastDepot>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepots>" . $SortedJunctionsDataArray[$i]->getTotalRouteDistance() . "</DistanceBetweenDepots>";
                        $totalDistance = $startOffsetDistance + $distanceBetweenStartStopAndFirstDepot + $SortedJunctionsDataArray[$i]->getTotalRouteDistance() + $distanceBetweenEndStopAndLastDepot + $endOffsetDistance;
                        $routeDetail = $routeDetail . "<TotalDistance>" . $totalDistance . "</TotalDistance>";
                        $routeDetail = $routeDetail . "<UseDepot>" . $useDepot . "</UseDepot>";
                        $strRoute = $strRoute . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        //echo "<hr/>";
                        $strRoute = $strRoute . '</Route>';
                    } else {
                        //echo "False positive";
                        //$strRoute=$strRoute.'<ErrorCode>6</ErrorCode>';
                        $FalseAlarmCounter++;
                    }
                }
                //echo $strRoute;
            }
            $strRoute = $strRoute . '</Routes>';
            // check if every thing was wrong that means we need to send the erro codes.
            if ($FalseAlarmCounter == sizeof($SortedJunctionsDataArray)) {
                /*$strRoute='<Routes>';
                  $strRoute=$strRoute.'<Route>';
                  $strRoute=$strRoute.'<IsDirectRoute>N</IsDirectRoute>';
                  $strRoute=$strRoute.'<ErrorCode>4</ErrorCode>';
                  $strRoute=$strRoute.'</Route>';
                  $strRoute=$strRoute.'</Routes>';
                  */
                //echo "inside 410";
                return "410";
            }
        }
        // echo "---------------------------------<br/>";
        // echo $strRoute;
        return $strRoute;
    }
}
Exemple #6
0
function getData($startStop, $endStop, $startDistance, $endDistance)
{
    //$showOnlyIndirectRoutes=$_GET['onlyIndirectRoutes'];
    // find out the buses that pass through these stops
    $checkString = findDistanceBetweenSourceDestination($startStop, $endStop);
    $arr = array();
    $arr = explode(":", $checkString);
    //print_r($arr);
    if ($arr[4] < 0.7) {
        $strRoute = '';
        $routeDetails = htmlentities($startStop) . ":" . $arr[0] . ":" . $arr[1] . ":" . htmlentities($endStop) . ":" . $arr[2] . ":" . $arr[3] . ":" . $arr[4];
        //$st='sdsd';
        $strRoute = '<Routes>';
        $strRoute = $strRoute . '<Route>';
        $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
        $strRoute = $strRoute . '<ErrorCode>5</ErrorCode>';
        $strRoute = $strRoute . '<RouteDetails>' . $routeDetails . '</RouteDetails>';
        $strRoute = $strRoute . '</Route>';
        $strRoute = $strRoute . '</Routes>';
        return $strRoute;
        //echo "The distance is walkable";
    } else {
        $startBuses = explode(",", getBusesForStopWithFrequency($startStop));
        $endBuses = explode(",", getBusesForStopWithFrequency($endStop));
        //removed the use of the showdirect buses form the helper
        $status = getJunctionsForIndirectBusesRevamp2($startStop, $endStop, $startBuses, $endBuses, $startDistance, $endDistance, 0);
        //echo "normal status".$status."<br/>";
        // this should not be the case now but just for the sake of eror handling
        if ($status == "404" || $status == "405") {
            list($endStopDepotName, $endStopDepotDistance) = explode(":", getDepotName($endStop));
            list($startStopDepotName, $startStopDepotDistance) = explode(":", getDepotName($startStop));
            $totalDistanceForCase1 = 10000;
            $totalDistanceForCase2 = 10000;
            if ($startStopDepotDistance < (double) 7) {
                //find direct bus between start stop and start depot + distance
                $startStopStartDepotCommonBuses = getBusesCommonBetweenTwoStops($startStop, $startStopDepotName);
                if (sizeof($startStopStartDepotCommonBuses) > 0) {
                    $startStopStartDepotDistance = $startStopDepotDistance;
                    $startDepotEndStopCommonBuses = getBusesCommonBetweenTwoStops($startStopDepotName, $endStop);
                    //print_r($startDepotEndStopCommonBuses);
                    //echo sizeof($startDepotEndStopCommonBuses);
                    if (sizeof($startDepotEndStopCommonBuses) > 0) {
                        $startDepotEndStopDistance = distanceBetweenStops($startStopDepotName, $endStop);
                        $totalDistanceForCase1 = $startDistance + $startStopStartDepotDistance + $startDepotEndStopDistance + $endDistance;
                        $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . " We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
                        $strRoute1 = '<Routes>';
                        $strRoute1 = $strRoute1 . '<Route>';
                        $strRoute1 = $strRoute1 . '<IsDirectRoute>N</IsDirectRoute>';
                        $strRoute1 = $strRoute1 . '<ErrorCode>7</ErrorCode>';
                        $strRoute1 = $strRoute1 . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                        $routeDetail = "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                        $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                        $routeDetail = $routeDetail . "<Depot>" . htmlentities($startStopDepotName) . ":" . getLatitudeLongitude($startStopDepotName) . "</Depot>";
                        $routeDetail = $routeDetail . "<BusesStartStopAndDepot>" . implode(",", $startStopStartDepotCommonBuses) . "</BusesStartStopAndDepot>";
                        $routeDetail = $routeDetail . "<BusesEndStopAndDepot>" . implode(",", $startDepotEndStopCommonBuses) . "</BusesEndStopAndDepot>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndStartStop>" . $startStopStartDepotDistance . "</DistanceBetweenDepotAndStartStop>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndEndStop>" . $startDepotEndStopDistance . "</DistanceBetweenDepotAndEndStop>";
                        $routeDetail = $routeDetail . "<TotalRouteDistance>" . $totalDistanceForCase1 . "</TotalRouteDistance>";
                        $routeDetail = $routeDetail . "<UseDepot>1</UseDepot>";
                        $strRoute1 = $strRoute1 . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        $strRoute1 = $strRoute1 . '</Route>';
                        $strRoute1 = $strRoute1 . '</Routes>';
                        // echo $strRoute1;
                    }
                }
            }
            // check if the detour is from the endpoint side
            //2. possible to have startStop->EndDepot->endpoint using Bus1, Bus2
            if ($endStopDepotDistance < (double) 7) {
                //echo "second case";
                //find the direct bus between start stop and end depot +distance
                $startStopEndDepotCommonBuses = getBusesCommonBetweenTwoStops($startStop, $endStopDepotName);
                //print_r($startStopEndDepotCommonBuses);
                if (sizeof($startStopEndDepotCommonBuses) > 0) {
                    //echo "first condifition";
                    $startStopEndDepotDistance = distanceBetweenStops($startStop, $endStopDepotName);
                    $endDepotEndStopCommonBuses = getBusesCommonBetweenTwoStops($endStopDepotName, $endStop);
                    if (sizeof($endDepotEndStopCommonBuses) > 0) {
                        //find the direct bus between end depot and the end stop + distnace
                        $endDepotEndStopDistance = $endStopDepotDistance;
                        $totalDistanceForCase2 = $startDistance + $startStopEndDepotDistance + $endDepotEndStopDistance + $endDistance;
                        $routeInfoString = "There is no direct or indirect bus availalble between " . $startStop . " and " . $endStop . ". We have tried to find a route that takes you to a stop where you can find a bus to your destination. However you might have to travel little offroute to reach to the intermediate stop";
                        $strRoute2 = '<Routes>';
                        $strRoute2 = $strRoute2 . '<Route>';
                        $strRoute2 = $strRoute2 . '<IsDirectRoute>N</IsDirectRoute>';
                        $strRoute2 = $strRoute2 . '<ErrorCode>8</ErrorCode>';
                        $strRoute1 = $strRoute1 . "<RouteInfo>" . $routeInfoString . "</RouteInfo>";
                        $routeDetail = "<StartStop>" . htmlentities($startStop) . "</StartStop>";
                        $routeDetail = $routeDetail . "<EndStop>" . htmlentities($endStop) . "</EndStop>";
                        $routeDetail = $routeDetail . "<Depot>" . htmlentities($endStopDepotName) . ":" . getLatitudeLongitude($endStopDepotName) . "</Depot>";
                        $routeDetail = $routeDetail . "<BusesStartStopAndDepot>" . implode(",", $startStopEndDepotCommonBuses) . "</BusesStartStopAndDepot>";
                        $routeDetail = $routeDetail . "<BusesEndStopAndDepot>" . implode(",", $endDepotEndStopCommonBuses) . "</BusesEndStopAndDepot>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndStartStop>" . $startStopEndDepotDistance . "</DistanceBetweenDepotAndStartStop>";
                        $routeDetail = $routeDetail . "<DistanceBetweenDepotAndEndStop>" . $endDepotEndStopDistance . "</DistanceBetweenDepotAndEndStop>";
                        $routeDetail = $routeDetail . "<TotalRouteDistance>" . $totalDistanceForCase2 . "</TotalRouteDistance>";
                        $routeDetail = $routeDetail . "<UseDepot>1</UseDepot>";
                        $strRoute2 = $strRoute2 . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                        $strRoute2 = $strRoute2 . '</Route>';
                        $strRoute2 = $strRoute2 . '</Routes>';
                        // echo $strRoute2;
                    }
                }
            }
            if ($totalDistanceForCase1 < 10000 && $totalDistanceForCase2 < 10000) {
                if ($totalDistanceForCase1 > $totalDistanceForCase2) {
                    return $strRoute2;
                } else {
                    return $strRoute1;
                }
            } else {
                if ($totalDistanceForCase1 == 10000 && $totalDistanceForCase2 == 10000) {
                    if ($startStopDepotDistance < (double) 7 && $endStopDepotDistance < (double) 7) {
                        //find the direct bus between start stop and end depot +distance
                        $startStopStartDepotCommonBuses = getBusesCommonBetweenTwoStops($startStop, $startStopDepotName);
                        //print_r($startStopStartDepotCommonBuses);
                        $endDepotEndStopCommonBuses = getBusesCommonBetweenTwoStops($endStopDepotName, $endStop);
                        //print_r($endDepotEndStopCommonBuses);
                        if (sizeof($startStopStartDepotCommonBuses) > 0 && sizeof($endDepotEndStopCommonBuses) > 0) {
                            //echo "hhh";
                            //get the buses between the two depots
                            $busesForStartDepot = explode(",", getBusesForStopWithFrequency($startStopDepotName));
                            $busesForEndDepot = explode(",", getBusesForStopWithFrequency($endStopDepotName));
                            $startStopOffsetDistance = $startDistance;
                            $endStopOffsetDistance = $endDistance;
                            $startStopStartDepotCommonBusesString = implode(",", $startStopStartDepotCommonBuses);
                            $endDepotEndStopCommonBusesString = implode(",", $endDepotEndStopCommonBuses);
                            $interDepotStatus = getJunctionsForInterDepotTravel($startStop, $endStop, $startStopDepotName, $endStopDepotName, $busesForStartDepot, $busesForEndDepot, $startStopOffsetDistance, $endStopOffsetDistance, $startStopStartDepotCommonBusesString, $endDepotEndStopCommonBusesString, $startStopDepotDistance, $endStopDepotDistance, 0);
                            //need to add the bus info between the startstop and depot+last depot and end point
                            if ($interDepotStatus == "409" || $interDepotStatus == "410") {
                                // buses not found between the depots using a single or no hop
                                $strRoute = '<Routes>';
                                $strRoute = $strRoute . '<Route>';
                                $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
                                $strRoute = $strRoute . '<ErrorCode>' . $interDepotStatus . '</ErrorCode>';
                                $strRoute = $strRoute . '</Route>';
                                $strRoute = $strRoute . '</Routes>';
                                return $strRoute;
                            } else {
                                $strRoute = $interDepotStatus;
                                return $strRoute;
                            }
                        }
                    } else {
                        //the depots are too far away
                        $strRoute = '<Routes>';
                        $strRoute = $strRoute . '<Route>';
                        $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
                        $strRoute = $strRoute . '<ErrorCode>411</ErrorCode>';
                        $strRoute = $strRoute . '</Route>';
                        $strRoute = $strRoute . '</Routes>';
                        return $strRoute;
                    }
                }
            }
        } else {
            return $status;
        }
    }
    //echo "<sample>hhhh</sample>";
}