How can I get all posible paths between two nodes with Graphhopper - path

I'm trying to find all paths between 2 nodes by using graphhopper but there is something wrong with my code. When remove setAlgorith line, it returns only one path but when I add setAlgorithm(Parameters.Algorithms.ALT_ROUTE), it returns 0 path. Here is my code:
GraphHopper graphHopper = new GraphHopper().forServer();
graphHopper.load("E:\\graphhopper\\[asia_vietnam].osm-gh");
GHRequest req = new GHRequest(21.006399, 105.820359, 21.022409, 105.819163).
setAlgorithm(Parameters.Algorithms.ALT_ROUTE).
setLocale(Locale.US);
GHResponse rsp = graphHopper.route(req);
List<PathWrapper> paths = rsp.getAll();
System.out.println(paths.size());
According to this post, it should return all possible path but seems like it doesn't work.

Related

How to create an url from an absolute path in elm

I want to create an url (not a link) for a text field for a share functionality.
Like for example the one stackoverflow uses
I already hava function that produces the path part for the url, like
toUrl : Route -> String
toUrl route = ...
toUrl (Home (Just "hallo")) --> "/?b=hallo"
and using this string for a link as a href attribute works, but I'm wondering how I could create a complete url from this string.
PS: I'm using a single page application so I get an Url at the beginning.
What you say is "the path part for the url" isn't actually just the path part, but the path and query parts of the URL. Ideally you'd separate them so you can create a well-formed URL representation:
{ initialUrl
| path = "/"
, query = Just "b=hallo"
}
But since it's just a record, with no validation, it'll work if you just use it as the path as well. At least if you later just use Url.toString on it. Other operations might cause unexpected results.
{ initialUrl | path = "/?b=hallo" }

Neo4j syntax for WITH statement

I am trying to auto generate a a text file that can be run to create the nodes and relationships for a Neoj4 Graph.
The text file is being created in two sections:
First the nodes are created in a For loop (6000 nodes) with a result like this:
create(SystemLogic_d6:FB {type:"SUB_DINT", instanceName:"d6", section:"SystemLogic"})
create(SystemLogic_d5:FB {type:"SUB_DINT", instanceName:"d5", section:"SystemLogic"})
create(SystemLogic_d7:FB {type:"ADD_DINT", instanceName:"d7", section:"SystemLogic"})
create(SystemLogic_d8:FB {type:"SEL", instanceName:"d8", section:"SystemLogic"})
Then in the next section of the text file relationships are created in another For loop wih a result like this:
MATCH (SystemLogic_d8:FB), (SystemLogic_d12:FB) WHERE SystemLogic_d8.instanceName = "d8" AND SystemLogic_d12.instanceName = "d12" CREATE (SystemLogic_d8)-[: c]->(SystemLogic_d12)
MATCH (SystemLogic_d17:FB), (SystemLogic_d18:FB) WHERE SystemLogic_d17.instanceName = "d17" AND SystemLogic_d18.instanceName = "d18" CREATE (SystemLogic_d17)-[: c]->(SystemLogic_d18)
MATCH (SystemLogic_d16:FB), (SystemLogic_d17:FB) WHERE SystemLogic_d16.instanceName = "d16" AND SystemLogic_d17.instanceName = "d17" CREATE (SystemLogic_d16)-[: c]->(SystemLogic_d17)
MATCH (SystemLogic_d11:FB), (SystemLogic_d5:FB) WHERE SystemLogic_d11.instanceName = "d11" AND SystemLogic_d5.instanceName = "d5" CREATE (SystemLogic_d11)-[: c]->(SystemLogic_d5)
This is giving the error WITH is required between CREATE and MATCH
I tried inserting a WITH in between as in this answer
Neo4j Cypher WITH is required between CREATE and MATCH:
Which gives a result like this:
MATCH (SystemLogic_d8:FB), (SystemLogic_d12:FB) WITH SystemLogic_d8,SystemLogic_d12 WHERE SystemLogic_d8.instanceName = "d8" AND SystemLogic_d12.instanceName = "d12" CREATE (SystemLogic_d8)-[: c]->(SystemLogic_d12)
MATCH (SystemLogic_d17:FB), (SystemLogic_d18:FB) WITH SystemLogic_d17,SystemLogic_d18 WHERE SystemLogic_d17.instanceName = "d17" AND SystemLogic_d18.instanceName = "d18" CREATE (SystemLogic_d17)-[: c]->(SystemLogic_d18)
MATCH (SystemLogic_d16:FB), (SystemLogic_d17:FB) WITH SystemLogic_d16,SystemLogic_d17 WHERE SystemLogic_d16.instanceName = "d16" AND SystemLogic_d17.instanceName = "d17" CREATE (SystemLogic_d16)-[: c]->(SystemLogic_d17)
MATCH (SystemLogic_d11:FB), (SystemLogic_d5:FB) WITH SystemLogic_d11,SystemLogic_d5 WHERE SystemLogic_d11.instanceName = "d11" AND SystemLogic_d5.instanceName = "d5" CREATE (SystemLogic_d11)-[: c]->(SystemLogic_d5)
MATCH (SystemLogic_FBI_1407:FB), (SystemLogic_FBI_1408:FB) WITH SystemLogic_FBI_1407,SystemLogic_FBI_1408 WHERE SystemLogic_FBI_1407.instanceName = "FBI_1407" AND SystemLogic_FBI_1408.instanceName = "FBI_1408" CREATE (SystemLogic_FBI_1407)-[: c]->(SystemLogic_FBI_1408)
But I still get the same error
I also tried putting the WITH statement after the create statement but that gives another error.
Are you able to import and run multiple node/relationships creation statements in this fashion?
It works fine for creating the nodes but I am new to using Neo4J / Cypher and I am not sure if it is my syntax that is incorrect or that you can't create multiple relatiionships in this fasion.
Thanks for your help
You need to separate the statements with a semicolon, Please refer following queries:
create(SystemLogic_d8:FB {type:"SEL", instanceName:"d8", section:"SystemLogic"});
create(SystemLogic_d9:FB {type:"SEL", instanceName:"d8", section:"SystemLogic"});
MATCH (SystemLogic_d2:FB), (SystemLogic_d21:FB) WHERE SystemLogic_d2.instanceName = "d8" AND SystemLogic_d21.instanceName = "d12" CREATE (SystemLogic_d2)-[: c]->(SystemLogic_d21);
MATCH (SystemLogic_d1:FB), (SystemLogic_d12:FB) WHERE SystemLogic_d1.instanceName = "d8" AND SystemLogic_d12.instanceName = "d12" CREATE (SystemLogic_d1)-[: c]->(SystemLogic_d12)
If you have only CREATE statements then there is no need to use semicolon it will work,
But if you are using MATCH and CREATE combined then you need to separate the statements with a semicolon.
#Raj answer is valid. However, as you are already capturing the nodes in your create statements, you do not need to perform a match on them to create relations.
Your file could then be :
create(SystemLogic_d6:FB {type:"SUB_DINT", instanceName:"d6", section:"SystemLogic"})
create(SystemLogic_d5:FB {type:"SUB_DINT", instanceName:"d5", section:"SystemLogic"})
create(SystemLogic_d7:FB {type:"ADD_DINT", instanceName:"d7", section:"SystemLogic"})
create(SystemLogic_d8:FB {type:"SEL", instanceName:"d8", section:"SystemLogic"})
CREATE (SystemLogic_d8)-[:c]->(SystemLogic_d6)
CREATE (SystemLogic_d7)-[:c]->(SystemLogic_d6)
CREATE (SystemLogic_d8)-[:c]->(SystemLogic_d5)

How to compile custom format ini file with redirects?

I'm working with an application that has 3 ini files in a somewhat irritating custom format. I'm trying to compile these into a 'standard' ini file.
I'm hoping for some inspiration in the form of pseudocode to help me code some sort of 'compiler'.
Here's an example of one of these ini files. The less than/greater than indicates a redirect to another section in the file. These redirects could be recursive.. i.e. one redirect then redirects to another. It could also mean a redirect to an external file (3 values are present in that case). Comments start with a # symbol
[PrimaryServer]
name = DEMO1
baseUrl = http://demo1.awesome.com
[SecondaryServer]
name = DEMO2
baseUrl = http://demo2.awesome.com
[LoginUrl]
# This is a standard redirect
baseLoginUrl = <PrimaryServer:baseUrl>
# This is a redirect appended with extra information
fullLoginUrl = <PrimaryServer:baseUrl>/login.php
# Here's a redirect that points to another redirect
enableSSL = <SSLConfiguration:enableSSL>
# This is a key that has mutliple comma-separated values, some of which are redirects.
serverNames = <PrimaryServer:name>,<SecondaryServer:name>,AdditionalRandomServerName
# This one is particularly nasty. It's a redirect to another file...
authenticationMechanism = <Authenication.ini:Mechanisms:PrimaryMechanism>
[SSLConfiguration]
enableSSL = <SSLCertificates:isCertificateInstalled>
[SSLCertificates]
isCertificateInstalled = true
Here's an example of what I'm trying to achieve. I've removed the comments for readability.
[PrimaryServer]
name = DEMO1
baseUrl = http://demo1.awesome.com
[SecondaryServer]
name = DEMO2
baseUrl = http://demo2.awesome.com
[LoginUrl]
baseLoginUrl = http://demo1.awesome.com
fullLoginUrl = http://demo1.awesome.com/login.php
enableSSL = true
serverNames = DEMO1,DEMO2,AdditionalRandomServerName
authenticationMechanism = valueFromExternalFile
[SSLConfiguration]
enableSSL = <SSLCertificates:isCertificateInstalled>
[SSLCertificates]
isCertificateInstalled = true
I'm looking at using ini4j (Java) to achieve this, but am by no means fixed on using that language.
My main questions are:
1) How can I handle the recursive redirects
2) How am I best to handle the redirects that have an additional string, e.g. serverNames
3) Bonus points for any suggestions about how to handle the external redirects. No big deal if that part isn't working just yet.
So far, I'm able to parse and tidy up the file, but I'm struggling with these redirects.
Once again, I'm only hoping for pseudocode. Perhaps I need more coffee, but I'm really puzzled by this one.
Thanks in advance for any suggestions.

Using python list as node properties in py2neo

I have a list of urls:
urls = ['http://url1', 'http://url2', 'http://url3']
Mind you the list can have any number of entries including 0 (none). I want to create new node property for each url (list entry).
Example how the node will look like
(label{name='something', url1='http://url1', url2='http://url2'}, etc...)
It is possible to expand a dictionary with ** with the same effect I need but is there any way to do this with a list?
You can put your list in a dictionary and use this to create a node:
from py2neo import Node
urls = ['http://1', 'http://2']
props = {}
for i, url in enumerate(urls):
# get a key like 'url1'
prop_key = 'url' + str(i)
props[prop_key] = url
my_node = Node('Person', **props)
graph.create(my_node)

How to get rid of the starting slash in URI or URL?

I am using
URL res = this.getClass().getClassLoader().getResource(dictionaryPath);
String path = res.getPath();
String path2 = path.substring(1);
because the output of the method getPath() returns sth like this:
/C:/Users/......
and I need this
C:/Users....
I really need the below address because some external library refuses to work with the slash at the beginning or with file:/ at the beginning or anything else.
I tried pretty much all the methods in URL like toString() toExternalPath() etc. and done the same with URI and none of it returns it like I need it. (I totally don't understand, why it keeps the slash at the beginning).
It is okay to do it on my machine with just erasing the first char. But a friend tried to run it on linux and since the addresses are different there, it does not work...
What should with such problem?
Convert the URL to a URI and use that in the File constructor:
URL res = this.getClass().getClassLoader().getResource(dictionaryPath);
File file = new File(res.toURI());
String fileName = file.getPath();
As long as UNIX paths are not supposed to contain drive letters, you may try this:
URL res = this.getClass().getClassLoader().getResource(dictionaryPath);
String path = res.getPath();
char a_char = text.charAt(2);
if (a_char==':') path = path.substring(1);
Convert to a URI, then use Paths.get().
URL res = this.getClass().getClassLoader().getResource(dictionaryPath);
String path = Paths.get(res.toURI()).toString();
You could probably just format the string once you get it.
something like this:
path2= path2[1:];
I was searching for one-line solution, so the best what i came up with was deleting it manually like this:
String url = this.getClass().getClassLoader().getResource(dictionaryPath).getPath().replaceFirst("/","");
In case if someone also needs to have it on different OS, you can make IF statement with
System.getProperty("os.name");

Resources