All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.standalone.config.routerequest.WheelchairConfig Maven / Gradle / Ivy

There is a newer version: 2.6.0
Show newest version
package org.opentripplanner.standalone.config.routerequest;

import static org.opentripplanner.routing.api.request.preference.WheelchairPreferences.DEFAULT;
import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V2_0;
import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V2_2;

import org.opentripplanner.routing.api.request.preference.AccessibilityPreferences;
import org.opentripplanner.routing.api.request.preference.WheelchairPreferences;
import org.opentripplanner.standalone.config.framework.json.NodeAdapter;

public class WheelchairConfig {

  static boolean wheelchairEnabled(NodeAdapter root, String parameterName) {
    return WheelchairConfig
      .wheelchairRoot(root, parameterName)
      .of("enabled")
      .since(V2_0)
      .summary("Enable wheelchair accessibility.")
      .asBoolean(false);
  }

  static WheelchairPreferences mapWheelchairPreferences(NodeAdapter root, String parameterName) {
    var a = wheelchairRoot(root, parameterName);

    return new WheelchairPreferences(
      mapAccessibilityPreferences(
        a
          .of("trip")
          .since(V2_2)
          .summary("Configuration for when to use inaccessible trips.")
          .asObject(),
        DEFAULT.trip()
      ),
      mapAccessibilityPreferences(
        a
          .of("stop")
          .since(V2_2)
          .summary("Configuration for when to use inaccessible stops.")
          .asObject(),
        DEFAULT.stop()
      ),
      mapAccessibilityPreferences(
        a
          .of("elevator")
          .since(V2_2)
          .summary("Configuration for when to use inaccessible elevators.")
          .asObject(),
        DEFAULT.elevator()
      ),
      a
        .of("inaccessibleStreetReluctance")
        .since(V2_2)
        .summary(
          "The factor to multiply the cost of traversing a street edge that is not wheelchair-accessible."
        )
        .asDouble(DEFAULT.inaccessibleStreetReluctance()),
      a
        .of("maxSlope")
        .since(V2_0)
        .summary("The maximum slope as a fraction of 1.")
        .description("9 percent would be `0.09`")
        .asDouble(DEFAULT.maxSlope()),
      a
        .of("slopeExceededReluctance")
        .since(V2_2)
        .summary("How much streets with high slope should be avoided.")
        .description(
          """
            What factor should be given to street edges, which are over the
            max slope. The penalty is not static but scales with how much you
            exceed the maximum slope. Set to negative to disable routing on
            too steep edges.
            """
        )
        .asDouble(DEFAULT.slopeExceededReluctance()),
      a
        .of("stairsReluctance")
        .since(V2_2)
        .summary("How much stairs should be avoided.")
        .description(
          """
            Stairs are not completely excluded for wheelchair users but
            severely punished. This value determines how much they are
            punished. This should be a very high value as you want to only
            include stairs as a last result."""
        )
        .asDouble(DEFAULT.stairsReluctance())
    );
  }

  static NodeAdapter wheelchairRoot(NodeAdapter root, String parameterName) {
    var a = root
      .of(parameterName)
      .since(V2_2)
      .summary("See [Wheelchair Accessibility](Accessibility.md)")
      .asObject();
    return a;
  }

  private static AccessibilityPreferences mapAccessibilityPreferences(
    NodeAdapter adapter,
    AccessibilityPreferences defaultValue
  ) {
    var onlyAccessible = adapter
      .of("onlyConsiderAccessible")
      .since(V2_2)
      .summary(
        "Whether to only use this entity if it is explicitly marked as wheelchair accessible."
      )
      .asBoolean(defaultValue.onlyConsiderAccessible());

    var unknownCost = adapter
      .of("unknownCost")
      .since(V2_2)
      .summary("The cost to add when traversing an entity with unknown accessibility information.")
      .asInt(60 * 10);
    var inaccessibleCost = adapter
      .of("inaccessibleCost")
      .since(V2_2)
      .summary("The cost to add when traversing an entity which is know to be inaccessible.")
      .asInt(60 * 60);
    if (onlyAccessible) {
      return AccessibilityPreferences.ofOnlyAccessible();
    } else {
      return AccessibilityPreferences.ofCost(unknownCost, inaccessibleCost);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy