Search in sources :

Example 6 with GeneralRouter

use of net.osmand.router.GeneralRouter in project OsmAnd-tools by osmandapp.

the class ManyToOneRoadCalculation method calculateManyToMany.

private void calculateManyToMany(RoutingContext ctx, TLongObjectHashMap<ManyToManySegment> allSegments, List<ManyToManySegment> topIntersects, List<ManyToManySegment> bottomIntersects, int stop, final int sbottom) {
    final GeneralRouter router = ctx.config.router;
    float DISTANCE_THRESHOLD = 50000;
    // TODO depth search from one top intersect
    List<TLongArrayList> sets = new ArrayList<TLongArrayList>();
    for (int i = 0; i < topIntersects.size(); i++) {
        ManyToManySegment oneTop = topIntersects.get(i);
        clearAllSegments(allSegments);
        List<ManyToManySegment> finalSegmentResult = calculateOneToMany(allSegments, bottomIntersects, sbottom, router, oneTop);
        for (ManyToManySegment fnsResult : finalSegmentResult) {
            TLongArrayList set = convertToRoadIds(fnsResult, DISTANCE_THRESHOLD / router.getMaxSpeed());
            combineWithLocal(sets, set);
        }
        System.out.println(oneTop.road.getHighway() + " " + oneTop.road.id + " " + oneTop.segmentIndex + " common ways=" + sets.size());
    }
    System.out.println(sets.size());
    for (TLongArrayList s : sets) {
        System.out.println(s);
    }
}
Also used : TLongArrayList(gnu.trove.list.array.TLongArrayList) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) GeneralRouter(net.osmand.router.GeneralRouter)

Example 7 with GeneralRouter

use of net.osmand.router.GeneralRouter in project OsmAnd-tools by osmandapp.

the class RoutingController method routingParams.

@RequestMapping(path = "/routing-modes", produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<?> routingParams() {
    Map<String, RoutingMode> routers = new LinkedHashMap<String, RoutingMode>();
    RoutingParameter nativeRouting = new RoutingParameter("nativerouting", "Development", "[Dev] C++ routing", true);
    RoutingParameter nativeTrack = new RoutingParameter("nativeapproximation", "Development", "[Dev] C++ route track", true);
    RoutingParameter calcMode = new RoutingParameter("calcmode", "[Dev] Route mode", "Algorithm to calculate route", null, RoutingParameterType.SYMBOLIC.name().toLowerCase());
    calcMode.section = "Development";
    calcMode.value = "";
    calcMode.valueDescriptions = new String[] { "Optimal", "Basic", "Slow" };
    calcMode.values = new String[] { RouteCalculationMode.COMPLEX.name(), RouteCalculationMode.BASE.name(), RouteCalculationMode.NORMAL.name() };
    for (Map.Entry<String, GeneralRouter> e : RoutingConfiguration.getDefault().getAllRouters().entrySet()) {
        if (!e.getKey().equals("geocoding") && !e.getKey().equals("public_transport")) {
            RoutingMode rm = new RoutingMode();
            rm.key = e.getKey();
            rm.name = Algorithms.capitalizeFirstLetter(rm.key).replace('_', ' ');
            routers.put(rm.key, rm);
            List<RoutingParameter> rps = new ArrayList<RoutingParameter>();
            for (Entry<String, GeneralRouter.RoutingParameter> epm : e.getValue().getParameters().entrySet()) {
                net.osmand.router.GeneralRouter.RoutingParameter pm = epm.getValue();
                RoutingParameter rp = new RoutingParameter(pm.getId(), pm.getName(), pm.getDescription(), pm.getGroup(), pm.getType().name().toLowerCase());
                if (pm.getId().startsWith("avoid")) {
                    rp.section = "Avoid";
                } else if (pm.getId().startsWith("allow") || pm.getId().startsWith("prefer")) {
                    rp.section = "Allow";
                } else if (pm.getGroup() != null) {
                    rp.section = Algorithms.capitalizeFirstLetter(pm.getGroup().replace('_', ' '));
                }
                if (pm.getType() == RoutingParameterType.BOOLEAN) {
                    rp.value = pm.getDefaultBoolean();
                } else {
                    if (pm.getType() == RoutingParameterType.NUMERIC) {
                        rp.value = 0;
                    } else {
                        rp.value = "";
                    }
                    rp.valueDescriptions = pm.getPossibleValueDescriptions();
                    rp.values = pm.getPossibleValues();
                }
                int lastIndex = -1;
                for (int i = 0; i < rps.size(); i++) {
                    if (Algorithms.objectEquals(rp.section, rps.get(i).section)) {
                        lastIndex = i;
                    }
                }
                if (lastIndex != -1 && !Algorithms.isEmpty(rp.section)) {
                    rps.add(lastIndex + 1, rp);
                } else {
                    rps.add(rp);
                }
            }
            for (RoutingParameter rp : rps) {
                rm.params.put(rp.key, rp);
            }
            rm.params.put(nativeRouting.key, nativeRouting);
            rm.params.put(nativeTrack.key, nativeTrack);
            rm.params.put(calcMode.key, calcMode);
        }
    }
    for (RoutingServerConfigEntry rs : osmAndMapsService.getRoutingConfig().config.values()) {
        RoutingMode rm = new RoutingMode();
        rm.key = rs.name;
        rm.name = Algorithms.capitalizeFirstLetter(rs.name).replace('_', ' ');
        routers.put(rm.key, rm);
        rm.params.put(nativeRouting.key, nativeRouting);
        rm.params.put(nativeTrack.key, nativeTrack);
    }
    return ResponseEntity.ok(gson.toJson(routers));
}
Also used : ArrayList(java.util.ArrayList) GeneralRouter(net.osmand.router.GeneralRouter) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) RoutingServerConfigEntry(net.osmand.server.api.services.OsmAndMapsService.RoutingServerConfigEntry) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

GeneralRouter (net.osmand.router.GeneralRouter)7 ArrayList (java.util.ArrayList)6 TLongArrayList (gnu.trove.list.array.TLongArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)2 RoutingParameter (net.osmand.router.GeneralRouter.RoutingParameter)2 Builder (net.osmand.router.RoutingConfiguration.Builder)2 CheckBoxPreference (android.preference.CheckBoxPreference)1 ListPreference (android.preference.ListPreference)1 Preference (android.preference.Preference)1 PreferenceCategory (android.preference.PreferenceCategory)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 TreeMap (java.util.TreeMap)1 Location (net.osmand.Location)1 LatLon (net.osmand.data.LatLon)1 LocationPoint (net.osmand.data.LocationPoint)1 ApplicationMode (net.osmand.plus.ApplicationMode)1 GPXUtilities (net.osmand.plus.GPXUtilities)1 OsmandSettings (net.osmand.plus.OsmandSettings)1