Beispiel #1
0
void DirectedGraph::deriveEdges(shared_ptr<const OsmMap> map)
{
  const WayMap& ways = map->getWays();

  for (WayMap::const_iterator it = ways.begin(); it != ways.end(); ++it)
  {
    const shared_ptr<Way>& way = it->second;
    double cost = determineCost(way);
    double length = ElementConverter(map).convertToLineString(way)->getLength();

    long nStart = way->getNodeId(0);
    long nEnd = way->getNodeId(way->getNodeCount() - 1);
    if (cost >= 0)
    {
      if (isOneWay(way))
      {
        addEdge(nStart, nEnd, cost * length);
      }
      else
      {
        addEdge(nStart, nEnd, cost * length);
        addEdge(nEnd, nStart, cost * length);
      }
    }
  }
}
Beispiel #2
0
void Problem::expand(Node* currentNode)
{
	visitedStates.insert(currentNode->state);

	std::string newState;
	unsigned int cost;
	//generate the child nodes of the current Node and if they haven't been visited yet, place them in the queue
	for(unsigned int tileToBeMoved = 0; tileToBeMoved < currentNode->state.size(); tileToBeMoved++)
	{
		//in the state string if the char is not a space, then it is a tile, so we can move it

		if(currentNode->state[tileToBeMoved] != 'x')
		{
			//currentNode->action = tileToBeMoved;
			newState = generateNextStateString(currentNode->state, tileToBeMoved);			

			//if the state has not yet been visited, we can throw it in the frontier
			if(hasStateBeenVisited(newState) == false)
			{
				//create a node for this new state
				if(hasCost == true)
				{
					cost = determineCost(tileToBeMoved, newState);					
				}
				else
				{
					cost = 0;
				}
				Node newNode(newState, tileToBeMoved, currentNode, cost);
				addToStorage(newNode);
				visitedStates.insert(newState);

				//put a pointer to this newly made node in the queue
				queue.push_front(&nodeStorage[nodesInStorage - 1]);
				//std::cout << "added to queue : " << newNode.state << std::endl;
			}
		}
	}
}