private Capacity getCurrentMaxLoadInRoute(VehicleRoute route) {
   Capacity maxLoad = stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class);
   if (maxLoad == null) maxLoad = Capacity.Builder.newInstance().build();
   return maxLoad;
 }
Esempio n. 2
0
  @Before
  public void doBefore() {
    Vehicle vehicle = mock(Vehicle.class);
    VehicleType type = mock(VehicleType.class);
    when(type.getCapacityDimensions())
        .thenReturn(Capacity.Builder.newInstance().addDimension(0, 20).build());
    when(vehicle.getType()).thenReturn(type);

    VehicleRoutingProblem.Builder serviceProblemBuilder =
        VehicleRoutingProblem.Builder.newInstance();
    Service s1 =
        Service.Builder.newInstance("s").addSizeDimension(0, 10).setLocationId("loc").build();
    Service s2 =
        Service.Builder.newInstance("s2").addSizeDimension(0, 5).setLocationId("loc").build();
    serviceProblemBuilder.addJob(s1).addJob(s2);
    final VehicleRoutingProblem serviceProblem = serviceProblemBuilder.build();

    final VehicleRoutingProblem.Builder pdProblemBuilder =
        VehicleRoutingProblem.Builder.newInstance();
    Pickup pickup =
        (Pickup)
            Pickup.Builder.newInstance("pick").addSizeDimension(0, 10).setLocationId("loc").build();
    Delivery delivery =
        (Delivery)
            Delivery.Builder.newInstance("del").addSizeDimension(0, 5).setLocationId("loc").build();
    pdProblemBuilder.addJob(pickup).addJob(delivery);
    final VehicleRoutingProblem pdProblem = pdProblemBuilder.build();

    final VehicleRoutingProblem.Builder shipmentProblemBuilder =
        VehicleRoutingProblem.Builder.newInstance();
    Shipment shipment1 =
        Shipment.Builder.newInstance("s1")
            .addSizeDimension(0, 10)
            .setPickupLocation("pick")
            .setDeliveryLocation("del")
            .build();
    Shipment shipment2 =
        Shipment.Builder.newInstance("s2")
            .addSizeDimension(0, 5)
            .setPickupLocation("pick")
            .setDeliveryLocation("del")
            .build();
    shipmentProblemBuilder.addJob(shipment1).addJob(shipment2).build();
    final VehicleRoutingProblem shipmentProblem = shipmentProblemBuilder.build();

    VehicleRoute.Builder serviceRouteBuilder = VehicleRoute.Builder.newInstance(vehicle);
    serviceRouteBuilder.setJobActivityFactory(
        new JobActivityFactory() {

          @Override
          public List<AbstractActivity> createActivities(Job job) {
            return serviceProblem.copyAndGetActivities(job);
          }
        });
    serviceRoute = serviceRouteBuilder.addService(s1).addService(s2).build();

    VehicleRoute.Builder pdRouteBuilder = VehicleRoute.Builder.newInstance(vehicle);
    pdRouteBuilder.setJobActivityFactory(
        new JobActivityFactory() {
          @Override
          public List<AbstractActivity> createActivities(Job job) {
            return pdProblem.copyAndGetActivities(job);
          }
        });
    pickup_delivery_route = pdRouteBuilder.addService(pickup).addService(delivery).build();

    VehicleRoute.Builder shipmentRouteBuilder = VehicleRoute.Builder.newInstance(vehicle);
    shipmentRouteBuilder.setJobActivityFactory(
        new JobActivityFactory() {
          @Override
          public List<AbstractActivity> createActivities(Job job) {
            return shipmentProblem.copyAndGetActivities(job);
          }
        });
    shipment_route =
        shipmentRouteBuilder
            .addPickup(shipment1)
            .addPickup(shipment2)
            .addDelivery(shipment2)
            .addDelivery(shipment1)
            .build();

    stateManager = new StateManager(mock(VehicleRoutingProblem.class));
    stateManager.updateLoadStates();
  }
Esempio n. 3
0
  /**
   * Builder that builds the vehicle-type.
   *
   * @author schroeder
   */
  public static class Builder {

    public static VehicleTypeImpl.Builder newInstance(String id) {
      if (id == null) throw new IllegalStateException();
      return new Builder(id);
    }

    private String id;
    private int capacity = 0;
    private double maxVelo = Double.MAX_VALUE;
    /** default cost values for default vehicle type */
    private double fixedCost = 0.0;

    private double perDistance = 1.0;
    private double perTime = 0.0;
    private double perWaitingTime = 0.0;
    private double perServiceTime = 0.0;

    private String profile = "car";

    private Capacity.Builder capacityBuilder = Capacity.Builder.newInstance();

    private Capacity capacityDimensions = null;

    private boolean dimensionAdded = false;

    private Builder(String id) {
      this.id = id;
    }

    /**
     * Sets the maximum velocity this vehicle-type can go [in meter per seconds].
     *
     * @param inMeterPerSeconds
     * @return this builder
     * @throws IllegalStateException if velocity is smaller than zero
     */
    public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds) {
      if (inMeterPerSeconds < 0.0)
        throw new IllegalStateException("velocity cannot be smaller than zero");
      this.maxVelo = inMeterPerSeconds;
      return this;
    }

    /**
     * Sets the fixed costs of the vehicle-type.
     *
     * <p>
     *
     * <p>by default it is 0.
     *
     * @param fixedCost
     * @return this builder
     * @throws IllegalStateException if fixedCost is smaller than zero
     */
    public VehicleTypeImpl.Builder setFixedCost(double fixedCost) {
      if (fixedCost < 0.0)
        throw new IllegalStateException("fixed costs cannot be smaller than zero");
      this.fixedCost = fixedCost;
      return this;
    }

    /**
     * Sets the cost per distance unit, for instance € per meter.
     *
     * <p>
     *
     * <p>by default it is 1.0
     *
     * @param perDistance
     * @return this builder
     * @throws IllegalStateException if perDistance is smaller than zero
     */
    public VehicleTypeImpl.Builder setCostPerDistance(double perDistance) {
      if (perDistance < 0.0)
        throw new IllegalStateException("cost per distance must not be smaller than zero");
      this.perDistance = perDistance;
      return this;
    }

    /**
     * Sets cost per time unit, for instance € per second.
     *
     * <p>
     *
     * <p>by default it is 0.0
     *
     * @param perTime
     * @return this builder
     * @throws IllegalStateException if costPerTime is smaller than zero
     * @deprecated use .setCostPerTransportTime(..) instead
     */
    @Deprecated
    public VehicleTypeImpl.Builder setCostPerTime(double perTime) {
      if (perTime < 0.0) throw new IllegalStateException();
      this.perTime = perTime;
      return this;
    }

    /**
     * Sets cost per time unit, for instance € per second.
     *
     * <p>
     *
     * <p>by default it is 0.0
     *
     * @param perTime
     * @return this builder
     * @throws IllegalStateException if costPerTime is smaller than zero
     */
    public VehicleTypeImpl.Builder setCostPerTransportTime(double perTime) {
      if (perTime < 0.0) throw new IllegalStateException();
      this.perTime = perTime;
      return this;
    }

    /**
     * Sets cost per waiting time unit, for instance € per second.
     *
     * <p>
     *
     * <p>by default it is 0.0
     *
     * @param perWaitingTime
     * @return this builder
     * @throws IllegalStateException if costPerTime is smaller than zero
     */
    public VehicleTypeImpl.Builder setCostPerWaitingTime(double perWaitingTime) {
      if (perWaitingTime < 0.0) throw new IllegalStateException();
      this.perWaitingTime = perWaitingTime;
      return this;
    }

    public VehicleTypeImpl.Builder setCostPerServiceTime(double perServiceTime) {
      if (perServiceTime < 0.0) throw new IllegalStateException();
      this.perServiceTime = perServiceTime;
      return this;
    }

    /**
     * Builds the vehicle-type.
     *
     * @return VehicleTypeImpl
     */
    public VehicleTypeImpl build() {
      if (capacityDimensions == null) {
        capacityDimensions = capacityBuilder.build();
      }
      return new VehicleTypeImpl(this);
    }

    /**
     * Adds a capacity dimension.
     *
     * @param dimIndex
     * @param dimVal
     * @return the builder
     * @throws IllegalArgumentException if dimVal < 0
     * @throws IllegalStateException if capacity dimension is already set
     */
    public Builder addCapacityDimension(int dimIndex, int dimVal) {
      if (dimVal < 0) throw new IllegalArgumentException("capacity value cannot be negative");
      if (capacityDimensions != null)
        throw new IllegalStateException(
            "either build your dimension with build your dimensions with "
                + "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)."
                + "You used both methods.");
      dimensionAdded = true;
      capacityBuilder.addDimension(dimIndex, dimVal);
      return this;
    }

    /**
     * Sets capacity dimensions.
     *
     * <p>
     *
     * <p>Note if you use this you cannot use <code>addCapacityDimension(int dimIndex, int dimVal)
     * </code> anymore. Thus either build your dimensions with <code>
     * addCapacityDimension(int dimIndex, int dimVal)</code> or set the already built dimensions
     * with this method.
     *
     * @param capacity
     * @return this builder
     * @throws IllegalStateException if capacityDimension has already been added
     */
    public Builder setCapacityDimensions(Capacity capacity) {
      if (dimensionAdded)
        throw new IllegalStateException(
            "either build your dimension with build your dimensions with "
                + "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)."
                + "You used both methods.");
      this.capacityDimensions = capacity;
      return this;
    }

    public Builder setProfile(String profile) {
      this.profile = profile;
      return this;
    }
  }