1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

internal ruinStrat improvement

This commit is contained in:
oblonski 2013-08-12 22:27:07 +02:00
parent d9391c6d45
commit f78886767b
3 changed files with 41 additions and 10 deletions

View file

@ -0,0 +1,22 @@
package algorithms;
import java.util.Collection;
import basics.Job;
import basics.route.VehicleRoute;
abstract class AbstractRuinStrategy implements RuinStrategy{
public void ruinStarts(Collection<VehicleRoute> routes){
}
public void ruinEnds(Collection<VehicleRoute> routes){
}
public void jobRemoved(Job job, VehicleRoute fromRoute){
}
}

View file

@ -82,10 +82,6 @@ final class RuinRadial implements RuinStrategy {
private JobDistance jobDistance; private JobDistance jobDistance;
private JobRemover jobRemover;
private VehicleRouteUpdater routeUpdater;
public void setRandom(Random random) { public void setRandom(Random random) {
this.random = random; this.random = random;
} }
@ -154,6 +150,7 @@ final class RuinRadial implements RuinStrategy {
} }
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>();
TreeSet<ReferencedJob> tree = distanceNodeTree.get(targetJob.getId()); TreeSet<ReferencedJob> tree = distanceNodeTree.get(targetJob.getId());
Iterator<ReferencedJob> descendingIterator = tree.descendingIterator(); Iterator<ReferencedJob> descendingIterator = tree.descendingIterator();
@ -165,18 +162,32 @@ final class RuinRadial implements RuinStrategy {
counter++; counter++;
boolean removed = false; boolean removed = false;
for (VehicleRoute route : vehicleRoutes) { for (VehicleRoute route : vehicleRoutes) {
removed = jobRemover.removeJobWithoutTourUpdate(job, route); removed = route.getTourActivities().removeJob(job);;
if (removed) { if (removed) {
jobRemoved(job,route);
break; break;
} }
} }
} }
for(VehicleRoute route : vehicleRoutes){ ruinEnds(vehicleRoutes);
routeUpdater.updateRoute(route);
}
return unassignedJobs; return unassignedJobs;
} }
private void ruinEnds(Collection<VehicleRoute> vehicleRoutes) {
// TODO Auto-generated method stub
}
private void jobRemoved(Job job, VehicleRoute route) {
// TODO Auto-generated method stub
}
private void ruinStarts(Collection<VehicleRoute> vehicleRoutes) {
// TODO Auto-generated method stub
}
private Job pickRandomJob() { private Job pickRandomJob() {
int totNuOfJobs = vrp.getJobs().values().size(); int totNuOfJobs = vrp.getJobs().values().size();
int randomIndex = random.nextInt(totNuOfJobs); int randomIndex = random.nextInt(totNuOfJobs);

View file

@ -73,11 +73,9 @@ 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;
} }