Beispiel #1
0
  /*
   * (non-Javadoc)
   *
   * @see
   * vroom.common.heuristics.GenericNeighborhood#evaluateCandidateMove(vroom.
   * common.heuristics.Move)
   */
  @Override
  protected double evaluateCandidateMove(TwoOptMove cand) {
    CostCalculationDelegate costHelper = cand.mSolution.getParentInstance().getCostDelegate();
    Vehicle v1 = cand.mSolution.getRoute(cand.getRouteI()).getVehicle();
    Vehicle v2 = cand.mSolution.getRoute(cand.getRouteJ()).getVehicle();

    INodeVisit a = cand.mSolution.getRoute(cand.getRouteI()).getNodeAt(cand.getI());
    INodeVisit b = cand.mSolution.getRoute(cand.getRouteI()).getNodeAt(cand.getI() + 1);
    INodeVisit c = cand.mSolution.getRoute(cand.getRouteJ()).getNodeAt(cand.getJ());
    INodeVisit d = cand.mSolution.getRoute(cand.getRouteJ()).getNodeAt(cand.getJ() + 1);

    double improv = 0;
    boolean star = false;

    // 2-opt intra/inter-route
    // nodeI (a) linked with nodeJ (c)
    // nodeI+1 (b) linked with nodeJ+1 (d)
    improv =
        -costHelper.getCost(a, c, v1)
            - costHelper.getCost(b, d, v2)
            + costHelper.getCost(a, b, v1)
            + costHelper.getCost(c, d, v2);

    if (cand.getRouteI() != cand.getRouteJ()) {
      // special 2-opt*
      // nodeI (a) linked with nodeJ+1 (d)
      // nodeI+1 (b) linked with nodeJ (c)
      double improvStar =
          -costHelper.getCost(a, d, v1)
              - costHelper.getCost(b, c, v2)
              + costHelper.getCost(a, b, v1)
              + costHelper.getCost(c, d, v2);
      if (improvStar > improv) {
        improv = improvStar;
        star = true;
      }
    }

    cand.setStar(star);
    return improv;
  }
Beispiel #2
0
  /**
   * Compute the (best) 2-opt move defined by the arcs <code>(nodeI,nodeI+1)</code> in route <code>
   * rJ</code> and <code>(nodeJ,nodeJ+1)</code> in route <code>rJ</code>
   *
   * @param mSolution
   * @param rI
   * @param rJ
   * @param nodeI
   * @param nodeJ
   * @return the (best) 2-opt move for the given routes and nodes
   */
  protected TwoOptMove newMove(IVRPSolution<?> solution, int rI, int rJ, int i, int j) {
    CostCalculationDelegate costHelper = solution.getParentInstance().getCostDelegate();
    Vehicle v1 = solution.getRoute(rI).getVehicle();
    Vehicle v2 = solution.getRoute(rJ).getVehicle();

    INodeVisit a = solution.getRoute(rI).getNodeAt(i);
    INodeVisit b = solution.getRoute(rI).getNodeAt(i + 1);
    INodeVisit c = solution.getRoute(rJ).getNodeAt(j);
    INodeVisit d = solution.getRoute(rJ).getNodeAt(j + 1);

    double improv = 0;
    boolean star = false;

    // 2-opt intra/inter-route
    // nodeI (a) linked with nodeJ (c)
    // nodeI+1 (b) linked with nodeJ+1 (d)
    improv =
        -costHelper.getCost(a, c, v1)
            - costHelper.getCost(b, d, v2)
            + costHelper.getCost(a, b, v1)
            + costHelper.getCost(c, d, v2);

    if (rI != rJ) {
      // special 2-opt*
      // nodeI (a) linked with nodeJ+1 (d)
      // nodeI+1 (b) linked with nodeJ (c)
      double improvStar =
          -costHelper.getCost(a, d, v1)
              - costHelper.getCost(b, c, v2)
              + costHelper.getCost(a, b, v1)
              + costHelper.getCost(c, d, v2);
      if (improvStar > improv) {
        improv = improvStar;
        star = true;
      }
    }

    return new TwoOptMove(improv, solution, rI, rJ, i, j, star);
  }