Ejemplo n.º 1
0
  public double cost() {
    double totalCost = 0;
    for (MyVehicle v : vehicleActions.keySet()) {
      City c = v.homeCity();
      long vehicleDistanceSum = 0;
      for (Action action : vehicleActions.get(v)) {
        vehicleDistanceSum += c.distanceUnitsTo(action.getCity());
        c = action.getCity();
      }
      double vehicleCost = Measures.unitsToKM(vehicleDistanceSum * v.costPerKm());
      totalCost += vehicleCost;
    }

    return totalCost;
  }
Ejemplo n.º 2
0
 public boolean appendTaskToBiggestMyVehicle(Task t) {
   MyVehicle biggestMyVehicle = domainVal.vehicles.get(0);
   for (MyVehicle v : domainVal.vehicles) {
     if (biggestMyVehicle.capacity() < v.capacity()) {
       biggestMyVehicle = v;
     }
   }
   if (biggestMyVehicle.capacity() < t.weight) {
     return false;
   } else {
     appendActionForMyVehicle(new Action(Type.PICKUP, t), biggestMyVehicle);
     appendActionForMyVehicle(new Action(Type.DELIVERY, t), biggestMyVehicle);
     return true;
   }
 }
Ejemplo n.º 3
0
  public Plan getPlanForMyVehicle(int index) {
    MyVehicle v = domainVal.vehicles.get(index);
    City currentCity = v.homeCity();
    Plan plan = new Plan(currentCity);

    for (Action a : vehicleActions.get(v)) {
      City destination = a.getCity();

      for (City c : currentCity.pathTo(destination)) {
        plan.appendMove(c);
      }

      if (a.type == Type.PICKUP) plan.appendPickup(a.task);
      else plan.appendDelivery(a.task);

      currentCity = destination;
    }

    return plan;
  }