diff --git a/jsprit-core/src/main/java/jsprit/core/util/RandomUtils.java b/jsprit-core/src/main/java/jsprit/core/util/RandomUtils.java new file mode 100644 index 00000000..5dfa66d8 --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/util/RandomUtils.java @@ -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 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 jobs, Random random){ + int randomIndex = random.nextInt(jobs.size()); + int count = 0; + for(Job job : jobs){ + if(count <= randomIndex) return job; + count++; + } + return null; + } + +}