I'm building a graph editor in Javascript and I need an algorithm to identify all possible routes between two 'node' objects.
Given the following JSON object:
{
"failureNode": {
"failureNode": {
"failureNode": {
"failureNode": {
"failureNode": null,
"successNode": null,
"id": "node-endpointfailure",}
},
"successNode": {
"failureNode": null,
"successNode": null,
"id": "node-endpointsuccess",
},
"id": "node-1",
},
"successNode": {
"failureNode": null,
"successNode": null,
"id": "node-endpointsuccess",
},
"id": "node-2",
},
"successNode": {
"failureNode": {
"failureNode": {
"failureNode": null,
"successNode": null,
"id": "node-endpointfailure",
},
"successNode": {
"failureNode": null,
"successNode": null,
"id": "node-endpointsuccess",
},
"id": "node-1",
},
"successNode": {
"failureNode": null,
"successNode": null,
"id": "node-endpointsuccess",
},
"id": "node-3",
},
"id": "node-4",
},
"successNode": {
"failureNode": null,
"successNode": null,
"id": "node-endpointsuccess",
},
"id": "node-root",
}
I need all possible routes between nodes with ID = 'node-root' &'node-endpointfailure'. In this example, there are two possible ways to start at 'Start' (which is node-root in the data structure) and end and 'Failure' (node-endpointfailure):
- Start -> node1 -> node2 -> node4 -> failure
- Start -> node1 -> node3 -> node4 -> failure
For this example, the output would be an array of JSON paths. Something like this...
[
failureNode.failureNode.failureNode.failureNode,
failureNode.successNode.failureNode.failureNode
]
Most of the application is using jQuery, so either a pure Javascript or jQuery solution will work.