Scenario - ScenarioBuilder
Scenario.ScenarioBuilderA builder to define a scenario to simulate and optionally optimise.
Example
const cash = new ResourceBuilder("cash")
.mapFromValue(1.0)
.assert({
predicate: x => GreaterEqual(x, 0),
message: "Cash must be positive",
});
const sales = new ProcessBuilder("sales")
.resource(cash)
.value("amount", FloatType)
.set("cash", (props, resources) => Add(resources.cash, props.amount))
.mapFromValue({ date: new Date(0), amount: 42.0, });
const scenario = new ScenarioBuilder('my_scenario')
.resource(cash)
.process(sales);
Type parameters
| Name | Type |
|---|---|
Resources | extends Record<string, ResourceDescription> = |
Processes | extends Object = |
Results | extends Record = |
MultiTrajectory | extends boolean = false |
Hierarchy
-
Builder↳
ScenarioBuilder
Other
endSimulation
▸ endSimulation(date):
ScenarioBuilder
End the scenario simulation at the specified date.
Note that the simulation will terminate before processes scheduled at this exact date.
Parameters
| Name | Type | Description |
|---|---|---|
date | null | Date | Stream | either a Date object, or a Stream of DateTimeType. |
Returns
ScenarioBuilder
objective
▸ objective(objective):
ScenarioBuilder
Define a contribution to the objective function to be optimized (maximised), by computing a float
Parameters
| Name | Type |
|---|---|
objective | (resources: { [K in string | number | symbol]: Variable }) => EastFunction |
Returns
ScenarioBuilder
Remarks
optimization will use the sum of all objective values in the case that multiple are defined
Example
const cash = new ResourceBuilder("cash")
.mapFromValue(1.0)
.assert({
predicate: x => GreaterEqual(x, 0),
message: "Cash must be positive",
});
const sales = new ProcessBuilder("sales")
.resource(cash)
.value("amount", FloatType)
.set("cash", (props, resources) => Add(resources.cash, props.amount))
.mapFromValue({ date: new Date(0), amount: 42.0, });
const scenario = new ScenarioBuilder('my_scenario')
.resource(cash)
.process(sales)
// optimization will try to maximise this - the cash balance!
.objective(resources => resources.cash)
overrideProcess
▸ overrideProcess(name, process):
ScenarioBuilder<Resources, Omit & { [K in string | number | symbol]: ProcessDescription<StructType<{ [P in string | number | symbol]: Properties[P]["type"] }>, StructType> }, Results, MultiTrajectory>
Override an existing process in a scenario with another. This is used to redefine a process inherited by
copyScenario or continueScenario for this scenario.This method will redirect all references to the existing process in the scenario (e.g.
ProcessBuilder.execute statements) to the new process, and remove the old process. To allow the translation of execute statements and continuation of the event queue, it is a requirement that the new process and old process share the same name and set of input value properties (defined through ProcessBuilder.value). Any computed properties or other process statements may differ. The ProcessBuilder.overrides method can help to construct an appropriate process.Type parameters
| Name | Type |
|---|---|
Name | extends string | number | symbol |
Values | extends Omit |
Properties | extends Record |
Parameters
| Name | Type | Description |
|---|---|---|
name | Name | the name of the process to override |
process | AbstractProcessBuilder<string, Values, Properties, Record, Record, Record> | a ProcessBuilder for the new process |
Returns
ScenarioBuilder<Resources, Omit & { [K in string | number | symbol]: ProcessDescription<StructType<{ [P in string | number | symbol]: Properties[P]["type"] }>, StructType> }, Results, MultiTrajectory>
Scenario
constructor
• new ScenarioBuilder(name, module?):
ScenarioBuilder
Create a builder to define a scneario to simulate and optionally optimise.
Type parameters
| Name | Type |
|---|---|
Resources | extends Record<string, ResourceDescription> = |
Processes | extends Object = |
Results | extends Record = |
MultiTrajectory | extends boolean = false |
Parameters
| Name | Type | Description |
|---|---|---|
name | string | the name of the builder |
module? | ModulePath | ModuleBuilder | - |
Returns
ScenarioBuilder
Example
const cash = new ResourceBuilder("cash")
.mapFromValue(1.0)
.assert({
predicate: x => GreaterEqual(x, 0),
message: "Cash must be positive",
});
const sales = new ProcessBuilder("sales")
.resource(cash)
.value("amount", FloatType)
.set("cash", (props, resources) => Add(resources.cash, props.amount))
.mapFromValue({ date: new Date(0), amount: 42.0, });
const scenario = new ScenarioBuilder('my_scenario')
.resource(cash)
.process(sales);
Overrides
Builder.constructor
alterProcessFromPipeline
▸ alterProcessFromPipeline(name, pipeline):
ScenarioBuilder
Replace the initial executions of a process in this scenario with values from a new pipeline.
Type parameters
| Name | Type |
|---|---|
Name | extends string | number | symbol |
Parameters
| Name | Type | Description |
|---|---|---|
name | Name | the name of the process |
pipeline | (builder: PipelineBuilder, baseline?: Stream<DictType>) => TabularPipelineBuilder<DictType, Record> | a function that builds and returns a Pipeline outputting the new executions to override the existing |
Returns
ScenarioBuilder
Remarks
The entire contents of the initial process executions will be overwritten (but any already existing "baseline" executions are made available to the pipeline).
Example
// create a process
const sales = new ProcessBuilder("sales")
.resource(cash)
.value("amount", FloatType)
.set("cash", (props, resources) => Add(resources.cash, props.amount))
.mapManyFromValue(new Map([["1", { date: new Date(0), amount: 42.0, }]]))
// create a scenario and add the process with doubled sales amount
const scenario = new ScenarioBuilder('my_scenario')
.resource(cash)
.process(sales)
.alterProcessFromPipeline(
"sales",
(builder, baseline) => builder.
.from(baseline)
.select({
keep_all: true,
selections: {
amount: fields => Multiply(fields.amount, 2.0),
}
})
)
alterProcessFromStream
▸ alterProcessFromStream(name, stream):
ScenarioBuilder
Replace the initial executions of a process in this scenario with values from a data stream.
Type parameters
| Name | Type |
|---|---|
Name | extends string | number | symbol |
Parameters
| Name | Type | Description |
|---|---|---|
name | Name | the name of the process |
stream | Stream<DictType> | a Stream containing the new executions to override the existing |
Returns
ScenarioBuilder
Remarks
The entire contents of the initial process executions will be overwritten.
Example
// create a process
const sales = new ProcessBuilder("sales")
.resource(cash)
.value("amount", FloatType)
.set("cash", (props, resources) => Add(resources.cash, props.amount))
.mapManyFromValue(new Map([["1", { date: new Date(0), amount: 42.0, }]]))
// create a stream for alternative sales executions
const alternative_sales = new SourceBuilder("alternative_sales")
.value({ value: new Map([["1", { date: new Date(0), amount: 84.0, }]]) })
// create a scenario and add the process with doubled sales amount
const scenario = new ScenarioBuilder('my_scenario')
.resource(cash)
.process(sales)
.alterProcessFromStream("sales", alternative_sales)
alterProcessFromValue
▸ alterProcessFromValue(name, value):
ScenarioBuilder
Replace the initial executions of a process in this scenario with provided values.
Type parameters
| Name | Type |
|---|---|
Name | extends string | number | symbol |
Parameters
| Name | Type | Description |
|---|---|---|
name | Name | the name of the process |
value | Map<string, ValueTypeOf> | the new executions to override the existing |
Returns
ScenarioBuilder
Remarks
The entire contents of the initial process executions will be overwritten.
Example
// create a process
const sales = new ProcessBuilder("sales")
.resource(cash)
.value("amount", FloatType)
.set("cash", (props, resources) => Add(resources.cash, props.amount))
.mapManyFromValue(new Map([["1", { date: new Date(0), amount: 42.0, }]]))
// create a scenario and add the process with doubled sales amount
const scenario = new ScenarioBuilder('my_scenario')
.resource(cash)
.process(sales)
.alterProcessFromValue("sales", new Map([["1", { date: new Date(0), amount: 84.0, }]]))
alterResourceFromPipeline
▸ alterResourceFromPipeline(name, pipeline):
ScenarioBuilder
Replace the initial value of a resource in this scenario with the output of a new pipeline.
Type parameters
| Name | Type |
|---|---|
Name | extends string | number | symbol |
Parameters
| Name | Type | Description |
|---|---|---|
name | Name | the name of the resource |
pipeline | (builder: PipelineBuilder, baseline: Stream) => Resources[Name]["type"] extends DictType ? TabularPipelineBuilder<any[any], Record> : GenericPipelineBuilder<Resources[Name]["type"], Record> | a function that builds and returns a Pipeline outputting the new value to override the existing |
Returns
ScenarioBuilder
Remarks
The entire contents of the initial resource value will be overwritten (but the already existing "baseline" inital value is made available to the pipeline).
Example
// create a resource
const cash = new ResourceBuilder("cash")
.mapFromValue(1000.0)
// create an alternative scenario with different initial cash balance from a pipeline
const scenario = new ScenarioBuilder('my_scenario')
.resource(cash)
.alterResourceFromPipeline(
"cash",
(builder, baseline) => Builder
.from(baseline)
.transform(cash => Multiply(cash, 2.0))
)
alterResourceFromStream
▸ alterResourceFromStream(name, stream):
ScenarioBuilder
Replace the initial value of a resource in this scenario with a value from a data stream.
Type parameters
| Name | Type |
|---|---|
Name | extends string | number | symbol |
Parameters
| Name | Type | Description |
|---|---|---|
name | Name | the name of the resource |
stream | Stream | the Stream containing the new value to override the existing |
Returns
ScenarioBuilder
Remarks
The entire contents of the initial resource value will be overwritten.
Example
// create a resource
const cash = new ResourceBuilder("cash")
.mapFromValue(1000.0)
// create a stream for alternative initial cash balance
const alternative_cash = new SourceBuilder("alternative_cash")
.value({ value: 2000.0 })
// create an alternative scenario with different initial cash balance from a stream
const scenario = new ScenarioBuilder('my_scenario')
.resource(cash)
.alterResourceFromStream("cash", alternative_cash)
alterResourceFromValue
▸ alterResourceFromValue(name, value):
ScenarioBuilder
Replace the initial value of a resource in this scenario with a provided value.
Type parameters
| Name | Type |
|---|---|
Name | extends string | number | symbol |
Parameters
| Name | Type | Description |
|---|---|---|
name | Name | the name of the resource |
value | ValueTypeOf | the new value to override the existing |
Returns
ScenarioBuilder
Remarks
The entire contents of the initial resource value will be overwritten.
Example
// create a resource
const cash = new ResourceBuilder("cash")
.mapFromValue(1000.0)
// create an alternative scenario with different initial cash balance from a value
const scenario = new ScenarioBuilder('my_scenario')
.resource(cash)
.alterResourceFromValue("cash", 2000.0)
continueScenario
▸ continueScenario(builder):
ScenarioBuilder
Inherit all details from a given ScenarioBuilder in this scenario, starting with the
simulation state (resource values and process event queue) from the end of the previous
scenario. This can be used to chain two scenario simulations in time (for example,
having a first scenario simulating historical events followed by a second scenario
predicting future events).
This differs from
copyScenario by starting with the final simulation state of the other scenario, rather than the initial state. Also, the simulation end date is not copied.Type parameters
| Name | Type |
|---|---|
R | extends Record<string, ResourceDescription> |
P | extends Record<string, ProcessDescription> |
Res | extends Record |
Parameters
| Name | Type | Description |
|---|---|---|
builder | ScenarioBuilder | the ScenarioBuilder to continue from |
Returns
ScenarioBuilder
Example
// create a resource
const cash = new ResourceBuilder("cash")
.mapFromValue(1.0)
// create a first scenario
const first_scenario = new ScenarioBuilder('first_scenario')
.resource(cash)
// create a second scenario following the first
const second_scenario = new ScenarioBuilder('second_scenario')
.continueScenario(first_scenario)
copyScenario
▸ copyScenario(builder):
ScenarioBuilder
Inherit all details from a given ScenarioBuilder in this scenario. This can be used
to create two similar scenarios for comparison (for example, to compare predictions
of optimized and unoptimized scenarios).
This differs from
continueScenario by starting with the same initial simulation state as the copied scenario.Type parameters
| Name | Type |
|---|---|
R | extends Record<string, ResourceDescription> |
P | extends Record<string, ProcessDescription> |
Res | extends Record |
Parameters
| Name | Type | Description |
|---|---|---|
builder | ScenarioBuilder | the ScenarioBuilder to copy from |
Returns
ScenarioBuilder
Example
// create a resource
const cash = new ResourceBuilder("cash")
.mapFromValue(1.0)
// create a scenario
const scenario = new ScenarioBuilder('my_scenario')
.resource(cash)
// create a scenario from the other one
const similar_scenario = new ScenarioBuilder('similar_scenario')
.copyScenario(scenario)
distributed
▸ distributed(is_distributed):
ScenarioBuilder
Set the calculations to be performed in a distributed way, accross multiple tasks and able to take advantage of multiple worker nodes in parallel (instead of the default in-process, single-task method).
Parameters
| Name | Type | Description |
|---|---|---|
is_distributed | boolean | true if the calculations should be performed distributed |
Returns
ScenarioBuilder
Remarks
Distributed simulations are faster for demanding simulations with many trajectories, but orchestration overheads may make it slower for simple simulations.
optimizationAlgorithm
▸ optimizationAlgorithm(algorithm):
ScenarioBuilder
Set the optimzation algorithm to employ to search the parameter space (default = "gradient_free").
Parameters
| Name | Type | Description |
|---|---|---|
algorithm | OptimizationAlgorithm | the algorithm to apply |
Returns
ScenarioBuilder
optimizationAtol
▸ optimizationAtol(atol):
ScenarioBuilder
Set the absolute tolerance required to trigger convergence detection. Set to 0 if absolute convergence detection is not desired.
Parameters
| Name | Type | Description |
|---|---|---|
atol | number | the absolute tolerance required for convergence (default = 0.0) |
Returns
ScenarioBuilder
optimizationInMemory
▸ optimizationInMemory(in_memory):
ScenarioBuilder
Set the optimization to be performed in memory (instead of the default out-of-core method).
Parameters
| Name | Type | Description |
|---|---|---|
in_memory | boolean | true if the optimization should be performed in memory |
Returns
ScenarioBuilder
Remarks
In-memory optimization may be faster but requires more RAM.
optimizationMaxIterations
▸ optimizationMaxIterations(max_iterations):
ScenarioBuilder
Set the maximum number of optimization iterations to complete.
Parameters
| Name | Type | Description |
|---|---|---|
max_iterations | number | the maximum number of optimization iterations |
Returns
ScenarioBuilder
optimizationMinIterations
▸ optimizationMinIterations(min_iterations):
ScenarioBuilder
Set the minimum number of iterations to complete before detecting for convergence
Parameters
| Name | Type | Description |
|---|---|---|
min_iterations | number | the minimum number of iterations to complete before detecting for convergence. |
Returns
ScenarioBuilder
optimizationMultithreaded
▸ optimizationMultithreaded(threads):
ScenarioBuilder
Set the optimzation to be performed multi-threaded (instead of the default single-thread method).
Parameters
| Name | Type | Description |
|---|---|---|
threads | boolean | true if the optimization should use multiple threads |
Returns
ScenarioBuilder
optimizationRtol
▸ optimizationRtol(rtol):
ScenarioBuilder
Set the relative tolerance required to trigger convergence detection. Set to 0 if relative convergence detection is not desired.
Parameters
| Name | Type | Description |
|---|---|---|
rtol | number | the relative tolerance required for convergence (default = 1.0e-3) |
Returns
ScenarioBuilder
optimizationStream
▸ optimizationStream():
Stream
Return a
Stream detailing the optimzation procedure, where convergence of optimization can be validated.Returns
Stream
optimizationTrajectories
▸ optimizationTrajectories(n_trajectories):
ScenarioBuilder
Set the number of Monte-Carlo trajectories to be performed during optimization.
Parameters
| Name | Type | Description |
|---|---|---|
n_trajectories | number | the number of monte carlo trajectories |
Returns
ScenarioBuilder
Remarks
More trajectories will give greater certainty that the optimized recommendations are robust to any randomness in the scenario simulation, but will incur a greater computational cost.
optimize
▸ optimize(name, config):
ScenarioBuilder
Optimize the initial value of a resource to maximize the final objective.
The optimizer can search for optimal values using one of three different strategies:
- searching between
minandmaxvalues (for float/integer/datetime resources) - selecting one of a
rangecontaining an array of possible values - using a custom
transformto construct a value from a search parameter between0.0and1.0
Type parameters
| Name | Type |
|---|---|
Name | extends string | number | symbol |
Parameters
| Name | Type | Description |
|---|---|---|
name | Name | the resource to optimize |
config | Object | the configuration of the optimization |
config.max | ValueTypeOf | (resources: { [K in string | number | symbol]: Variable }) => EastFunction | The maximum value that the optimzer may apply (inclusive) |
config.min? | ValueTypeOf | (resources: { [K in string | number | symbol]: Variable }) => EastFunction | The minimum value that the optimzer may apply (inclusive, default 0) |
Returns
ScenarioBuilder
Remarks
each optimize added results in significant compute so should be used sparingly
Example
// create a some cash
const cash = new ResourceBuilder("cash")
.mapFromValue(1.0)
.assert({
predicate: x => GreaterEqual(x, 0),
message: "Cash must be positive",
});
// the price resource to optimize
const price = new ResourceBuilder("price")
.mapFromValue(1.0)
const sales = new ProcessBuilder("sales")
.resource(cash)
.resource(price)
.value("qty", FloatType)
.set("cash", (props, resources) => Add(resources.cash, Multiply(props.qty, resources.price)))
.mapFromValue({ date: new Date(0), qty: 10.0, });
const scenario = new ScenarioBuilder('my_scenario')
.resource(cash)
.process(sales)
.resource(price)
// optimization will try to maximise this - the cash balance!
.objective("cash", (cash) => cash)
// tell optimization to find the price that will
// satisfy the objective and maximise cash
.optimize("price", { min: 0, max: 20.0 })
optimizeEvery
▸ optimizeEvery(name, field, config):
ScenarioBuilder
Optimize the initial values of a field inside a tabular (i.e. dictionary of structs) resource to maximize the final objective.
The optimizer can search for optimal values using one of three different strategies:
- searching between
minandmaxvalues (for float/integer/datetime fields) - selecting one of a
rangecontaining an array of possible values - using a custom
transformto construct a value from a search parameter between0.0and1.0
Type parameters
| Name | Type |
|---|---|
Name | extends string |
Parameters
| Name | Type | Description |
|---|---|---|
name | Name | the resource to optimize |
field | Resources[Name]["type"] extends DictType ? keyof any[any]["value"]["value"]["value"] : never | - |
config | Object | the configuration of the optimization (available fields include active, min, max, range and transform) |
config.active? | (resources: { [K in string | number | symbol]: Variable }, value: Resources[Name]["type"] extends DictType ? Variable : never, key: Resources[Name]["type"] extends DictType ? Variable : never) => EastFunction | - |
config.max | number | bigint | Date | (resources: { [K in string | number | symbol]: Variable }, value: Resources[Name]["type"] extends DictType ? Variable : never, key: Resources[Name]["type"] extends DictType ? Variable : never) => EastFunction<IntegerType | FloatType | DateTimeType> | - |
config.min? | number | bigint | Date | (resources: { [K in string | number | symbol]: Variable }, value: Resources[Name]["type"] extends DictType ? Variable : never, key: Resources[Name]["type"] extends DictType ? Variable : never) => EastFunction<IntegerType | FloatType | DateTimeType> | - |
Returns
ScenarioBuilder
Remarks
each optimize added results in significant compute so should be used sparingly
Example
// create a some cash
const cash = new ResourceBuilder("cash")
.mapFromValue(1.0)
.assert({
predicate: x => GreaterEqual(x, 0),
message: "Cash must be positive",
});
// the prices resource to optimize
const prices = new ResourceBuilder("prices")
.mapFromValue(new Map([
["socks", { price: 1 }],
["chairs", { price: 4 }],
["coffee", { price: 3 }]
]))
// create a process
const sales = new ProcessBuilder("sales")
.resource(cash)
.resource(prices)
.value("qty", FloatType)
.value("item", StringType)
.set("cash", (props, resources) => Add(
resources.cash,
Multiply(props.qty, GetField(Get(resources.prices, props.item), "price"))
))
.mapFromValue({ date: new Date(0), qty: 10.0, item: "coffee" });
// create a scenario
const scenario = new ScenarioBuilder('my_scenario')
.resource(cash)
.process(sales)
.resource(prices)
// optimization will try to maximise this - the cash balance!
.objective("cash", (cash) => cash)
// tell optimization to find the price that will
// satisfy the objective and maximise cash
.optimizeEvery("prices", "price", { min: 0, max: 20.0 })
optimizedStreams
▸ optimizedStreams(): { [K in string | number | symbol]: Stream }
Return a record of
Streams containing the automatically optimized values for the initial simulation resources.Returns
{ [K in string | number | symbol]: Stream }
process
▸ process(process):
ScenarioBuilder<Resources, Processes & { [K in string]: ProcessDescription<StructType<{ [P in string | number | symbol]: Properties[P]["type"] }>, StructType> }, Results, MultiTrajectory>
Add a process to the scenario.
Type parameters
| Name | Type |
|---|---|
Name | extends string |
Values | extends Record |
Properties | extends Record |
Parameters
| Name | Type | Description |
|---|---|---|
process | AbstractProcessBuilder<Name, Values, Properties, Record, Record, Record> | the ProcessBuilder to add to this ScenarioBuilder |
Returns
ScenarioBuilder<Resources, Processes & { [K in string]: ProcessDescription<StructType<{ [P in string | number | symbol]: Properties[P]["type"] }>, StructType> }, Results, MultiTrajectory>
Example
// create a process
const sales = new ProcessBuilder("sales")
.resource(cash)
.value("amount", FloatType)
.set("cash", (props, resources) => Add(resources.cash, props.amount))
.mapFromValue({ date: new Date(0), amount: 42.0, });
// create a scenario and add the process
const scenario = new ScenarioBuilder('my_scenario')
.process(sales);
resource
▸ resource(resource, config?):
ScenarioBuilder<Resources & { [K in string]: ResourceDescription }, Processes, Results & { [K in string]: T }, MultiTrajectory>
Add a resource to the scenario.
Type parameters
| Name | Type |
|---|---|
Name | extends string |
T | extends EastType |
Parameters
| Name | Type | Description |
|---|---|---|
resource | SimulationResourceBuilder | the ResourceBuilder to add to this ScenarioBuilder |
config? | Object | the configuration of the addition |
config.result? | true | if the true the result Stream will be created (default true) |
Returns
ScenarioBuilder<Resources & { [K in string]: ResourceDescription }, Processes, Results & { [K in string]: T }, MultiTrajectory>
Example
// create a resource
const cash = new ResourceBuilder("cash")
.mapFromValue(1.0)
.assert({
predicate: x => GreaterEqual(x, 0),
message: "Cash must be positive",
});
// create a scenario and add the resource
const scenario = new ScenarioBuilder('my_scenario')
.resource(cash)
result
▸ result(name, result):
ScenarioBuilder<Resources, Processes, Results & { [K in string]: ReturnType["type"] }, MultiTrajectory>
Add a result to return from the scenario simulation. Results are computed from the resource values at the end of the simulation.
Type parameters
| Name | Type |
|---|---|
Name | extends string |
R | extends (resources: { [K in string | number | symbol]: Variable }) => EastFunction |
Parameters
| Name | Type | Description |
|---|---|---|
name | Name | the name of this result |
result | R | a function returning an EastFunction to compute the value to return |
Returns
ScenarioBuilder<Resources, Processes, Results & { [K in string]: ReturnType["type"] }, MultiTrajectory>
Example
const cash = new ResourceBuilder("cash")
.mapFromValue(1.0);
const sales = new ProcessBuilder("sales")
.resource(cash)
.value("amount", FloatType)
.set("cash", (props, resources) => Add(resources.cash, props.amount))
.mapFromValue({ date: new Date(0), amount: 42.0, });
// add a result that computes whether the final cash balance is positive or negative
const scenario = new ScenarioBuilder('my_scenario')
.resource(cash)
.process(sales)
.result("cash_is_positive", resources => GreaterEqual(resources.cash, 0));
// get the datastream containing the result
const cash_is_positive_stream = scenario.simulationResultStreams()["cash_is_positive"]
setInitialQueueStream
▸ setInitialQueueStream(stream):
ScenarioBuilder
Set the initial simulation queue present at the beginning of the similation.
This is an alternative method to instantiating processes via ProcessBuilder mappings,
and allows one to import the final simulation queue from one scenario into another
scenario (e.g. to simulate the continuation of time across scenarious). Note that any
existing process mappings are also added to the queue before the simulation begins.
Parameters
| Name | Type | Description |
|---|---|---|
stream | null | The datastream defining the initial queue. The queue itself is an array of variants (where each variant case corresponding to a process in the scenario and associated execution date and value properties). Can be set to null if no initial queue is desired. |
Returns
ScenarioBuilder
simulationDebugMode
▸ simulationDebugMode(enable):
ScenarioBuilder
Set the simulation to be in debug mode, where errors become warnings.
Parameters
| Name | Type | Description |
|---|---|---|
enable | boolean | true if the simulation should be run in debug mode |
Returns
ScenarioBuilder
Remarks
This can help to debug problems with simulation models, but is not recommended for production settings.
simulationInMemory
▸ simulationInMemory(in_memory):
ScenarioBuilder
Set the simulation to be performed in-memory or out-of-core.
Parameters
| Name | Type | Description |
|---|---|---|
in_memory | boolean | true if the simulation should be performed in-memory or false for an out-of-core method |
Returns
ScenarioBuilder
Remarks
In-memory simulations may be faster but require more RAM.
simulationJournal
▸ simulationJournal(enabled):
ScenarioBuilder
Set whether to produce an output
Stream containing the simulation journal detailing all process executions (default =true).
Parameters
| Name | Type | Description |
|---|---|---|
enabled | boolean | true if the simulation journal should be created |
Returns
ScenarioBuilder
simulationJournalStream
▸ simulationJournalStream(): MultiTrajectory extends false ?
Stream<ArrayType<VariantType<{ [K in string | number | symbol]: Processes[K]["type"] }>>> : Stream<ArrayType<ArrayType<VariantType<{ [K in string | number | symbol]: Processes[K]["type"] }>>>>
Return a
Stream containing a single journal detailing all the processes that occurs during a simulation in chronological order.Returns
MultiTrajectory extends false ?
Stream<ArrayType<VariantType<{ [K in string | number | symbol]: Processes[K]["type"] }>>> : Stream<ArrayType<ArrayType<VariantType<{ [K in string | number | symbol]: Processes[K]["type"] }>>>>
Remarks
the simulation journal can be disabled using the simulationJournal method.
Example
simulationQueue
▸ simulationQueue(enabled):
ScenarioBuilder
Set whether to produce an output
Stream containing the simulation queue detailing all processes awaiting execution at the end of the simulation (default =true).
Parameters
| Name | Type | Description |
|---|---|---|
enabled | boolean | true if the simulation queue should be created |
Returns
ScenarioBuilder
simulationQueueStream
▸ simulationQueueStream(): MultiTrajectory extends false ?
Stream<ArrayType<VariantType<{ [K in string | number | symbol]: Processes[K]["values"] }>>> : Stream<ArrayType<ArrayType<VariantType<{ [K in string | number | symbol]: Processes[K]["values"] }>>>>
Return a
Stream containing an array ofall the processes pending at the end of simulation in priority queue order.Returns
MultiTrajectory extends false ?
Stream<ArrayType<VariantType<{ [K in string | number | symbol]: Processes[K]["values"] }>>> : Stream<ArrayType<ArrayType<VariantType<{ [K in string | number | symbol]: Processes[K]["values"] }>>>>
Remarks
the simulation queue can be disabled using the simulationQueue method.
Example
simulationResultStreams
▸ simulationResultStreams(): MultiTrajectory extends false ? { [K in string | number | symbol]: Stream } : { [K in string | number | symbol]: Stream<ArrayType> }
Return a record of
Streams containing the final simulation results.Returns
MultiTrajectory extends false ? { [K in string | number | symbol]: Stream } : { [K in string | number | symbol]: Stream<ArrayType> }
Remarks
results default to the final value of each resource (unless explicitly disabled), and additional results can be computed with
ScenarioBuilder.resourcesimulationTrajectories
▸ simulationTrajectories(n_trajectories):
ScenarioBuilder
Set the number of Monte-Carlo trajectories to be performed during simulation.
Using this setting affects the result, journal and queue types. For each result an array of individual trajactory results will be emitted. Similarly an array of journals and queues will be emitted, with the data recorded for each trajectory.
Parameters
| Name | Type | Description |
|---|---|---|
n_trajectories | null | the number of Monte-Carlo trajectories, or null for single trajectory (default null) |
Returns
ScenarioBuilder
Remarks
More trajectories will give greater statistical certainty in the results, but will incur a greater computational cost.
toTemplate
▸ toTemplate():
Template
Convert the built scenario into an
Template, for usage in an EDK project.Returns
Template
a
TemplateExample
const cash = new ResourceBuilder("cash")
.mapFromValue(1.0)
.assert({
predicate: x => GreaterEqual(x, 0),
message: "Cash must be positive",
});
const sales = new ProcessBuilder("sales")
.resource(cash)
.value("amount", FloatType)
.set("cash", (props, resources) => Add(resources.cash, props.amount))
.mapFromValue({ date: new Date(0), amount: 42.0, });
const scenario = new ScenarioBuilder('my_scenario')
.resource(cash)
.process(sales)
.toTemplate();
Overrides
Builder.toTemplate