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

enhance RandomUtils

This commit is contained in:
oblonski 2015-02-12 20:33:47 +01:00
parent f8f063773a
commit 2acfad31ba

View file

@ -4,6 +4,7 @@ import jsprit.core.problem.job.Job;
import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.VehicleRoute;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.Random; import java.util.Random;
/** /**
@ -19,6 +20,10 @@ public class RandomUtils {
return nextItem(jobs,random); return nextItem(jobs,random);
} }
public static Job nextJob(List<Job> jobs, Random random){
return nextItem(jobs,random);
}
public static <T> T nextItem(Collection<T> items, Random random){ public static <T> T nextItem(Collection<T> items, Random random){
int randomIndex = random.nextInt(items.size()); int randomIndex = random.nextInt(items.size());
int count = 0; int count = 0;
@ -29,4 +34,9 @@ public class RandomUtils {
return null; return null;
} }
public static <T> T nextItem(List<T> items, Random random){
int randomIndex = random.nextInt(items.size());
return items.get(randomIndex);
}
} }