Hi Vipul,

Out of curiosity, what does "process" in this context mean?

As Rick alludes to, you'd have some component performing the simulation
using the domain objects and possibly a graph traversal.

An example of an algorithm for this would be to walk the graph from 1, and
whenever you find a branch, you split the walk. When you finish walking a
branch (a point where more than one branch joins) you use some kind of
synchronization to join the walks.

Does this make sense?

David

On Wed, Apr 20, 2011 at 11:16 PM, Vipul Gupta <vipulgupta...@gmail.com>wrote:

> Hi David,
>
> Inputs are 1 and 6 + Graph is acyclic.
>
> domain.Client@1 -> domain.Router@2 -> domain.Router@3 -> domain.Router@5-> 
> domain.Server@6
>                           -> domain.Router@7 -> domain.Router@8 ->
>
> I want a way to start from 1,
>
> process the 2 path till it reaches 5 (say in a thread)
> process the 7 path till it reaches 5 (in another thread)
>
>  then process 5 and eventually 6.
> the above step of processing intermediate path and waiting on the blocking
> point can happen over and over again in a more complex graph (that is there
> could be a number of loops in between even) and the traversal stops only we
> reach 6
>
> I hope this makes it a bit clear. I was working out something for this, but
> it is turning out to be too complex a solution for this sort of traversal of
> a graph, so I am hoping if you can suggest something.
>
> Best Regards,
> Vipul
>
>
> On Thu, Apr 21, 2011 at 11:36 AM, David Montag <
> david.mon...@neotechnology.com> wrote:
>
>> Hi Vipul,
>>
>> Zooming out a little bit, what are the inputs to your algorithm, and what
>> do you want it to do?
>>
>> For example, given 1 and 6, do you want to find any points in the chain
>> between them that are join points of two (or more) subchains (5 in this
>> case)?
>>
>> David
>>
>>
>> On Wed, Apr 20, 2011 at 10:56 PM, Vipul Gupta <vipulgupta...@gmail.com>wrote:
>>
>>> my mistake - I meant "5" depends on both 3 and 8 and acts as a blocking
>>> point till 3 and 8 finishes
>>>
>>>
>>> On Thu, Apr 21, 2011 at 11:19 AM, Vipul Gupta 
>>> <vipulgupta...@gmail.com>wrote:
>>>
>>>> David/Michael,
>>>>
>>>> Let me modify the example a bit.
>>>> What if my graph structure is like this
>>>>
>>>> domain.Client@1 -> domain.Router@2 -> domain.Router@3 ->
>>>> domain.Router@5 -> domain.Server@6
>>>>                           -> domain.Router@7 -> domain.Router@8 ->
>>>>
>>>>
>>>> Imagine a manufacturing line.
>>>> 6 depends on both 3 and 8 and acts as a blocking point till 3 and 8
>>>> finishes.
>>>>
>>>> Is there a way to get a cleaner traversal for such kind of
>>>> relationship. I want to get a complete intermediate traversal from
>>>> Client to Server.
>>>>
>>>> Thank a lot for helping out on this.
>>>>
>>>> Best Regards,
>>>> Vipul
>>>>
>>>>
>>>>
>>>>
>>>> On Thu, Apr 21, 2011 at 12:09 AM, David Montag <
>>>> david.mon...@neotechnology.com> wrote:
>>>>
>>>>> Hi Vipul,
>>>>>
>>>>> Thanks for listening!
>>>>>
>>>>> It's a very good question, and the short answer is: yes! I'm cc'ing our
>>>>> mailing list so that everyone can take part in the answer.
>>>>>
>>>>> Here's the long answer, illustrated by an example:
>>>>>
>>>>> Let's assume you're modeling a network. You'll have some domain classes
>>>>> that are all networked entities with peers:
>>>>>
>>>>> @NodeEntity
>>>>> public class NetworkEntity {
>>>>>     @RelatedTo(type = "PEER", direction = Direction.BOTH, elementClass
>>>>> = NetworkEntity.class)
>>>>>     private Set<NetworkEntity> peers;
>>>>>
>>>>>     public void addPeer(NetworkEntity peer) {
>>>>>         peers.add(peer);
>>>>>     }
>>>>> }
>>>>>
>>>>> public class Server extends NetworkEntity {}
>>>>> public class Router extends NetworkEntity {}
>>>>> public class Client extends NetworkEntity {}
>>>>>
>>>>> Then we can build a small network:
>>>>>
>>>>> Client c = new Client().persist();
>>>>> Router r1 = new Router().persist();
>>>>> Router r21 = new Router().persist();
>>>>> Router r22 = new Router().persist();
>>>>> Router r3 = new Router().persist();
>>>>> Server s = new Server().persist();
>>>>>
>>>>> c.addPeer(r1);
>>>>> r1.addPeer(r21);
>>>>> r1.addPeer(r22);
>>>>> r21.addPeer(r3);
>>>>> r22.addPeer(r3);
>>>>> r3.addPeer(s);
>>>>>
>>>>> c.persist();
>>>>>
>>>>> Note that after linking the entities, I only call persist() on the
>>>>> client. You can read more about this in the reference documentation, but
>>>>> essentially it will cascade in the direction of the relationships created,
>>>>> and will in this case cascade all the way to the server entity.
>>>>>
>>>>> You can now query this:
>>>>>
>>>>> Iterable<EntityPath<Client, Server>> paths =
>>>>> c.findAllPathsByTraversal(Traversal.description());
>>>>>
>>>>> The above code will get you an EntityPath per node visited during the
>>>>> traversal from c. The example does however not use a very interesting
>>>>> traversal description, but you can still print the results:
>>>>>
>>>>> for (EntityPath<Client, Server> path : paths) {
>>>>>     StringBuilder sb = new StringBuilder();
>>>>>     Iterator<NetworkEntity> iter =
>>>>> path.<NetworkEntity>nodeEntities().iterator();
>>>>>     while (iter.hasNext()) {
>>>>>         sb.append(iter.next());
>>>>>         if (iter.hasNext()) sb.append(" -> ");
>>>>>     }
>>>>>     System.out.println(sb);
>>>>> }
>>>>>
>>>>> This will print each path, with all entities in the path. This is what
>>>>> it looks like:
>>>>>
>>>>>     domain.Client@1
>>>>>     domain.Client@1 -> domain.Router@2
>>>>>     domain.Client@1 -> domain.Router@2 -> domain.Router@3
>>>>>     domain.Client@1 -> domain.Router@2 -> domain.Router@3 ->
>>>>> domain.Router@5
>>>>>     domain.Client@1 -> domain.Router@2 -> domain.Router@3 ->
>>>>> domain.Router@5 -> domain.Server@6
>>>>>     domain.Client@1 -> domain.Router@2 -> domain.Router@3 ->
>>>>> domain.Router@5 -> domain.Router@4
>>>>>
>>>>> Let us know if this is what you looked for. If you want to only find
>>>>> paths that end with a server, you'd use this query instead:
>>>>>
>>>>> Iterable<EntityPath<Client, Server>> paths =
>>>>> c.findAllPathsByTraversal(Traversal.description().evaluator(new 
>>>>> Evaluator()
>>>>> {
>>>>>     @Override
>>>>>     public Evaluation evaluate(Path path) {
>>>>>         if (new ConvertingEntityPath(graphDatabaseContext,
>>>>> path).endEntity() instanceof Server) {
>>>>>             return Evaluation.INCLUDE_AND_PRUNE;
>>>>>         }
>>>>>         return Evaluation.EXCLUDE_AND_CONTINUE;
>>>>>     }
>>>>> }));
>>>>>
>>>>> In the above code example, graphDatabaseContext is a bean of type
>>>>> GraphDatabaseContext created by Spring Data Graph. This syntax will
>>>>> dramatically improve in future releases. It will print:
>>>>>
>>>>>     domain.Client@1 -> domain.Router@2 -> domain.Router@3 ->
>>>>> domain.Router@5 -> domain.Server@6
>>>>>
>>>>> Regarding your second question about types: If you want to convert a
>>>>> node into an entity, you would use the TypeRepresentationStrategy 
>>>>> configured
>>>>> internally in Spring Data Graph. See the reference documentation for more
>>>>> information on this. If you want to convert Neo4j paths to entity paths, 
>>>>> you
>>>>> can use the ConvertingEntityPath class as seen above. As an implementation
>>>>> detail, the class name is stored on the node as a property.
>>>>>
>>>>> Hope this helped!
>>>>>
>>>>> David
>>>>>
>>>>> On Wed, Apr 20, 2011 at 9:20 AM, Emil Eifrem 
>>>>> <e...@neotechnology.com>wrote:
>>>>>
>>>>>> David / Michael, do you guys want to dig in and help out Vipul below?
>>>>>>
>>>>>> -EE
>>>>>>
>>>>>> On Wed, Apr 20, 2011 at 09:17, Vipul Gupta <vipulgupta...@gmail.com>
>>>>>> wrote:
>>>>>> > Hi Emil,
>>>>>> > I would like to start by thanking you for the webinar. It was very
>>>>>> useful .
>>>>>> > This is the question I asked on the webinar as well.
>>>>>> > How can we traverse a graph which consists of nodes of different
>>>>>> types using
>>>>>> > SDG?
>>>>>> > Say first Node in relationship is of type A, next 3 nodes in path
>>>>>> are of
>>>>>> > type B, and next node is of type C.
>>>>>> > Is there a way to traverse the path and keep getting the domain
>>>>>> objects at
>>>>>> > each stage of traversal.
>>>>>> > answer mentioned on the webinar is to look at
>>>>>> findAllPathsByTraversal in
>>>>>> > NodeBacked.
>>>>>> > I am not able to understand how to get an Iterator or a path with
>>>>>> starts
>>>>>> > with Type A, ends with Type C and has number of Type C in between.
>>>>>> >
>>>>>> > Also if I convert a domain POJO to a Node object, is there a way to
>>>>>> know
>>>>>> > what domain type it represents or is wrapped around so that it can
>>>>>> be
>>>>>> > converted back to that type.
>>>>>> > Please let me know.
>>>>>> > Best Regards,
>>>>>> > Vipul Gupta
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Emil Eifrém, CEO [e...@neotechnology.com]
>>>>>> Neo Technology, www.neotechnology.com
>>>>>> Cell: +46 733 462 271 | US: 206 403 8808
>>>>>> http://blogs.neotechnology.com/emil
>>>>>> http://twitter.com/emileifrem
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> David Montag <david.mon...@neotechnology.com>
>>>>> Neo Technology, www.neotechnology.com
>>>>> Cell: 650.556.4411
>>>>> Skype: ddmontag
>>>>>
>>>>
>>>>
>>>
>>
>>
>> --
>> David Montag <david.mon...@neotechnology.com>
>> Neo Technology, www.neotechnology.com
>> Cell: 650.556.4411
>> Skype: ddmontag
>>
>
>


-- 
David Montag <david.mon...@neotechnology.com>
Neo Technology, www.neotechnology.com
Cell: 650.556.4411
Skype: ddmontag
_______________________________________________
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to