MATSIM
VehicleType.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * *
4  * *********************************************************************** *
5  * *
6  * copyright : (C) 2008 by the members listed in the COPYING, *
7  * LICENSE and WARRANTY file. *
8  * email : info at matsim dot org *
9  * *
10  * *********************************************************************** *
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * See also COPYING, LICENSE and WARRANTY file *
17  * *
18  * *********************************************************************** */
19 
20 package org.matsim.vehicles;
21 
22 import org.matsim.api.core.v01.Id;
28 
29 import java.util.Objects;
30 
34 public final class VehicleType implements Attributable, Identifiable<VehicleType> {
35  // deliberately final, please do not change.
36  // If something like inheritance is needed, please change this class to VehicleTypeImpl, and extract interface under previous name VehicleType.
37  // And then use delegation. kai, sep'19
38 
39  // yy should maybe the whole type be immutable? I guess that the question is how people use this. If they have a vehicle, get the type, and then keep
40  // a reference to the type, then replacing the type means that it will have another reference, and these users will not notice. ???????
41 
42  private double width = 1.0;
43  private double maxVelocity = Double.POSITIVE_INFINITY; // default: constrained only by the link speed
44  private double length = 7.5;
45  private double pcuEquivalents = 1.0;
46  private double flowEfficiencyFactor = 1.0;
49  private String description;
50  private final VehicleCapacity capacity = new VehicleCapacity();
51  private String networkMode;
53  private final Attributes attributes = new AttributesImpl();
54 
55  VehicleType( Id<VehicleType> typeId ) {
56  this.id = typeId;
57  // For car typ default network mode is assumed, for others it needs to be set explicitly.
58  if (typeId != null && Objects.equals(typeId.toString(), TransportMode.car))
59  this.networkMode = TransportMode.car;
60  else if (typeId != null && Objects.equals(typeId.toString(), TransportMode.bike))
61  this.networkMode = TransportMode.bike;
62  }
63 
64  VehicleType(Id<VehicleType> typeId, String networkMode) {
65  this.id = typeId;
66  this.networkMode = networkMode;
67  }
68 
69  public final String getDescription() {
70  return description;
71  }
72  public final VehicleCapacity getCapacity() {
73  return capacity;
74  }
75 
76  @Override
77  public final Id<VehicleType> getId() {
78  return id;
79  }
80 
81  public final double getPcuEquivalents() {
82  return pcuEquivalents;
83  }
84  public final VehicleType setPcuEquivalents( double pcuEquivalents ) {
85  this.pcuEquivalents = pcuEquivalents;
86  return this;
87  }
88  public final double getFlowEfficiencyFactor() {
89  return flowEfficiencyFactor;
90  }
91  public final VehicleType setFlowEfficiencyFactor( double flowEfficiencyFactor ) {
92  this.flowEfficiencyFactor = flowEfficiencyFactor;
93  return this;
94  }
95  @Override public final Attributes getAttributes() {
96  return attributes ;
97  }
98  public final VehicleType setDescription( String desc ) {
99  this.description = desc;
100  return this;
101  }
102  public final VehicleType setLength( double length ) {
103  this.length = length;
104  return this;
105  }
106  public final VehicleType setMaximumVelocity( double meterPerSecond ) {
107  this.maxVelocity = meterPerSecond;
108  return this;
109  }
110  public final VehicleType setWidth( double width ) {
111  this.width = width;
112  return this;
113  }
114  public final double getWidth() {
115  return width;
116  }
117  public final double getMaximumVelocity() {
118  return maxVelocity;
119  }
120  public final double getLength() {
121  return length;
122  }
124  return engineInformation;
125  }
127  return costInformation;
128  }
129 
133  public final boolean hasNetworkMode() {
134  return networkMode != null;
135  }
136 
137  public final String getNetworkMode() {
138  return Objects.requireNonNull(networkMode, () -> "Network mode not set for vehicle type %s. Network mode needs to be set explicitly for non car modes. You can do this in XML by adding \t<networkMode networkMode=\"%s\"/>\n".formatted(id, id));
139  }
140  public final VehicleType setNetworkMode( String networkMode ) {
141  this.networkMode = networkMode;
142  return this;
143  }
144 
145  // the following are attributes that did not seem universal enough and thus were relegated to free-form Attributes for the time being. kai/kai, sep'19
149  @Deprecated
150  public final double getAccessTime() {
151  return VehicleUtils.getAccessTime(this);
152  }
156  @Deprecated
157  public final double getEgressTime() {
158  return VehicleUtils.getEgressTime(this);
159  }
163  @Deprecated
164  public final void setAccessTime( double seconds ) {
165  VehicleUtils.setAccessTime(this, seconds);
166  }
170  @Deprecated
171  public final void setEgressTime( double seconds ) {
172  VehicleUtils.setEgressTime(this, seconds);
173  }
177  @Deprecated
179  return VehicleUtils.getDoorOperationMode( this ) ;
180  }
184  @Deprecated
185  public final void setDoorOperationMode( DoorOperationMode mode ) {
186  VehicleUtils.setDoorOperationMode( this, mode ) ;
187  }
188  @Deprecated // refactoring device, please inline
190  return this.getCostInformation() ;
191  }
192 
193  public enum DoorOperationMode { serial, parallel }
194 
195 }
final EngineInformation getEngineInformation()
static void setDoorOperationMode(VehicleType vehicleType, VehicleType.DoorOperationMode mode)
final VehicleType setDescription(String desc)
final void setAccessTime(double seconds)
static void setEgressTime(VehicleType vehicleType, double egressTime)
final double getFlowEfficiencyFactor()
final VehicleType setLength(double length)
final VehicleType setWidth(double width)
final DoorOperationMode getDoorOperationMode()
static double getAccessTime(VehicleType vehicleType)
final CostInformation costInformation
final VehicleCapacity getCapacity()
static double getEgressTime(VehicleType vehicleType)
final void setDoorOperationMode(DoorOperationMode mode)
final CostInformation getVehicleCostInformation()
final VehicleType setPcuEquivalents(double pcuEquivalents)
final VehicleCapacity capacity
static void setAccessTime(VehicleType vehicleType, double accessTime)
final void setEgressTime(double seconds)
final CostInformation getCostInformation()
final Attributes getAttributes()
final VehicleType setMaximumVelocity(double meterPerSecond)
final Id< VehicleType > getId()
static VehicleType.DoorOperationMode getDoorOperationMode(VehicleType vehicleType)
boolean equals(Object obj)
Definition: Id.java:139
final VehicleType setFlowEfficiencyFactor(double flowEfficiencyFactor)
final EngineInformation engineInformation
final VehicleType setNetworkMode(String networkMode)