@Override public Id<VehicleType> getId() { return vType.getId(); }
/** * Adds the vehicle type to the container. * * @param type * @throws IllegalArgumentException if another {@link VehicleType} with the * same {@link Id} already exists in the container. */ @Override public void addVehicleType(VehicleType type){ /* Validation. */ if(this.getVehicleTypes().containsKey(type.getId())){ throw new IllegalArgumentException("Vehicle type with id = " + type.getId() + " already exists."); } /* Add the vehicle type. */ this.vehicleTypes.put(type.getId(), type); }
@Override public void removeVehicleType(Id<VehicleType> vehicleTypeId) { for (Vehicle veh : this.vehicles.values()) { if (veh.getType().getId().equals(vehicleTypeId)) { throw new IllegalArgumentException("Cannot remove vehicle type as it is used by at least one vehicle."); } } this.vehicleTypes.remove(vehicleTypeId); }
@Override public double getLinkTravelDisutility(Link link, double time, Person person, org.matsim.vehicles.Vehicle vehicle) { VehicleTypeVarCosts typeCosts = typeSpecificCosts.get(vehicle.getType().getId().toString()); if(typeCosts == null) throw new IllegalStateException("type specific costs for " + vehicle.getType().getId().toString() + " are missing."); double tt = travelTime.getLinkTravelTime(link, time, person, vehicle); return typeCosts.perMeter*link.getLength() + typeCosts.perSecond*tt; }
private void writeVehicles(Map<Id<Vehicle>, Vehicle> veh) throws UncheckedIOException { for (Vehicle v : veh.values()) { atts.clear(); atts.add(this.createTuple(VehicleSchemaV1Names.ID, v.getId().toString())); atts.add(this.createTuple(VehicleSchemaV1Names.TYPE, v.getType().getId().toString())); this.writeStartTag(VehicleSchemaV1Names.VEHICLE, atts, true); } }
private Id<Umlauf> createUmlaufIdFromVehicle(Vehicle vehicle){ Id<Umlauf> id = Id.create(vehicle.getId().toString() + "_" + vehicle.getType().getId().toString(), Umlauf.class); this.umlaufIdsByVehicleId.put(vehicle.getId(), id); return id; }
private int getVehicleCapacity(Id<Vehicle> vehicleId) { VehicleType type = vehicles.get(vehicleId).getType(); VehicleCapacity capacity = vehicleTypes.get(type.getId()).getCapacity(); return capacity.getSeats() + capacity.getStandingRoom(); }
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()); } } }
/** * Add the vehicle to the container. * * @param v * @throws IllegalArgumentException if another {@link Vehicle} with * the same {@link Id} already exists in the container. */ @Override public void addVehicle(final Vehicle v) { /* Validation. */ if(this.getVehicles().containsKey(v.getId())){ throw new IllegalArgumentException("Vehicle with id = " + v.getId() + " already exists."); } /* Check if the VehicleType associated with the vehicle already exist. * Here only an error message is given. A RuntimeException is thrown * when the VehicleWriterV1 is called (JWJ, '14). */ if(!this.vehicleTypes.containsKey(v.getType().getId())){ throw new IllegalArgumentException("Cannot add Vehicle with type = " + v.getType().getId().toString() + " if the VehicleType has not been added to the Vehicles container."); } /* Add the vehicle. */ this.vehicles.put(v.getId(), v); this.counter.incCounter(); }
@Override public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) { double costs = base.getLinkTravelDisutility(link, time, person, vehicle); Id<VehicleType> typeId = vehicle.getType().getId(); double toll = roadPricing.getTollAmount(typeId, link, time); return costs + toll; }
@Override public double getLinkTravelDisutility(Link link, double time, Person person, org.matsim.vehicles.Vehicle vehicle) { double costs = baseTransportDisutility.getLinkTravelDisutility(link, time, person, vehicle); Id<org.matsim.vehicles.VehicleType> typeId = vehicle.getType().getId(); double toll = vehicleTypeDependentPricingCalculator.getTollAmount(typeId, link, time); // System.out.println("huuuuuuuuuuuuuuuuuuuu - paid toll"); return costs + toll; }
@Override public double getLinkTravelDisutility(Link link, double time, Person person, org.matsim.vehicles.Vehicle vehicle) { CarrierVehicleType type = vehicleTypes.getVehicleTypes().get(vehicle.getType().getId()); if(type == null) throw new IllegalStateException("vehicle "+vehicle.getId()+" has no type"); double tt = travelTime.getLinkTravelTime(link, time, person, vehicle); return type.getVehicleCostInformation().perDistanceUnit*link.getLength() + type.getVehicleCostInformation().perTimeUnit*tt; }
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; }
private void writeVehicleTypes(Map<Id<VehicleType>, VehicleType> vts) throws UncheckedIOException { for (VehicleType vt : vts.values()) { atts.clear(); atts.add(this.createTuple(VehicleSchemaV1Names.ID, vt.getId().toString())); this.writeStartTag(VehicleSchemaV1Names.VEHICLETYPE, atts); if (vt.getDescription() != null) {
&& context.qsimConfig.getSeepModes().contains(veh.getVehicle().getType().getId().toString()) ){
if(vehicle.getType().getDescription()==null) { // emission specification is in vehicle type id vehicle.getType().setDescription(EmissionSpecificationMarker.BEGIN_EMISSIONS +vehicle.getType().getId().toString()+ EmissionSpecificationMarker.END_EMISSIONS); } else if( vehicle.getType().getDescription().contains(EmissionSpecificationMarker.BEGIN_EMISSIONS.toString()) ) { + vehicle.getType().getId().toString()+ EmissionSpecificationMarker.END_EMISSIONS; vehicle.getType().setDescription(vehicleDescription);
if(vehicle.getType().getDescription()==null) { // emission specification is in vehicle type id vehicle.getType().setDescription(EmissionSpecificationMarker.BEGIN_EMISSIONS +vehicle.getType().getId().toString()+ EmissionSpecificationMarker.END_EMISSIONS); } else if( vehicle.getType().getDescription().contains(EmissionSpecificationMarker.BEGIN_EMISSIONS.toString()) ) { + vehicle.getType().getId().toString()+ EmissionSpecificationMarker.END_EMISSIONS; vehicle.getType().setDescription(vehicleDescription);
if(context.qsimConfig.isSeepModeStorageFree() && context.qsimConfig.getSeepModes().contains( veh.getVehicle().getType().getId().toString() ) ){
@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)); }