Skip to content

Rule-Based Control Functions

These functions are used for working with rule-based controls.

FunctionDescription
addRuleAdds a new rule-based control to a project.
deleteRuleDeletes an existing rule-based control.
getRuleRetrieves summary information about a rule-based control.
getRuleIdGets the ID name of a rule-based control given its index.
getPremiseGets the properties of a premise in a rule-based control.
setPremiseSets the properties of a premise in a rule-based control.
setPremiseIndexSets the index of an object in a premise of a rule-based control.
setPremiseStatusSets the status being compared to in a premise of a rule-based control.
setPremiseValueSets the value in a premise of a rule-based control.
getThenActionGets the properties of a THEN action in a rule-based control.
setThenActionSets the properties of a THEN action in a rule-based control.
getElseActionGets the properties of an ELSE action in a rule-based control.
setElseActionSets the properties of an ELSE action in a rule-based control.
setRulePrioritySets the priority of a rule-based control.

Adds a new rule-based control to a project.

addRule(rule: string): void;

Parameters

ParameterTypeDescription
ruleruletext of the rule following the format used in an EPANET input file.

Consult the [RULES] section of the Input File topic to learn about a rule’s format. Each clause of the rule must end with a newline character \n.


Deletes an existing rule-based control.

deleteRule(index: number): void;

Parameters

ParameterTypeDescription
indexnumberthe index of the rule to be deleted (starting from 1).

Retrieves summary information about a rule-based control.

getRule(index: number): {
premiseCount: number;
thenActionCount: number;
elseActionCount: number;
priority: number;
};

Parameters

ParameterTypeDescription
indexnumberthe rule’s index (starting from 1).

Returns

Object

{
premiseCount: number;
thenActionCount: number;
elseActionCount: number;
priority: number;
}
PropertyTypeDescription
premiseCountnumbernumber of premises in the rule’s IF section.
thenActionCountnumbernumber of actions in the rule’s THEN section.
elseActionCountnumbernumber of actions in the rule’s ELSE section.
prioritynumberthe rule’s priority value.

Gets the ID name of a rule-based control given its index.

getRuleId(index: number): string;

Parameters

ParameterTypeDescription
indexnumberthe rule’s index (starting from 1).

Returns

string the rule’s ID name.


Gets the properties of a premise in a rule-based control.

getPremise(ruleIndex: number, premiseIndex: number): {
logop: number;
object: RuleObject;
objIndex: number;
variable: RuleVariable;
relop: RuleOperator;
status: RuleStatus;
value: number;
};

Parameters

ParameterTypeDescription
ruleIndexnumber the rule’s index (starting from 1).
premiseIndexnumber the position of the premise in the rule’s list of premises (starting from 1).

Returns

Object

{
logop: number;
object: RuleObject;
objIndex: number;
variable: RuleVariable;
relop: RuleOperator;
status: RuleStatus;
value: number;
}
PropertyTypeDescription
logopnumberthe premise’s logical operator ( IF = 1, AND = 2, OR = 3 ).
objectRuleObjectthe type of object the premise refers to (see RuleObject).
objIndexnumberthe index of the object (e.g. the index of a tank).
variableRuleVariablethe object’s variable being compared (see RuleVariable).
relopRuleOperatorthe premise’s comparison operator (see RuleOperator).
statusRuleStatusthe status that the object’s status is compared to (see RuleStatus).
valuenumberthe value that the object’s variable is compared to.

Sets the properties of a premise in a rule-based control.

setPremise(ruleIndex: number, premiseIndex: number, logop: number, object: RuleObject, objIndex: number, variable: RuleVariable, relop: RuleOperator, status: RuleStatus, value: number): void;

Parameters

ParameterTypeDescription
ruleIndexnumber the rule’s index (starting from 1).
premiseIndexnumber the position of the premise in the rule’s list of premises (starting from 1).
logopnumberthe premise’s logical operator ( IF = 1, AND = 2, OR = 3 ).
objectRuleObjectthe type of object the premise refers to (see RuleObject).
objIndexnumberthe index of the object (e.g. the index of a tank).
variableRuleVariablethe object’s variable being compared (see RuleVariable).
relopRuleOperatorthe premise’s comparison operator (see RuleOperator).
statusRuleStatusthe status that the object’s status is compared to (see RuleStatus).
valuenumberthe value that the object’s variable is compared to.

Sets the index of an object in a premise of a rule-based control.

setPremiseIndex(ruleIndex: number, premiseIndex: number, objIndex: number): void;

Parameters

ParameterTypeDescription
ruleIndexnumberthe rule’s index (starting from 1).
premiseIndexnumberthe premise’s index (starting from 1).
objIndexnumberthe index of the premise’s object (e.g. the index of a tank).

Sets the status being compared to in a premise of a rule-based control.

setPremiseStatus(ruleIndex: number, premiseIndex: number, status: RuleStatus): void;

Parameters

ParameterTypeDescription
ruleIndexnumberthe rule’s index (starting from 1).
premiseIndexnumberthe premise’s index (starting from 1).
statusRuleStatusthe status that the premise’s object status is compared to (see RuleStatus).

Sets the value in a premise of a rule-based control.

setPremiseValue(ruleIndex: number, premiseIndex: number, value: number): void;

Parameters

ParameterTypeDescription
ruleIndexnumberthe rule’s index (starting from 1).
premiseIndexnumberthe premise’s index (starting from 1).
valuenumberThe value that the premise’s variable is compared to.

Gets the properties of a THEN action in a rule-based control.

getThenAction(ruleIndex: number, actionIndex: number): {
linkIndex: number;
status: RuleStatus;
setting: number;
};

Parameters

ParameterTypeDescription
ruleIndexnumberthe rule’s index (starting from 1).
actionIndexnumberthe index of the THEN action to retrieve (starting from 1).

Returns

Object

{
linkIndex: number;
status: RuleStatus;
setting: number;
}
PropertyTypeDescription
linkIndexnumberthe index of the link in the action (starting from 1).
statusRuleStatusthe status assigned to the link (see RuleStatus)
settingnumberthe value assigned to the link’s setting.

Sets the properties of a THEN action in a rule-based control.

setThenAction(ruleIndex: number, actionIndex: number, linkIndex: number, status: RuleStatus, setting: number): void;

Parameters

ParameterTypeDescription
ruleIndex numberthe rule’s index (starting from 1).
actionIndexnumber the index of the THEN action to modify (starting from 1).
linkIndex numberthe index of the link in the action.
statusRuleStatus the new status assigned to the link (see RuleStatus).
settingnumber the new value assigned to the link’s setting.

Sets the properties of an ELSE action in a rule-based control.

getElseAction(ruleIndex: number, actionIndex: number): {
linkIndex: number;
status: RuleStatus;
setting: number;
};

Parameters

ParameterTypeDescription
ruleIndexnumberthe rule’s index (starting from 1).
actionIndexnumberthe index of the ELSE action to retrieve (starting from 1).

Returns

Object

{
linkIndex: number;
status: RuleStatus;
setting: number;
}
PropertyTypeDescription
linkIndexnumberthe index of the link in the action (starting from 1).
statusRuleStatusthe status assigned to the link (see RuleStatus)
settingnumberthe value assigned to the link’s setting.

Sets the properties of an ELSE action in a rule-based control.

setElseAction(ruleIndex: number, actionIndex: number, linkIndex: number, status: RuleStatus, setting: number): void;

Parameters

ParameterTypeDescription
ruleIndexnumberthe rule’s index (starting from 1).
actionIndexnumberthe index of the ELSE action being modified (starting from 1).
linkIndexnumberthe index of the link in the action (starting from 1).
statusRuleStatusthe status assigned to the link (see RuleStatus)
settingnumberthe value assigned to the link’s setting.

Sets the priority of a rule-based control.

setRulePriority(index: number, priority: number): void;

Parameters

ParameterTypeDescription
indexnumberthe rule’s index (starting from 1).
prioritynumberthe priority value assigned to the rule.