I have a transition matrix using dictionary
{'hex1': {'hex2': 1.0},
'hex2': {'hex4': 0.4, 'hex7': 0.2, 'hex6': 0.2, 'hex1': 0.2},
'hex4': {'hex3': 1.0},
'hex3': {'hex6': 0.3333333333333333, 'hex2': 0.6666666666666666},
'hex6': {'hex1': 0.3333333333333333,
'hex4': 0.3333333333333333,
'hex5': 0.3333333333333333},
'hex7': {'hex6': 1.0},
'hex5': {'hex3': 1.0}}
which shows the probability of going from a certain hex to another hex (e.g. hex1
has probability 1 going to hex2
, hex2
has probability 0.4 going to hex4
).
Taking the starting and endpoint, I want to find the path that has the highest probability.
The structure of the code will look like
def find_most_probable_path(start_hex, end_hex, max_path):
path = compute for maximum probability path from start_hex to end_hex
return path
where max_path is the maximum hexes to traverse. If there is no path within the max_path, return empty/null. Also, drop the path if goes back to the starting hex before reaching the ending hex.
Example would be
find_most_probable_path(hex2, hex3, 5)
>> "hex2,hex4,hex3"
The output can be a list of hexes or just concatenated strings.