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
I'm using the Java-API in my Android-Project to create offline routing. With the standard profiles everything works as it should. My next goal is now to use the CustomProfile functionality.
The CustomProfile leads to an exception very deep in graphhopper CustomModelParser.java:createClazz::172. I havn't looked into the SimpleCompiler code yet.
Is the specification of the CustomProfile wrong, am I missing something?
I'm using com.graphhopper:graphhopper-core:6.2, but tested version 6.0 as well without luck.
See this issue janino-compiler/janino#191. It is a mess with Android, but instead of messing with byte code, for GraphHopper it should be possible to create the Java source file via janino with a real JVM (openjdk) and use this class for Android instead of the inbuilt mechanism. (at least for profiles that are known at start)
To create the Java Weighting class you specify -Dorg.codehaus.janino.source_debugging.enable=true as JVM (openjdk) parameter and the output directory -Dorg.codehaus.janino.source_debugging.dir=/home/user/somedir (the directory must exist). See CustomModelParser.
Return this weighting from your own DefaultWeightingFactory and inject this into the GraphHopper class:
GraphHoppergraphHopper = newGraphHopper() {
protectedWeightingFactorycreateWeightingFactory() {
returnnewDefaultWeightingFactory() {
publicWeightingcreateWeighting(Profileprofile, PMaprequestHints, booleandisableTurnCosts) {
if("custom".equals(profile.getWeighting()))
// see DefaultWeightingFactory on how to get the required objects like accessEnc, speedEnc, etcreturnmyWeighting;
returnsuper.createWeighting(profile, requestHints, disableTurnCosts);
}
}
}
}
Please let us know if you have success with this approach. The same approach should be possible to make the latest GH version working for our iOS port.
First of all thx for the quick response. I have now copied the relevant Graphhoper Code into a Java-Project which I have created with the IntelliJ Idea IDE.
Than I have added the additional parameters you have mentioned
I have encountered a problem. CustomWeighting.Parameters is Package-Private and therefore I'm not able to use it to describe my CustomProfile. Any idea how to solve this issue? I already tried reflection, but the constructor CustomWeighting is not satisfied with just an Object.
And where does avgSpeedEnc and priorityEnc actually come from?
@easbar what do you think about making this public? (IMO it is currently suboptimal that CustomWeighting is public but this Parameters class is not, although it is part of the public constructor)
Thx for the change, I have now cloned this repository and added core and web-api as modules into my Android-Project. That is the only way to integrate the updates you made. I also found out that it is not enough to set the static class Parameter to public, the visibility of the constructor has to be changed as well to public.
And just for anyone who is interested to add the source code directly
Open a Terminal
Navigate to the root folder of an Android Project
Clone the complete Graphhopper Repository (well I think it is important to clone it directly into the root Android Project Folder, it should work from any place I guess)
Enter the cloned graphhopper repository folder
Execute gradlew init
Start Android Studio
Open the settings.gradle
include ':graphhopper-core'
include ':graphhopper-web-api'
project(':graphhopper-core').projectDir =newFile(rootDir, 'graphhopper/core')
project(':graphhopper-web-api').projectDir =newFile(rootDir, 'graphhopper/web-api')
Activity
easbar commentedon Jan 7, 2023
This is probably because the Janino library needed for custom models is missing and I am not sure if it works with Android at all.
karussell commentedon Jan 7, 2023
See this issue janino-compiler/janino#191. It is a mess with Android, but instead of messing with byte code, for GraphHopper it should be possible to create the Java source file via janino with a real JVM (openjdk) and use this class for Android instead of the inbuilt mechanism. (at least for profiles that are known at start)
To create the Java Weighting class you specify
-Dorg.codehaus.janino.source_debugging.enable=trueas JVM (openjdk) parameter and the output directory-Dorg.codehaus.janino.source_debugging.dir=/home/user/somedir(the directory must exist). See CustomModelParser.To use this class you do:
Return this weighting from your own
DefaultWeightingFactoryand inject this into the GraphHopper class:Please let us know if you have success with this approach. The same approach should be possible to make the latest GH version working for our iOS port.
[-]Java API create a custom profile[/-][+]Java API create a custom profile on Android[/+][-]Java API create a custom profile on Android[/-][+]create a custom profile on Android[/+]RGregat commentedon Jan 8, 2023
First of all thx for the quick response. I have now copied the relevant Graphhoper Code into a Java-Project which I have created with the IntelliJ Idea IDE.
Than I have added the additional parameters you have mentioned
After the execution I have got this java file
Next step is to add this to my Android-Project. I keep you informed if that is working as well!
RGregat commentedon Jan 8, 2023
I have encountered a problem.
CustomWeighting.Parametersis Package-Private and therefore I'm not able to use it to describe my CustomProfile. Any idea how to solve this issue? I already tried reflection, but the constructorCustomWeightingis not satisfied with just an Object.And where does
avgSpeedEncandpriorityEncactually come from?karussell commentedon Jan 9, 2023
@easbar what do you think about making this public? (IMO it is currently suboptimal that CustomWeighting is public but this
Parametersclass is not, although it is part of the public constructor)easbar commentedon Jan 9, 2023
Yes, sure.
make CustomWeighting.Parameters public, #2717
karussell commentedon Jan 9, 2023
@RGregat with the latest master this should be possible now.
See the DefaultWeightingFactory:
RGregat commentedon Jan 10, 2023
Thx for the change, I have now cloned this repository and added core and web-api as modules into my Android-Project. That is the only way to integrate the updates you made. I also found out that it is not enough to set the static class Parameter to public, the visibility of the constructor has to be changed as well to public.
And just for anyone who is interested to add the source code directly
gradlew initsettings.gradlebuild.gradlefrom the core projectbuild.gradlefrom the web-api projectkarussell commentedon Jan 11, 2023
After a new release of GraphHopper this won't be necessary, I guess.
But finally it worked for you?
I've added this change as well.
make CustomWeighting.Parameters constructor public too, #2717
RGregat commentedon Jan 11, 2023
That is true, but It's also good to know how to add the lib as a module :)
make CustomWeighting.Parameters public, graphhopper#2717
make CustomWeighting.Parameters constructor public too, graphhopper#2717
[RSPS-1174] : Upgrade gh7 (#35)