Liam
Liam

Reputation: 513

Neo4j APOC A* with conditions

I have successfully used the following to get the shortest path using A* in the APOC library.

apoc.algo.aStar("A", "B", 'Link', 'Length','X','Y') YIELD path, weight

apoc.algo.aStar("A", "B", 'Link', {weight:'Length',default:1, x:'X',y:'Y'}) YIELD path, weight

How would I go about adding a filter so that it only uses edges where "Value" is true. The documentation doesn't provide an example.

public class Node{
    public long Id {get;set;}
    public string Name {get;set;}
    public long X {get;set;}
    public long Y {get;set;}
}

public class Link{
   public bool Value {get;set;}
   public long Length {get;set;}
}

Upvotes: 0

Views: 185

Answers (1)

logisima
logisima

Reputation: 7478

There is no example because this feature is not available.

So you have three choices :

  • add a Length value very high on relationships where "Value" is true
  • modify your model by adding the property "Value" in the relationship type (ie to have two types : Link_On and Link_value_Off), so you can use the apoc procedure.
  • create your own A* procedure by taking example on the one from APOC (source code here)

Upvotes: 2

Related Questions