Hi Gary,

For

#1. Distance

I need to find the distance between each Vendor and each Retailer

Data should be as in the below format.

Example:

VENDORA |
WAREHOUSEA |
HUB |
WHOLESALER |
RETAILER |
Distance(KM) |

Nestle |
WAREHOUSEA0 |
HUB |
WHOLESALER0 |
Aldi |
14000 |

Nestle |
WAREHOUSEA1 |
HUB |
WHOLESALER0 |
Aldi |
13000 |

Nestle |
WAREHOUSEA2 |
HUB |
WHOLESALER0 |
Aldi |
15000 |

Nestle |
WAREHOUSEA0 |
HUB |
WHOLESALER1 |
Aldi |
17000 |

Nestle |
WAREHOUSEA1 |
HUB |
WHOLESALER1 |
Aldi |
12000 |

Nestle |
WAREHOUSEA2 |
HUB |
WHOLESALER1 |
Aldi |
19000 |

Kraft |
WAREHOUSEA0 |
HUB |
WHOLESALER0 |
Aldi |
4000 |

Kraft |
WAREHOUSEA1 |
HUB |
WHOLESALER0 |
Aldi |
23000 |

Kraft |
WAREHOUSEA2 |
HUB |
WHOLESALER0 |
Aldi |
15000 |

Kraft |
WAREHOUSEA0 |
HUB |
WHOLESALER1 |
Aldi |
18000 |

Kraft |
WAREHOUSEA1 |
HUB |
WHOLESALER1 |
Aldi |
8000 |

Kraft |
WAREHOUSEA2 |
HUB |
WHOLESALER1 |
Aldi |
10000 |

Heinz |
WAREHOUSEA0 |
HUB |
WHOLESALER0 |
Kroger |
11000 |

Heinz |
WAREHOUSEA1 |
HUB |
WHOLESALER0 |
Kroger |
16000 |

Heinz |
WAREHOUSEA2 |
HUB |
WHOLESALER0 |
Kroger |
9000 |

Heinz |
WAREHOUSEA0 |
HUB |
WHOLESALER1 |
Kroger |
7800 |

Heinz |
WAREHOUSEA1 |
HUB |
WHOLESALER1 |
Kroger |
12000 |

Heinz |
WAREHOUSEA2 |
HUB |
WHOLESALER1 |
Kroger |
16600 |

#2. Shortest Path

As you can see from the above table, from Kraft-Warehouse0-HUB-Wholesaler0-Aldi, we have the least distance as 4000.

a) I need to find the shortest path for each Retailer and

b) the one retailer holding shortest path among all the retailers.

Example:

a)

VENDORA |
WAREHOUSEA |
HUB |
WHOLESALER |
RETAILER |
Distance(KM) |

Kraft |
WAREHOUSEA0 |
HUB |
WHOLESALER0 |
Aldi |
4000 |

Heinz |
WAREHOUSEA0 |
HUB |
WHOLESALER1 |
Kroger |
7800 |

b)

VENDORA |
WAREHOUSEA |
HUB |
WHOLESALER |
RETAILER |
Distance(KM) |

Kraft |
WAREHOUSEA0 |
HUB |
WHOLESALER0 |
Aldi |
4000 |

I need a query to show the shortest path in the graph format with nodes and relationships as below.

My code:

//Creation of Nodes

CREATE (:HUB { name: "HUB", lat: tan(rand())*100, lon: tan(rand())*100, co2: 200, cost: 100, time: 0 })

FOREACH (r IN range(0,1)|

CREATE (:Wholesaler { name:"Wholesaler" + r, cost: round(exp(rand()*3)+20), co2: round(exp(rand()*8)+250), lat: tan(rand())*100, lon: tan(rand())*100, time: round(rand()*5)}))

FOREACH (r IN range(0,2)|

CREATE (:WAREHOUSEA { name:"WAREHOUSEA" + r, cost: round(exp(rand()*3)+20), co2: round(exp(rand()*8)+250), lat: tan(rand())*100, lon: tan(rand())*100, time: round(rand()*5)}))

FOREACH (r IN range(0,1)|

CREATE (:WAREHOUSEB { name:"WAREHOUSEB" + r, cost: round(exp(rand()*3)+20), co2: round(exp(rand()*8)+250), lat: tan(rand())*100, lon: tan(rand())*100, time: round(rand()*5)}))

CREATE(:Retailer{name:"kroger",cost:round(exp(rand()*3)+20),co2:round(exp(rand()*8)+250),lat:tan(rand())*100,lon:tan(rand())*100,time:1})

CREATE(:Retailer{name:"Aldi",cost:round(exp(rand()*3)+20),co2:round(exp(rand()*8)+250),lat:tan(rand())*100,lon:tan(rand())*100,time:1})

CREATE(:Retailer{name:"Safeway",cost:round(exp(rand()*3)+20),co2:round(exp(rand()*8)+250),lat:tan(rand())*100,lon:tan(rand())*100,time:1})

CREATE(:Retailer{name:"Aroma",cost:round(exp(rand()*3)+20),co2:round(exp(rand()*8)+250),lat:tan(rand())*100,lon:tan(rand())*100,time:1})

CREATE(:Retailer{name:"Target",cost:round(exp(rand()*3)+20),co2:round(exp(rand()*8)+250),lat:tan(rand())*50,lon:tan(rand())*50,time:1})

CREATE(:VENDORA{name:"Nestle",cost:round(exp(rand()*3)+20),co2:round(exp(rand()*8)+250),lat:tan(rand())*100,lon:tan(rand())*100,time:round(rand()*5)})

CREATE(:VENDORA{name:"Danone",cost:round(exp(rand()*3)+20),co2:round(exp(rand()*8)+250),lat:tan(rand())*100,lon:tan(rand())*100,time:round(rand()*5)})

CREATE(:VENDORA{name:"Schreiber",cost:round(exp(rand()*3)+20),co2:round(exp(rand()*8)+250),lat:tan(rand())*100,lon:tan(rand())*100,time:round(rand()*5)})

CREATE(:VENDORA{name:"Kraft",cost:round(exp(rand()*3)+20),co2:round(exp(rand()*8)+250),lat:tan(rand())*100,lon:tan(rand())*100,time:round(rand()*5)})

CREATE(:VENDORA{name:"Heinz",cost:round(exp(rand()*3)+20),co2:round(exp(rand()*8)+250),lat:tan(rand())*100,lon:tan(rand())*100,time:round(rand()*5)})

CREATE(:VENDORB{name:"Kimberly Clark",cost:round(exp(rand()*3)+20),co2:round(exp(rand()*8)+250),lat:tan(rand())*100,lon:tan(rand())*100,time:round(rand()*5)})

CREATE(:VENDORB{name:"P&G",cost:round(exp(rand()*3)+20),co2:round(exp(rand()*8)+250),lat:tan(rand())*100,lon:tan(rand())*100,time:round(rand()*5)})

CREATE(:VENDORB{name:"J&J",cost:round(exp(rand()*3)+20),co2:round(exp(rand()*8)+250),lat:tan(rand())*100,lon:tan(rand())*100,time:round(rand()*5)})

CREATE(:VENDORB{name:"Colgate",cost:round(exp(rand()*3)+20),co2:round(exp(rand()*8)+250),lat:tan(rand())*100,lon:tan(rand())*100,time:round(rand()*5)})

CREATE(:VENDORB{name:"Palmolive",cost:round(exp(rand()*3)+20),co2:round(exp(rand()*8)+250),lat:tan(rand())*100,lon:tan(rand())*100,time:round(rand()*5)})

//Creation of Relations

match (p:HUB), (w:Wholesaler)

with p,w

merge (p)-[:DELIVER]->(w)

MATCH (w:Wholesaler), (r:Retailer)

WITH w, r

MERGE (w)-[:DELIVER]->(r)

MATCH (sa:WAREHOUSEA), (p:HUB)

WITH p, sa

MERGE (sa)-[:DELIVER]->(p)

MATCH (sb:WAREHOUSEB), (p:HUB)

MERGE (sb)-[:DELIVER]->(p)

WITH sb, p

MATCH (va:VENDORA), (vb:VENDORB)

MERGE (va)-[:DELIVER]->(sa)

MERGE (vb)-[:DELIVER]->(sb)

Please do needful.