Skip to content

Instantly share code, notes, and snippets.

@phivk
Last active September 17, 2015 17:11
Show Gist options
  • Save phivk/244303c089cc222025ac to your computer and use it in GitHub Desktop.
Save phivk/244303c089cc222025ac to your computer and use it in GitHub Desktop.

Honeycomb Icecream Supply Chain

Data Model, most directly copied from MCR site

///////////
// NODES //
///////////

// create consumers
CREATE (toby:Person:Consumer {name:'Toby'})
CREATE (olivia:Person:Consumer {name:'Olivia'})
CREATE (fi:Person:Consumer {name:'Fi'})
CREATE (steve:Person:Consumer {name:'Steve'})
CREATE (jan:Person:Consumer {name:'Jan'})
CREATE (tenny:Person:Consumer {name:'Tenny'})

// create Manufacturer
CREATE (kate:Person:Manufacturer {
	name:'Kate',
	based_in:'Stroud'
})

// create Product
CREATE (icecream:Product {name:'Honeycomb Ice Cream'})

// create retailers / Suppliers
CREATE (susan:Person:Supplier {
	name:'Susan',
	based_in:'Norfolk'
})

CREATE (coop:Company:Supplier {
	name:'Coop',
	based_in:'Stroud'
})

// create Ingredients
CREATE (sugar:Ingredient {name:'Sugar'})
CREATE (syrup:Ingredient {name:'Syrup'})
CREATE (bicarbonate:Ingredient {name:'Bicarbonate of Soda'})
CREATE (whippingcream:Ingredient {name:'Whipping Cream'})
CREATE (condensedmilk:Ingredient {name:'Condensed Milk'})

CREATE (honeycomb:Ingredient {name:'Honeycomb'})

// add sub-ingredients
CREATE (milk:Ingredient {name:'Milk'})
CREATE (sugarbeet:Ingredient {name:'Sugar Beet'})

// create Producers
CREATE (liz:Person:Producer {name:'Liz'})


///////////////////
// RELATIONSHIPS //
///////////////////

// create consumer relationships
CREATE (toby)-[:CONSUMER_OF]->(icecream)
CREATE (olivia)-[:CONSUMER_OF]->(icecream)
CREATE (fi)-[:CONSUMER_OF]->(icecream)
CREATE (steve)-[:CONSUMER_OF]->(icecream)
CREATE (jan)-[:CONSUMER_OF]->(icecream)
CREATE (tenny)-[:CONSUMER_OF]->(icecream)

// create family & friend relationships
CREATE (toby)-[:FRIEND_OF]->(tenny)
CREATE (tenny)-[:FRIEND_OF]->(toby)
CREATE (olivia)-[:FRIEND_OF]->(tenny)
CREATE (tenny)-[:FRIEND_OF]->(olivia)

CREATE (kate)-[:MOTHER_OF]->(toby)
CREATE (kate)-[:MOTHER_OF]->(olivia)

CREATE (fi)-[:FRIEND_OF]->(kate)
CREATE (kate)-[:FRIEND_OF]->(fi)
CREATE (steve)-[:FRIEND_OF]->(kate)
CREATE (kate)-[:FRIEND_OF]->(steve)

CREATE (jan)-[:FRIEND_OF]->(kate)
CREATE (kate)-[:FRIEND_OF]->(jan)

CREATE (jan)-[:MOTHER_OF]->(tenny)
CREATE (liz)-[:AUNT_OF]->(tenny)

CREATE (susan)-[:MOTHER_OF]->(kate)

// create Manufacturer relationships
CREATE (kate)-[:MANUFACTURER_OF]->(icecream)

// create Producer relationships
CREATE (liz)-[:PRODUCER_OF]->(milk)
CREATE (susan)-[:PRODUCER_OF]->(honeycomb)


// create Supplier relationships
CREATE (susan)-[:SUPPLIER_OF]->(honeycomb)
CREATE (coop)-[:SUPPLIER_OF]->(whippingcream)
CREATE (coop)-[:SUPPLIER_OF]->(condensedmilk)

// create Ingredient relationships
CREATE (sugar)<-[:USES]-(kate)
CREATE (syrup)<-[:USES]-(kate)
CREATE (bicarbonate)<-[:USES]-(kate)
CREATE (whippingcream)<-[:USES]-(kate)
CREATE (condensedmilk)<-[:USES]-(kate)
CREATE (honeycomb)<-[:USES]-(kate)

CREATE (milk)-[:INGREDIENT_IN]->(condensedmilk)
CREATE (sugarbeet)-[:INGREDIENT_IN]->(sugar)
CREATE (sugarbeet)-[:INGREDIENT_IN]->(syrup)
RETURN *

TBC…​

Isolate the Burst Pipe Using Only Remote Calls to API-Accessible Valves

START burstPipe=node:node_auto_index(name='BurstPipe')
MATCH (burstPipe)-[:CONNECTS|EXCAV_CONNECTS|MANHOLE_CONNECTS*0..]-()-[:API_CONNECTS]- (h)-[:CLOSES]-(v{access:'API'})
RETURN v

Isolate the Burst Pipe Using Manhole-Accessible and API-Accessible Valves

START burstPipe=node:node_auto_index(name='BurstPipe')
MATCH (burstPipe)-[:CONNECTS|EXCAV_CONNECTS*0..]-()-[:MANHOLE_CONNECTS|API_CONNECTS]- (h)-[:CLOSES]-(v)
RETURN v

Isolate the Burst Pipe Using Any Existing Valves

START burstPipe=node:node_auto_index(name='BurstPipe')
MATCH (burstPipe)-[:CONNECTS*0..]-()-[:EXCAV_CONNECTS|MANHOLE_CONNECTS|API_CONNECTS]- (h)-[:CLOSES]-(v)
RETURN v

Extension

For real world application, there are some necessary modifications (e.g. modelling state information in relationships, such as whether a connection is presently closed or scheduled for opening/closing; limiting query depth and notifying of query failure in event of maximum query depth being reached).

In real world application, extending the above model, there is potential for adding greater value still:

  • estimating the marginal water savings from replacing any defined set of components

  • estimating the resilience of network water pressure to failure of specific pumps (both current and under hypothetical modifications to the network)

  • scheduling replacement or state-change of parts, and communicating this seamlessly (and automatically) in real time to all other parties that this might affect etc

This approach is more generic than it may initially seem. Many resource problems involve networks of distribution in which many components interact across sparse relationships (electricity generation and distribution, natural gas, sewage, district-piped heating); rapid and efficient querying on these relationships is necessary for efficient resource allocation and better environmental and cost outcomes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment