-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68b36e0
commit 74d451d
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
.../src/main/java/org/kalasim/examples/taxiinc/vehiclerouting/SimpleVRPVariableListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package org.kalasim.examples.taxiinc.vehiclerouting; | ||
|
||
import org.kalasim.examples.taxiinc.vehiclerouting.domain.Customer; | ||
import org.kalasim.examples.taxiinc.vehiclerouting.domain.VehicleRoutingSolution; | ||
import org.kalasim.examples.taxiinc.vehiclerouting.domain.timewindowed.TimeWindowedCustomer; | ||
import org.kalasim.examples.taxiinc.vehiclerouting.domain.timewindowed.TimeWindowedDepot; | ||
import org.optaplanner.core.api.domain.variable.VariableListener; | ||
import org.optaplanner.core.api.score.director.ScoreDirector; | ||
|
||
import java.util.Objects; | ||
|
||
// TODO When this class is added only for TimeWindowedCustomer, use TimeWindowedCustomer instead of Customer | ||
public class SimpleVRPVariableListener implements VariableListener<VehicleRoutingSolution, Customer> { | ||
|
||
@Override | ||
public void beforeEntityAdded(ScoreDirector<VehicleRoutingSolution> scoreDirector, Customer customer) { | ||
// Do nothing | ||
} | ||
|
||
@Override | ||
public void afterEntityAdded(ScoreDirector<VehicleRoutingSolution> scoreDirector, Customer customer) { | ||
updateArrivalTime(scoreDirector, customer); | ||
} | ||
|
||
@Override | ||
public void beforeVariableChanged(ScoreDirector<VehicleRoutingSolution> scoreDirector, Customer customer) { | ||
// Do nothing | ||
} | ||
|
||
@Override | ||
public void afterVariableChanged(ScoreDirector<VehicleRoutingSolution> scoreDirector, Customer customer) { | ||
updateArrivalTime(scoreDirector, customer); | ||
} | ||
|
||
@Override | ||
public void beforeEntityRemoved(ScoreDirector<VehicleRoutingSolution> scoreDirector, Customer customer) { | ||
// Do nothing | ||
} | ||
|
||
@Override | ||
public void afterEntityRemoved(ScoreDirector<VehicleRoutingSolution> scoreDirector, Customer customer) { | ||
// Do nothing | ||
} | ||
|
||
protected void updateArrivalTime(ScoreDirector<VehicleRoutingSolution> scoreDirector, | ||
Customer customer) { | ||
|
||
if (customer.getVehicle() == null) { | ||
if (customer.routePostion != null) { | ||
scoreDirector.beforeVariableChanged(customer, "routePostion"); | ||
customer.routePostion = null; | ||
scoreDirector.afterVariableChanged(customer, "routePostion"); | ||
} | ||
|
||
return; | ||
}else{ | ||
customer.routePostion = 10; | ||
} | ||
|
||
Customer previousCustomer = customer.getPreviousCustomer(); | ||
|
||
// Long departureTime; | ||
// if (previousCustomer == null) { | ||
// departureTime = ((TimeWindowedDepot) customer.getVehicle().getDepot()).getReadyTime(); | ||
// } else { | ||
// departureTime = ((TimeWindowedCustomer) previousCustomer).getDepartureTime(); | ||
// } | ||
// Customer shadowCustomer = customer; | ||
// | ||
// Long arrivalTime = calculateArrivalTime(shadowCustomer, departureTime); | ||
// | ||
// while (shadowCustomer != null && !Objects.equals(shadowCustomer.getArrivalTime(), arrivalTime)) { | ||
// scoreDirector.beforeVariableChanged(shadowCustomer, "arrivalTime"); | ||
// shadowCustomer.setArrivalTime(arrivalTime); | ||
// scoreDirector.afterVariableChanged(shadowCustomer, "arrivalTime"); | ||
// departureTime = shadowCustomer.getDepartureTime(); | ||
// shadowCustomer = (TimeWindowedCustomer) shadowCustomer.getNextCustomer(); | ||
// arrivalTime = calculateArrivalTime(shadowCustomer, departureTime); | ||
// } | ||
} | ||
|
||
private Long calculateArrivalTime(TimeWindowedCustomer customer, Long previousDepartureTime) { | ||
if (customer == null || previousDepartureTime == null) { | ||
return null; | ||
} | ||
return previousDepartureTime + customer.getDistanceFromPreviousStandstill(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters