mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
refactor RuinRadial and RuinRandom
This commit is contained in:
parent
e2ab285d01
commit
d9391c6d45
3 changed files with 28 additions and 31 deletions
|
|
@ -29,8 +29,6 @@ import util.RandomNumberGeneration;
|
||||||
import util.StopWatch;
|
import util.StopWatch;
|
||||||
import basics.Job;
|
import basics.Job;
|
||||||
import basics.VehicleRoutingProblem;
|
import basics.VehicleRoutingProblem;
|
||||||
import basics.VehicleRoutingProblemSolution;
|
|
||||||
import basics.algo.SearchStrategyModule;
|
|
||||||
import basics.route.VehicleRoute;
|
import basics.route.VehicleRoute;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -49,7 +47,7 @@ final class RuinRadial implements RuinStrategy {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static RuinRadial newInstance(VehicleRoutingProblem vrp, double fraction, JobDistance jobDistance, JobRemover jobRemover, VehicleRouteUpdater routeUpdater){
|
static RuinRadial newInstance(VehicleRoutingProblem vrp, double fraction, JobDistance jobDistance, JobRemover jobRemover, VehicleRouteUpdater routeUpdater){
|
||||||
return new RuinRadial(vrp, fraction, jobDistance, jobRemover, routeUpdater);
|
return new RuinRadial(vrp, fraction, jobDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -92,12 +90,10 @@ final class RuinRadial implements RuinStrategy {
|
||||||
this.random = random;
|
this.random = random;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RuinRadial(VehicleRoutingProblem vrp, double fraction, JobDistance jobDistance, JobRemover jobRemover, VehicleRouteUpdater routeUpdater) {
|
public RuinRadial(VehicleRoutingProblem vrp, double fraction, JobDistance jobDistance) {
|
||||||
super();
|
super();
|
||||||
this.vrp = vrp;
|
this.vrp = vrp;
|
||||||
this.jobDistance = jobDistance;
|
this.jobDistance = jobDistance;
|
||||||
this.jobRemover = jobRemover;
|
|
||||||
this.routeUpdater = routeUpdater;
|
|
||||||
this.fractionOfAllNodes2beRuined = fraction;
|
this.fractionOfAllNodes2beRuined = fraction;
|
||||||
calculateDistancesFromJob2Job();
|
calculateDistancesFromJob2Job();
|
||||||
logger.info("intialise " + this);
|
logger.info("intialise " + this);
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ import basics.route.VehicleRoute;
|
||||||
final class RuinRandom implements RuinStrategy {
|
final class RuinRandom implements RuinStrategy {
|
||||||
|
|
||||||
public static RuinRandom newInstance(VehicleRoutingProblem vrp, double fraction, JobRemover jobRemover, VehicleRouteUpdater routeUpdater){
|
public static RuinRandom newInstance(VehicleRoutingProblem vrp, double fraction, JobRemover jobRemover, VehicleRouteUpdater routeUpdater){
|
||||||
return new RuinRandom(vrp, fraction, jobRemover, routeUpdater);
|
return new RuinRandom(vrp, fraction);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Logger logger = Logger.getLogger(RuinRandom.class);
|
private Logger logger = Logger.getLogger(RuinRandom.class);
|
||||||
|
|
@ -48,10 +48,6 @@ final class RuinRandom implements RuinStrategy {
|
||||||
|
|
||||||
private Random random = RandomNumberGeneration.getRandom();
|
private Random random = RandomNumberGeneration.getRandom();
|
||||||
|
|
||||||
private JobRemover jobRemover;
|
|
||||||
|
|
||||||
private VehicleRouteUpdater vehicleRouteUpdater;
|
|
||||||
|
|
||||||
public void setRandom(Random random) {
|
public void setRandom(Random random) {
|
||||||
this.random = random;
|
this.random = random;
|
||||||
}
|
}
|
||||||
|
|
@ -61,14 +57,10 @@ final class RuinRandom implements RuinStrategy {
|
||||||
*
|
*
|
||||||
* @param vrp
|
* @param vrp
|
||||||
* @param fraction which is the fraction of total c
|
* @param fraction which is the fraction of total c
|
||||||
* @param jobRemover
|
|
||||||
* @param vehicleRouteUpdater
|
|
||||||
*/
|
*/
|
||||||
public RuinRandom(VehicleRoutingProblem vrp, double fraction, JobRemover jobRemover, VehicleRouteUpdater vehicleRouteUpdater) {
|
public RuinRandom(VehicleRoutingProblem vrp, double fraction) {
|
||||||
super();
|
super();
|
||||||
this.vrp = vrp;
|
this.vrp = vrp;
|
||||||
this.jobRemover = jobRemover;
|
|
||||||
this.vehicleRouteUpdater = vehicleRouteUpdater;
|
|
||||||
this.fractionOfAllNodes2beRuined = fraction;
|
this.fractionOfAllNodes2beRuined = fraction;
|
||||||
logger.info("initialise " + this);
|
logger.info("initialise " + this);
|
||||||
logger.info("done");
|
logger.info("done");
|
||||||
|
|
@ -81,9 +73,11 @@ final class RuinRandom implements RuinStrategy {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Collection<Job> ruin(Collection<VehicleRoute> vehicleRoutes) {
|
public Collection<Job> ruin(Collection<VehicleRoute> vehicleRoutes) {
|
||||||
|
|
||||||
List<Job> unassignedJobs = new ArrayList<Job>();
|
List<Job> unassignedJobs = new ArrayList<Job>();
|
||||||
int nOfJobs2BeRemoved = selectNuOfJobs2BeRemoved();
|
int nOfJobs2BeRemoved = selectNuOfJobs2BeRemoved();
|
||||||
ruin(vehicleRoutes, nOfJobs2BeRemoved, unassignedJobs);
|
ruin(vehicleRoutes, nOfJobs2BeRemoved, unassignedJobs);
|
||||||
|
|
||||||
return unassignedJobs;
|
return unassignedJobs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,19 +86,22 @@ final class RuinRandom implements RuinStrategy {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Collection<Job> ruin(Collection<VehicleRoute> vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved) {
|
public Collection<Job> ruin(Collection<VehicleRoute> vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved) {
|
||||||
|
ruinStarts(vehicleRoutes);
|
||||||
List<Job> unassignedJobs = new ArrayList<Job>();
|
List<Job> unassignedJobs = new ArrayList<Job>();
|
||||||
if(targetJob != null){
|
if(targetJob != null){
|
||||||
boolean removed = false;
|
boolean removed = false;
|
||||||
for (VehicleRoute route : vehicleRoutes) {
|
for (VehicleRoute route : vehicleRoutes) {
|
||||||
removed = jobRemover.removeJobWithoutTourUpdate(targetJob, route);
|
removed = route.getTourActivities().removeJob(targetJob);
|
||||||
if (removed) {
|
if (removed) {
|
||||||
nOfJobs2BeRemoved--;
|
nOfJobs2BeRemoved--;
|
||||||
unassignedJobs.add(targetJob);
|
unassignedJobs.add(targetJob);
|
||||||
|
jobRemoved(targetJob,route);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ruin(vehicleRoutes, nOfJobs2BeRemoved, unassignedJobs);
|
ruin(vehicleRoutes, nOfJobs2BeRemoved, unassignedJobs);
|
||||||
|
ruinEnds(vehicleRoutes);
|
||||||
return unassignedJobs;
|
return unassignedJobs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,19 +117,29 @@ final class RuinRandom implements RuinStrategy {
|
||||||
unassignedJobs.add(job);
|
unassignedJobs.add(job);
|
||||||
availableJobs.remove(job);
|
availableJobs.remove(job);
|
||||||
for (VehicleRoute route : vehicleRoutes) {
|
for (VehicleRoute route : vehicleRoutes) {
|
||||||
boolean removed = jobRemover.removeJobWithoutTourUpdate(job, route);
|
boolean removed = route.getTourActivities().removeJob(job);
|
||||||
if (removed) break;
|
if (removed) {
|
||||||
|
jobRemoved(job,route);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateRoutes(vehicleRoutes);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateRoutes(Collection<VehicleRoute> vehicleRoutes) {
|
|
||||||
for(VehicleRoute route : vehicleRoutes){
|
|
||||||
vehicleRouteUpdater.updateRoute(route);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ruinEnds(Collection<VehicleRoute> vehicleRoutes) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ruinStarts(Collection<VehicleRoute> vehicleRoutes) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void jobRemoved(Job job, VehicleRoute route) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
||||||
|
|
@ -76,15 +76,9 @@ public class TourActivities {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ArrayList<TourActivity> tourActivities = new ArrayList<TourActivity>();
|
private final ArrayList<TourActivity> tourActivities = new ArrayList<TourActivity>();
|
||||||
// private final LinkedList<TourActivity> tourActivities = new LinkedList<TourActivity>();
|
|
||||||
// private final TreeList tourActivities = new TreeList();
|
|
||||||
|
|
||||||
private final Set<Job> jobs = new HashSet<Job>();
|
private final Set<Job> jobs = new HashSet<Job>();
|
||||||
|
|
||||||
private int load = 0;
|
|
||||||
|
|
||||||
private double cost = 0.0;
|
|
||||||
|
|
||||||
private ReverseActivityIterator backward;
|
private ReverseActivityIterator backward;
|
||||||
|
|
||||||
private TourActivities(TourActivities tour2copy) {
|
private TourActivities(TourActivities tour2copy) {
|
||||||
|
|
@ -125,7 +119,7 @@ public class TourActivities {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes job AND belonging activity from tour.
|
* Removes job AND belonging activity from tour and returns true if job has been removed, otherwise false.
|
||||||
*
|
*
|
||||||
* @param job
|
* @param job
|
||||||
* @return
|
* @return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue