You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make encoders/profiles available to a scripting language #193
I have an application in which I am using a walking path (using Graphhopper (Awesome!)) to figure out the distance to a nearest gas main from a person's house. It is to calculate how much it would cost to connect that person up to the network. Been working fabulous for over a year now but then a request came in from a person on a private drive. "access" = "private". And suddenly the routine didn't work. So I tracked it down to the line in FootFlagEncoder.
restrictedValues.add("private");
I have forked the code, commented that above line out, recompiled, reran the data import and voila it works now on private drives!
But I would love to submit a pull in which this is configurable through say the config.properties, but the problem is you use reflection to create this class and I don't see how I can read the props from FootFlagEncoder. Wonder if you could ponder how to make this happen?
You can create a subclass which removes this property and handing over this subclass to the encodingmanager via the other constructor. Or do you want/meant something like scripting support e.g. via JavaScript or something?
Well, I guess I wa looking for a solution using just the properties files
since i already have a few changes to the default already. But I can make
this work I suppose. Cheers.
You can create a subclass which removes this property and handing over
this subclass to the encodingmanager via the other constructor. Or do you
want/meant something like scripting support e.g. via JavaScript or
something?
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/193#issuecomment-42014435
.
We cannot use the properties for this. But something like this will come
via interpreted languages ala "foot-profile.js" at a later stage.
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/193#issuecomment-42285358
.
I thought a bit about a more detailed design for such a scripting feature. This is my current conclusion:
I would start with implementing a brand new flagEncoder and configure it by something like this:
graph.flagEncoders=script|scriptpath=FullQualifiedPathToScript.js
Then I would try to implement such a new script encoder, duplicate one of the existing tests (e.g. for one of the bicycle types) and attempt to pass the existing tests by putting as much of the configuration logic into the JS file and in parallel implement the scripted encoder.
I'm sure many more questions about a good interface between the script and the script encoder will arise and need to be answered during the implementation.
One problem is the deployment of such server sided java scripts to servers hosted on the Internet. The coolest feature would be to offer users the possiblity to provide their own scripts. But in this case one needs to be very cautious about the security issues as I guess that some people might start hacking the server with all the capability java script provides. But maybe this could be solved by some very restrictive sophisticated parsing of the script. But I'm not sure if it eventually would not be better to invent a dedicated own simple syntax (and an interpreter for such a syntax) similar as to what brouter does in its profiles (http://brouter.de/brouter/costfunctions.html), because in this case you don't need to care that much about security issues. Anyhow I guess the implementation effort for such a solution would be higher and the long-term flexibility much lower. What do you think about the approach?
@ratrun What do you think about Nashorn or Groovy? With one of them you can just extend existing encoders and override speed's definition or "accept node-way" logic or create new.
Extending just one of the existing encoders would be the easiest. Actually I have started with this playing around a bit. But I see following drawbacks:
You need to implement the extension capability in every single encoder
It will be hard and next to impossible to maintain the same extension capabilities in every encoder.
In case that you choose to provide different extension possibilities per encoder, it well be next to impossible to document and explain the feature set for a sprecific encoder to the users. If you provide feature X for "bicycle", then it is quite sure that somebody else wants to use this feature also for "foot".
I'm sure we want to keep the existing none flexible encoders because of better runtime. If you move all configurations to the Java Script, then tehy do not work without extensions any longer. In case that you only modifiy the current behaviour via the script, then the overall behaviour will is very complicated because you need to know both implementations. And if we change something in the existing Java encoders the influence on the Java script extensions maintained by useres is very hard to predict.
The way we plan to integrate this into GraphHopper is more high level so it could theoretically work for data which is not OSM:
implement a generic FlagEncoder which stores max-height, max speed for several vehicles and directions, access properties for various vehicles, surface, etc
then provide certain properties one could configure like access to max-speed for car or preferring route relations for big etc. This would be done within a custom ScriptedWeighting class
Finally allow passing parameters to the ScriptedWeighting class OR writing such classes via server-side groovy or JS scripts or a new lang called painless or janino. We would not allow client side scripts for now (see below) but as we allow the params to change this is not that bad I think
The coolest feature would be to offer users the possiblity to provide their own scripts.
Anyhow I guess the implementation effort for such a solution would be higher and
the long-term flexibility much lower. What do you think about the approach?
I've emailed with the author of brouter and he is willing to put this under the Apache license. Although I would find this a powerful solution and it would be very valueable for the GraphHopper community it has the drawback of a relative complex scripting languages (polnish notation etc) and the dependency on the OSM notation etc.
The configuration-approach we would try first (ScriptedWeighting with params) will be less powerful but faster than a scripting language
Any progress with this?
here is how I imagined it before reading this thread:
A user will be able to create an XML or JSON or something that can be read easily (not sure what's native to Java) defining the properties in the encoder flag.
Implement a FileFlagEncoder that can use this data in order to define everything it needs.
Define in the config the file names to use - each file name will represent the name of the flag encoder.
define a folder in the config so that GH will know where to look for the files.
This way you can implement any type of routing. no security. and you can change it without compiling GH.
I'm currently testing the current profiles and I feel that I need to be able to tweak them without recompiling every change - just delete the cache and refresh the server.
What do you think?
I think it will be easier to implement...
Yes, something like this is planned in the near future. It goes even further that you'll be able to send these json's over HTTP and the profile is completely configurable even per request.
I'd love to try it out as I really need to fine tune the profiles before releasing the routing to production.
If you have something I can tryout it will be great! (the sooner the better).
make it possible to specify such a profile on import (this likely requires adding the jackson dependency and the scripting languages like janino to core, which we should avoid to keep it lean)
create new vehicle profiles like trucks and make testing very easy
For later reference: instead of a "full" scripting language like janino that comes with security challenges we can try exp4j that can also support boolean operators.
Activity
karussell commentedon May 2, 2014
You can create a subclass which removes this property and handing over this subclass to the encodingmanager via the other constructor. Or do you want/meant something like scripting support e.g. via JavaScript or something?
crowmagnumb commentedon May 6, 2014
Well, I guess I wa looking for a solution using just the properties files
since i already have a few changes to the default already. But I can make
this work I suppose. Cheers.
On Fri, May 2, 2014 at 3:27 AM, Peter [email protected] wrote:
karussell commentedon May 6, 2014
We cannot use the properties for this. But something like this will come via interpreted languages ala "foot-profile.js" at a later stage.
crowmagnumb commentedon May 6, 2014
Great! That sounds exciting!
On Tue, May 6, 2014 at 3:09 AM, Peter [email protected] wrote:
[-]FootFlagEncoder configurable[/-][+]Make encoders/profiles available to a scripting language[/+]ratrun commentedon Apr 6, 2015
I thought a bit about a more detailed design for such a scripting feature. This is my current conclusion:
I would start with implementing a brand new flagEncoder and configure it by something like this:
graph.flagEncoders=script|scriptpath=FullQualifiedPathToScript.js
Then I would try to implement such a new script encoder, duplicate one of the existing tests (e.g. for one of the bicycle types) and attempt to pass the existing tests by putting as much of the configuration logic into the JS file and in parallel implement the scripted encoder.
I'm sure many more questions about a good interface between the script and the script encoder will arise and need to be answered during the implementation.
One problem is the deployment of such server sided java scripts to servers hosted on the Internet. The coolest feature would be to offer users the possiblity to provide their own scripts. But in this case one needs to be very cautious about the security issues as I guess that some people might start hacking the server with all the capability java script provides. But maybe this could be solved by some very restrictive sophisticated parsing of the script. But I'm not sure if it eventually would not be better to invent a dedicated own simple syntax (and an interpreter for such a syntax) similar as to what brouter does in its profiles (http://brouter.de/brouter/costfunctions.html), because in this case you don't need to care that much about security issues. Anyhow I guess the implementation effort for such a solution would be higher and the long-term flexibility much lower. What do you think about the approach?
dos65 commentedon Apr 6, 2015
@ratrun What do you think about Nashorn or Groovy? With one of them you can just extend existing encoders and override speed's definition or "accept node-way" logic or create new.
ratrun commentedon Apr 6, 2015
Thanks for pointing out the usage of Nashorn (http://www.oracle.com/technetwork/articles/java/jf14-nashorn-2126515.html). Its convenient way of extending Java types from JavaScript would be beneficial for the Java script approach. But it does not help with the security aspects, please correct me if I'm wrong.
I did not know Groovy and having read its high level decription I do not get the point what benefits it would bring in our use-case.
Extending just one of the existing encoders would be the easiest. Actually I have started with this playing around a bit. But I see following drawbacks:
dos65 commentedon Apr 6, 2015
There is way to restrict scripting access in Nashorn javadoc
karussell commentedon Apr 7, 2015
The way we plan to integrate this into GraphHopper is more high level so it could theoretically work for data which is not OSM:
Yes, but a big risc. ElasticSearch has done this and tried this with Groovy as it has a sandbox, but currently there seems to be no safe solution: http://www.elastic.co/guide/en/elasticsearch/reference/1.x/modules-scripting.html also JS seems to not have a sandbox not sure if the classfilter mentioned from @dos65 could solve this (as the guys from ES have looked into JS too)
karussell commentedon Apr 7, 2015
I've emailed with the author of brouter and he is willing to put this under the Apache license. Although I would find this a powerful solution and it would be very valueable for the GraphHopper community it has the drawback of a relative complex scripting languages (polnish notation etc) and the dependency on the OSM notation etc.
The configuration-approach we would try first (ScriptedWeighting with params) will be less powerful but faster than a scripting language
devemux86 commentedon Apr 7, 2015
Very interesting news!
HarelM commentedon Oct 13, 2015
Any progress with this?
here is how I imagined it before reading this thread:
This way you can implement any type of routing. no security. and you can change it without compiling GH.
I'm currently testing the current profiles and I feel that I need to be able to tweak them without recompiling every change - just delete the cache and refresh the server.
What do you think?
I think it will be easier to implement...
Here's an example of a json file:
{ turnCosts: true, restrictions: ["motorcar"], restrictionsValues: ["private", "agricultural"], intendedValues: ["yes", "permissive"], trackTypeSpeedMap: [{"grade1": 20}, {"grade2": 15}], ... }karussell commentedon Oct 14, 2015
Yes, something like this is planned in the near future. It goes even further that you'll be able to send these json's over HTTP and the profile is completely configurable even per request.
See https://discuss.graphhopper.com/t/more-flexibility-in-gh/71
HarelM commentedon Oct 14, 2015
I'd love to try it out as I really need to fine tune the profiles before releasing the routing to production.
If you have something I can tryout it will be great! (the sooner the better).
HarelM commentedon Apr 26, 2016
Any updates on this issue? I'm having troubles with fords now... :-/
karussell commentedon Apr 26, 2016
Sorry, not yet. Too many things on the table although this is very exciting.
Regarding fords: what is your problem? You can enable them already. When reading the referenced issue:
then there seems to be a misconception. Just create the FlagEncoder and enable fords ...
Also we should move the discussion to our forum.
karussell commentedon Jul 18, 2019
This issue needs to be split into several sub issues:
The work for this was started in flex_vehicleprofile branch but the most recent work (not all features yet) happens in https://github.com/graphhopper/graphhopper/compare/flex_vehicleprofile2
karussell commentedon Nov 1, 2019
Closing in favor of #1776
karussell commentedon Feb 21, 2020
For later reference: instead of a "full" scripting language like janino that comes with security challenges we can try exp4j that can also support boolean operators.
do not zoom if marker was dragged (graphhopper#193)