- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
bool PathProcessor::Process(PPProcess *pProcess)
{
std::vector<int> viRoute; int nRouteCount; bool bRetVal = false;
for (int i = 0; i < m_viExcludeStop.size(); i++){
if (m_viExcludeStop[i] == pProcess->nStartStopId) return false;
}
int bbb = 0;
if (pProcess->nRouteId < 0){
viRoute = GetRoutesID(pProcess->nStartStopId);
nRouteCount = viRoute.size();
if (nRouteCount <= 0) return false;
}
else{
viRoute = GetRoutesID(pProcess->nStartStopId, pProcess->nRouteId);
nRouteCount = viRoute.size();
if (nRouteCount <= 0) return false;
nRouteCount = 1;
}
for (int i = 0; i < nRouteCount; i++){
RouteDataInfo rdCur = GetRoute(viRoute[i]);
pProcess->nRoutePartId = rdCur.nId;
PPResult *pRes;
bool bCurRetVal = false;
if (pProcess->bIsFirstStop == true){
pRes = new PPResult();
pRes->bFinished = false;
pRes->nFirstStopId = pProcess->nFirstId;
pRes->nLastStopId = -1;
pRes->nRouteId = rdCur.nRouteId;
m_viResult.push_back(pRes);
}
else pRes = pProcess->pLastResult;
if (pRes != NULL){
PartInfo piTemp(rdCur.nId, rdCur.nLastStopId);
pRes->viPartsId.push_back(piTemp);
}
if (IsEndStop(rdCur.nLastStopId) == true){
if (pRes != NULL){
pRes->bFinished = true;
pRes->nLastStopId = rdCur.nLastStopId;
}
bRetVal = true; bCurRetVal = true;
}
if ((pProcess->IsStopExist(rdCur.nLastStopId) == false) && (bCurRetVal == false)){
if ((pProcess->nCurStep < m_nMaxStep) && (pProcess->nRouteId >= 0)){
PPProcess ppProc;
ppProc.nCurStep = pProcess->nCurStep;
ppProc.nRouteId = pProcess->nRouteId;
ppProc.nStartStopId = rdCur.nLastStopId;
ppProc.pPrevProc = pProcess;
ppProc.bIsFirstStop = false;
ppProc.nFirstId = pProcess->nFirstId;
if (pProcess->pLastResult == NULL) ppProc.pLastResult = pRes;
else ppProc.pLastResult = pProcess->pLastResult;
if (Process(&ppProc) == true) bRetVal = true;
}
else if (pProcess->nCurStep < m_nMaxStep){
PPProcess ppProc;
ppProc.nCurStep = pProcess->nCurStep;
ppProc.nRouteId = rdCur.nRouteId;
ppProc.nStartStopId = rdCur.nLastStopId;
ppProc.pPrevProc = pProcess;
ppProc.bIsFirstStop = false;
ppProc.nFirstId = pProcess->nFirstId;
if (pProcess->pLastResult == NULL) ppProc.pLastResult = pRes;
else ppProc.pLastResult = pProcess->pLastResult;
if (Process(&ppProc) == true) bRetVal = true;
}
if (pProcess->nCurStep+1 < m_nMaxStep){
PPProcess ppProc2;
ppProc2.nCurStep = pProcess->nCurStep+1;
ppProc2.nRouteId = -1;
ppProc2.nStartStopId = rdCur.nLastStopId;
ppProc2.pPrevProc = pProcess;
ppProc2.bIsFirstStop = true;
ppProc2.nFirstId = rdCur.nLastStopId;
ppProc2.pLastResult = NULL;
if (Process(&ppProc2) == true){
PPResult *pRes2;
pRes2 = new PPResult();
pRes2->bFinished = true;
pRes2->nFirstStopId = pRes->nFirstStopId;
pRes2->nLastStopId = rdCur.nLastStopId;
pRes2->nRouteId = pRes->nRouteId;
PPProcess *pProc = pProcess;
while (pProc != NULL){
PartInfo piTemp(pProc->nRoutePartId, pProc->nStartStopId);
pRes2->viPartsId.push_back(piTemp);
pProc = pProc->pPrevProc;
}
m_viResult.push_back(pRes2); bRetVal = true;
}
}
}
}
if ((bRetVal == false) && (pProcess->nRouteId < 0))
m_viExcludeStop.push_back(pProcess->nStartStopId);
return bRetVal;
}
Когда-то давно писал алгоритм поиска маршрутов, теперь удевляюсь как это все работает да еще и не виснет
guest 09.04.2010 14:27 # +0.2
Snake2101 09.04.2010 14:28 # +0.2
guest 10.04.2010 02:06 # +0.2