org.opentrafficsim.road.od.OdOptions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ots-road Show documentation
Show all versions of ots-road Show documentation
OpenTrafficSim road classes
The newest version!
package org.opentrafficsim.road.od;
import java.util.LinkedHashMap;
import java.util.Map;
import org.djunits.value.vdouble.scalar.Frequency;
import org.djunits.value.vdouble.scalar.Length;
import org.djutils.exceptions.Throw;
import org.opentrafficsim.core.gtu.GtuErrorHandler;
import org.opentrafficsim.core.gtu.GtuType;
import org.opentrafficsim.core.idgenerator.IdGenerator;
import org.opentrafficsim.core.network.LinkType;
import org.opentrafficsim.core.network.Node;
import org.opentrafficsim.road.gtu.generator.CfBaRoomChecker;
import org.opentrafficsim.road.gtu.generator.GeneratorPositions.LaneBiases;
import org.opentrafficsim.road.gtu.generator.LaneBasedGtuGenerator.RoomChecker;
import org.opentrafficsim.road.gtu.generator.MarkovCorrelation;
import org.opentrafficsim.road.gtu.generator.characteristics.LaneBasedGtuCharacteristicsGeneratorOd;
import org.opentrafficsim.road.gtu.generator.headway.ArrivalsHeadwayGenerator.HeadwayDistribution;
import org.opentrafficsim.road.network.lane.Lane;
/**
* Options for vehicle generation based on an OD matrix.
*
* Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License.
*
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
*/
public class OdOptions
{
/** Headway randomization option. */
public static final Option HEADWAY_DIST =
new Option<>("headway distribution", HeadwayDistribution.EXPONENTIAL);
/** ID generator option. */
public static final Option GTU_ID = new Option<>("gtu id", new IdGenerator(""));
/** GTU characteristics generator option. */
public static final Option GTU_TYPE = new Option<>("gtu type", null);
/** Room checker option. */
public static final Option ROOM_CHECKER = new Option<>("room checker", new CfBaRoomChecker());
/** Markov chain for GTU type option. */
public static final Option> MARKOV = new Option<>("markov", null);
/** Initial distance over which lane changes shouldn't be performed option. */
public static final Option NO_LC_DIST = new Option<>("no lc distance", null);
/** Whether to perform instantaneous lane changes. */
public static final Option INSTANT_LC = new Option<>("instant lc", false);
/** Error handler when GTU exceptions occur. */
public static final Option ERROR_HANDLER = new Option<>("error handler", GtuErrorHandler.THROW);
/** Lane bias. Default is none, i.e. uniform distribution over lanes for all GTU types. */
public static final Option LANE_BIAS = new Option<>("lane bias", new LaneBiases());
/** Options overall. */
private OptionSet options = new OptionSet<>();
/** Options per lane. */
private OptionSet laneOptions = new OptionSet<>();
/** Options per node. */
private OptionSet nodeOptions = new OptionSet<>();
/** Options per road type. */
private OptionSet linkTypeOptions = new OptionSet<>();
/**
* Set option value.
* @param option Option<K>; option
* @param value K; option value
* @param value type
* @return this option set
*/
public final OdOptions set(final Option option, final K value)
{
this.options.set(null, option, value);
return this;
}
/**
* Set option value for lane.
* @param lane Lane; lane
* @param option Option<K>; option
* @param value K; option value
* @param value type
* @return this option set
*/
public final OdOptions set(final Lane lane, final Option option, final K value)
{
this.laneOptions.set(lane, option, value);
return this;
}
/**
* Set option value for node.
* @param node Node; node
* @param option Option<K>; option
* @param value K; option value
* @param value type
* @return this option set
*/
public final OdOptions set(final Node node, final Option option, final K value)
{
this.nodeOptions.set(node, option, value);
return this;
}
/**
* Set option value for link type.
* @param linkType LinkType; link type
* @param option Option<K>; option
* @param value K; option value
* @param value type
* @return this option set
*/
public final OdOptions set(final LinkType linkType, final Option option, final K value)
{
this.linkTypeOptions.set(linkType, option, value);
return this;
}
/**
* Get option value. If a value is specified for a specific category, it is returned. The following order is used:
*
* - {@code Lane}
* - {@code Node} (origin)
* - {@code LinkType}
* - None (global option value)
* - Default option value
*
* @param option Option<K>; option
* @param lane Lane; lane to obtain specific option value, may be null
* @param node Node; node to obtain specific option value, may be null
* @param linkType LinkType; link type to obtain specific option value, may be null
* @param value type
* @return K; option value
*/
public final K get(final Option option, final Lane lane, final Node node, final LinkType linkType)
{
Throw.whenNull(option, "Option may not be null.");
K value = this.laneOptions.get(lane, option);
if (value != null)
{
return value;
}
value = this.nodeOptions.get(node, option);
if (value != null)
{
return value;
}
value = this.linkTypeOptions.get(linkType, option);
if (value != null)
{
return value;
}
value = this.options.get(null, option);
if (value != null)
{
return value;
}
return option.getDefaultValue();
}
/**
* Utility class to store options.
*
* Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
*
* BSD-style license. See OpenTrafficSim License.
*
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
* @param option value type
*/
public static final class Option
{
/** Id. */
private final String id;
/** Default value. */
private final K defaultValue;
/**
* Constructor.
* @param id String; id
* @param defaultValue K; default value
*/
Option(final String id, final K defaultValue)
{
this.id = id;
this.defaultValue = defaultValue;
}
/**
* Returns the default value.
* @return default value
*/
public K getDefaultValue()
{
return this.defaultValue;
}
/** {@inheritDoc} */
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
return result;
}
/** {@inheritDoc} */
@Override
public boolean equals(final Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
Option> other = (Option>) obj;
if (this.id == null)
{
if (other.id != null)
{
return false;
}
}
else if (!this.id.equals(other.id))
{
return false;
}
return true;
}
/** {@inheritDoc} */
@Override
public String toString()
{
return "Option [id=" + this.id + "]";
}
}
/**
* Single set of options for a certain category, i.e. lane, node, link type or null (i.e. global).
*
* Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
*
* BSD-style license. See OpenTrafficSim License.
*
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
* @param category type, i.e. {@code Lane}, {@code Node}, {@code LinkType} or {@code Void} (i.e. global).
*/
private class OptionSet
{
/** Options. */
private Map, Object>> optionsSet = new LinkedHashMap<>();
/**
* Constructor.
*/
OptionSet()
{
//
}
/**
* Set value in option set.
* @param category C; category
* @param option Option<K>; option
* @param value K; value
* @param option value type
*/
public void set(final C category, final Option option, final K value)
{
Map