Beispiel #1
0
 public State(ArrayList<Order> orders, int gScore, Truck truck, State origin) {
   this.orders = orders;
   this.gScore = gScore;
   this.truck = truck;
   this.origin = origin;
   this.currentNode = truck.getCurrentNode();
   this.stateMessage = null;
 }
Beispiel #2
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());
  }
Beispiel #3
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());
  }
Beispiel #4
0
  private State followRouteAction(Road road, Truck truck) {
    Node2 finalNode;
    ArrayList<Order> orders = new ArrayList<>(this.orders);
    if (truck.getCurrentNode().equals(road.getStart())) finalNode = road.getEnd();
    else finalNode = road.getStart();

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

    return new State(
        orders,
        this.gScore + road.getWeight(),
        newTruck,
        this,
        "Followed road to "
            + newTruck.getCurrentNode().getId()
            + "("
            + newTruck.getCurrentNode().getName()
            + ").");
  }
Beispiel #5
0
  private ArrayList<State> extractPickupTransitions() {
    ArrayList<State> states = new ArrayList<>();

    int totalVolume = 0;
    for (Order order : orders)
      if (order.isPickedUp() && !order.isDelivered()) totalVolume += order.getVolume();

    if (totalVolume < truck.getTruckCapacity()) {
      orders
          .stream()
          .filter(
              order ->
                  order.getLocation().equals(currentNode)
                      && !order.isPickedUp()
                      && !order.isDelivered())
          .forEach(
              order -> {
                State pickupState = pickupAction(order);
                states.add(pickupState);
              });
    }

    return states;
  }