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:
parent
95decbaa3d
commit
b357bed413
1 changed files with 34 additions and 0 deletions
34
jsprit-core/src/main/java/jsprit/core/util/RandomUtils.java
Normal file
34
jsprit-core/src/main/java/jsprit/core/util/RandomUtils.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue