File |
Line |
nl/tudelft/simulation/jstats/distributions/empirical/DistributionFrequencies.java |
37 |
nl/tudelft/simulation/jstats/distributions/empirical/DistributionFrequencies.java |
117 |
public static DiscreteEmpiricalDistribution createDiscreteDistribution(final Number[] values, final long[] frequencies)
{
Throw.whenNull(values, "values array cannot be null");
Throw.whenNull(frequencies, "frequencies array cannot be null");
Throw.when(values.length == 0, IllegalArgumentException.class, "values array cannot be empty");
Throw.when(frequencies.length == 0, IllegalArgumentException.class, "frequencies array cannot be empty");
Throw.when(frequencies.length != values.length, IllegalArgumentException.class,
"values array and frequencies array should have the same length");
double sum = 0.0;
for (int i = 0; i < frequencies.length; i++)
{
Throw.when(frequencies[i] <= 0, IllegalArgumentException.class, "frequency cannot be zero or negative");
sum += 1.0 * frequencies[i];
}
double[] cumulativeProbabilities;
double partialSum = 0;
cumulativeProbabilities = new double[frequencies.length];
for (int i = 0; i < frequencies.length; i++)
{
partialSum += 1.0 * frequencies[i];
cumulativeProbabilities[i] = partialSum / sum;
}
cumulativeProbabilities[cumulativeProbabilities.length - 1] = 1.0;
return new DiscreteEmpiricalDistribution(values.clone(), cumulativeProbabilities);
}
/**
* Create a discrete empirical distribution from two arrays, one with frequencies or weights, and one with corresponding
* values.
* @param values double[] the values
* @param frequencies long[]; the frequencies for the corresponding values
* @return the cumulative distribution object belonging to the given arrays
* @throws NullPointerException when values array is null or frequencies array is null, or when one of the values is null
* @throws IllegalArgumentException when frequencies array or values array are empty, or have unequal length, or when
* frequencies are zero or negative, or when values are not in ascending order
*/
public static DiscreteEmpiricalDistribution createDiscreteDistribution(final double[] values, final long[] frequencies) |
File |
Line |
nl/tudelft/simulation/jstats/ode/integrators/RungeKuttaCashCarp.java |
49 |
nl/tudelft/simulation/jstats/ode/integrators/RungeKuttaFehlberg.java |
49 |
public RungeKuttaCashCarp(final double stepSize, final DifferentialEquationInterface equation)
{
super(stepSize, equation);
}
/** {@inheritDoc} */
@Override
public double[] next(final double x, final double[] y)
{
double[][] k = new double[nk][];
for (int i = 0; i < nk; i++)
{
double[] ysum = y.clone();
for (int j = 0; j < i; j++)
{
if (b[i][j] != 0.0)
{
ysum = add(ysum, multiply(b[i][j], k[j]));
}
}
k[i] = multiply(this.stepSize, this.equation.dy(x + a[i] * this.stepSize, ysum));
}
double[] sum = y.clone();
super.error = new double[y.length];
for (int i = 0; i < nk; i++)
{
sum = add(sum, this.multiply(c[i], k[i])); |
File |
Line |
nl/tudelft/simulation/dsol/simulators/DevDessAnimator.java |
89 |
nl/tudelft/simulation/dsol/simulators/DevsAnimator.java |
72 |
&& runUntil.compareTo(this.eventList.first().getAbsoluteExecutionTime()) >= 0)
{
synchronized (super.semaphore)
{
int cmp = this.eventList.first().getAbsoluteExecutionTime().compareTo(this.runUntilTime);
if ((cmp == 0 && !this.runUntilIncluding) || cmp > 0)
{
this.simulatorTime = SimTime.copy(this.runUntilTime);
this.runState = RunState.STOPPING;
break;
}
SimEventInterface<T> event = this.eventList.removeFirst();
if (event.getAbsoluteExecutionTime().compareTo(super.simulatorTime) != 0)
{
super.fireUnverifiedTimedEvent(SimulatorInterface.TIME_CHANGED_EVENT, null,
event.getAbsoluteExecutionTime());
}
this.simulatorTime = event.getAbsoluteExecutionTime();
try
{
event.execute();
if (this.eventList.isEmpty())
{
this.simulatorTime = SimTime.copy(this.runUntilTime);
this.runState = RunState.STOPPING;
break;
}
}
catch (Exception exception)
{
handleSimulationException(exception);
}
}
} |
File |
Line |
nl/tudelft/simulation/dsol/simulators/DevDessAnimator.java |
91 |
nl/tudelft/simulation/dsol/simulators/DevDessSimulator.java |
80 |
nl/tudelft/simulation/dsol/simulators/DevsAnimator.java |
74 |
synchronized (super.semaphore)
{
int cmp = this.eventList.first().getAbsoluteExecutionTime().compareTo(this.runUntilTime);
if ((cmp == 0 && !this.runUntilIncluding) || cmp > 0)
{
this.simulatorTime = SimTime.copy(this.runUntilTime);
this.runState = RunState.STOPPING;
break;
}
SimEventInterface<T> event = this.eventList.removeFirst();
if (event.getAbsoluteExecutionTime().compareTo(super.simulatorTime) != 0)
{
super.fireUnverifiedTimedEvent(SimulatorInterface.TIME_CHANGED_EVENT, null,
event.getAbsoluteExecutionTime());
}
this.simulatorTime = event.getAbsoluteExecutionTime();
try
{
event.execute();
if (this.eventList.isEmpty())
{
this.simulatorTime = SimTime.copy(this.runUntilTime);
this.runState = RunState.STOPPING;
break;
}
}
catch (Exception exception)
{
handleSimulationException(exception);
}
} |
File |
Line |
nl/tudelft/simulation/dsol/statistics/SimCounter.java |
59 |
nl/tudelft/simulation/dsol/statistics/SimTally.java |
57 |
public SimCounter(final String description, final DsolModel<T, ? extends SimulatorInterface<T>> model)
{
super(description);
Throw.whenNull(model, "model cannot be null");
model.getOutputStatistics().add(this);
this.simulator = model.getSimulator();
try
{
// only if we are before the warmup time, subscribe to the warmul event
if (this.simulator.getSimulatorTime().compareTo(this.simulator.getReplication().getWarmupTime()) < 0)
{
this.simulator.addListener(this, Replication.WARMUP_EVENT, ReferenceType.STRONG);
}
ContextInterface context =
ContextUtil.lookupOrCreateSubContext(this.simulator.getReplication().getContext(), "statistics");
context.bindObject(this);
}
catch (NamingException | RemoteException exception)
{
this.simulator.getLogger().always().warn(exception, "<init>");
}
}
/**
* constructs a new SimCounter.
* @param description String; the description
* @param model DsolModel<T, SimulatorInterface<T>>; the model
* @param target EventProducer; the target on which to count
* @param eventType EventType; the EventType for which counting takes place
*/
public SimCounter(final String description, final DsolModel<T, ? extends SimulatorInterface<T>> model, |
File |
Line |
nl/tudelft/simulation/dsol/eventlists/EventListPriorityQueue.java |
49 |
nl/tudelft/simulation/dsol/eventlists/RedBlackTree.java |
64 |
}
/** {@inheritDoc} */
@Override
public void add(final SimEventInterface<T> event)
{
this.eventList.add(event);
}
/** {@inheritDoc} */
@Override
public boolean contains(final SimEventInterface<T> event)
{
return this.eventList.contains(event);
}
/** {@inheritDoc} */
@Override
public void clear()
{
this.eventList.clear();
}
/** {@inheritDoc} */
@Override
public boolean isEmpty()
{
return this.eventList.isEmpty();
}
/** {@inheritDoc} */
@Override
public Iterator<SimEventInterface<T>> iterator()
{
return this.eventList.iterator();
}
/** {@inheritDoc} */
@Override
public boolean remove(final SimEventInterface<T> event)
{
return this.eventList.remove(event);
}
/** {@inheritDoc} */
@Override
public int size()
{
return this.eventList.size();
}
} |
File |
Line |
nl/tudelft/simulation/dsol/statistics/SimCounter.java |
89 |
nl/tudelft/simulation/dsol/statistics/SimTally.java |
87 |
public SimCounter(final String description, final DsolModel<T, ? extends SimulatorInterface<T>> model,
final EventProducer target, final EventType eventType)
{
this(description, model);
try
{
target.addListener(this, eventType, ReferenceType.STRONG);
}
catch (RemoteException exception)
{
this.simulator.getLogger().always().warn(exception, "<init>");
}
}
/** {@inheritDoc} */
@Override
public void initialize()
{
super.initialize();
// note that when initialize() is called from the (super) constructor, there cannot be listeners yet
if (this.simulator != null)
{
try
{
fireTimedEvent(TIMED_INITIALIZED_EVENT, this, this.simulator.getSimulatorTime());
}
catch (RemoteException exception)
{
this.simulator.getLogger().always().warn(exception, "initialize()");
}
}
}
/** {@inheritDoc} */
@Override |
File |
Line |
nl/tudelft/simulation/dsol/statistics/SimCounter.java |
89 |
nl/tudelft/simulation/dsol/statistics/SimPersistent.java |
90 |
nl/tudelft/simulation/dsol/statistics/SimTally.java |
87 |
public SimCounter(final String description, final DsolModel<T, ? extends SimulatorInterface<T>> model,
final EventProducer target, final EventType eventType)
{
this(description, model);
try
{
target.addListener(this, eventType, ReferenceType.STRONG);
}
catch (RemoteException exception)
{
this.simulator.getLogger().always().warn(exception, "<init>");
}
}
/** {@inheritDoc} */
@Override
public void initialize()
{
super.initialize();
// note that when initialize() is called from the (super) constructor, there cannot be listeners yet
if (this.simulator != null)
{
try
{
fireTimedEvent(TIMED_INITIALIZED_EVENT, this, this.simulator.getSimulatorTime());
}
catch (RemoteException exception)
{
this.simulator.getLogger().always().warn(exception, "initialize()");
}
}
}
/** {@inheritDoc} */
@Override |
File |
Line |
nl/tudelft/simulation/jstats/ode/integrators/RungeKutta3.java |
27 |
nl/tudelft/simulation/jstats/ode/integrators/RungeKutta4.java |
27 |
public RungeKutta3(final double stepSize, final DifferentialEquationInterface equation)
{
super(stepSize, equation);
}
/** {@inheritDoc} */
@Override
public double[] next(final double x, final double[] y)
{
double[] k1 = this.equation.dy(x, y);
double[] k2 = this.equation.dy(x + 0.5 * this.stepSize, add(y, multiply(0.5 * this.stepSize, k1)));
double[] k3 = this.equation.dy(x + 0.5 * this.stepSize, add(y, multiply(0.5 * this.stepSize, k2)));
double[] sum = add(k1, multiply(4.0, k2), k3); |
File |
Line |
nl/tudelft/simulation/dsol/simulators/DevDessAnimator.java |
43 |
nl/tudelft/simulation/dsol/simulators/DevsAnimator.java |
40 |
@Override
public long getAnimationDelay()
{
return this.animationDelay;
}
/** {@inheritDoc} */
@Override
public void setAnimationDelay(final long animationDelay)
{
this.animationDelay = animationDelay;
this.fireEvent(ANIMATION_DELAY_CHANGED_EVENT, animationDelay);
}
/** {@inheritDoc} */
@Override
public void updateAnimation()
{
this.fireTimedEvent(AnimatorInterface.UPDATE_ANIMATION_EVENT, null, this.simulatorTime);
}
/** {@inheritDoc} */
@Override
public void run()
{
AnimationThread animationThread = new AnimationThread(this);
animationThread.start();
// set the run flag semaphore to signal to startImpl() that the run method has started
this.runflag = true;
while (!isStoppingOrStopped() && !this.eventList.isEmpty()
&& this.simulatorTime.compareTo(this.replication.getEndTime()) <= 0)
{ |
File |
Line |
nl/tudelft/simulation/dsol/model/inputparameters/InputParameterDoubleScalar.java |
76 |
nl/tudelft/simulation/dsol/model/inputparameters/InputParameterFloatScalar.java |
75 |
public InputParameterDoubleScalar(final String key, final String shortName, final String description, final T defaultValue,
final T minimumValue, final T maximumValue, final boolean minIncluded, final boolean maxIncluded,
final String format, final double displayPriority) throws InputParameterException
{
this(key, shortName, description, defaultValue, minimumValue.si, maximumValue.si, minIncluded, maxIncluded, format,
displayPriority);
Throw.whenNull(format, "format cannot be null");
Throw.whenNull(defaultValue, "defaultValue cannot be null");
Throw.whenNull(minimumValue, "minimumValue cannot be null");
Throw.whenNull(maximumValue, "maximumValue cannot be null");
}
/**
* Construct a new InputParameterDoubleScalar.
* @param key String; unique (within the parent's input parameter map) name of the new InputParameterDoubleUnit
* @param shortName String; concise description of the input parameter
* @param description String; double description of the input parameter (may use HTML markup)
* @param defaultValue T; the default value of this input parameter
* @param minimumValueSI double; the lowest value allowed as input (in SI units)
* @param maximumValueSI double; the highest value allowed as input (in SI units)
* @param minIncluded boolean; is the minimum value included or excluded in the allowed interval?
* @param maxIncluded boolean; is the maximum value included or excluded in the allowed interval?
* @param format String; the format to use in displaying the double
* @param displayPriority double; sorting order when properties are displayed to the user
* @throws NullPointerException when key, shortName, defaultValue, description, format, or defaultValue is null
* @throws IllegalArgumentException when displayPriority is NaN
* @throws InputParameterException when unit for the default value cannot be found in the unit definition
*/
@SuppressWarnings("checkstyle:parameternumber")
public InputParameterDoubleScalar(final String key, final String shortName, final String description, final T defaultValue, |
File |
Line |
nl/tudelft/simulation/dsol/model/inputparameters/InputParameterDoubleScalar.java |
113 |
nl/tudelft/simulation/dsol/model/inputparameters/InputParameterFloatScalar.java |
112 |
-Double.MAX_VALUE, Double.MAX_VALUE, false, false, format, 1.0));
add(new InputParameterUnit<U>("unit", "unit", "unit for the value", defaultValue.getDisplayUnit(), 2.0));
this.minimumValueSI = minimumValueSI;
this.maximumValueSI = maximumValueSI;
this.minIncluded = minIncluded;
this.maxIncluded = maxIncluded;
}
/**
* @return the unit sub-parameter
* @throws RuntimeException when parameter map has been corrupted and no unit parameter can be found
*/
@SuppressWarnings("unchecked")
public InputParameterUnit<U> getUnitParameter()
{
try
{
return (InputParameterUnit<U>) get("unit");
}
catch (InputParameterException exception)
{
throw new RuntimeException(
"Parameter map has been corrupted and no unit parameter can be found for field " + getShortName(),
exception);
}
}
/**
* @return the double sub-parameter
* @throws RuntimeException when parameter map has been corrupted and no value parameter can be found
*/
public InputParameterDouble getDoubleParameter() |