void CPathPlan::Floyd()
{
for(int k = 1;k < 51;k++)
{
for(int i = 1;i < 51;i++)
{
if(CostMap[i][destination]
> CostMap[i][k] + CostMap[k][destination])
{
minCost[i] = CostMap[i][k] + CostMap[k][destination];
}
else
{
minCost[i] = CostMap[i][destination];
}
}
}
minCost[destination]
= 0;
}
bool CPathPlan::Plan()
{
if(origin
== destination)
{
this->m_pTailArcItem = pLinkCurItem;
this->m_pHeadArcItem = pLinkCurItem;
bFoundPath = true;
return bFoundPath;
}
priorityQueue.PushHeap(pLinkCurItem);
openTable.insert(std::make_pair<int,void*>(origin,pLinkCurItem));
DomSet.insert(std::make_pair<int,int>(origin,0));
while(!priorityQueue.isEmpty())
{
pLinkCurItem = priorityQueue.PopHeap();
openTable.erase(pLinkCurItem->m_CityID);
closeTable.insert(std::make_pair<int,void*>(pLinkCurItem->m_CityID,pLinkCurItem));
curCol = pLinkCurItem->m_CityID;
if(curCol == destination)
{
m_pTailArcItem = pLinkCurItem;
bFoundPath = true;
return bFoundPath;
}
for(curRow = 1;curRow < 51;curRow++)
{
if(DisMap[curCol][curRow] == NO_ROAD_DIS)
continue;
else
{
disToStart = pLinkCurItem->m_dDisToStart + DisMap[curCol][curRow];
costToStart = pLinkCurItem->m_dCostToStart + CostMap[curCol][curRow];
}
if(costToStart + minCost[curRow]<=
upCost)
{
it = DomSet.insert(std::make_pair<int,int>(curRow,disToStart));
if(it.second ||it.first->second
> disToStart)
{
it.first->second = disToStart;
tableIt = closeTable.find(curRow);
if(tableIt == closeTable.end())
{
//不在close表中
tableIt = openTable.find(curRow);
if(tableIt == openTable.end())
{ //不在close表中也不再open表中//作为一个新状态插入
CArcItem_Ptr pNewItem = new CArcItem;
pNewItem->m_CityID
= curRow;
pNewItem->m_pParentArcItem
= pLinkCurItem;
pNewItem->m_dDisToStart
= disToStart;
pNewItem->m_dCostToStart
= costToStart;
priorityQueue.PushHeap(pNewItem);
openTable.insert(std::make_pair<int,void*>(pNewItem->m_CityID,pNewItem));
}
else
{
//不在close表中,但在open表中,如果值比以前小,那么更新
CArcItem_Ptr pItem
= (CArcItem_Ptr)(tableIt->second);
if(pItem->m_dDisToStart - disToStart
> 0)
{
//_ASSERT(FALSE);
pItem->m_pParentArcItem
= pLinkCurItem;
pItem->m_dDisToStart
= disToStart;
pItem->m_dCostToStart
= costToStart;
priorityQueue.EditItem(pItem);
}
}
}
}
}
}
}
return bFoundPath;
}