Skip to content

Refactoring to reduce set/getFlags usage #472

Closed

Description

@karussell

The get/setFlags usage is very low level and confusing for new users. Additionally it hurts that the behaviour often cannot be overloaded. For example for #464 I needed a different flags layout for shortcuts which is FlagEncoder-independent and therefor e.g. edgeState.isForward(flags) would not work for multiple encoders. The solution in #464 needs to be rolled out for more properties like get/setSpeed etc via just attaching the methods to the edge ala edgeState.isForward(FlagEncoder). A similar problem we had when introducing edge.getBool for a different behaviour for virtual edges.

Then I was able to easily throw an exception if shortcut.getFlags was called because reading the speed from a shortcut does not make sense.

Of course we could even go further and avoid the FlagEncoder argument for every method call and e.g. specify the encoder already for the EdgeExplorer to make it available for all EdgeIterator calls. Which would make the usage very Java-way and user friendly: edge.getSpeed() or edge.isForward().

Another possibility is to do encoder.getSpeed(edge) and a check inside if it is a shortcut or not. But this has not the possibility of getting rid of the argument.

We need to take care that such a refactoring does not hurt performance.

Additionally with this refactoring in place we need to investigate if we can get rid of the EncodingManager withing the BaseGraph, as well as avoiding the expensive loop over the flagEncoders in encodingManager.reverseFlags and instead call this just for the FlagEncoder specified at the first place while creating the EdgeExplorer.

Another possibility to hide this complexity is to do something like:

car = encodingManager.getEncoder("car")
maxSpeed = car.getProperty("max_speed");
maxSpeed.get/set // internally we map this to the correct car max_speed property

Update

The usage is now much simpler in 99% of the cases: edge.get(accessEnc) via #1447. Will keep it open until the 1% is fixed too. Also see #1625.

  • remove FlagEncoder.flagsDefault

Activity

  1. devemux86 commented on Jul 22, 2015

    @devemux86
    Contributor

    👍
    This refactoring seems interesting and indeed would make the API very user friendly.

  2. Azbesciak commented on Nov 15, 2018

    @Azbesciak
    Contributor

    Just a question - maybe allow to call getFlags on shortcut (rather opposite to the title but...)?
    There may be case when you have custom weighting over PreparationWeighting which depends also on flags, for example - avoid highways. Such information may be included on base edge, then when creating shortcut (which include that edge) with or on this field you would avoid such edge if weighting will discover it.
    It requires change in NodeBasedNodeContractor, but it would rather call (in base option) something like getVetoFlagsMask (which actually assumes that all of them are booleans [switches] - multiple fields would require harder logic than simple or) and then use it with both edges (and or operator) with direction etc. But, to be honest, I was not able to spy whole implementation, so if it is totaly no sense, just let me know.

  3. karussell commented on Nov 15, 2018

    @karussell
    MemberAuthor

    There will be a few changes that should allow customizing the information on the shortcut but I don't see a use case besides tweaking precision of the weight as the current form of CH can only use the weight of a shortcut. (This weight is created from edges and one can use it to avoid highways of course but not related to flags in shortcuts. See discussion.)

  4. Azbesciak commented on Nov 15, 2018

    @Azbesciak
    Contributor

    Thanks, looks interesting, but DataFlagEncoder is rather not mentioned to use with CH... nevertheless, when I have my own flag encoder defined and still want to use CH, it would allow to use some wrapping - not every customization would require to disable CH or create separate graph.

  5. modified the milestone: 0.12 on Feb 19, 2019
  6. added a commit that references this issue on Jan 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions