1 package org.opentrafficsim.core.egtf.typed; 2 3 import org.djunits.unit.SpeedUnit; 4 import org.djunits.unit.Unit; 5 import org.djunits.value.Scalar; 6 import org.djunits.value.vdouble.matrix.DoubleMatrixInterface; 7 import org.djunits.value.vdouble.scalar.Duration; 8 import org.djunits.value.vdouble.scalar.Length; 9 import org.djunits.value.vdouble.scalar.Speed; 10 import org.djunits.value.vdouble.vector.DoubleVectorInterface; 11 import org.djunits.value.vdouble.vector.DurationVector; 12 import org.djunits.value.vdouble.vector.LengthVector; 13 import org.opentrafficsim.core.egtf.DataStream; 14 import org.opentrafficsim.core.egtf.EGTF; 15 import org.opentrafficsim.core.egtf.KernelShape; 16 import org.opentrafficsim.core.egtf.Quantity; 17 18 /** 19 * Typed version of the EGTF. 20 * <p> 21 * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 22 * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>. 23 * <p> 24 * @version $Revision$, $LastChangedDate$, by $Author$, initial version 26 okt. 2018 <br> 25 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> 26 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a> 27 * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a> 28 */ 29 public class TypedEGTF extends EGTF 30 { 31 32 /** 33 * Constructor using cCong = -18km/h, cFree = 80km/h, deltaV = 10km/h and vc = 80km/h. A default kernel is set. 34 */ 35 public TypedEGTF() 36 { 37 super(); 38 } 39 40 /** 41 * Constructor defining global settings. A default kernel is set. 42 * @param cCong Speed; shock wave speed in congestion 43 * @param cFree Speed; shock wave speed in free flow 44 * @param deltaV Speed; speed range between congestion and free flow 45 * @param vc Speed; flip-over speed below which we have congestion 46 */ 47 public TypedEGTF(final Speed cCong, final Speed cFree, final Speed deltaV, final Speed vc) 48 { 49 super(cCong.getInUnit(SpeedUnit.KM_PER_HOUR), cFree.getInUnit(SpeedUnit.KM_PER_HOUR), 50 deltaV.getInUnit(SpeedUnit.KM_PER_HOUR), vc.getInUnit(SpeedUnit.KM_PER_HOUR)); 51 } 52 53 /** 54 * Convenience constructor that also sets a specified kernel. 55 * @param cCong Speed; shock wave speed in congestion 56 * @param cFree Speed; shock wave speed in free flow 57 * @param deltaV Speed; speed range between congestion and free flow 58 * @param vc Speed; flip-over speed below which we have congestion 59 * @param sigma Length; spatial kernel size 60 * @param tau Duration; temporal kernel size 61 * @param xMax Length; maximum spatial range 62 * @param tMax Duration; maximum temporal range 63 */ 64 @SuppressWarnings("parameternumber") 65 public TypedEGTF(final Speed cCong, final Speed cFree, final Speed deltaV, final Speed vc, final Length sigma, 66 final Duration tau, final Length xMax, final Duration tMax) 67 { 68 super(cCong.getInUnit(SpeedUnit.KM_PER_HOUR), cFree.getInUnit(SpeedUnit.KM_PER_HOUR), 69 deltaV.getInUnit(SpeedUnit.KM_PER_HOUR), vc.getInUnit(SpeedUnit.KM_PER_HOUR), sigma.si, tau.si, xMax.si, 70 tMax.si); 71 } 72 73 /** 74 * Adds point data. 75 * @param quantity Quantity<Z, ?>; quantity of the data 76 * @param location Length; location 77 * @param time Duration; time 78 * @param value Z; data value 79 * @param <U> unit of type 80 * @param <Z> value type 81 * @throws IllegalStateException if data was added with a data stream previously 82 */ 83 public synchronized <U extends Unit<U>, Z extends Scalar<U>> void addPointData(final Quantity<Z, ?> quantity, 84 final Length location, final Duration time, final Z value) 85 { 86 addPointDataSI(quantity, location.si, time.si, value.doubleValue()); 87 } 88 89 /** 90 * Adds point data. 91 * @param dataStream DataStream<Z>; data stream of the data 92 * @param location Length; location 93 * @param time Duration; time 94 * @param value Z; data value 95 * @param <U> unit of type 96 * @param <Z> value type 97 * @throws IllegalStateException if data was added with a quantity previously 98 */ 99 public synchronized <U extends Unit<U>, Z extends Scalar<U>> void addPointData(final DataStream<Z> dataStream, 100 final Length location, final Duration time, final Z value) 101 { 102 addPointDataSI(dataStream, location.si, time.si, value.doubleValue()); 103 } 104 105 /** 106 * Adds vector data. 107 * @param quantity Quantity<Z, ?>; quantity of the data 108 * @param location LengthVector; locations 109 * @param time DurationVector; times 110 * @param values DoubleVectorInterface<U>; data values 111 * @param <U> unit of type 112 * @param <Z> value type 113 * @throws IllegalStateException if data was added with a data stream previously 114 */ 115 public synchronized <U extends Unit<U>, Z extends Scalar<U>> void addVectorData(final Quantity<Z, ?> quantity, 116 final LengthVector location, final DurationVector time, final DoubleVectorInterface<U> values) 117 { 118 addVectorDataSI(quantity, location.getValuesSI(), time.getValuesSI(), values.getValuesSI()); 119 } 120 121 /** 122 * Adds vector data. 123 * @param dataStream DataStream<Z>; data stream of the data 124 * @param location LengthVector; locations 125 * @param time DurationVector; times 126 * @param values DoubleVectorInterface<U>; data values 127 * @param <U> unit of type 128 * @param <Z> value type 129 * @throws IllegalStateException if data was added with a quantity previously 130 */ 131 public synchronized <U extends Unit<U>, Z extends Scalar<U>> void addVectorData(final DataStream<Z> dataStream, 132 final LengthVector location, final DurationVector time, final DoubleVectorInterface<U> values) 133 { 134 addVectorDataSI(dataStream, location.getValuesSI(), time.getValuesSI(), values.getValuesSI()); 135 } 136 137 /** 138 * Adds grid data. 139 * @param quantity Quantity<Z, ?>; quantity of the data 140 * @param location LengthVector; locations 141 * @param time DurationVector; times 142 * @param values DoubleMatrixInterface<U>; data values 143 * @param <U> unit of type 144 * @param <Z> value type 145 * @throws IllegalStateException if data was added with a data stream previously 146 */ 147 public synchronized <U extends Unit<U>, Z extends Scalar<U>> void addGridData(final Quantity<Z, ?> quantity, 148 final LengthVector location, final DurationVector time, final DoubleMatrixInterface<U> values) 149 { 150 addGridDataSI(quantity, location.getValuesSI(), time.getValuesSI(), values.getValuesSI()); 151 } 152 153 /** 154 * Adds grid data. 155 * @param dataStream DataStream<Z>; data stream of the data 156 * @param location LengthVector; locations 157 * @param time DurationVector; times 158 * @param values DoubleMatrixInterface<U>; data values 159 * @param <U> unit of type 160 * @param <Z> value type 161 * @throws IllegalStateException if data was added with a quantity previously 162 */ 163 public synchronized <U extends Unit<U>, Z extends Scalar<U>> void addGridData(final DataStream<Z> dataStream, 164 final LengthVector location, final DurationVector time, final DoubleMatrixInterface<U> values) 165 { 166 addGridDataSI(dataStream, location.getValuesSI(), time.getValuesSI(), values.getValuesSI()); 167 } 168 169 /** 170 * Removes all data from before the given time. This is useful in live usages of this class, where older data is no longer 171 * required. 172 * @param time Duration; time before which all data can be removed 173 */ 174 public void clearDataBefore(final Duration time) 175 { 176 clearDataBefore(time.si); 177 } 178 179 /** 180 * Sets an exponential kernel with infinite range. 181 * @param sigma Length; spatial kernel size 182 * @param tau Duration; temporal kernel size 183 */ 184 public void setKernel(final Length sigma, final Duration tau) 185 { 186 setKernelSI(sigma.si, tau.si); 187 } 188 189 /** 190 * Returns an exponential kernel with limited range. 191 * @param sigma Length; spatial kernel size in [m] 192 * @param tau Duration; temporal kernel size in [s] 193 * @param xMax Length; maximum spatial range in [m] 194 * @param tMax Duration; maximum temporal range in [s] 195 */ 196 public void setKernel(final Length sigma, final Duration tau, final Length xMax, final Duration tMax) 197 { 198 setKernelSI(sigma.si, tau.si, xMax.si, tMax.si); 199 } 200 201 /** 202 * Sets a Gaussian kernel with infinite range. 203 * @param sigma Length; spatial kernel size 204 * @param tau Duration; temporal kernel size 205 */ 206 public void setGaussKernel(final Length sigma, final Duration tau) 207 { 208 setGaussKernelSI(sigma.si, tau.si); 209 } 210 211 /** 212 * Returns a Gaussian kernel with limited range. 213 * @param sigma Length; spatial kernel size in [m] 214 * @param tau Duration; temporal kernel size in [s] 215 * @param xMax Length; maximum spatial range in [m] 216 * @param tMax Duration; maximum temporal range in [s] 217 */ 218 public void setGaussKernel(final Length sigma, final Duration tau, final Length xMax, final Duration tMax) 219 { 220 setGaussKernelSI(sigma.si, tau.si, xMax.si, tMax.si); 221 } 222 223 /** 224 * Sets a kernel with limited range and provided shape. The shape allows using non-exponential kernels. 225 * @param xMax Length; maximum spatial range 226 * @param tMax Duration; maximum temporal range 227 * @param shape KernelShape; shape of the kernel 228 */ 229 public void setKernel(final Length xMax, final Duration tMax, final KernelShape shape) 230 { 231 setKernelSI(xMax.si, tMax.si, shape); 232 } 233 234 /** 235 * Returns filtered data. 236 * @param location LengthVector; location of output grid 237 * @param time DurationVector; time of output grid 238 * @param quantities Quantity<?, ?>...; quantities to calculate filtered data of 239 * @return Filter; filtered data, {@code null} when interrupted 240 */ 241 public TypedFilter filter(final LengthVector location, final DurationVector time, final Quantity<?, ?>... quantities) 242 { 243 return new TypedFilter(filterSI(location.getValuesSI(), time.getValuesSI(), quantities)); 244 } 245 246 /** {@inheritDoc} */ 247 @Override 248 public String toString() 249 { 250 return "TypedEGTF []"; 251 } 252 253 }