org.matsim.core.gbl.MatsimRandom Java Examples

The following examples show how to use org.matsim.core.gbl.MatsimRandom. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RandomDensityGenerator.java    From amodeus with GNU General Public License v2.0 6 votes vote down vote up
@Override
public List<DvrpVehicleSpecification> generateVehicles() {
    long generatedVehicles = 0;
    List<DvrpVehicleSpecification> vehicles = new LinkedList<>();
    while (generatedVehicles < operatorConfig.getGeneratorConfig().getNumberOfVehicles()) {
        ++generatedVehicles;

        int bound = network.getLinks().size();
        int elemRand = MatsimRandom.getRandom().nextInt(bound);
        Link link = network.getLinks().values().stream().skip(elemRand).findFirst().get();
        LOGGER.info("car placed at link " + link);

        Id<DvrpVehicle> id = AmodeusIdentifiers.createVehicleId(operatorConfig.getMode(), generatedVehicles);
        vehicles.add(ImmutableDvrpVehicleSpecification.newBuilder() //
                .id(id) //
                .serviceBeginTime(0.0) //
                .serviceEndTime(Double.POSITIVE_INFINITY) //
                .capacity(capacity) //
                .startLinkId(link.getId()) //
                .build());
    }
    return vehicles;
}
 
Example #2
Source File: DemoGenerator.java    From amod with GNU General Public License v2.0 6 votes vote down vote up
@Override
public List<DvrpVehicleSpecification> generateVehicles() {
    long generatedVehicles = 0;
    List<DvrpVehicleSpecification> vehicles = new LinkedList<>();
    while (generatedVehicles < operatorConfig.getGeneratorConfig().getNumberOfVehicles()) {
        ++generatedVehicles;

        /** select one of the 10 random links for placement */
        int elemRand = MatsimRandom.getRandom().nextInt(randomLinks.size());
        Link linkSel = randomLinks.stream().skip(elemRand).findFirst().get();

        LOGGER.info("car placed at link " + linkSel);

        Id<DvrpVehicle> id = AmodeusIdentifiers.createVehicleId(operatorConfig.getMode(), generatedVehicles);

        vehicles.add(ImmutableDvrpVehicleSpecification.newBuilder() //
                .id(id) //
                .serviceBeginTime(0.0) //
                .serviceEndTime(Double.POSITIVE_INFINITY) //
                .capacity(capacity) //
                .startLinkId(linkSel.getId()) //
                .build());
    }
    return vehicles;
}
 
Example #3
Source File: DemoGenerator.java    From amod with GNU General Public License v2.0 5 votes vote down vote up
public DemoGenerator(AmodeusModeConfig operatorConfig, Network network, int capacity) {
    this.operatorConfig = operatorConfig;
    this.capacity = capacity;

    /** determine 10 random links in the network */
    int bound = network.getLinks().size();
    for (int i = 0; i < 10; ++i) {
        int elemRand = MatsimRandom.getRandom().nextInt(bound);
        Link link = network.getLinks().values().stream().skip(elemRand).findFirst().get();
        randomLinks.add(link);
    }
}
 
Example #4
Source File: MATSimVirtualNetworkTravelDataTest.java    From amodeus with GNU General Public License v2.0 4 votes vote down vote up
private static Controler prepare() throws IOException {
    File scenarioDirectory = new File(Locate.repoFolder(StandardMATSimScenarioTest.class, "amodeus"), "resources/testScenario");
    File workingDirectory = MultiFileTools.getDefaultWorkingDirectory();
    GlobalAssert.that(workingDirectory.isDirectory());
    TestFileHandling.copyScnearioToMainDirectory(scenarioDirectory.getAbsolutePath(), workingDirectory.getAbsolutePath());

    StaticHelper.setup();
    MatsimRandom.reset();

    // Set up
    Config config = ConfigUtils.createConfig(new AmodeusConfigGroup(), new DvrpConfigGroup());
    Scenario scenario = TestScenarioGenerator.generateWithAVLegs(config);

    ScenarioOptions simOptions = new ScenarioOptions(workingDirectory, ScenarioOptionsBase.getDefault());
    LocationSpec locationSpec = simOptions.getLocationSpec();
    ReferenceFrame referenceFrame = locationSpec.referenceFrame();
    MatsimAmodeusDatabase db = MatsimAmodeusDatabase.initialize(scenario.getNetwork(), referenceFrame);

    PlanCalcScoreConfigGroup.ModeParams modeParams = config.planCalcScore().getOrCreateModeParams(AmodeusModeConfig.DEFAULT_MODE);
    modeParams.setMonetaryDistanceRate(0.0);
    modeParams.setMarginalUtilityOfTraveling(8.86);
    modeParams.setConstant(0.0);

    // Config

    AmodeusConfigGroup avConfig = AmodeusConfigGroup.get(config);

    AmodeusModeConfig operatorConfig = new AmodeusModeConfig(AmodeusModeConfig.DEFAULT_MODE);
    avConfig.addMode(operatorConfig);

    GeneratorConfig generatorConfig = operatorConfig.getGeneratorConfig();
    generatorConfig.setType("VehicleToVSGenerator");
    generatorConfig.setNumberOfVehicles(100);

    // Choose a dispatcher
    DispatcherConfig dispatcherConfig = operatorConfig.getDispatcherConfig();
    dispatcherConfig.addParam("infoLinePeriod", "3600");
    dispatcherConfig.setType("FeedforwardFluidicRebalancingPolicy");

    // Make sure that we do not need the SimulationObjectCompiler
    dispatcherConfig.addParam("publishPeriod", "-1");

    // Set up stuff for TravelData (but we'll generate it on the fly)
    LPOptions lpOptions = new LPOptions(simOptions.getWorkingDirectory(), LPOptionsBase.getDefault());
    lpOptions.setProperty(LPOptionsBase.LPSOLVER, "timeInvariant");
    lpOptions.saveAndOverwriteLPOptions();

    // Set up paths
    operatorConfig.getDispatcherConfig().setVirtualNetworkPath("generatedVirtualNetwork");
    operatorConfig.getDispatcherConfig().setTravelDataPath("generatedTravelData");

    // Controller
    Controler controller = new Controler(scenario);
    AmodeusConfigurator.configureController(controller, db, simOptions);

    // Run
    return controller;
}