mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
Merge branch 'master' into relaxAPI
This commit is contained in:
commit
781bacb2d1
1 changed files with 25 additions and 8 deletions
|
|
@ -32,7 +32,15 @@ import basics.VehicleRoutingProblem;
|
||||||
import basics.route.VehicleRoute;
|
import basics.route.VehicleRoute;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* RuinStrategy that ruins the neighborhood of a randomly selected service. The size and the structure of the neighborhood is defined by
|
||||||
|
* the share of jobs to be removed and the distance between jobs (where distance not necessarily mean Euclidean distance but an arbitrary
|
||||||
|
* measure).
|
||||||
|
*
|
||||||
|
* @author stefan
|
||||||
|
*
|
||||||
|
*/
|
||||||
final class RuinRadial implements RuinStrategy {
|
final class RuinRadial implements RuinStrategy {
|
||||||
|
|
||||||
static class ReferencedJob {
|
static class ReferencedJob {
|
||||||
|
|
@ -72,21 +80,23 @@ final class RuinRadial implements RuinStrategy {
|
||||||
this.random = random;
|
this.random = random;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RuinRadial(VehicleRoutingProblem vrp, double fraction, JobDistance jobDistance) {
|
/**
|
||||||
|
* Constructs RuinRadial.
|
||||||
|
*
|
||||||
|
* @param vrp
|
||||||
|
* @param fraction2beRemoved i.e. the share of jobs to be removed (relative to the total number of jobs in vrp)
|
||||||
|
* @param jobDistance i.e. a measure to define the distance between two jobs and whether they are located close or distant to eachother
|
||||||
|
*/
|
||||||
|
public RuinRadial(VehicleRoutingProblem vrp, double fraction2beRemoved, JobDistance jobDistance) {
|
||||||
super();
|
super();
|
||||||
this.vrp = vrp;
|
this.vrp = vrp;
|
||||||
this.jobDistance = jobDistance;
|
this.jobDistance = jobDistance;
|
||||||
this.fractionOfAllNodes2beRuined = fraction;
|
this.fractionOfAllNodes2beRuined = fraction2beRemoved;
|
||||||
ruinListeners = new RuinListeners();
|
ruinListeners = new RuinListeners();
|
||||||
calculateDistancesFromJob2Job();
|
calculateDistancesFromJob2Job();
|
||||||
logger.info("intialise " + this);
|
logger.info("intialise " + this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRuinFraction(double fractionOfAllNodes) {
|
|
||||||
this.fractionOfAllNodes2beRuined = fractionOfAllNodes;
|
|
||||||
logger.info("fraction set " + this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void calculateDistancesFromJob2Job() {
|
private void calculateDistancesFromJob2Job() {
|
||||||
logger.info("preprocess distances between locations ...");
|
logger.info("preprocess distances between locations ...");
|
||||||
StopWatch stopWatch = new StopWatch();
|
StopWatch stopWatch = new StopWatch();
|
||||||
|
|
@ -122,6 +132,10 @@ final class RuinRadial implements RuinStrategy {
|
||||||
return "[name=radialRuin][fraction="+fractionOfAllNodes2beRuined+"]";
|
return "[name=radialRuin][fraction="+fractionOfAllNodes2beRuined+"]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ruins the collection of vehicleRoutes, i.e. removes a share of jobs. First, it selects a job randomly. Second, it identifies its neighborhood. And finally, it removes
|
||||||
|
* the neighborhood plus the randomly selected job from the number of vehicleRoutes. All removed jobs are then returned as a collection.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Collection<Job> ruin(Collection<VehicleRoute> vehicleRoutes) {
|
public Collection<Job> ruin(Collection<VehicleRoute> vehicleRoutes) {
|
||||||
if(vehicleRoutes.isEmpty()){
|
if(vehicleRoutes.isEmpty()){
|
||||||
|
|
@ -136,6 +150,9 @@ final class RuinRadial implements RuinStrategy {
|
||||||
return unassignedJobs;
|
return unassignedJobs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes targetJob and its neighborhood and returns the removed jobs.
|
||||||
|
*/
|
||||||
public Collection<Job> ruin(Collection<VehicleRoute> vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved){
|
public Collection<Job> ruin(Collection<VehicleRoute> vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved){
|
||||||
ruinListeners.ruinStarts(vehicleRoutes);
|
ruinListeners.ruinStarts(vehicleRoutes);
|
||||||
List<Job> unassignedJobs = new ArrayList<Job>();
|
List<Job> unassignedJobs = new ArrayList<Job>();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue