i follow the algo in the wiki page below: So during while loop, i remove a 
node n from s and traversal each path(depth 1). and remove this path from 
graph. I can set property to this relationship like visited. but how to 
check no other incoming edges into node m. Does this mean i have make 
traversal from m inside the traversal from n? 

L ← Empty list that will contain the sorted elements
S ← Set of all nodes with no incoming edges*while* S is non-empty *do*
    remove a node n from S
    add n to *tail* of L
    *for each* node m with an edge *e* from n to m *do*
        remove edge e from the graph
        *if* m has no other incoming edges *then*
            insert m into S*if* graph has edges *then*
    return error (graph has at least one cycle)*else* 
    return L (a topologically sorted order)


On Wednesday, June 4, 2014 12:35:15 AM UTC-7, TC wrote:
>
> The graph maybe has loop inside and multiple source node(no incoming 
> edges).
> Even using traversal description (Uniqueness.Relationship-Global), it will 
> need a starting node from users to begin. So it cannot deal with multiple 
> source node graph. 
> like figure in this wiki page:
> http://en.wikipedia.org/wiki/Topological_sorting 
> <http://www.google.com/url?q=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FTopological_sorting&sa=D&sntz=1&usg=AFQjCNGwQKUHMuuQvSbJz27tZZ-2F8wBHA>
>
>
> On Tuesday, June 3, 2014 11:12:21 PM UTC-7, Michael Hunger wrote:
>>
>> You mean in general? I think toposort is only defined for trees? You can 
>> ignore the loops though in a traversal description 
>> (Uniqueness.Relationship-Global) and in theory start at any random node in 
>> the graph to find the topologically first (tree-root). 
>>
>>
>> On Wed, Jun 4, 2014 at 6:50 AM, TC <[email protected]> wrote:
>>
>>> Does neo4j has topological sort function for directed graph data(with 
>>> loops)?
>>> If I follow
>>>  for ( Path position : db.traversalDescription()
>>>                 .depthFirst()
>>>                 .relationships( Rels.LIKES, Direction.INCOMING )
>>>                 .traverse( node ) )
>>> but how to choose the starting node in topo sort order for this graph?
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Neo4j" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to