Commit 0febfba5 authored by Andrew McDonnell's avatar Andrew McDonnell

Includes fix for unwanted vertex when vertex not in graph

parents 9e6832e1 73c19f84
......@@ -212,7 +212,6 @@ latch origid destid weight seq linkid
breadth_first 7 NULL 0 1 7
SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 8;
latch origid destid weight seq linkid
breadth_first 8 NULL 0 1 8
SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 9;
latch origid destid weight seq linkid
breadth_first 9 NULL 0 1 9
......@@ -233,7 +232,6 @@ breadth_first 12 NULL 1 2 10
breadth_first 12 NULL 0 1 12
SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 666;
latch origid destid weight seq linkid
breadth_first 666 NULL 0 1 666
SELECT * FROM graph WHERE latch = 'breadth_first' AND origid = 1 AND weight = 1;
latch origid destid weight seq linkid
breadth_first 1 NULL 1 3 3
......@@ -447,7 +445,6 @@ latch origid destid weight seq linkid
breadth_first NULL 7 0 1 7
SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 8;
latch origid destid weight seq linkid
breadth_first NULL 8 0 1 8
SELECT * FROM graph WHERE latch = 'breadth_first' AND destid = 9;
latch origid destid weight seq linkid
breadth_first NULL 9 0 1 9
......@@ -607,7 +604,6 @@ latch origid destid weight seq linkid
2 7 NULL 0 1 7
SELECT * FROM graph WHERE latch = '2' AND origid = 8;
latch origid destid weight seq linkid
2 8 NULL 0 1 8
SELECT * FROM graph WHERE latch = '2' AND origid = 9;
latch origid destid weight seq linkid
2 9 NULL 0 1 9
......@@ -628,7 +624,6 @@ latch origid destid weight seq linkid
2 12 NULL 0 1 12
SELECT * FROM graph WHERE latch = '2' AND origid = 666;
latch origid destid weight seq linkid
2 666 NULL 0 1 666
SELECT * FROM graph WHERE latch = '2' AND origid = 1 AND weight = 1;
latch origid destid weight seq linkid
2 1 NULL 1 3 3
......@@ -842,7 +837,6 @@ latch origid destid weight seq linkid
2 NULL 7 0 1 7
SELECT * FROM graph WHERE latch = '2' AND destid = 8;
latch origid destid weight seq linkid
2 NULL 8 0 1 8
SELECT * FROM graph WHERE latch = '2' AND destid = 9;
latch origid destid weight seq linkid
2 NULL 9 0 1 9
......@@ -1061,7 +1055,6 @@ latch origid destid weight seq linkid
dijkstras 7 NULL 0 1 7
SELECT * FROM graph WHERE latch='dijkstras' AND origid=8;
latch origid destid weight seq linkid
dijkstras 8 NULL 0 1 8
SELECT * FROM graph WHERE latch='dijkstras' AND origid=9;
latch origid destid weight seq linkid
dijkstras 9 NULL 0 1 9
......@@ -1082,7 +1075,6 @@ dijkstras 12 NULL 0 2 10
dijkstras 12 NULL 0 1 12
SELECT * FROM graph WHERE latch='dijkstras' AND origid=666;
latch origid destid weight seq linkid
dijkstras 666 NULL 0 1 666
SELECT * FROM graph WHERE latch='dijkstras' AND destid=1;
latch origid destid weight seq linkid
dijkstras NULL 1 2 4 4
......@@ -1122,7 +1114,6 @@ latch origid destid weight seq linkid
dijkstras NULL 7 0 1 7
SELECT * FROM graph WHERE latch='dijkstras' AND destid=8;
latch origid destid weight seq linkid
dijkstras NULL 8 0 1 8
SELECT * FROM graph WHERE latch='dijkstras' AND destid=9;
latch origid destid weight seq linkid
dijkstras NULL 9 0 1 9
......@@ -1239,7 +1230,6 @@ latch origid destid weight seq linkid
1 7 NULL 0 1 7
SELECT * FROM graph WHERE latch='1' AND origid=8;
latch origid destid weight seq linkid
1 8 NULL 0 1 8
SELECT * FROM graph WHERE latch='1' AND origid=9;
latch origid destid weight seq linkid
1 9 NULL 0 1 9
......@@ -1260,7 +1250,6 @@ latch origid destid weight seq linkid
1 12 NULL 0 1 12
SELECT * FROM graph WHERE latch='1' AND origid=666;
latch origid destid weight seq linkid
1 666 NULL 0 1 666
SELECT * FROM graph WHERE latch='1' AND destid=1;
latch origid destid weight seq linkid
1 NULL 1 2 4 4
......@@ -1300,7 +1289,6 @@ latch origid destid weight seq linkid
1 NULL 7 0 1 7
SELECT * FROM graph WHERE latch='1' AND destid=8;
latch origid destid weight seq linkid
1 NULL 8 0 1 8
SELECT * FROM graph WHERE latch='1' AND destid=9;
latch origid destid weight seq linkid
1 NULL 9 0 1 9
......
......@@ -593,3 +593,73 @@ TRUNCATE TABLE graph_base;
DROP TABLE graph_base;
DROP TABLE graph;
#-- Reminder - the basic spec is at http://openquery.com/graph/doc
#-- Query edges stored in graph engine (latch=NULL)
#-- SELECT * FROM foo;
#-- Results:
#-- vertex id for origin of edge in origid column.
#-- vertex id for destination of edge in destid column.
#-- weight of edge in weight column.
#-- Essentially this returns the values (origid,destid pairs with optional weight) you put in, in this mode OQGRAPH looks very close to a real table. But it also does nothing special, it's just store/retrieve for those columns. The other columns will be returned as NULL.
#--
#-- Query vertices stored in graph engine (latch=0)
#-- SELECT * FROM foo WHERE latch = 0;
#-- Results:
#-- vertex id in linkid column
#--
#-- Query out-edges for vertex (latch=0 AND origid=N)
#-- SELECT * FROM foo WHERE latch = 0 AND origid = 2;
#-- Results:
#-- vertex id in linkid column
#-- edge weight in weight column
#--
#-- Query in-edges for vertex (latch=0 AND destid=N)
#-- SELECT * FROM foo WHERE latch = 0 AND destid = 6;
#-- Results:
#-- vertex id in linkid column
#-- edge weight in weight column
#--
#-- Dijkstra's shortest path algorithm (latch=1)
#-- Find shortest path:
#-- SELECT * FROM foo WHERE latch = 1 AND origid = 1 AND destid = 6;
#-- Results:
#-- latch, origid, destid are same as input.
#-- vertex id of the current step in linkid column.
#-- weight of traversed edge in weight column.
#-- step counter in seq column, so you can sort and use the result (starting at step 0).
#-- Example: SELECT GROUP_CONCAT(linkid ORDER BY seq) ...
#--
#-- Find reachable vertices:
#-- SELECT * FROM foo WHERE latch = 1 AND origid = 1;
#-- Results:
#-- latch, origid, destid are same as input.
#-- vertex id in linkid column.
#-- aggregate of weights in weight column.
#--
#-- Find originating vertices:
#-- SELECT * FROM foo WHERE latch = 1 AND destid = 6;
#-- Results:
#-- latch, origid, destid are same as input.
#-- vertex id in linkid column.
#-- aggregate of weights in weight column.
#--
#-- Breadth-first search (latch=2, assumes that each vertex is weight 1)
#-- Find shortest path:
#-- SELECT * FROM foo WHERE latch = 2 AND origid = 1 AND destid = 6;
#-- Results:
#-- vertex id in linkid column.
#-- weight column = 1 for each hop.
#--
#-- Find reachable vertices:
#-- SELECT * FROM foo WHERE latch = 2 AND origid = 1;
#-- Results:
#-- vertex id in linkid column.
#-- computed number of hops in weight column.
#--
#-- Find originating vertices:
#-- SELECT * FROM foo WHERE latch = 2 AND destid = 6;
#-- Results:
#-- vertex id in linkid column.
#-- computed number of hops in weight column.
......@@ -479,6 +479,15 @@ namespace boost
inline optional<graph_traits<oqgraph3::graph>::vertex_descriptor>
find_vertex(oqgraph3::vertex_id id, const oqgraph3::graph& g)
{
// Fix for https://bugs.launchpad.net/oqgraph/+bug/1196020 returning vertex even when not in graph
// Psuedocode for fix:
// if count(*) from g->TABLE where source=id or target=id > 0 then return id else return null
oqgraph3::cursor* found = new oqgraph3::cursor(const_cast<oqgraph3::graph*>(&g));
if (found->seek_to(id, boost::none) &&
found->seek_to(boost::none, id)) {
// id is neither a from or a to in a link
return optional<graph_traits<oqgraph3::graph>::vertex_descriptor>();
}
return id;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment