@Override public void endTag(final String name, final String content, final Stack<String> context) { if (VehicleSchemaV1Names.DESCRIPTION.equalsIgnoreCase(name) && (content.trim().length() > 0)){ this.currentVehType.setDescription(content.trim()); } else if (VehicleSchemaV1Names.ENGINEINFORMATION.equalsIgnoreCase(name)){ EngineInformation currentEngineInfo = this.builder.createEngineInformation(this.currentFuelType, this.currentGasConsumption); this.currentVehType.setEngineInformation(currentEngineInfo); this.currentFuelType = null; this.currentGasConsumption = Double.NaN; } else if (VehicleSchemaV1Names.FUELTYPE.equalsIgnoreCase(name)){ this.currentFuelType = this.parseFuelType(content.trim()); } else if (VehicleSchemaV1Names.FREIGHTCAPACITY.equalsIgnoreCase(name)){ this.currentCapacity.setFreightCapacity(this.currentFreightCap); this.currentFreightCap = null; } else if (VehicleSchemaV1Names.CAPACITY.equalsIgnoreCase(name)) { this.currentVehType.setCapacity(this.currentCapacity); this.currentCapacity = null; } else if (VehicleSchemaV1Names.VEHICLETYPE.equalsIgnoreCase(name)){ this.vehicles.addVehicleType(this.currentVehType); this.currentVehType = null; } }
private void addPVehiclesToOriginalOnes(Vehicles baseVehicles, Vehicles pVehicles){ for (VehicleType t : pVehicles.getVehicleTypes().values()) { if (!baseVehicles.getVehicleTypes().containsKey(t.getId())) { baseVehicles.addVehicleType(t); currentExclusivePVehicleTypeIDs.add(t.getId()); } } for (Vehicle v : pVehicles.getVehicles().values()) { if (!baseVehicles.getVehicles().containsKey(v.getId())) { baseVehicles.addVehicle(v); currentExclusivePVehicleIDs.add(v.getId()); } } }
private Map<String, VehicleType> getMode2VehicleType(){ Map<String, VehicleType> modeVehicleTypes = new HashMap<>(); switch ( this.qSimConfigGroup.getVehiclesSource() ) { case defaultVehicle: for (String mode : this.qSimConfigGroup.getMainModes()) { // initialize each mode with default vehicle type: VehicleType defaultVehicleType = VehicleUtils.getDefaultVehicleType(); modeVehicleTypes.put(mode, defaultVehicleType); if( scenario.getVehicles().getVehicleTypes().get(defaultVehicleType.getId())==null) { scenario.getVehicles().addVehicleType(defaultVehicleType); // adding default vehicle type to vehicles container } } break; case modeVehicleTypesFromVehiclesData: for (String mode : qSimConfigGroup.getMainModes()) { VehicleType vehicleType = scenario.getVehicles().getVehicleTypes().get( Id.create(mode, VehicleType.class) ) ; Gbl.assertNotNull(vehicleType); modeVehicleTypes.put(mode, vehicleType ); } break; case fromVehiclesData: // don't do anything break; default: throw new RuntimeException("not implemented yet."); } return modeVehicleTypes; }
public void run() { VehiclesFactory vb = this.vehicles.getFactory(); VehicleType vehicleType = vb.createVehicleType(Id.create("defaultTransitVehicleType", VehicleType.class)); VehicleCapacity capacity = new VehicleCapacityImpl(); capacity.setSeats(Integer.valueOf(101)); capacity.setStandingRoom(Integer.valueOf(0)); vehicleType.setCapacity(capacity); this.vehicles.addVehicleType(vehicleType); long vehId = 0; for (TransitLine line : this.schedule.getTransitLines().values()) { for (TransitRoute route : line.getRoutes().values()) { for (Departure departure : route.getDepartures().values()) { Vehicle veh = vb.createVehicle(Id.create("tr_" + Long.toString(vehId++), Vehicle.class), vehicleType); this.vehicles.addVehicle(veh); departure.setVehicleId(veh.getId()); } } } } }
@Test public void testAddVehicleType(){ Vehicles vehicles = VehicleUtils.createVehiclesContainer(); VehicleType t1 = vehicles.getFactory().createVehicleType(Id.create("type1", VehicleType.class)); VehicleType t2 = vehicles.getFactory().createVehicleType(Id.create("type1", VehicleType.class)); vehicles.addVehicleType(t1); try{ vehicles.addVehicleType(t2); Assert.fail("Cannot add another vehicle type with the same Id"); } catch (IllegalArgumentException e){ /* Pass. */ } }
private void createVehicles() { Vehicles vehicles = this.scenario.getTransitVehicles(); VehiclesFactory vb = vehicles.getFactory(); VehicleType vehicleType = vb.createVehicleType(Id.create("transitVehicleType", VehicleType.class)); vehicles.addVehicleType(vehicleType); VehicleCapacity capacity = vb.createVehicleCapacity(); capacity.setSeats(101); capacity.setStandingRoom(0); vehicleType.setCapacity(capacity); for (int i = 0; i < nOfBuses; i++) { vehicles.addVehicle( vb.createVehicle(Id.create(i, Vehicle.class), vehicleType)); } }
vehType.setEgressTime(this.pConfig.getDelayPerAlightingPassenger()); vehType.setDoorOperationMode(this.pConfig.getDoorOperationMode()); vehicles.addVehicleType( vehType);
private void storeVehicleTypeInfo(SimpleNetwork net) { net.scenario.getConfig().qsim().setVehiclesSource(QSimConfigGroup.VehiclesSource.modeVehicleTypesFromVehiclesData); Vehicles vehicles = net.scenario.getVehicles(); VehicleType car = VehicleUtils.getFactory().createVehicleType(Id.create("car", VehicleType.class)); car.setMaximumVelocity(20); car.setPcuEquivalents(1.0); vehicles.addVehicleType(car); VehicleType bike = VehicleUtils.getFactory().createVehicleType(Id.create("bike", VehicleType.class)); bike.setMaximumVelocity(5); bike.setPcuEquivalents(0.25); vehicles.addVehicleType(bike); }
private void createVehicles() { Vehicles vehicles = this.scenario.getTransitVehicles(); VehiclesFactory vb = vehicles.getFactory(); VehicleType vehicleType = vb.createVehicleType(Id.create("transitVehicleType", VehicleType.class)); VehicleCapacity capacity = vb.createVehicleCapacity(); capacity.setSeats(101); capacity.setStandingRoom(0); vehicleType.setCapacity(capacity); vehicles.addVehicleType(vehicleType); Id<Vehicle> id = Id.create("tr_1", Vehicle.class); vehicles.addVehicle( vb.createVehicle(id, vehicleType)); id = Id.create("tr_2", Vehicle.class); vehicles.addVehicle( vb.createVehicle(id, vehicleType)); }
public void run(Config config, boolean considerMotorizedInteraction) { config.global().setNumberOfThreads(1); config.controler().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); config.plansCalcRoute().setRoutingRandomness(3.); Scenario scenario = ScenarioUtils.loadScenario(config); VehicleType car = VehicleUtils.getFactory().createVehicleType(Id.create(TransportMode.car, VehicleType.class)); scenario.getVehicles().addVehicleType(car); VehicleType bicycle = VehicleUtils.getFactory().createVehicleType(Id.create("bicycle", VehicleType.class)); bicycle.setMaximumVelocity(20.0/3.6); bicycle.setPcuEquivalents(0.25); scenario.getVehicles().addVehicleType(bicycle); scenario.getConfig().qsim().setVehiclesSource(QSimConfigGroup.VehiclesSource.modeVehicleTypesFromVehiclesData); Controler controler = new Controler(scenario); BicycleModule bicycleModule = new BicycleModule(); if (considerMotorizedInteraction) { bicycleModule.setConsiderMotorizedInteraction(true); } controler.addOverridingModule(bicycleModule); controler.run(); }
@Test public void testRemoveVehicle() { Vehicles vehicles = VehicleUtils.createVehiclesContainer(); VehicleType t1 = vehicles.getFactory().createVehicleType(Id.create("type1", VehicleType.class)); vehicles.addVehicleType(t1); Vehicle v1 = vehicles.getFactory().createVehicle(Id.create("v1", Vehicle.class), t1); Assert.assertEquals(0, vehicles.getVehicles().size()); vehicles.addVehicle(v1); Assert.assertEquals(1, vehicles.getVehicles().size()); vehicles.removeVehicle(Id.create("v1", Vehicle.class)); Assert.assertEquals(0, vehicles.getVehicles().size()); }
@Test public void testGetVehicles(){ Vehicles vehicles = VehicleUtils.createVehiclesContainer(); VehicleType testType = vehicles.getFactory().createVehicleType(Id.create("test", VehicleType.class)); vehicles.addVehicleType(testType); Vehicle v1 = vehicles.getFactory().createVehicle(Id.create("v1", Vehicle.class), testType); /* Should get an unmodifiable Map of the Vehicles container. */ try{ vehicles.getVehicles().put(Id.create("v1", Vehicle.class), v1 ); vehicles.getVehicles(); Assert.fail("Should not be able to add to an unmodiafiable Map"); } catch (UnsupportedOperationException e){ /* Pass. */ } }
car.setPcuEquivalents(1.0); modesType.put(TransportMode.car, car); sc.getVehicles().addVehicleType(car); walk.setPcuEquivalents(0.1); modesType.put(TransportMode.walk, walk); sc.getVehicles().addVehicleType(walk);
car.setMaximumVelocity(this.vehSpeed); car.setPcuEquivalents(1.0); net.scenario.getVehicles().addVehicleType(car);
@Test public void testAddVehicle() { Vehicles vehicles = VehicleUtils.createVehiclesContainer(); VehicleType testType = vehicles.getFactory().createVehicleType(Id.create("test", VehicleType.class)); Vehicle v1 = vehicles.getFactory().createVehicle(Id.create("v1", Vehicle.class), testType); /* Must add vehicle type before adding vehicle. */ try{ vehicles.addVehicle(v1); Assert.fail("Should not allow adding a vehicle if vehicle type has not been added to container first."); } catch(IllegalArgumentException e){ /* Pass. */ } vehicles.addVehicleType(testType); vehicles.addVehicle(v1); Vehicle v2 = vehicles.getFactory().createVehicle(Id.create("v1", Vehicle.class), testType); try{ vehicles.addVehicle(v2); Assert.fail("Cannot add another vehicle with the same Id."); } catch (IllegalArgumentException e){ /* Pass. */ } }
@Test public void testRemoveVehicleType() { Vehicles vehicles = VehicleUtils.createVehiclesContainer(); VehicleType t1 = vehicles.getFactory().createVehicleType(Id.create("type1", VehicleType.class)); vehicles.addVehicleType(t1); Vehicle v1 = vehicles.getFactory().createVehicle(Id.create("v1", Vehicle.class), t1); vehicles.addVehicle(v1); try { vehicles.removeVehicleType(t1.getId()); Assert.fail("expected exception, as vehicle type is still in use."); } catch (IllegalArgumentException e) { // pass } vehicles.removeVehicle(v1.getId()); vehicles.removeVehicleType(t1.getId()); // also test for non-existant vehicle types vehicles.removeVehicleType(Id.create("type2", VehicleType.class)); }
scenario.getVehicles().addVehicleType(vehTypes[i]); scenario.getVehicles().addVehicleType(vehTypes[i]);
vt.setMaximumVelocity(travelMode == "bike" ? 5.0 : 20.0 ); vt.setPcuEquivalents(travelMode == "car" ? 1.0 : 0.25); scenario.getVehicles().addVehicleType(vt);
vt.setMaximumVelocity(20); vt.setPcuEquivalents(travelMode == "motorbike" ? 0.25 : 1.0); scenario.getVehicles().addVehicleType(vt);
scenario.getVehicles().addVehicleType(VehicleUtils.getDefaultVehicleType()); scenario.getVehicles().addVehicle(vehicle);