I'm implementing the A* search algorithm given here, https://en.wikipedia.org/wiki/A*_search_algorithm
This line indicates we need to initiliaze a map with the default values of INFINITY,
gScore := map with default value of Infinity
So I tried that here,
Map<State, Double> gScore = new HashMap<State, Double>(Double.POSITIVE_INFINITY);
This does not work however the following does;
Map<State, Double> gScore = new HashMap<State, Double>((int) Double.POSITIVE_INFINITY);
I'm wondering why, and what impact (if any) it will have on my implementation.
There is no way to initialize a map with a default value in Java, and your second version will not create a map with a default value of infinity, but instead will try to create an infinitely large map. (Not really, but it'll try creating the largest map possible.)
Instead, modify the algorithm: anytime you do map.get(key)
, check if the value is null and, if so, replace it with infinity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With