Class PercentSpeedCap

java.lang.Object
rgu.transport.util.PercentSpeedCap

public final class PercentSpeedCap extends Object

Can apply a speed cap and default speed to a graph. The maximum speed is specified for a predicate, and all edges for which one or both vertices test true will be limited to the given speed.

The maximum speed edges are set to the cap if the original value was over, and all other edges are reduced by the same percentage. If the original maximum in the graph was under the stated maximum, then no edges are reduced. Any edges which did have any specified speed will be set to the minimum resulting speed of any other edge.

Edges which are not inside the predicate will be capped to a maximum speed of the minimum speed within any of the predicates.

If predicates overlap, then the first one added takes priority.

  • Constructor Details

    • PercentSpeedCap

      public PercentSpeedCap(Graph<GeoLocation, RoadEdge> graph)
      Creates an instance of percent speed cap.
      Parameters:
      graph - the graph, not null
  • Method Details

    • add

      public void add(String name, Predicate<GeoLocation> predicate, Speed maximum)
      Adds a predicate with a speed cap.
      Parameters:
      name - the name, not empty, not null, unique
      predicate - the predicate for vertices, not null
      maximum - the maximum for the predicate, >= 0
    • apply

      public Graph<GeoLocation, RoadEdge> apply()
      Applies the speed cap to the given graph, returning a new speed-capped graph.
      Returns:
      the speed-capped graph
    • apply

      public Graph<GeoLocation, RoadEdge> apply(boolean verbose)
      Applies the speed cap to the given graph, returning a new speed-capped graph.
      Parameters:
      verbose - if true, extra information will be printed to STDOUT.
      Returns:
      the speed-capped graph