Is there a way to provide dynamic speed to vehicles (e.g. dependent on the vehicle payload)?
The VehicleDTO
class is immutable and not extensible, yet is required in the PDPModel
base class and all its subclasses.
If you want to extend VehicleDTO
you can do so via composition (as you shouldn't inherit from value objects):
@AutoValue
abstract class MyVehicleDTO {
public abstract VehicleDTO getVehicleDto();
// add more properties
}
The example above uses AutoValue to create a value object, but that's not required. You can use this value object to define your custom vehicle as follows:
public class MyVehicle extends Vehicle {
public MyVehicle(MyVehicleDTO vehicleDto) {
super(vehicleDto.getVehicleDto());
}
@Override
public double getSpeed() {
// change the following line to have a dynamic speed
return dto.getSpeed();
}
@Override
protected void tickImpl(TimeLapse time) {}
}
By creating your own Vehicle
you can change the speed dynamically.
Note: make sure you are using RinSim v4.4.4 (or later) to be able to override the speed.