Hi, interesting traversal... so you're saying that paths like this could be
returned:

   (start)-B->()-A[P=1]->()-A[P=1]->()-B->(end)

but not paths like this:

   (start)-A[P=1]->()-B->()-A[P=2]->(end)

am I correct? There are common path algorithms in
GraphAlgoFactory<http://components.neo4j.org/neo4j-graph-algo/apidocs/org/neo4j/graphalgo/GraphAlgoFactory.html>but
they don't support an evaluator as an argument, an evaluator which
could
look like:

    {
        public Evaluation evaluate( Path position )
        {
            Relationship rel = position.lastRelationship();
            if ( rel == null || !rel.isType( MyRelTypes.A ) )
                return Evaluation.INCLUDE_AND_CONTINUE;

            Object p = rel.getProperty( "P" );
            Object previousP = lookBackwardsForP( position );
            if ( previousP != null && !p.equals( previousP ) )
                return Evaluation.EXCLUDE_AND_PRUNE;
            return Evaluation.INCLUDE_AND_CONTINUE;
        }

        private Object lookBackwardsForP( Path position )
        {
            int count = 0;
            for ( Relationship rel : position.relationships() )
            {
                // Skip the first one
                if ( count++ > 0 )
                {
                    if ( rel.isType( MyRelTypes.A ) )
                        return rel.getProperty( "P" );
                }
            }
            return null;
        }
    }

You could probably create a breadth first traverser with such an evaluator
to get your paths. I don't know about performance since each evaluation
needs to go back one or more steps in the path, but you could try it out.

2010/12/23 Amos Ben Israel <lucis.domi...@gmail.com>

> Hello,
>
> I'm trying to find all paths between two nodes when relations can be of one
> of two types (A or B) without repeating the same node twice - so far quite
> simple.
> the complication is that relations of type A have a property P and I want
> only paths where P has the same value all the way (but can have two
> different values in two different paths).
> I tried to have a variable that is reset every time the traverse "starts
> again from the beginning" but find it difficult to know when did this
> happen. position.length() helps when I only have relations of type A - it
> does not ignore relations of type B which can be on the path.
> iterating over the path at each position works but seems inefficient - I'd
> like to hear ideas for a more efficient solution.
>
> Amos.
> _______________________________________________
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>



-- 
Mattias Persson, [matt...@neotechnology.com]
Hacker, Neo Technology
www.neotechnology.com
_______________________________________________
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to