예제 #1
0
/**
* getJunctionsForIndirectBuses: function to find the junction. The junction is same as the stop only difference is that some
* of the stops have mulitple names we need to normalize them. It will combine the buses that are passing to the same 
* junction. The function is mailnly to control the way the informatioin is displayed to the user

change: 27Dec2011
In case when either the bus from the start stop to first junction is not present or the bus from the second jucntion to the end stop is not present
I am removing that particular entry (error code6) but we can as well say in the javascript that this is the case when the user can just walk to/from the 
junction .. Need to chekc on this

The error codes
0: Direct buses are found
1: only one jucntion found same as search" Bellandur" to Forum Mall
2.: One junction but then the user needs to walk to the endpoint. no need to take a bus: search string abhi yaad nahin aa rahi
3: two junctions. User needs to walk between the junction search "Bellandur" "Meanee Avenue Road"
4: No route was found ....give some junk values
5: Distance is walkable no bus to take search Bellandur and Accenture
6: Ignore this particular enetry


**/
function getJunctionsForIndirectBuses($arrBuses, $startStop, $endStop, $startOffsetDistance, $endOffsetDistance)
{
    //print_r($arrBuses);
    $array_size = sizeof($arrBuses);
    // check if the buses are direct buses
    list($firstBus, $secondBus) = split(":", $arrBuses[0]);
    if ($array_size > 0 && strcmp($firstBus, $secondBus) == 0) {
        return displayDirectBuses($arrBuses);
    } else {
        $arrFirstJunctions = array();
        $arrSecondJunctions = array();
        $arrFirstBuses = array();
        $arrSecondBuses = array();
        for ($i = 0; $i < $array_size; $i++) {
            list($firstBus, $secondBus) = split(":", $arrBuses[$i]);
            array_push($arrFirstBuses, $firstBus);
            array_push($arrSecondBuses, $secondBus);
        }
        //print_r($arrFirstBuses);
        $arrayUniqueJunctions = array();
        for ($i = 0; $i < $array_size; $i++) {
            list($firstBus, $secondBus) = split(":", $arrBuses[$i]);
            list($firstBus, $firstBusRouteNumber, $firstJunction, $secondBus, $secondBusRouteNumber, $secondJunction, $distance) = split(":", getIntermediateStopsAndDistance($firstBus, $secondBus));
            if (strlen($firstBus) == 0) {
                continue;
            }
            // this is the case of wrong combinations
            //  echo getIntermediateStopsAndDistance($firstBus,$secondBus)."<br/>";
            // find the uniue combinations of fisrt and second junctions
            if ($distance < 0.6) {
                if (checkUniqueJunctions($arrayUniqueJunctions, $firstJunction, $secondJunction, $distance) == 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(getNormalizedStopName($firstJunction), $startStop) == 0 || strcmp(getNormalizedStopName($firstJunction), $endStop) == 0 || strcmp(getNormalizedStopName($secondJunction), $startStop) == 0 || strcmp(getNormalizedStopName($secondJunction), $endStop) == 0) {
                        continue;
                    } else {
                        $element = getNormalizedStopName($firstJunction) . ":" . getNormalizedStopName($secondJunction) . ":" . $distance;
                        array_push($arrayUniqueJunctions, $element);
                    }
                }
            }
        }
        //print_r($arrayUniqueJunctions);
        // module to sort the results on the basids of the total distance
        $displayJunctionsDataArray = array();
        for ($i = 0; $i < sizeof($arrayUniqueJunctions); $i++) {
            $tempJunctionString = $arrayUniqueJunctions[$i];
            list($firstJnName, $secondJnName, $distanceJn) = split(":", $arrayUniqueJunctions[$i]);
            $tot = getTotalRouteDistance($startStop, $firstJnName, $secondJnName, $distanceJn, $endStop, $startOffsetDistance, $endOffsetDistance);
            $element = new DisplayJunctionsData($tempJunctionString, $tot);
            array_push($displayJunctionsDataArray, $element);
        }
        $SortedJunctionsDataArray = prioritizeAndSortJunctionArray(BubbleSort($displayJunctionsDataArray, sizeof($displayJunctionsDataArray)));
        //echo "sdsd";
        //print_r($SortedJunctionsDataArray);
        // display the results
        $strRoute = '';
        if (sizeof($SortedJunctionsDataArray) == 0) {
            $strRoute = '<Routes>';
            $strRoute = $strRoute . '<Route>';
            $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
            $strRoute = $strRoute . '<ErrorCode>4</ErrorCode>';
            $strRoute = $strRoute . '</Route>';
            $strRoute = $strRoute . '</Routes>';
        } 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;
            for ($i = 0; $i < sizeof($SortedJunctionsDataArray); $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) = split(":", $SortedJunctionsDataArray[$i]->getJunctionString());
                //get all the buses for firstJn
                $strRoute = $strRoute . '<Route>';
                $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
                //get all the buses for second jun
                if ($distanceJn == 0 && strcmp(getNormalizedStopName($firstJnName), $startStop) != 0) {
                    $getCommonBusesForFirstJunction = getCommonBusesForNormalizedStopName($firstJnName, $arrFirstBuses);
                    $getCommonBusesForSecondJunction = getCommonBusesForNormalizedStopName($secondJnName, $arrSecondBuses);
                    if (strlen($getCommonBusesForFirstJunction) > 0 && strlen($getCommonBusesForSecondJunction) > 0) {
                        $strRoute = $strRoute . '<ErrorCode>1</ErrorCode>';
                        $routeDetail = htmlentities($startStop) . ":" . $getCommonBusesForFirstJunction . ":";
                        $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($firstJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($firstJnName)) . ":0:";
                        $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($firstJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($firstJnName)) . ":" . $getCommonBusesForSecondJunction . ":";
                        $routeDetail = $routeDetail . htmlentities($endStop);
                    } else {
                        $strRoute = $strRoute . '<ErrorCode>6</ErrorCode>';
                        $FalseAlarmCounter++;
                    }
                } else {
                    // if the end point is same as the second junction it may happend that you juct have to walk from the first junction to the end point
                    if (strcmp(getNormalizedStopName($secondJnName), $endStop) == 0) {
                        $strRoute = $strRoute . '<ErrorCode>2</ErrorCode>';
                        $routeDetail = htmlentities($startStop) . ":" . getCommonBusesForNormalizedStopName($firstJnName, $arrFirstBuses) . ":";
                        $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($firstJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($firstJnName)) . ":" . $distanceJn . ":";
                        $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($firstJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($firstJnName)) . ":" . getCommonBusesForNormalizedStopName($secondJnName, $arrSecondBuses) . ":";
                        $routeDetail = $routeDetail . htmlentities($endStop);
                    } else {
                        $getCommonBusesForFirstJunction = getCommonBusesForNormalizedStopName($firstJnName, $arrFirstBuses);
                        $getCommonBusesForSecondJunction = getCommonBusesForNormalizedStopName($secondJnName, $arrSecondBuses);
                        if (strlen($getCommonBusesForFirstJunction) > 0 && strlen($getCommonBusesForSecondJunction) > 0) {
                            $strRoute = $strRoute . '<ErrorCode>3</ErrorCode>';
                            $routeDetail = htmlentities($startStop) . ":" . getCommonBusesForNormalizedStopName($firstJnName, $arrFirstBuses) . ":";
                            $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($firstJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($firstJnName)) . ":" . $distanceJn . ":";
                            $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($secondJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($secondJnName)) . ":" . getCommonBusesForNormalizedStopName($secondJnName, $arrSecondBuses) . ":";
                            $routeDetail = $routeDetail . htmlentities($endStop);
                        } else {
                            $FalseAlarmCounter++;
                        }
                    }
                }
                //echo "The approximate route distance="."<b>".$SortedJunctionsDataArray[$i]->getDistance()."KM</b>";
                $routeDetail = $routeDetail . ":" . $SortedJunctionsDataArray[$i]->getDistance();
                $strRoute = $strRoute . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                //echo "<hr/>";
                $strRoute = $strRoute . '</Route>';
                //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>';
            }
        }
        return $strRoute;
    }
}
예제 #2
0
/**
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;
    }
}
예제 #3
0
/**
* getJunctionsForIndirectBuses: function to find the junction. The junction is same as the stop only difference is that some
* of the stops have mulitple names we need to normalize them. It will combine the buses that are passing to the same 
* junction. The function is mailnly to control the way the informatioin is displayed to the user
**/
function getJunctionsForIndirectBuses($arrBuses,$startStop,$endStop,$startOffsetDistance,$endOffsetDistance)
{
	//print_r($arrBuses);
	$array_size=sizeof($arrBuses);
	// check if the buses are direct buses
	list($firstBus,$secondBus)=split(":",$arrBuses[0]);
	if(strcmp($firstBus,$secondBus)==0)
		displayDirectBuses($arrBuses);
	
	// indirect buses
	else
	{
		$arrFirstJunctions=array();
		$arrSecondJunctions=array();
		$arrFirstBuses=array();
		$arrSecondBuses=array();
	

		for($i=0;$i<$array_size;$i++)
		{
			list($firstBus,$secondBus)=split(":",$arrBuses[$i]);
			
			array_push($arrFirstBuses,$firstBus);
			array_push($arrSecondBuses,$secondBus);
			
		}
		//print_r($arrFirstBuses);
		$arrayUniqueJunctions=array();
		for($i=0;$i<$array_size;$i++)
		{
			list($firstBus,$secondBus)=split(":",$arrBuses[$i]);
			list($firstBus,$firstBusRouteNumber,$firstJunction,$secondBus,$secondBusRouteNumber,$secondJunction,$distance)=split(":",getIntermediateStopsAndDistance($firstBus,$secondBus));
			if(strlen($firstBus)==0)
				continue;// this is the case of wrong combinations
		  //  echo getIntermediateStopsAndDistance($firstBus,$secondBus)."<br/>";
			// find the uniue combinations of fisrt and second junctions
			if($distance<1)// make suere that the distance between the junctions is not more than 1 km.
			{
				if(checkUniqueJunctions($arrayUniqueJunctions,$firstJunction,$secondJunction,$distance)==0)
				{
					$element=getNormalizedStopName($firstJunction).":".getNormalizedStopName($secondJunction).":".$distance;
					array_push($arrayUniqueJunctions,$element);
				}
			}
		}
		
		//echo "the unique ones are "."<br/>";
		//print_r($arrayUniqueJunctions);
		echo "<br/>";
		
		// module to sort the results on the basids of the total distance
		$displayJunctionsDataArray=array();
		for($i=0;$i<sizeof($arrayUniqueJunctions);$i++)
		{
			$tempJunctionString=$arrayUniqueJunctions[$i];
			list($firstJnName,$secondJnName,$distanceJn)=split(":",$arrayUniqueJunctions[$i]);
			$tot=getTotalRouteDistance($startStop,$firstJnName,$secondJnName,$distanceJn,$endStop,$startOffsetDistance,$endOffsetDistance);
			$element=new DisplayJunctionsData($tempJunctionString,$tot);
			array_push($displayJunctionsDataArray,$element);

		}
		
		$SortedJunctionsDataArray=BubbleSort($displayJunctionsDataArray,sizeof($displayJunctionsDataArray));
		//print_r($SortedJunctionsDataArray);
		// print the buses
		/*for($i=0;$i<sizeof($arrayUniqueJunctions);$i++)
		{
			list($firstJnName,$secondJnName,$distanceJn)=split(":",$arrayUniqueJunctions[$i]);
			//get all the buses for firstJn
			echo "From "."<b>".$startStop." (Starting Point)</b> take ". getCommonBusesForNormalizedStopName($firstJnName,$arrFirstBuses)." and go to ". "<b>".getNormalizedStopName($firstJnName)."</b><br/>" ;

			//get all the buses for second jun
			if($distanceJn==0)
			{
				echo "Now from ". "<b>".getNormalizedStopName($firstJnName)."</b>". " take one of the". getCommonBusesForNormalizedStopName($secondJnName,$arrSecondBuses)." buses to go to ". "<b>".$endStop. " (Your Destination)</b><br/>";
				//echo "The distance between the junction is ". $distanceJn ."<br/>";
			}
			else
			{
				echo "You need to walk to  "."<b>".getNormalizedStopName($secondJnName)."</b>" ." which is ".$distanceJn. "KM from ". "<b>".$firstJnName."</b><br/>";
				echo "Now from ". "<b>".getNormalizedStopName($secondJnName)."</b>"."take one of the". getCommonBusesForNormalizedStopName($secondJnName,$arrSecondBuses)." buses to go to ". "<b>".$endStop. "(Your Destination)</b><br/>";
			}
			
			echo "The approximate route distance="."<b>".getTotalRouteDistance($startStop,$firstJnName,$secondJnName,$distanceJn,$endStop,$startOffsetDistance,$endOffsetDistance)."KM</b>";
			echo "<hr/>";
			
			
		}*/
		for($i=0;$i<sizeof($SortedJunctionsDataArray);$i++)
		{
			list($firstJnName,$secondJnName,$distanceJn)=split(":",$SortedJunctionsDataArray[$i]->getJunctionString());
			//get all the buses for firstJn
			echo "From "."<b>".$startStop." (Starting Point)</b> take ". getCommonBusesForNormalizedStopName($firstJnName,$arrFirstBuses)." and go to ". "<b>".getNormalizedStopName($firstJnName)."</b><br/>" ;

			//get all the buses for second jun
			if($distanceJn==0)
			{
				echo "Now from ". "<b>".getNormalizedStopName($firstJnName)."</b>". " take one of the". getCommonBusesForNormalizedStopName($secondJnName,$arrSecondBuses)." buses to go to ". "<b>".$endStop. " (Your Destination)</b><br/>";
				//echo "The distance between the junction is ". $distanceJn ."<br/>";
			}
			else
			{
				if(strcmp(getNormalizedStopName($secondJnName),$endStop)==0)
				{
					echo "You need to walk from  "."<b>".getNormalizedStopName($firstJnName)."</b>" ." which is ".$distanceJn. "KM from ". "<b>".$endStop."</b><br/>";
				

				}
				else
				{
				echo "You need to walk to  "."<b>".getNormalizedStopName($secondJnName)."</b>" ." which is ".$distanceJn. "KM from ". "<b>".$firstJnName."</b><br/>";
				echo "Now from ". "<b>".getNormalizedStopName($secondJnName)."</b>"."take one of the". getCommonBusesForNormalizedStopName($secondJnName,$arrSecondBuses)." buses to go to ". "<b>".$endStop. "(Your Destination)</b><br/>";
				}
			}
			
			echo "The approximate route distance="."<b>".$SortedJunctionsDataArray[$i]->getDistance()."KM</b>";
			echo "<hr/>";
			
			
		}

	}
}