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

add helper to easily get random routes and jobs from collection

This commit is contained in:
oblonski 2015-01-14 19:35:28 +01:00
parent 95decbaa3d
commit b357bed413

View file

@ -0,0 +1,34 @@
package jsprit.core.util;
import jsprit.core.problem.job.Job;
import jsprit.core.problem.solution.route.VehicleRoute;
import java.util.Collection;
import java.util.Random;
/**
* Created by schroeder on 14/01/15.
*/
public class RandomUtils {
public static VehicleRoute nextRoute(Collection<VehicleRoute> routes, Random random){
int randomIndex = random.nextInt(routes.size());
int count = 0;
for(VehicleRoute route : routes){
if(count <= randomIndex) return route;
count++;
}
return null;
}
public static Job nextJob(Collection<Job> jobs, Random random){
int randomIndex = random.nextInt(jobs.size());
int count = 0;
for(Job job : jobs){
if(count <= randomIndex) return job;
count++;
}
return null;
}
}