/** * Check if a {@linkplain TRSPShiftMove shift move} is feasible for the given <code>solution * </code> * * @param solution the base solution * @param move the {@link TRSPShiftMove} to be tested * @return <code>true</code> if applying <code>move</code> to the given <code>solution</code> will * result in a feasible mSolution */ @Override public boolean isShiftFeasible(ITRSPTour itour, TRSPShiftMove move) { if (!TRSPTour.class.isAssignableFrom(itour.getClass())) { TRSPLogging.getOptimizationLogger() .warn( String.format( "ToolsConstraint.isShiftFeasible: unsupported tour class (%s)", itour.getClass())); return true; } TRSPTour tour = (TRSPTour) itour; if (!tour.isMainDepotVisited()) { // The main depot is not visited, we assume that the tour is and will remain feasible return true; } else { // The main depot is visited if (move.getNode() == tour.getMainDepotId()) { // The shifted node is the main depot if (!move.isForward()) { // A backward move of the main depot is always feasible return true; } else { // Check if the requests between the current depot position and its new one require a // visit to // the depot to be served List<Integer> seq = move.getChangedSequence(); for (int s : seq) { if (s == tour.getMainDepotId()) // The requests after the main depot will be feasible return true; else if (!tour.getInstance().hasRequiredTools(tour.getTechnician().getID(), s)) // This request will be before the depot visit but the technician does not have the // required // skills return false; } throw new IllegalStateException( "Illegal state when checking the feasibility of move " + move); } } else { if (tour.getInstance().hasRequiredTools(tour.getTechnician().getID(), move.getNode())) // The technician already has the tools to serve the shifted node, the move is feasible in // all cases return true; int pred = move.getNewSucc() != ITRSPTour.UNDEFINED ? tour.getPred(move.getNewSucc()) : tour.getLastNode(); if (tour.isMainDepotVisited(move.getNode()) == tour.isMainDepotVisited(pred)) { // Both the shifted node and its new predecessor are on the same "side" of the tour // (either before // or after the depot visit), the move is therefore feasible return true; } else { // The shifted node and its new predecessor are on different "side" of the tour (one is // before // while the other is after the depot visit) if (move.isForward()) { // The node will be after the depot visit, the move is therefore feasible return true; } else { // The node is shifted before the depot visit, while the technician does not have the // required // tools (tested before) return false; } } } } }