#include <roadangel/heurismfile.h>
#include <roadangel/routing.h>
#include <roadangel/linkfile.h>
#include <roadangel/nodefile.h>
#include "shortdistance.h"
LinkHandle pLinkHandle;
LinkObjectSet *pGLinkObjectSet;
#ifndef false
#define false 0
#define true 1
#define bool unsigned int
#endif
LinkObjectSet* LoadLink(const char* strfile, LinkHandle *pinkhandle);
/*
*loat the link data
*para:
*strfile: the file that link file
*plinkhandle:the handle of the link
*return: the set of linkobject
*/
LinkObjectSet* LoadLink(const char* strfile, LinkHandle /*out*/*plinkhandle)
{
LinkObjectSet* pLinkObjectSet;
*plinkhandle = LinkOpen(strfile,"rb") ;
if(!(*plinkhandle)->fpLinkFile)
{
return NULL;
}
getLinkInfo(*plinkhandle);
pLinkObjectSet = loadLinkObjectSet(*plinkhandle);
if(!(pLinkObjectSet))
{
return NULL;
}
return pLinkObjectSet;
}
/*
*loat the node data
*para:
*strfile: the file that node file
*pnodehandle:the handle of the node
*return: the set of nodeobject
*/
NodeObjectSet * loadNode(const char* /*in*/ strfile, LinkHandle /*out*/*pnodehandle)
{
NodeObjectSet* pNodeObjectSet;
*pnodehandle = NodeOpen(strfile,"rb") ;
if(!(*pnodehandle)->fpLinkFile)
{
return NULL;
}
getNodeInfo(*pnodehandle);
pNodeObjectSet = loadNodeObjectSet(*pnodehandle);
if(!(pNodeObjectSet))
{
return NULL;
}
return pNodeObjectSet;
}
/*
*delete the linkhandle data
*para:
*plinkhandle: the handle of link
*LinkObjectSet: the set of linkobject
*caution: no
*/
void DeleteNode(NodeHandle pnodehandle,NodeObjectSet *pNodeObjectSet)
{
if(pNodeObjectSet)
{
DestroyNodeObjectSet(pNodeObjectSet);
}
NodeClose(pnodehandle);
}
/*
*delete the nodehandle data
*para:
*pnodehandle: the handle of link
*nodeObjectSet: the set of linkobject
*caution: no
*/
void DeleteLink(LinkHandle plinkhandle,LinkObjectSet *pLinkObjectSet)
{
if(pLinkObjectSet)
{
DestroyLinkObjectSet(pLinkObjectSet);
}
LinkClose(plinkhandle);
}
/*
*find the collection by the path that supply the set of id
*pLinkObjectSet: the set of pLinkObject
*path: the set of id
*len: the num of id
*/
LinkObject** FindPathLink(LinkObjectSet *pLinkObjectSet,uint32* path,int len)
{
LinkObject** retval;
int i;
int j;
if(!pLinkObjectSet)
{
return NULL;
}
retval =(LinkObject**) malloc(sizeof(LinkObject*)* len);
if(retval == NULL)
{
return retval;
}
for(i = 0 ; i < len; ++i)
{
retval[i]=NULL;
}
// printf("linknum is %d\n",pLinkObjectSet->iObjectNumber);
for(i = 0; i < len; ++i)
{
for(j = 0 ; j < pLinkObjectSet->iObjectNumber; ++j)
{
if(pLinkObjectSet->pObject[j] != NULL)
{
if(path[i] == pLinkObjectSet->pObject[j][0].iLinkId)
{
retval[i] = pLinkObjectSet->pObject[j];
break;
}
}
}
}
/*if(i== len && j == pLinkObjectSet->iObjectNumber)
{
free(retval);
return NULL;
}*/
return retval;
}
/*
* deletet the set of link data
* para:
*pLinkObject :the set of link data
*cation:no
*/
void DeletePathLink(LinkObject *pLinkObject)
{
if(pLinkObject)
{
free(pLinkObject);
}
return;
}
/*
*create the shortdistanceinfo
*para:
*pshortestInfo: the shortestdistaceinfo
*szHeurismFile:the file of the szHeurismFile
*return : no
*caution:no
*/
void CreateShortDistanceInfo(ShortestDistanceInfo*/*out*/ pShortestInfo,
const char* szHeurismFile)
{
int i;
//int j;
pShortestInfo->psHeurism = HeurismOpen ( szHeurismFile, "rb" );
getHeurismInfo ( pShortestInfo->psHeurism );
pShortestInfo->LinkArray = getLinkArray ( pShortestInfo->psHeurism );
pShortestInfo->junctionTable = getNodeArray ( pShortestInfo->psHeurism );
pShortestInfo->TurnMatrix = initHeurismMatrix (
pShortestInfo->psHeurism->iLinkNumber,
pShortestInfo->LinkArray );
loadHeurismMatrix ( pShortestInfo->TurnMatrix, pShortestInfo->psHeurism );
pShortestInfo->node = initNodeArray ( pShortestInfo->psHeurism->iLinkNumber + 1 );
for ( i = 0; i < pShortestInfo->psHeurism->iLinkNumber; ++i )
{
pShortestInfo->node[i+1].iNodeId = pShortestInfo->TurnMatrix[i][0];
pShortestInfo->node[i+1].Pred = NULL;
pShortestInfo->node[i+1].iFCost = 0;
pShortestInfo->node[i+1].iCost = 0;
pShortestInfo->node[i+1].Next = NULL;
}
pShortestInfo->node[0].iNodeId = 0;
pShortestInfo->node[0].Pred = NULL;
pShortestInfo->node[0].iFCost = 0;
pShortestInfo->node[0].iCost = 0;
pShortestInfo->node[0].Next = NULL;
}
/*
*init the shortdistanceinfo
*pshorttestinfo: the info of shortdistance
*
*
*/
void initNode(ShortestDistanceInfo* pShortestInfo)
{
int i;
for ( i = 0; i < pShortestInfo->psHeurism->iLinkNumber; ++i )
{
pShortestInfo->node[i+1].iNodeId = pShortestInfo->TurnMatrix[i][0];
pShortestInfo->node[i+1].Pred = NULL;
pShortestInfo->node[i+1].iFCost = 0;
pShortestInfo->node[i+1].iCost = 0;
pShortestInfo->node[i+1].Next = NULL;
}
pShortestInfo->node[0].iNodeId = 0;
pShortestInfo->node[0].Pred = NULL;
pShortestInfo->node[0].iFCost = 0;
pShortestInfo->node[0].iCost = 0;
pShortestInfo->node[0].Next = NULL;
}
/*
path = AStar( 291003494, 291005963, 291003237, node, psHeurism->iLinkNumber,
TurnMatrix, psHeurism->iLinkNumber, LinkArray,
junctionTable, (int)psHeurism->iNodeNumber, &linknum );
*/
/*
*delete the shortdistanceinfo
*para:
*pshortestInfo: the shortestdistaceinfo
*
*return : no
*caution:no
*/
void DeleteShortDistanceInfo( ShortestDistanceInfo pShortestInfo )
{
releaseLinkArray ( pShortestInfo.psHeurism );
releaseNodeArray ( pShortestInfo.psHeurism );
releaseHeurismMatrix ( pShortestInfo.psHeurism );
destroyNodeArray ( pShortestInfo.node );
HeurismClose ( pShortestInfo.psHeurism );
}