Question

I have a graph network stored in an SQL server. The graph network ( collection of labeled, undirected and connected graphs) is stored in Vertex-Edge mapping scheme (i.e there are 2 tables..one for vertices and one for edges) :

Vertices ( graphID , vertexID, vertexLabel )

Edges ( graphID , sourceVertex , destinationVertex ,edgeLabel )

I am looking for a simple way of counting a particular subgraph in this network. For example: I would like to find how many instances of "A-B-C" are present in this network : "C-D-A-B-C-E-A-B-C-F". I have a few ideas on how this can be done in say Java or C++ ...but I have no clue how to approach this problem using SQL. any ideas?

A little background: I'm no student..this is a small project I would like to pursue. I do a lot of social media analysis (in memory) but have little experience mining graphs against an SQL database.

Était-ce utile?

La solution

my idea is to create a stored procedure which input is a string like 'A-B-C' or a precreated table with vertices in proper order ('A', 'B', 'C'). So you will have a loop and step by step you should walk through the path 'A-B-C'. For this you need a temp table for vertices on current step:
1)step 0

@currentLabel = getNextVertexLabel(...) --need to decide how to do this
select 
  * 
into #v
from Vertices 
where 
  vertexLabel = @currentLabel

--we need it later
select 
  * 
into #tempV 
from #v 
where 
  0 <> 0

2)step i

@currentLabel = getNextVertexLabel(...)

insert #tempV
select
  vs.*
from #v v
join Edges e on
  e.SourceVertex = v.VertexID
  and e.graphID = v.graphID
join Vertices vs on
  e.destinationVertex = vs.VertexID
  and e.graphID = vs.graphID
where
  vs.vertexLabel = @currentLabel

truncate table #v
insert #v
select * from #tempV

truncate table #tempV

3)after loop

You result will store at #v. So the number of subgraphs will be:

select count(*) from #v
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top