Example #1
0
 /**
  * This function make the move on the solution and updates the originalPosition to be able to undo
  * quickly
  *
  * @param solution
  */
 public void operateOn(Solution solution) {
   MySolution sol = (MySolution) solution;
   Route insertRoute = sol.getRoute(insertRouteNr);
   Route deleteRoute = sol.getRoute(deleteRouteNr);
   Cost initialInsertCost = new Cost(insertRoute.getCost());
   Cost initialDeleteCost = new Cost(deleteRoute.getCost());
   evaluateDeleteRoute(deleteRoute, customer, deletePositionIndex);
   evaluateInsertRoute(insertRoute, customer, insertPositionIndex);
   evaluateTotalCostVariation(sol, this, initialInsertCost, initialDeleteCost);
 } // end operateOn
Example #2
0
 private void evaluateTotalCostVariation(
     MySolution sol, MySwapMove move, Cost initialInsertCost, Cost initialDeleteCost) {
   Route insertRoute = sol.getRoute(move.getInsertRouteNr());
   Route deleteRoute = sol.getRoute(move.getDeleteRouteNr());
   sol.addTravelTime(
       -initialInsertCost.travelTime
           - initialDeleteCost.travelTime
           + deleteRoute.getCost().travelTime
           + insertRoute.getCost().travelTime);
   sol.addServiceTime(
       -initialInsertCost.serviceTime
           - initialDeleteCost.serviceTime
           + deleteRoute.getCost().serviceTime
           + insertRoute.getCost().serviceTime);
   sol.addWaitingTime(
       -initialInsertCost.waitingTime
           - initialDeleteCost.waitingTime
           + deleteRoute.getCost().waitingTime
           + insertRoute.getCost().waitingTime);
   sol.getCost().loadViol +=
       -initialInsertCost.loadViol
           - initialDeleteCost.loadViol
           + deleteRoute.getCost().loadViol
           + insertRoute.getCost().loadViol;
   sol.getCost().twViol +=
       -initialInsertCost.twViol
           - initialDeleteCost.twViol
           + deleteRoute.getCost().twViol
           + insertRoute.getCost().twViol;
   sol.getCost().waitingTime =
       Math.abs(sol.getCost().waitingTime) < instance.getPrecision()
           ? 0
           : sol.getCost().waitingTime;
   sol.getCost().loadViol =
       Math.abs(sol.getCost().loadViol) < instance.getPrecision() ? 0 : sol.getCost().loadViol;
   sol.getCost().twViol =
       Math.abs(sol.getCost().twViol) < instance.getPrecision() ? 0 : sol.getCost().twViol;
   sol.getCost().calculateTotal(sol.getAlpha(), sol.getBeta(), sol.getGamma());
 }