Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def findAllValidPaths(startState, destination, targetWeight):
- stack = []
- for e in startState.outgoingEdges:
- newPath = [e]
- stack.append(newPath)
- while len(stack) > 0:
- path = stack[-1]
- stack = stack[:-1]
- lastState = path[-1].targetState
- weight = 0
- for e in path:
- weight += e.weight
- if lastState == destination and weight == targetWeight:
- print(path)
- continue
- if lastState == destination or weight > targetWeight: # omit the "lastState == destination" part if its ok to find a paths which visit "destination" multiple times as long as they satisfy the target conditions in the end
- continue
- for e in lastState.outgoingEdges:
- newPath = []
- newPath.extend(path)
- newPath.append(e)
- stack.append(newPath)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement