Skip to content

Instantly share code, notes, and snippets.

@rvanbruggen
Last active December 29, 2015 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rvanbruggen/7605404 to your computer and use it in GitHub Desktop.
Save rvanbruggen/7605404 to your computer and use it in GitHub Desktop.
London Underground
// create indices and constraints
CREATE CONSTRAINT ON (n:Station) ASSERT n.name IS UNIQUE;
// create nodes
// create Stations
import-cypher -d ; -i ./IMPORT/INPUT/isdb.csv -o ./IMPORT/OUTPUT/nodeoutput.csv merge (n:Station {name:{StationA}}) return n
import-cypher -d ; -i ./IMPORT/INPUT/isdb.csv -o ./IMPORT/OUTPUT/nodeoutput.csv merge (n:Station {name:{StationB}}) return n
//create rels
import-cypher -d ; -i ./IMPORT/INPUT/isdb.csv -o ./IMPORT/OUTPUT/rel.csv MATCH (stationa:Station {name:{StationA}}), (stationb:Station {name:{StationB}}) CREATE stationa-[r:#{Line} {direction:{Direction}, distance:{Distance}, time:{Time}}]->stationb RETURN r
node {
diameter: 40px;
color: #DFE1E3;
border-color: #D4D6D7;
border-width: 2px;
text-color-internal: #000000;
caption: '{id}';
font-size: 10px;
}
relationship {
color: #D4D6D7;
shaft-width: 1px;
font-size: 8px;
padding: 3px;
text-color-external: #000000;
text-color-internal: #FFFFFF;
}
node.Station {
color: #F25A29;
border-color: #DC4717;
text-color-internal: #FFFFFF;
diameter: 60px;
border-width: 4px;
caption: '{name}';
font-size: 8px;
}
relationship.Circle {
color: #FFD300;
shaft-width: 13px;
font-size: 8px;
padding: 3px;
text-color-external: #000000;
text-color-internal: #FFFFFF;
border-color: #DC4717;
}
relationship.Central {
color: #E32017;
shaft-width: 13px;
font-size: 8px;
padding: 3px;
text-color-external: #000000;
text-color-internal: #FFFFFF;
border-color: #46A39E;
}
relationship.Northern {
color: #000000;
shaft-width: 13px;
font-size: 8px;
padding: 3px;
text-color-external: #000000;
text-color-internal: #FFFFFF;
border-color: #9453B1;
}
relationship.Jubilee {
color: #A0A5A9;
shaft-width: 13px;
font-size: 8px;
padding: 3px;
text-color-external: #000000;
text-color-internal: #000000;
border-color: #F3BA25;
}
relationship.District {
color: #00782A;
shaft-width: 13px;
font-size: 8px;
padding: 3px;
text-color-external: #000000;
text-color-internal: #000000;
border-color: #F3BA25;
}
relationship.HammersmithAndCity {
color: #F3A9BB;
shaft-width: 13px;
font-size: 8px;
padding: 3px;
text-color-external: #000000;
text-color-internal: #000000;
border-color: #F3BA25;
}
relationship.Metropolitan {
color: #9B0056;
shaft-width: 13px;
font-size: 8px;
padding: 3px;
text-color-external: #000000;
text-color-internal: #000000;
border-color: #F3BA25;
}
relationship.Piccadilly {
color: #003688;
shaft-width: 13px;
font-size: 8px;
padding: 3px;
text-color-external: #000000;
text-color-internal: #000000;
border-color: #F3BA25;
}
relationship.Victoria {
color: #0098D4;
shaft-width: 13px;
font-size: 8px;
padding: 3px;
text-color-external: #000000;
text-color-internal: #000000;
border-color: #F3BA25;
}
relationship.WaterlooAndCity {
color: #95CDBA;
shaft-width: 13px;
font-size: 8px;
padding: 3px;
text-color-external: #000000;
text-color-internal: #000000;
border-color: #F3BA25;
}
relationship.Bakerloo {
color: #B36305;
shaft-width: 13px;
font-size: 8px;
padding: 3px;
text-color-external: #000000;
text-color-internal: #000000;
border-color: #F3BA25;
}
//what labels/lines are there?
MATCH n RETURN DISTINCT labels(n);
//show me the different underground lines
MATCH (n:Station)-[r]->() return distinct type(r) as Line order by Line;
//show me London Bridge and surrounding stations
MATCH (n:Station {name:"LONDON BRIDGE"})-[r]-()
return n, r;
//most densely connected station
MATCH (n:Station)-[r]->()
WITH n.name as Station, type(r) as Lines
RETURN Station as Station, count(distinct Lines) as NrOfLines
ORDER BY NrOfLines DESC
LIMIT 10;
//shortest path calculations: Southwark to Bermondsey
MATCH p=shortestpath((stationa:Station {name:"SOUTHWARK"})-[*..5]->(stationb:Station {name:"BERMONDSEY"}))
return p
limit 1;
MATCH p=shortestpath((stationa:Station {name:"SOUTHWARK"})-[*..5]->(stationb:Station {name:"TOWER HILL"}))
return distinct p;
//weighted shortest path calculations
MATCH p=((stationa:Station {name:"SOUTHWARK"})-[*..3]->(stationb:Station {name:"BERMONDSEY"}))
RETURN p AS shortestPath,
reduce(distance=0, r in relationships(p) | distance+r.distance) AS totalDistance
ORDER BY totalDistance ASC
LIMIT 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment