How to gurrantee the nodes exist?

This topic is 1123 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

If I check the path from 2 to 1, and just 1 to 2 exists,

I need to swap the 2 nodes in order to find the cost.

How do I use the astar function no matter which way the from and to point to?

They are interchangable...

First thought,

Sorting the set,

If second is bigger than the first,

swap it then.

Should be correct, I think....

Thanks

Jack

float GridSingleton::getActualCost(int fromNode, int toNode) {

// if 1 => 2 exists
//    2 => 1 might not exists
// if checking for 2 => 1
// I still have to check 1 => 2
return m_astar->findCost(from, to);
//return m_actualCosts[std::make_pair(from,to)];

// cache this costs

}

Edited by lucky6969b

Share on other sites

What is your issue ? You have a half filled cost matrix/array ?

You are looking for something like this (?):

float GridSingleton::getActualCost(int fromNode, int toNode) {

// if 1 => 2 exists
//    2 => 1 might not exists
// if checking for 2 => 1
// I still have to check 1 => 2

return fromNode<toNode ? m_astar->findCost(from, to) : m_astar->findCost(to, from);
}



Or this (?):

float GridSingleton::getActualCost(int fromNode, int toNode) {

// if 1 => 2 exists
//    2 => 1 might not exists
// if checking for 2 => 1
// I still have to check 1 => 2

return max(m_astar->findCost(from, to),m_astar->findCost(to, from));
}


Edited by Ashaman73

Share on other sites
Unless you don't have cycles in your paths, I don't see how you can sort source and destination of your A* main call. The main call is about PATH, a some 'random' walk over a sequence of nodes.
In general, it is quite possible to have a path from A -> B, but not from B -> A (eg fall down a waterfall generally works only in in one way).

Instead, I'd handle the problem at individual node level (ie from one node to its direct neighbours).
Since A* asks a node for "from here" to my neighbours, the best solution is to have to search your current position only.

A simple solution is to store a bi-directional path as two one-way paths (that is, store bi-directional A -- B as one-way A -> B and one-way B -> A).
It does not matter which node you currently have, it always has a connection to the other node. Edited by Alberth

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• Forum Statistics

• Total Topics
632984
• Total Posts
3009716
• Who's Online (See full list)

There are no registered users currently online

×