Can't we optimize the path from the original graph so that we can see the shortest path for the particular retailer. The best route for the retailer who can get the goods from vendor depending on the constraints like distance, time, co2e. If in case we have the shortest distance between V1 & R1 but what is the best alternative for the retailer R1 to fetch the goods from other vendors like V2,V3,V4 & V5 with respective to the constraints?
it is the way the data is visualized by Neo4j Desktop. It is showing all the nodes in the result and links between them. It does not visualize all paths separately. You can see what I am referring to if you limit the result to one path.
MATCH p=(v)-[r1]->(wh)-[r2]->(:HUB)-[r3]->(:Wholesaler)-[r4]->(re:Retailer)
where (v:VENDORA or v:VENDORB) and (wh:WAREHOUSEA or wh:WAREHOUSEB)
WITH p, v.name as vendor, re.name as retailer, r1.km + r2.km + r3.km + r4.km as distance
WITH vendor, retailer, min(distance) as minDist, collect({path: p, distance: distance}) as paths
WITH vendor, retailer, [x in paths where x.distance = minDist] as shortestPaths
UNWIND shortestPaths as shortestPath
RETURN shortestPath.path as path, shortestPath.distance as distance
limit 1
I don't get it why we are seeing the Retailer 'Safeway' in the graph even though it is not mentioned in the code?
And can't we optimize the path from the original graph so that we can see the shortest path for the particular retailer. The best route for the retailer who can get the goods from vendor depending on the constraints like distance, time, co2e. If in case we have the shortest distance between V1 & R1 but what is the best alternative for the retailer R1 to fetch the goods from other vendors like V2,V3,V4 & V5 with respective to the constraints?
Best recommendation for the Retailers to get the goods from the vendors considering the above constraints
Do you want the shortest path across all vendors for a specific retailer? This would assume that all vendors can source all goods, so the shortest path across all vendors makes sense in this case. If not, you would have to have item nodes that represent what each vendor can source and have them linked to each vendor. Then you could ask the question what vendor is preferred to source a specific product to a specific retailer.
Assuming you want the shortestPath for a specific retailer, regardless of vendor, the following query should do that. The basic differences are limiting to one retailer and aggregating over retailer only, instead of retailer and vendor.
Change 'Safeway' to the name of the retailer you want.
MATCH (re:Retailer {name: 'Safeway'})
MATCH p=(v)-[r1]->(wh)-[r2]->(:HUB)-[r3]->(:Wholesaler)-[r4]->(re)
where (v:VENDORA or v:VENDORB) and (wh:WAREHOUSEA or wh:WAREHOUSEB)
WITH p, re.name as retailer, r1.km + r2.km + r3.km + r4.km as distance
WITH retailer, min(distance) as minDist, collect({path: p, distance: distance}) as paths
WITH retailer, [x in paths where x.distance = minDist] as shortestPaths
UNWIND shortestPaths as shortestPath
RETURN shortestPath.path as path, shortestPath.distance as distance
Currently we are using 'distance' as your cost metric. Do you have a more complex cost metric to use based on the additional attributes you mentioned? If so, we can probably incorporate the calculation of that cost metric instead of total distance for determining the optimal path.
Can we highlight by using different colors or increasing the size of the nodes both the shortest path for the Safeway Retailer in the original graph and the best alternative route based on the attributes like co2e, cost, time & waste.
Ex:
Can we highlight the Vendor 'Nestle' on the basis of the shortest distance and 'Danone' for the best recommendation in the graph?
I am trying to get most recommended vendor for the retailer based on calculating the cost metrics: distance, time, co2e, cost, wasteR.
You can manually change color and size of the nodes in neo4j desktop. I have not used it, but neo4j Bloom may have the capabilities to visualize the data the way you want to.
Here is a discussion of visualization options
Do you want to update the queries to use a more representative cost metric?