Scenario - ResourceBuilder
Scenario.ResourceBuilderA builder to define a resource for simulation.
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 |
---|---|
Name | extends string |
Resource
constructor
• new ResourceBuilder(name
, module?
):
ResourceBuilder
Construct a resource with a given name.
Type parameters
Name | Type |
---|---|
Name | extends string |
Parameters
Name | Type | Description |
---|---|---|
name | Name | the name of the ResourceBuilder. |
module? | ModulePath | ModuleBuilder | - |
Returns
ResourceBuilder
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);
mapFromPipeline
▸ mapFromPipeline(pipeline
): SimulationResourceBuilder
<Name
, ReturnType
<ReturnType
["outputStream"
]>["type"
]>
Assign the resource's initial state to the value contained output from a pipeline.
Type parameters
Name | Type |
---|---|
P | extends (builder : PipelineBuilder ) => TabularPipelineBuilder <DictType , Record > | GenericPipelineBuilder <EastType , Record > |
Parameters
Name | Type |
---|---|
pipeline | P |
Returns
SimulationResourceBuilder
<Name
, ReturnType
<ReturnType
["outputStream"
]>["type"
]>
Remarks
The pipeline
can output any EastType stream
Example
// a stream to map from
const data = new SourceBuilder("inventory data")
.value({
value: new Map([
["one", {
date: new Date(0),
qty: 10
}],
["two", {
date: new Date(0),
qty: 5
}]
])
})
const inventory = new ResourceBuilder("inventory")
.mapFromPipeline(builder => builder
.from(data.outputStream())
)
mapFromStream
▸ mapFromStream(stream
): SimulationResourceBuilder
Assign the resource's initial state to the value contained in a datastream.
Type parameters
Name | Type |
---|---|
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
stream | Stream | the stream to map from. |
Returns
SimulationResourceBuilder
Remarks
The stream
can be any EastType stream
Example
// create a stream with some inventory
const data = new SourceBuilder("inventory data")
.value({
value: new Map([
["one", {
date: new Date(0),
qty: 10
}],
["two", {
date: new Date(0),
qty: 5
}]
])
})
// map some inventory from the stream
const inventory = new ResourceBuilder("inventory")
.mapFromStream(data.outputStream())
mapFromValue
▸ mapFromValue(value
): SimulationResourceBuilder
<Name
, EastTypeOf
>
Assign the resource's initial state to the provided value.
Type parameters
Name | Type |
---|---|
T | extends Value |
Parameters
Name | Type | Description |
---|---|---|
value | T | the value to map from. |
Returns
SimulationResourceBuilder
<Name
, EastTypeOf
>
Remarks
The type value
may be a value of any valid EastType type, such as
Example
// map some inventory from data
const inventory = new ResourceBuilder("inventory")
.mapFromValue(new Map([
["socks", { qty: 1n }],
["chairs", { qty: 3n }]
]))
▸ mapFromValue(value
, type
): SimulationResourceBuilder
Assign the resource's initial state to the provided value and type.
Type parameters
Name | Type |
---|---|
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
value | ValueTypeOf | the value to map from. |
type | T | the type to use for the resource value. |
Returns
SimulationResourceBuilder
Remarks
The type
may be any valid EastType type, such as
Example
// map some inventory from data
const inventory = new ResourceBuilder("inventory")
.mapFromValue(new Map([
["socks", { qty: 1n }],
["chairs", { qty: 3n }]
]), DictType(StringType, StructType({ qty: IntegerType})))