Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package rinde.sim.pdptw.central;
 
 import static com.google.common.collect.Lists.newArrayList;
 import static com.google.common.collect.Sets.newHashSet;
 
 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.

Author(s):
Rinde van Lon <rinde.vanlon@cs.kuleuven.be>
public class RandomSolver implements Solver {
  private final RandomGenerator randomGenerator;

  
Creates a new instance using the specified random generator.

Parameters:
rng The random generator to use for creating random solutions.
  public RandomSolver(RandomGenerator rng) {
     = rng;
  }
    final LinkedListMultimap<VehicleStateObjectParcelDTOmap = LinkedListMultimap
        .create();
    final Set<ParcelDTOavailable = newHashSet(state.availableParcels);
    final Set<ParcelDTOdestinations = newHashSet();
    for (final VehicleStateObject vso : state.vehicles) {
      if (vso.destination != null) {
        destinations.add(vso.destination);
      }
    }
    available.removeAll(destinations);
    // 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
        .builder();
    // 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);
      conts.remove(vso.destination);
      assigned.addAll(conts);
      if (vso.destination != null
          && state.availableParcels.contains(vso.destination)) {
        assigned.add(vso.destination);
      }
      Collections.shuffle(assignednew RandomAdaptor());
      if (vso.destination != null) {
        assigned.add(0, vso.destination);
      }
      builder.add(ImmutableList.copyOf(assigned));
    }
    // System.out.println("---------");
    // System.out.println(Joiner.on("\n").join(builder.build()));
    return builder.build();
  }

  

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