A* search in neo4j - graph

I want to search for shortest path in the directed acyclic graph with neo4j. I have graph that looks similar to this:
I want to find path starting from Root down to Layer 3. At each layer I have different set of properties and I can calculate weight using this properties and user input. I need to find all shortest paths with minimal dynamic weight using A* or another search algorithm (it is possible to have several paths with equal weights). Is it possible with neo4j and cypher or gremlin?
I don't want to use embedded version because my project is written in python, so I can't use java library that as I know can do this.

As of now, Cypher does not allow you to pass in function e.g. your cost function. Adding this as feature must be decided very carefully as injecting runnable code by a query language has some security concerns.
That said what you can do now: create a unmanaged extension to the Neo4j server. Inside your unmanaged extension you make use of the the provided graph algorithms. Using JAX-RS parameter you provide data to identify the start and end node of your traversal and let graph algos do the dirty work.
You might want to take a look at https://github.com/sarmbruster/unmanaged-extension-archetype, this is a minimalistic sample project using gradle as a build system.
However, the sketched idea involved Java coding for the server side part. Client side you can use whatever stack you like.

Related

GraphDB paths through a a specified node

GraphDB 9.9 introduced a feature providing path searches with various configurations. Is there a way to filter obtained paths by a specific node which they need to traverse?
Using the recursive graph pattern instead of the wildcard pattern search does not help - the aim is not to repeatedly look for the specified node, only to pass through it once.
Currently this is not possible, but we do have it planned for a future release.

How to enforce typing in gremlin/tinkerpop?

In something like SQL, when I create a table I can create type constraints (String with certain lengths, booleans, etc).
How do I do that in gremlin? I am using a javascript implementation, and I know I can switch to typescript and add a lot of type enforcement on that side, but ideally I would also like to have type constraints on the database side too.
I know I can switch to typescript and add a lot of type enforcement on that side
There is an open issue for Typescript at TINKERPOP-2027 and while there was some activity there, no one has really picked up the work.
I would also like to have type constraints on the database side too.
Constraints in the database are not a feature of TinkerPop. For 3.x we long ago committed to allowing graph providers who implement TinkerPop interfaces to provide their own functionality for doing so. There are a lot of historical reasons for that which I won't bother to detail, but the basic answer to your question is that if you want such functionality you need to choose a graph that has that sort of thing. Perhaps take a look at JanusGraph or DS Graph as both have a fairly robust schema language.

Add or get vertex in Azure Cosmos DB Graph API

Using Gremlin, I can create a vertex in an Azure Cosmos DB graph by issuing
g.addV('the-label').property('id', 'the-id')
and subsequently find it using
g.V('the-label').has('id', 'the-id')
However, I haven't found a way to issue a query that will insert the node if it is missing, and just get the reference to it if it already exists. Is there a way?
My concrete use case is that I want to add an edge between two nodes, regardless of whether those nodes (or the edge, for that matter) exist already or not, in a single query. I tried this upsert approach, but apparently Cosmos DB does not support Groovy closures, so it won't work.
The "upsert pattern" is relatively well defined and accepted at this point. It is described here. If you want to extend that to also add an edge, that's possible too:
g.V().has('event','id','1').
fold().
coalesce(unfold(),
addV('event').property('id','1')).as('start').
coalesce(outE('link').has('id','3'),
coalesce(V().has('event','id','2'),
addV('event').property('id','2')).
addE('link').from('start').property('id','3'))
If that looks a bit complex you can definitely simplify with a Gremlin DSL (though I'm not sure that CosmosDB supports Gremlin bytecode at this point). Here's an example with even more complex upsert logic simplified by a DSL. It's discussed in this blog post in more detail.
Please look at this.
http://tinkerpop.apache.org/docs/current/reference/#coalesce-step
You can try
g.Inject(0).coalesce(__.V().has('id', 'the-id'), addV('the-label').property('id', 'the-id'))
btw, you won't able to find the vertex using g.V('the-label').has('id', 'the-id').
g.V() accepts vertex id as parameters and not vertex labels.

Library or advise on plotting box nodes interactively

I'm building an application that parses text files that contain information about specific nodes with incoming ports and outgoing ports that are interconnected. Doing some research there are some libraries but none of them support the exact characteristics needed.
this is what I'm trying to build and any language will do: Python, Perl, .net, etc.
One of the libraries I have found is GoDiagaram Node Classes
http://www.nwoods.com/components/dotnet/features-nodes.htm
The idea is to have boxes like so, interconnected and I should be able to click on one of them and link it to a new sub-diagram with more boxes contained in the one clicked.
Is there a counter part of these kind of charts that is opensource? and do these diagrams have a specific kind of name?
I don't know any specific details, since I never looked into this too closely, but here are some potential directions:
The data structure used for representing something like this is usually a graph (probably a directed graph). You could also try searching for graphical (or visual) programming languages. I seem to remember Pure Data as one that was relevant, but I never looked at it in detail.
Blender and VirtualDub both have a mode that's similar to this (the node editor and audio filters, respectively) and I believe both are open source, although I think neither has the option of having the nodes contain other nodes internally.
You could just use LabVIEW, which gives you the ability to create and edit LV code programmatically (search for "VI scripting"), but the code for that might not be very pretty and it's certainly not open source.

tool to create a domain model diagram

My requirement is to create a diagram which can represent the object relationship which is stored in an xml.
For example
This needs to get translated as Class abc has a field which is xyz. This heirarchy can be multi level. and we need to represent
a) high level struturing of classes
b) contents of these classes.
I looked at some tools like umlet, violet, visio. but all of these require a lot of manual intervention. Is there a tool which can be configured to read from xml.
Try using Graphviz and the dot language.
http://www.graphviz.org/
You'll need to write a translation layer, but that shouldn't be too hard in the language of your choice.
UModel might be a good pick for you on this one... http://www.altova.com/umodel/xml-schemas-in-uml.html

Resources