Пример #1
0
  private State pickupAction(Order order) {
    ArrayList<Order> orders = new ArrayList<>();

    Truck newTruck =
        new Truck(
            this.truck.getID(),
            this.truck.getCurrentNode(),
            this.truck.getTruckCapacity(),
            this.truck.getOrders());

    for (Order tmpOrder : this.orders) {
      if (order.getId() == tmpOrder.getId())
        orders.add(
            new Order(
                tmpOrder.getLocation(),
                tmpOrder.getDestination(),
                true,
                false,
                null,
                tmpOrder.getId(),
                tmpOrder.getVolume()));
      else
        orders.add(
            new Order(
                tmpOrder.getLocation(),
                tmpOrder.getDestination(),
                tmpOrder.isPickedUp(),
                tmpOrder.isDelivered(),
                tmpOrder.getDroppedIn(),
                tmpOrder.getId(),
                tmpOrder.getVolume()));
    }

    return new State(
        orders,
        this.gScore,
        newTruck,
        this,
        "Picked up an order with id "
            + order.getId()
            + ". Node is "
            + newTruck.getCurrentNode().getId());
  }
Пример #2
0
  private State deliverAction() {
    ArrayList<Order> orders = new ArrayList<>();
    Truck newTruck =
        new Truck(
            this.truck.getID(),
            this.truck.getCurrentNode(),
            this.truck.getTruckCapacity(),
            this.truck.getOrders());
    int count = 0;

    for (Order order : this.orders)
      if (order.getDestination().equals(this.truck.getCurrentNode())
          && !order.isDelivered()
          && order.isPickedUp()) {
        orders.add(
            new Order(
                order.getLocation(),
                order.getDestination(),
                true,
                true,
                this.truck.getCurrentNode(),
                order.getId(),
                order.getVolume()));
        count++;
      } else
        orders.add(
            new Order(
                order.getLocation(),
                order.getDestination(),
                order.isPickedUp(),
                order.isDelivered(),
                order.getDroppedIn(),
                order.getId(),
                order.getVolume()));

    return new State(
        orders,
        this.gScore,
        newTruck,
        this,
        "Delivered " + String.valueOf(count) + " orders at " + newTruck.getCurrentNode().getId());
  }