Question: is the astar function deterministic?
proehlen opened this issue · comments
I'm coding a game that relies on deterministic outcomes and wanted to make sure that, given the same inputs, the astar
function will always produce the same results I'm fairly new to rust and notice that the crate uses rand
, hence the question.
If you look carefully at Cargo.toml
, you'll notice that rand
is in dev-dependencies
, not in dependencies
. It means that it is used in tests, benchmarks and examples, but is not a dependency of the library itself.
We do not use any source of randomness in the pathfinding library. However, we might use data structures such as HashSet
from the Rust library who might not be deterministic. I do not think we use any in astar
in a way that would affect the result, so it is likely that astar
is deterministic while astar_bag
might not be.
astar isn't' deterministic it seems, I tried to unit test my results and it returns different paths in case I have same costs of multiple valid paths
it's probably HashSet or FxIndexMap to blame here
astar isn't' deterministic it seems, I tried to unit test my results and it returns different paths in case I have same costs of multiple valid paths
@Firfi Are you sure your successors
function is itself deterministic? The only non-deterministic structure in astar
seems to be FxIndexMap
but it is used to store the parents of the nodes, and it is not used as a keys iterator, so it should not matter.
astar isn't' deterministic it seems, I tried to unit test my results and it returns different paths in case I have same costs of multiple valid paths
@Firfi Are you sure your
successors
function is itself deterministic? The only non-deterministic structure inastar
seems to beFxIndexMap
but it is used to store the parents of the nodes, and it is not used as a keys iterator, so it should not matter.
You're right! My successors used HashSet and wasn't deterministic itself! Thank you for this direction. I re-tested and astar seems to return the same result every run now.