use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.
the class PrepareRoutingSubnetworks method doWork.
public void doWork() {
if (minNetworkSize <= 0 && minOneWayNetworkSize <= 0)
return;
logger.info("start finding subnetworks (min:" + minNetworkSize + ", min one way:" + minOneWayNetworkSize + ") " + Helper.getMemInfo());
int unvisitedDeadEnds = 0;
for (FlagEncoder encoder : encoders) {
// mark edges for one vehicle as inaccessible
PrepEdgeFilter filter = new PrepEdgeFilter(encoder);
if (minOneWayNetworkSize > 0)
unvisitedDeadEnds += removeDeadEndUnvisitedNetworks(filter);
List<IntArrayList> components = findSubnetworks(filter);
keepLargeNetworks(filter, components);
subnetworks = Math.max(components.size(), subnetworks);
logger.info(components.size() + " subnetworks found for " + encoder + ", " + Helper.getMemInfo());
}
markNodesRemovedIfUnreachable();
logger.info("optimize to remove subnetworks (" + subnetworks + "), " + "unvisited-dead-end-nodes (" + unvisitedDeadEnds + "), " + "maxEdges/node (" + maxEdgesPerNode.get() + ")");
ghStorage.optimize();
}
use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.
the class PrepareRoutingSubnetworks method keepLargeNetworks.
/**
* Deletes all but the largest subnetworks.
*/
int keepLargeNetworks(PrepEdgeFilter filter, List<IntArrayList> components) {
if (components.size() <= 1)
return 0;
int maxCount = -1;
IntIndexedContainer oldComponent = null;
int allRemoved = 0;
FlagEncoder encoder = filter.getEncoder();
EdgeExplorer explorer = ghStorage.createEdgeExplorer(filter);
for (IntArrayList component : components) {
if (maxCount < 0) {
maxCount = component.size();
oldComponent = component;
continue;
}
int removedEdges;
if (maxCount < component.size()) {
// new biggest area found. remove old
removedEdges = removeEdges(explorer, encoder, oldComponent, minNetworkSize);
maxCount = component.size();
oldComponent = component;
} else {
removedEdges = removeEdges(explorer, encoder, component, minNetworkSize);
}
allRemoved += removedEdges;
}
if (allRemoved > ghStorage.getAllEdges().getMaxId() / 2)
throw new IllegalStateException("Too many total edges were removed: " + allRemoved + ", all edges:" + ghStorage.getAllEdges().getMaxId());
return allRemoved;
}
use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.
the class TurnCostExtensionTest method testMergeFlagsBeforeAdding.
@Test
public void testMergeFlagsBeforeAdding() {
FlagEncoder carEncoder = new CarFlagEncoder(5, 5, 3);
FlagEncoder bikeEncoder = new BikeFlagEncoder(5, 5, 3);
EncodingManager manager = new EncodingManager(carEncoder, bikeEncoder);
GraphHopperStorage g = new GraphBuilder(manager).create();
initGraph(g);
TurnCostExtension tcs = (TurnCostExtension) g.getExtension();
long carRestricted = carEncoder.getTurnFlags(true, 0);
long bikeRestricted = bikeEncoder.getTurnFlags(true, 0);
int edge23 = getEdge(g, 2, 3).getEdge();
int edge02 = getEdge(g, 0, 2).getEdge();
tcs.addTurnInfo(edge02, 2, edge23, carRestricted | bikeRestricted);
long flags023 = tcs.getTurnCostFlags(edge02, 2, edge23);
assertEquals(Double.POSITIVE_INFINITY, carEncoder.getTurnCost(flags023), 0);
assertEquals(Double.POSITIVE_INFINITY, bikeEncoder.getTurnCost(flags023), 0);
}
use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.
the class LocationIndexTreeCHTest method testCHGraph.
@Test
public void testCHGraph() {
GraphHopperStorage ghStorage = createGHStorage(new RAMDirectory(), encodingManager, false);
CHGraph lg = ghStorage.getGraph(CHGraph.class);
// 0
// 1
// 2
// 3
// 4
NodeAccess na = ghStorage.getNodeAccess();
na.setNode(0, 1, 0);
na.setNode(1, 0.5, 0);
na.setNode(2, 0, 0);
na.setNode(3, -1, 1);
na.setNode(4, -2, 2);
EdgeIteratorState iter1 = ghStorage.edge(0, 1, 10, true);
EdgeIteratorState iter2 = ghStorage.edge(1, 2, 10, true);
EdgeIteratorState iter3 = ghStorage.edge(2, 3, 14, true);
EdgeIteratorState iter4 = ghStorage.edge(3, 4, 14, true);
// create shortcuts
ghStorage.freeze();
FlagEncoder car = encodingManager.getEncoder("car");
long flags = car.setProperties(60, true, true);
CHEdgeIteratorState iter5 = lg.shortcut(0, 2);
iter5.setDistance(20).setFlags(flags);
iter5.setSkippedEdges(iter1.getEdge(), iter2.getEdge());
CHEdgeIteratorState iter6 = lg.shortcut(2, 4);
iter6.setDistance(28).setFlags(flags);
iter6.setSkippedEdges(iter3.getEdge(), iter4.getEdge());
CHEdgeIteratorState tmp = lg.shortcut(0, 4);
tmp.setDistance(40).setFlags(flags);
tmp.setSkippedEdges(iter5.getEdge(), iter6.getEdge());
LocationIndex index = createIndex(ghStorage, -1);
assertEquals(2, findID(index, 0, 0.5));
}
use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.
the class SpatialRuleLookupHelper method buildAndInjectSpatialRuleIntoGH.
public static void buildAndInjectSpatialRuleIntoGH(GraphHopper graphHopper, CmdArgs args) {
String spatialRuleLocation = args.get("spatial_rules.location", "");
if (!spatialRuleLocation.isEmpty()) {
try {
final BBox maxBounds = BBox.parseBBoxString(args.get("spatial_rules.max_bbox", "-180, 180, -90, 90"));
final InputStreamReader reader = new InputStreamReader(new FileInputStream(spatialRuleLocation), UTF_CS);
final SpatialRuleLookup index = SpatialRuleLookupBuilder.buildIndex(new GHJsonFactory().create().fromJson(reader, JsonFeatureCollection.class), "ISO_A3", new CountriesSpatialRuleFactory(), .1, maxBounds);
logger.info("Set spatial rule lookup with " + index.size() + " rules");
final FlagEncoderFactory oldFEF = graphHopper.getFlagEncoderFactory();
graphHopper.setFlagEncoderFactory(new FlagEncoderFactory() {
@Override
public FlagEncoder createFlagEncoder(String name, PMap configuration) {
if (name.equals(GENERIC)) {
return new DataFlagEncoder(configuration).setSpatialRuleLookup(index);
}
return oldFEF.createFlagEncoder(name, configuration);
}
});
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
Aggregations