Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package rinde.sim.pdptw.central;
 import static;
 import static;
 import java.util.List;
 import java.util.Set;
A Solver that constructs random solutions. For each order it first randomly selects a vehicle. When all orders are assigned to a vehicle the ordering of the pickups and deliveries is shuffled randomly.

Rinde van Lon <>
public class RandomSolver implements Solver {
  private final RandomGenerator randomGenerator;

Creates a new instance using the specified random generator.

rng The random generator to use for creating random solutions.
  public RandomSolver(RandomGenerator rng) {
     = rng;
    final LinkedListMultimap<VehicleStateObjectParcelDTOmap = LinkedListMultimap
    final Set<ParcelDTOavailable = newHashSet(state.availableParcels);
    final Set<ParcelDTOdestinations = newHashSet();
    for (final VehicleStateObject vso : state.vehicles) {
      if (vso.destination != null) {
    // do random assignment of available parcels
    for (final ParcelDTO p : available) {
      final int index = .nextInt(state.vehicles.size());
      map.put(state.vehicles.get(index), p);
      map.put(state.vehicles.get(index), p);
    final ImmutableList.Builder<ImmutableList<ParcelDTO>> builder = ImmutableList
    // insert contents, shuffle ordering, insert destination if applicable
    for (final VehicleStateObject vso : state.vehicles) {
      final List<ParcelDTOassigned = newArrayList(map.get(vso));
      final List<ParcelDTOconts = newArrayList(vso.contents);
      if (vso.destination != null
          && state.availableParcels.contains(vso.destination)) {
      Collections.shuffle(assignednew RandomAdaptor());
      if (vso.destination != null) {
        assigned.add(0, vso.destination);
    // System.out.println("---------");
    // System.out.println(Joiner.on("\n").join(;


A rinde.sim.util.SupplierRng for RandomSolver instances.
  public static SupplierRng<Solversupplier() {
    return new DefaultSupplierRng<Solver>() {
      public Solver get(long seed) {
        return new RandomSolver(new MersenneTwister(seed));
New to GrepCode? Check out our FAQ X