1. C++ / Говнокод #2970

    +144.8

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 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;
    }

    Когда-то давно писал алгоритм поиска маршрутов, теперь удевляюсь как это все работает да еще и не виснет

    Запостил: Snake2101, 09 Апреля 2010

    Комментарии (3) RSS

    Добавить комментарий