Using of different weightings

Hello,

I have created some different weighting e.g. traffic jam, speed, …
I use [this][1] information to write my different classes.

My question is how I can use different weights during runtime?
I overwrite the method in this case

public Weighting createWeighting( final WeightingMap p_map, final FlagEncoder p_encoder )
{
    switch (p_map.getWeighting().toLowerCase())
    {
        case "trafficjam" :
            return new CTrafficJam( p_encoder, this );

        case "forbiddenedge" :
            return new CForbiddenEdge( p_encoder, this );

        default :
            return super.createWeighting( p_map, p_encoder );
    }
}

How can I use the two weights, should I define it on the routing call?
The default weight is “fastest”.

Thanks

Phil

[1]:https://github.com/graphhopper/graphhopper/blob/master/docs/core/weighting.md to

I’m not sure if I understand your question properly. It should already work if you disable CH. What exactly is the problem :slight_smile: ?

I need to disable CH (okay I don’t do that) and than I run e.g.

GHRequest x = new GHRequest( startgps, endgps );
x.setWeighting("forbiddenedge");

GHResult y = graphhopperinstance.route(x);

to use routing with my definied weight here “forbiddenedge”

Is this the correct way?

Thx

Yes & just try it out :slight_smile:

Thanks works :smile:

But how can I get access to the weighting object? I would like to call something like

graphhopperinstance.getWeighting( "forbiddenedge" )

I would like to get my CForbiddenEdge object back and would like to use it outside from GraphHopper

Thx

What is the use case then? And why not create it ‘outside’ and then pass it in your extended GraphHopper class?

My weighting class has got an UI representation (some plotting of the internal weight data within an OSM map) and it is created during the createWeighting call, so I need the current object, which is used by GraphHopper also in the UI

Then just inject the necessary parameters right into the Weighting instances and you should be able to change values via UI