Skip to main content

Scenario - ProcessBuilder

Scenario.ProcessBuilder

A builder to define a process 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

NameType
Nameextends string
Valuesextends Record =
Propertiesextends Record = { date: Variable }
Resourcesextends Record =
Processesextends Record<string, Record> =
MLsextends Record =
Procsextends Record =

Hierarchy

  • AbstractProcessBuilder

    ProcessBuilder

Function

clear

clear(collection):

ProcessBuilder

Delete all elements from an array, set or dictionary. The collection will be mutated in place.

Parameters

NameTypeDescription
collection(properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunction<SetType | ArrayType | DictType>a function returning the array, set or dictionary to clear

Returns

ProcessBuilder

Example

 // create a resource for inventory items
const inventory = new ResourceBuilder("inventory")
.mapFromValue(new Map([
["socks", { qty: 1n }],
["chairs", { qty: 3n }]
]))

// add the inventory resource and clear all values
const dump_inventory = new ProcessBuilder("dump_inventory")
.resource(inventory)
.clear((props, resources) => resources.inventory)
.mapFromValue({
date: new Date(0),
});

Process

constructor

new ProcessBuilder(name, module?):

ProcessBuilder

Construct a process with a given name.

Type parameters

NameType
Nameextends string
Valuesextends Record =
Propertiesextends Record = { date: Variable }
Resourcesextends Record =
Processesextends Record<string, Record> =
MLsextends Record =
Procsextends Record =

Parameters

NameTypeDescription
nameNamethe name for the ProcessBuilder
module?ModulePath | ModuleBuilder-

Returns

ProcessBuilder

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

AbstractProcessBuilder&lt;Name, Values, Properties, Resources, MLs, Procs&gt;.constructor


assign

assign(name, expression):

ProcessBuilder

Reassign an existing property value with the result of an expression of existing properties.

Type parameters

NameType
PropertyNameextends string | number | symbol
Exprextends (properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => { ast_type: AstType ; type: SubType }

Parameters

NameTypeDescription
namePropertyNamethe name of the property
expressionExprthe function of defining the new property value

Returns

ProcessBuilder

Remarks

You must overwrite an existing property, and the value must be of the same type as that property. The "date" property cannot be modified.

Example

 const my_process = new ProcessBuilder("my_process")
// let x = 5
.let("x", () => Const(5))
// x = x + 1
.assign("x", props => Add(props.x, 1))

delete

delete(collection, key):

ProcessBuilder

Delete an existing element from an array, set or dictionary. The collection will be mutated in place.

For arrays, you can delete the "first" or "last" element (i.e. pop the front or end of the array). For sets, you can delete an existing key. If the key doesn't exist an error will result. For dictionaries, you can delete an existing key (and associated value). If the key doesn't exist an error will result.

Type parameters

NameType
Cextends (properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunction

Parameters

NameTypeDescription
collectionCa function returning the array, set or dictionary to update
key(properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunction<ReturnType["type"]["value"]["key"]>the key of the item to delete

Returns

ProcessBuilder

Example

 // create a resource
const inventory = new ResourceBuilder("inventory")
.mapFromValue(new Map([
["socks", { qty: 1n }],
["chairs", { qty: 3n }]
]))

// unlist an item from inventory
const unlist = new ProcessBuilder("unlist")
.resource(inventory)
.value("qty", IntegerType)
.value("item", StringType)
.delete(
(props, resources) => resources.inventory,
(props) => props.item,
)
.mapFromValue({
date: new Date(0),
item: "socks",
});

describe

describe(description):

ProcessBuilder

Add a human-readable description of the process (as a whole).

Parameters

NameTypeDescription
descriptionstringthe description string.

Returns

ProcessBuilder

Example

 // create the sales process with some properties 
const sales = new ProcessBuilder("sales")
.describe("Process a sale event, determining the profit from revenue and cost")
.let("revenue", () => Const(5))
.let("cost", () => Const(6))
.let("profit", (props) => Subtract(props.revenue, props.cost))
.mapFromValue({ date: new Date(0) });

endSimulation

endSimulation(predicate?):

ProcessBuilder

End the entire simulation immediately. A user-defined predicate may be provided to control when this does or does not occur.

Parameters

NameTypeDescription
predicate?(properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunctiona function if set to true will end the entire simulation

Returns

ProcessBuilder

Remarks

Any later statements in this process instance will not be executed.

Example

 // create the sale process
const sales = new ProcessBuilder("sales")
// create another sale
.execute(
"sales",
(props) => Struct({
date: AddDuration(
props.date,
RandomExponential(),
'hour'
),
})
)
// end after an hour
.endSimulation((props) => Greater(props.date, new Date(3600000)))
// start simulating from a date
.mapFromValue({ date: new Date(0) });

error

error(message):

ProcessBuilder

Throw an error with a provided error message.

Parameters

NameTypeDescription
messagestring | (properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunctionthe error message

Returns

ProcessBuilder

Example

 // create the sales process with some properties 
const sales = new ProcessBuilder("sales")
// create random qty
.let("qty", () => RandomUniform(0, 1))
.if(
(props) => Less(props.qty, 0.5),
block => block
.error((props) => StringJoin`value ${props.qty} <= 0.5`)
)
.mapFromValue({ date: new Date(0) });

execute

execute(name, values):

ProcessBuilder

Execute a new process instance at a specified date.

Type parameters

NameType
Vextends (properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunction<StructType<{ date: DateTimeType } & { [K in string | number | symbol]: EastType }>>

Parameters

NameTypeDescription
nameNamethe ProcessBuilder name to execute
valuesV & StructType<{ date: DateTimeType } & Values> extends ReturnType["type"] ? unknown : neverthe values to execute the ProcessBuilder with

Returns

ProcessBuilder

Remarks

The values must be an object with at least date, but also any value property define in the

ProcessBuilder being executed

Example

 // create the process to be added
const receive_items = new ProcessBuilder("receive items")
.value("qty", FloatType)
.log({
message: (props) => StringJoin`Recieved ${props.qty} items`
})

// add a process to another and execute an hour after
const sales = new ProcessBuilder("sales")
.process(receive_items)
.execute("receive items", (props) => Struct({
date: AddDuration(props.date, 1, 'hour'),
qty: Const(5)
}))
.mapFromValue({ date: new Date(0) });

Example

 
// execute the sales process recursively every minute until an hour passes
const sales = new ProcessBuilder("sales")
.execute("sales", (props) => Struct({
date: AddDuration(props.date, 1, 'minute'),
}))
// note that `new Date(3600000)` will be constant in the simulation
.endSimulation((props) => Greater(props.date, new Date(3600000)))
.mapFromValue({ date: new Date(0) });

forArray

forArray(collection, loop_block):

ProcessBuilder

Perform a block of statements for each item in an array.

Type parameters

NameType
Collectionextends (properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunction

Parameters

NameTypeDescription
collectionCollectiona function that returns an array expression of properties and resources
loop_block(block: ProcessBlockBuilder<Properties, Resources, Processes & { [K in string]: Values }, MLs, Procs>, value: Variable<ReturnType["type"]["value"]>, key: Variable) => ProcessBlockBuilder<Record, Resources, Processes & { [K in string]: Values }, MLs, Procs>a function that returns a block of statements to be executed for each element of a collection.

Returns

ProcessBuilder

Example

// log out all indices and values of an array
new ProcessBuilder("my_process")
.let("array", _ => Const(["a", "b", "c"]))
.forArray(
props => props.array,
(block, value, key) => block
.log({
message: () => StringJoin`Index ${key} contains string ${value}`
})
)

forDict

forDict(collection, loop_block):

ProcessBuilder

Perform a block of statements for each item in a dictionary.

Type parameters

NameType
Collectionextends (properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunction

Parameters

NameTypeDescription
collectionCollectiona function that returns a dictionary expression of properties and resources
loop_block(block: ProcessBlockBuilder<Properties, Resources, Processes & { [K in string]: Values }, MLs, Procs>, value: Variable<ReturnType["type"]["value"]["value"]>, key: Variable<ReturnType["type"]["value"]["key"]>) => ProcessBlockBuilder<Record, Resources, Processes & { [K in string]: Values }, MLs, Procs>a function that returns a block of statements to be executed for each element of a collection.

Returns

ProcessBuilder

Example

// log out all keys and values of an dictionary
new ProcessBuilder("my_process")
.let("dict", _ => Const(new Map([["a", 1n], ["b", 2n], ["c", 3n]]))
.forDict(
props => props.dict,
(block, value, key) => block
.log({
message: () => StringJoin`Key ${key} contains value ${value}`
})
)

forSet

forSet(collection, loop_block):

ProcessBuilder

Perform a block of statements for each item in a set.

Type parameters

NameType
Collectionextends (properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunction

Parameters

NameTypeDescription
collectionCollectiona function that returns an set expression of properties and resources
loop_block(block: ProcessBlockBuilder<Properties, Resources, Processes & { [K in string]: Values }, MLs, Procs>, key: Variable<ReturnType["type"]["value"]>) => ProcessBlockBuilder<Record, Resources, Processes & { [K in string]: Values }, MLs, Procs>a function that returns a block of statements to be executed for each element of a collection.

Returns

ProcessBuilder

Example

// log out all keys of a set
new ProcessBuilder("my_process")
.let("set", _ => Const(new Set(["a", "b", "c"])))
.forSet(
props => props.set,
(block, key) => block
.log({
message: () => StringJoin`Key ${key}`
})
)

if

if(predicate, true_block, false_block?):

ProcessBuilder

Perform blocks of statements conditional on some predicate (Boolean) expression.

Parameters

NameTypeDescription
predicate(properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunctiona function that returns a BooleanType expression of properties and resources
true_block(block: ProcessBlockBuilder<Properties, Resources, Processes & { [K in string]: Values }, MLs, Procs>) => ProcessBlockBuilder<Record, Resources, Processes & { [K in string]: Values }, MLs, Procs>a function that returns a block of statements to be executed if the predicate is true.
false_block?(block: ProcessBlockBuilder<Properties, Resources, Processes & { [K in string]: Values }, MLs, Procs>) => ProcessBlockBuilder<Record, Resources, Processes & { [K in string]: Values }, MLs, Procs>an optional function that returns a block of statements to be executed if the predicate is false.

Returns

ProcessBuilder

Example

// stock level of products to sell
const stock = new ResourceBuilder("stock")
.fromValue(100.0)

// sales reduces stock level
const sales = new ProcessBuilder("sales")
.resource(stock)
.value("qty", FloatType)
// only deduct stock if qty is non-zero
.if(
props => Greater(qty, 0.0),
block => block
.set("stock", (props, resources) => Subtract(resources.stock, props.qty))
)

ifNull

ifNull(input, null_block, value_block?):

ProcessBuilder

Execute blocks of statements conditional on some input being null or not.

Type parameters

NameType
Iextends (properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunction

Parameters

NameTypeDescription
inputIa function that returns a Nullable expression of properties and resources
null_block(block: ProcessBlockBuilder<Properties, Resources, Processes & { [K in string]: Values }, MLs, Procs>) => ProcessBlockBuilder<Record, Resources, Processes & { [K in string]: Values }, MLs, Procs>a function that returns a block of statements to be executed if the input is null.
value_block?(block: ProcessBlockBuilder<Properties, Resources, Processes & { [K in string]: Values }, MLs, Procs>, value: Variable<NonNullable<ReturnType["type"]>>) => ProcessBlockBuilder<Record, Resources, Processes & { [K in string]: Values }, MLs, Procs>an optional function that returns a block of statements to be executed if the input is not null. The input value is available as a non-nullable variable.

Returns

ProcessBuilder

Example

// stock level of products to sell
const stock = new ResourceBuilder("stock")
.fromValue(100.0)

// sales reduces stock level (but only qty is not null)
const sales = new ProcessBuilder("sales")
.resource(stock)
.value("qty", Nullable(FloatType))
// only deduct stock if qty is non-zero
.ifNull(
props => qty,
block => block,
block => block,
.set("stock", (props, resources) => Subtract(resources.stock, props.qty))
)

insert

insert(collection, key, value):

ProcessBuilder

Insert a new entry into an array, set or dictionary.

For arrays, you can insert the "first" or "last" element (i.e. push to the front or end of the array). For sets, you can insert a new key. If the key already exists an error will result. For dictionaries, you can insert a new key and associated value. If the key already exists an error will result (see also

update).

Type parameters

NameType
Cextends (properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunction

Parameters

NameTypeDescription
collectionCa function returning the array, set or dictionary to insert into
key(properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunction<ReturnType["type"]["value"]["key"]>the key of the item to insert
value(properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => { ast_type: AstType ; type: SubType<ReturnType["type"]["value"]["value"]> }the value to insert (for arrays and dictionaries only)

Returns

ProcessBuilder

Example

 // create a resource
const inventory = new ResourceBuilder("inventory")
.mapFromValue(new Map([
["socks", { qty: 1n }],
["chairs", { qty: 3n }]
]))

// add the inventory resource and insert a value
const delivery = new ProcessBuilder("delivery")
.resource(inventory)
.value("qty", IntegerType)
.value("item", StringType)
.insert(
(props, resources) => resources.inventory,
(props) => props.item,
(props) => Struct({ qty: props.qty }),
)
.mapFromValue({
date: new Date(0),
item: "frame",
qty: 54n
});

let

let(name, expression):

ProcessBuilder<Name, Values, PropertyName extends keyof Properties ? Omit : Properties & { [K in string]: Variable<ReturnType["type"]> }, Resources, Processes, MLs, Procs>

Compute a property as an expression of existing properties.

Type parameters

NameType
PropertyNameextends string
Exprextends (properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunction

Parameters

NameTypeDescription
namePropertyNamethe name of the property
expressionExprthe function of defining the property

Returns

ProcessBuilder<Name, Values, PropertyName extends keyof Properties ? Omit : Properties & { [K in string]: Variable<ReturnType["type"]> }, Resources, Processes, MLs, Procs>

Remarks

you may overwrite an existing property of the same name with a new value of any type.

Example

 // create the sales process with some properties 
const sales = new ProcessBuilder("sales")
.let("revenue", () => Const(5))
.let("cost", () => Const(6))
.let("profit", (props) => Subtract(props.revenue, props.cost))
.mapFromValue({ date: new Date(0) });

log

log(message):

ProcessBuilder

Produce a log message.

Parameters

NameTypeDescription
messagestring | (properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunctionthe error message

Returns

ProcessBuilder

Example

 // create the sales process with some properties 
const sales = new ProcessBuilder("sales")
// create random qty
.let("qty", () => RandomUniform(0, 1))
.if(
(props) => Less(props.qty, 0.5),
block => block
.log((props) => StringJoin`value ${props.qty} <= 0.5`)
)
.mapFromValue({ date: new Date(0) });

mapFromPipeline

mapFromPipeline(pipeline): MappedProcessBuilder

Create a instance of a process from a

PipelineBuilder.

Parameters

NameType
pipeline(builder: PipelineBuilder) => GenericPipelineBuilder<StructType<{ date: DateTimeType } & Values>, Record>

Returns

MappedProcessBuilder

Remarks

The pipeline must output a

StructType stream with a date value, but also any value property define in the ProcessBuilder

Example

 // a stream to map from
const data = new SourceBuilder("receive items data")
.value({
value: {
date: new Date(0),
qty: 3
}
})

// create the process to map
const receive_items = new ProcessBuilder("receive items")
.value("qty", FloatType)
.mapFromPipeline(builder => builder
.from(data.outputStream())
);

mapFromStream

mapFromStream(stream): MappedProcessBuilder

Create an instance of a process from a

Stream.

Parameters

NameTypeDescription
streamStream<StructType<{ date: DateTimeType } & Values>>the stream to map from.

Returns

MappedProcessBuilder

Remarks

The stream must be a

StructType stream with a date value, but also any value property define in the ProcessBuilder

Example

 // a stream to map from
const data = new SourceBuilder("receive items data")
.value({
value: {
date: new Date(0),
qty: 3
}
})

// create the process to map
const receive_items = new ProcessBuilder("receive items")
.value("qty", FloatType)
.mapFromStream(data.outputStream());

mapFromValue

mapFromValue(value): MappedProcessBuilder

Create a single instance of a process from a

Value.

Parameters

NameTypeDescription
value{ [K in string | number | symbol]: ValueTypeOf }the value to map from.

Returns

MappedProcessBuilder

Remarks

The value must be an

StructValue typed object with at least a date value, but also any value property define in the ProcessBuilder

Example

 // map a process from a value
const receive_items = new ProcessBuilder("receive items")
.value("qty", FloatType)
.mapFromValue({
date: new Date(0),
qty: 10
});

mapManyFromPipeline

mapManyFromPipeline(pipeline): MappedProcessBuilder

Create many instances of a process from a

Pipeline.

Parameters

NameType
pipeline(builder: PipelineBuilder) => TabularPipelineBuilder<DictType<StringType, StructType<{ date: DateTimeType } & Values>>, Record>

Returns

MappedProcessBuilder

Remarks

The pipeline must output

DictType stream with a StructType value with a date value, but also any value property define in the ProcessBuilder

Example

 // a stream to map from
const data = new SourceBuilder("receive items data")
.value({
value: new Map([
["one", {
date: new Date(0),
qty: 10
}],
["two", {
date: new Date(0),
qty: 5
}]
])
})

// create the process to map
const receive_items = new ProcessBuilder("receive items")
.value("qty", FloatType)
.mapManyFromPipeline(builder => builder
.from(data.outputStream())
);

mapManyFromStream

mapManyFromStream(stream): MappedProcessBuilder

Create many instances of a process from a

Stream.

Parameters

NameTypeDescription
streamStream<DictType<StringType, StructType<{ date: DateTimeType } & Values>>>the stream to map from.

Returns

MappedProcessBuilder

Remarks

The stream must be a

DictType stream with StructType value with a date value, but also any value property define in the ProcessBuilder

Example

 // a stream to map from
const data = new SourceBuilder("receive items data")
.value({
value: new Map([
["one", {
date: new Date(0),
qty: 10
}],
["two", {
date: new Date(0),
qty: 5
}]
])
})

// create the process to map
const receive_items = new ProcessBuilder("receive items")
.value("qty", FloatType)
.mapManyFromStream(data.outputStream());

mapManyFromValue

mapManyFromValue(value): MappedProcessBuilder

Create many instances of a process from a

Value.

Parameters

NameTypeDescription
valueMap<string, { [K in string | number | symbol]: ValueTypeOf }>the Map object containing values to map from.

Returns

MappedProcessBuilder

Remarks

The value must be

DictValue with StructValue entries containing at least a date value, but also any value property define in the ProcessBuilder

Example

 // create the process to map
const receive_items = new ProcessBuilder("receive items")
.value("qty", FloatType)
.mapManyFromValue(
new Map([
["one", {
date: new Date(0),
qty: 10
}],
["two", {
date: new Date(0),
qty: 5
}]
]));

match

match(variant, cases):

ProcessBuilder

Perform blocks of statements matched on the cases of some variant expression.

Type parameters

NameType
Vextends (properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunction
Textends { [K in string | number | symbol]: Function }

Parameters

NameTypeDescription
variantVa function that returns a VariantType expression of properties and resources
casesTan object containing functions that return a block of statements to be executed for the given variant case

Returns

ProcessBuilder

Example

// sales produes a log message about the buyer
const sales = new ProcessBuilder("sales")
.value("buyer_name", MaybeType(StringType))
.let("message", _ => Const(""))
.match(
(_, resources) => resources.buyer,
{
Some: (block, name) => block.assign("message", _ => StringJoin`Initiating sale to ${name}`),
None: (block) => block.assign("message", _ => StringJoin`Initiating sale to unknown buyer`),
}
)

ml

ml(ml):

ProcessBuilder<Name, Values, Properties, Resources, Processes, MLs & { [K in string]: MLDescription<StructType, T> }, Procs>

Include a ML function that this process can evaluate as a kind of "procedure".

Type parameters

NameType
MLNameextends string
Featuresextends Record
Textends EastType

Parameters

NameTypeDescription
mlAbstractMLBuilderthe MLModelBuilder model add to the ProcessBuilder

Returns

ProcessBuilder<Name, Values, Properties, Resources, Processes, MLs & { [K in string]: MLDescription<StructType, T> }, Procs>

Example

 // create the ML function of the amount
const amount = new MLModelBuilder("amount")
// the output is amount which is FloatType
.output(FloatType)

// create the sales process and add the ML function
// which is evaluated in each sale
const sales = new ProcessBuilder("sales")
.resource(cash)
// the ML function can be added
.ml(demand)
// the ML can be evaluated similarly to a procedure
// (note, this ML function has no input features)
.let(
"amount",
(_props, _resources, procs) => mls.demand(Struct({}))
)
// ...

overrides

overrides(process):

ProcessBuilder<NewName, NewValues, { date: Variable } & { [K in string | number | symbol]: Variable }, Resources, Processes, MLs, Procs>

Override an existing process, inheriting its name (for the purposes of simulation) and input

value properties. Any computed properties, imports or other statements are not inherited.

The resulting process can then be used to override the process in a scenario that has been constructed with

ScenarioBuilder.copyScenario or ScenarioBuilder.continueScenario using the ScenarioBuilder.overrideProcess method. Given that the name and input value properties match, any execute statements or queued processes throughout the scenario will be executed by the new process.

Type parameters

NameType
NewNameextends string
NewValuesextends Record

Parameters

NameTypeDescription
processAbstractProcessBuilder<NewName, NewValues, Record, Record<string, Variable>, Record, Record>a process builder to copy the name and input value properties

Returns

ProcessBuilder<NewName, NewValues, { date: Variable } & { [K in string | number | symbol]: Variable }, Resources, Processes, MLs, Procs>


procedure

procedure(procedure):

ProcessBuilder<Name, Values, Properties, Resources, Processes, MLs, Procs & { [K in string]: ProcedureDescription<ProcName, StructType, T> }>

Include a sub-procedure that this process can evaluate.

Type parameters

NameType
ProcNameextends string
Inputsextends Record
Textends EastType

Parameters

NameTypeDescription
procedureProcedureFinalizerthe Procedure model add to the ProcessBuilder

Returns

ProcessBuilder<Name, Values, Properties, Resources, Processes, MLs, Procs & { [K in string]: ProcedureDescription<ProcName, StructType, T> }>

Example

 // create a procedure to calculate the tax to apply to a sale
const apply_tax = new Procedure("apply_tax")
// the input parameter
.input("amount", FloatType)
// the output is a FloatType
.output(FloatType)
// the body of the procedure
.body(b => b
// add a 10% tax and return the value
.return(vars => Multiply(vars.amount, 1.1))
)

// create the sales process and add the ml function
// which is evaluated in each sale
const sales = new ProcessBuilder("sales")
.resource(cash)
// import the procedure
.procedure(apply_tax)
// the pre-tax sale amount
.value("amount", FloatType)
// the procedure can be accessed and evaluated inside expressions within the function
.let(
"tax_adjusted_amount",
(vars, _resources, procs) => procs.apply_tax(Struct({ amount: vars.amount }))
)
// ...

process

process(process):

ProcessBuilder<Name, Values, Properties, Resources, Processes & { [K in string]: ProcessValues }, MLs, >

Include another process that this process can execute.

Type parameters

NameType
ProcessNameextends string
ProcessValuesextends Record

Parameters

NameTypeDescription
processAbstractProcessBuilder<ProcessName, ProcessValues, Record, Record, Record, Record>the ProcessBuilder to add to the ProcessBuilder

Returns

ProcessBuilder<Name, Values, Properties, Resources, Processes & { [K in string]: ProcessValues }, MLs, >

Example

 // create the process to be added
const receive_items = new ProcessBuilder("receive items")
.value("qty", FloatType)
.log({
message: (props) => StringJoin`Recieved ${props.qty} items`
})

// add a process to another and execute an hour after
const sales = new ProcessBuilder("sales")
.process(receive_items)
.execute("receive items", (props) => Struct({
date: AddDuration(props.date, 1, 'hour'),
qty: Const(5)
}))
.mapFromValue({ date: new Date(0) });

resource

resource(resource):

ProcessBuilder<Name, Values, Properties, Resources & { [K in string]: Variable }, Processes, MLs, Procs>

Include a resource that this process can read or modify.

Type parameters

NameType
ResourceNameextends string
Textends EastType

Parameters

NameTypeDescription
resourceSimulationResourceBuilderthe ResourceBuilder to add to the ProcessBuilder\

Returns

ProcessBuilder<Name, Values, Properties, Resources & { [K in string]: Variable }, Processes, MLs, Procs>

Example

 // create a resource
const cash = new ResourceBuilder("cash")
.mapFromValue(0)

// create the sale process
const sales = new ProcessBuilder("sales")
.resource(cash)
// set the cash balance
.set("cash", () => Const(5))
// simulate from a date
.mapFromValue({ date: new Date(0) });

set

set(name, value):

ProcessBuilder

Set a resource value.

Type parameters

NameType
ResourceNameextends string | number | symbol
Vextends (properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunction

Parameters

NameTypeDescription
nameResourceNamethe ResourceBuilder name to set
valueV & Resources[ResourceName]["type"] extends ReturnType["type"] ? unknown : neverthe function defining the value

Returns

ProcessBuilder

Remarks

this overwrites the existing resource value in it's entirety, even if it is a collection. Use the update, insert or delete methods to modify just part of a resource.

Example

 // create a resource
const cash = new ResourceBuilder("cash")
.mapFromValue(0)

// create the sale process
const sales = new ProcessBuilder("sales")
.resource(cash)
// set the cash balance
.set("cash", () => Const(5))
// simulate from a date
.mapFromValue({ date: new Date(0) });

update

update(collection, key, value):

ProcessBuilder

Update an existing value in an array or dictionary. The collection will be mutated in place.

For arrays, you can update any element by integer index (the first element has index 0n). If the index is out of bounds an error will result. For dictionaries, you can update any existing key to a new associated value. If the key does not exist an error will result (see also

insert). In both cases, you are given access the existing value when computing the new value.

Type parameters

NameType
Cextends (properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunction

Parameters

NameTypeDescription
collectionCa function returning the array, set or dictionary to update
key(properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunction<ReturnType["type"]["value"]["key"]>the key of the item to update
value(properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }, old_value: Variable<ReturnType["type"]["value"]["value"]>) => { ast_type: AstType ; type: SubType<ReturnType["type"]["value"]["value"]> }the value to update to

Returns

ProcessBuilder

Example

 // create a resource
const inventory = new ResourceBuilder("inventory")
.mapFromValue(new Map([
["socks", { qty: 1n }],
["chairs", { qty: 3n }]
]))

// subtract the appropriate qty from inventory
const dispatch = new ProcessBuilder("dispatch")
.resource(inventory)
.value("qty", IntegerType)
.value("item", StringType)
.update(
(props, resources) => resources.inventory,
(props) => props.item,
(props, _, _, old_value) => Struct({ qty: Subtract(GetField(old_value, "qty"), props.qty) }),
)
.mapFromValue({
date: new Date(0),
item: "chair",
qty: 2n
});

value

value(name, type):

ProcessBuilder<Name, Values & { [K in string]: T }, Properties & { [K in string]: Variable }, Resources, Processes, MLs, Procs>

Define an input value property for the process.

Type parameters

NameType
PropertyNameextends string
Textends EastType

Parameters

NameTypeDescription
namePropertyNamethe name of the property
typeTthe type of the property

Returns

ProcessBuilder<Name, Values & { [K in string]: T }, Properties & { [K in string]: Variable }, Resources, Processes, MLs, Procs>

Example

 // create a simple process with an input value 
const sales = new ProcessBuilder("sales")
.value("amount", FloatType)
.mapFromValue({ date: new Date(0), amount: 1 });

warn

warn(message):

ProcessBuilder

Produce a warning with a message.

Parameters

NameTypeDescription
messagestring | (properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunctionthe error message

Returns

ProcessBuilder

Example

 // create the sales process with some properties 
const sales = new ProcessBuilder("sales")
// create random qty
.let("qty", () => RandomUniform(0, 1))
.if(
(props) => Less(props.qty, 0.5),
block => block
.warn((props) => StringJoin`value ${props.qty} <= 0.5`)
)
.mapFromValue({ date: new Date(0) });

while

while(predicate, loop_block):

ProcessBuilder

Repeatedly perform a block of statements, conditional on some predicate (Boolean) expression.

Parameters

NameTypeDescription
predicate(properties: Properties, resources: Resources, procs: { [K in string | number | symbol]: MLEvaluator } & { [K in string | number | symbol]: ProcedureEvaluator }) => EastFunctiona function that returns a BooleanType expression of properties and resources
loop_block(block: ProcessBlockBuilder<Properties, Resources, Processes & { [K in string]: Values }, MLs, Procs>) => ProcessBlockBuilder<Record, Resources, Processes & { [K in string]: Values }, MLs, Procs>a function that returns a block of statements to be executed repeatedly until the predicate is false.

Returns

ProcessBuilder

Example

// perform a loop from i = 0 to 10
new ProcessBuilder("my_process")
.let("i", 0n)
.while(
props => LessEqual(props.i, 10n),
block => block
.assign("i", props => Add(props.i, 1n))
)