Sign in to follow this  

How to gurrantee the nodes exist?

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

If you intended to correct an error in the post then please contact us.

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
    QuadNode* from = grid[fromNode];
    QuadNode* to = grid[toNode];
    return m_astar->findCost(from, to);
    //return m_actualCosts[std::make_pair(from,to)];

    // cache this costs
    
}
Edited by lucky6969b

Share this post


Link to post
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
    QuadNode* from = grid[fromNode];
    QuadNode* to = grid[toNode];


    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
    QuadNode* from = grid[fromNode];
    QuadNode* to = grid[toNode];


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

Edited by Ashaman73

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this