コード例 #1
0
  @Override
  public double evaluate() {
    DeterministicMaxWorkTimeNodes wton = new DeterministicMaxWorkTimeNodes();

    int vehiType = -1;
    int departureNode, arrivalNode;
    double timeSpent = 0, speed;
    Request req;

    // each route
    for (Route r : Solution.getRoutes()) {
      vehiType = (r.isHasType() ? r.getType() : -1);
      if (Instance.getRequest(r.getRequests().get(0).getId()).getAttribute("serviceTime") != null)
        timeSpent +=
            ((DoubleValue)
                    Instance.getRequest(r.getRequests().get(0).getId())
                        .getAttribute("serviceTime")
                        .get(0))
                .getValue();

      for (int reqIndex = 1; reqIndex < r.getRequests().size(); reqIndex++) {
        req = r.getRequests().get(reqIndex);
        arrivalNode = req.getNodeId();
        departureNode = r.getRequests().get(reqIndex - 1).getNodeId();

        if (vehiType != -1)
          speed =
              wton.getSpeed(Instance.getVehicle(vehiType).getAttribute("speedProfile"), timeSpent);
        else
          speed =
              wton.getSpeed(Instance.getVehicle(vehiType).getAttribute("speedProfile"), timeSpent);
        timeSpent += DistanceCalculator.calculateDistance(departureNode, arrivalNode) / speed;
        if (Instance.getRequest(req.getId()).getAttribute("serviceTime") != null)
          timeSpent +=
              ((DoubleValue) Instance.getRequest(req.getId()).getAttribute("serviceTime").get(0))
                  .getValue();
      }
    }

    return timeSpent;
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * vrpRep.solutionChecker.constraint.IConstraint#evaluate(vrpRep.solutionChecker
   * .instance.DefaultInstance,
   * vrpRep.solutionChecker.solution.DefaultSolution)
   */
  @Override
  public ConstraintEvaluation checkConstraint() {
    cEval = new ConstraintEvaluation();
    VehicleCResult vcr;
    DeterministicCapacitySingleVehicleSingleProduct dcsvsp =
        new DeterministicCapacitySingleVehicleSingleProduct();

    // each route
    for (Route r : Solution.getRoutes()) {
      vcr = dcsvsp.new VehicleCResult(-1);

      // sum demands
      for (Request n : r.getRequests()) {
        if (n.getDemand().size() != 0) {
          for (Demand d : n.getDemand()) {
            vcr.addDemand(d.getId(), d.getDemand());
          }
        }
      }

      checkDemands(vcr);
    }
    return cEval;
  }