/** 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; } }
/** * 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; } }