Skip to content

Custom weighting helper cleanup - #2211

Merged
easbar merged 5 commits into
janino_scriptingfrom
custom_weighting_helper_cleanup
Dec 14, 2020
Merged

easbar merged 5 commits into
janino_scriptingfrom
custom_weighting_helper_cleanup

Conversation

@easbar

@easbar easbar commented Dec 13, 2020

Copy link
Copy Markdown
Member

Here I tried separating the custom model parsing from the custom weighting creation a bit, such that e.g. we can test extracting speeds and priorities from the custom model definition without creating a CustomWeighting.

Follow-up of this comment: https://github.com/graphhopper/graphhopper/pull/2209/files#r541899846


@FunctionalInterface
public interface EdgeToDoubleMapping {
double apply(EdgeIteratorState edge, boolean reverse);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In current master this is named EdgeToValueEntry and getValue but the class name you have is better, unsure about apply :D

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

java.util.Function calls it apply, but honestly this never sounded very intuitive to me either. Maybe call it get like java.util.Supplier? Or map? Don't know really.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get sounds better, yes :)

@karussell karussell left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I now better understand what you mean. Especially testing priority calculation without CustomWeighting is useful to avoid relying (only) on some magic weight numbers :)

@easbar

easbar commented Dec 14, 2020

Copy link
Copy Markdown
Member Author

After merging this maybe we can migrate some tests from CustomWeightingTest to ExpressionBuilderTest, but no need to rush and we can also do this later in master.

@easbar
easbar marked this pull request as ready for review December 14, 2020 12:03
@easbar
easbar merged commit 591317a into janino_scripting Dec 14, 2020
@easbar
easbar deleted the custom_weighting_helper_cleanup branch December 14, 2020 12:03
karussell added a commit that referenced this pull request Jan 19, 2021
* basic test with janino passing

* move janino scripting to safe whitelisted approach

* create a class to add encoded values on the fly but limit user input to expression

* compilation unit via overwriting getValue method safely

* minor fix regarding ClassName

* ensure it is not called twice

* separate parsing of condition and number

* CustomWeighting: ensure Map is ordered (#2162)

* CustomWeighting: ensure Map is ordered

* minor

* cleaner junit5 assertThrows

* one more assertThrow

* change expression from factor multiplication to if-then-elseif-else and make speed factor working too

* replace catch all with true and make max_speed working

* no need to parse value which is always a number

* use global max speed

* minor cleanup and fix regarding sharedEV

* found a way to avoid Unparser.unparse

* use scripting in CustomWeighting. This revealed: we need if and if-else-if clauses and maybe a different variable initialization

* reduce max speed and fix priority bug

* cosmetics

* minor truck.yml tweaks

* adapt benchmarks

* a bit more details in exception

* see perf with ugly caching hack

* revert and see bench

* workaround bug with import conflict (two imports for enum 'NO')

* inject class for constants, avoid static imports that can easily collide

* special case of RouteNetwork for bike

* introduce thread-safe caching; minor restructuring

* reduce code duplication in ScriptHelper

* move code out of ScriptHelper and rename it to ExpressionBuilder

* less recursion for more clear protection

* further cleanup and improved naming

* adapt CustomModel.merge to scripting and throw exception if query-CustomModel contains factors >1

* improved docs about custom model

* adapted docs to new format

* removed CustomWeightingOld and all related classes

* minor fixes

* make debugging possible; every dynamic class has a different name now; fix two issues in source code creation (RoadClass->EncodedValue and import JsonFeature)

* improve caching: remove oldest accessed entry, instead oldest inserted

* introduce cache to keep certain classes in cache forever

* try perf with disabled cache to see CH numbers again

* Revert "try perf with disabled cache to see CH numbers again"

This reverts commit 85c9743.

* make it possible to disable dyn cache; clarify about the static cache which is populated via checkProfilesConsistency

* allow multiple first_match and make names of encoded values even stricter

* non-shared EncodedValue is too complex due to '.' we should use '$' or '__'

* use non-shared encoded values

* test again without cache

* call in-area method only when necessary, improves speed where pre-conditional checks are done like road_class!=PRIMARY && in_area_custom1

* make area names stricter

* already consider parts of the pull request reviews

* Custom weighting helper cleanup (#2211)

* Chain CustomWeighting constructors, use static creator method

* CustomWeighting no longer depends on CustomWeightingHelper

* Extract parameter object for CustomWeighting

* Use SpeedAndAccessProvider interface, add ExpressionBuilderTest

* Change apply -> get

* More fine-grained usage of try statement

* revert DEFAULT to true

* docs: remove confusing statement

* better name for subclass

* no need for the extra line in test

* simple max_speed_fallback handling, still explicit

* migrate to if-then notation

* fix benchmarks for if-then notation

* made Clause methods shorter

* introduce different Op

* merge speed_factor and max_speed into speed via introduced 'multiply with' and 'limit to' operators; cleanup

* further simplify custom model: remove max_speed_fallback

* bug fix

* docs: adapt to know notation

* multiply with -> by

* minor cleanup

* support for StringEncodedValue

* UI fixes for new format; make isSharedEncodedValues method private again

* bug fix for findMaxSpeed calculation

* test perf: disable cache for comparison

* test perf: again

* enable cache to permanently store internal Weighting classes

* uhm, test perf: without cache but push separately

* Revert "uhm, test perf: without cache but push separately"

This reverts commit 6bb9fd0.

* minor improvements

* removed SpeedAndAccessProvider

* make sure that the internal cache will never be too big

* fix package of JaninoCustomWeightingHelperSubclass

* rename ExpressionBuilder to CustomModelParser

* made CustomModelParser parser public and move create method to it from CustomWeighting

* comment regarding internal cache method

* create -> createWeighting

* move CustomModel to different package to hide useInternalCache methods

* limit size of the whole script, not single expressions

* Rename CustomModelParser#create etc.

* minor

* rename internal and throw exception if found in query

* fix contentString

* Improve profiles.md

* Fix road_surface->surface and else: "" -> else: null

* Explain how to use else statement in JSON

* Fix GH maps example

* Warn instead of error in case the edge distance of very long edges differs from way geometry length

(cherry picked from commit dfee21c)

* rename

* error message e.g. in case of encoded value wasn't added

* distanceInfluence: use default value only if not initialized

* less cryptic error message

Co-authored-by: Andi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants