Rule-Based Control Functions
These functions are used for working with rule-based controls.
| Function | Description |
|---|---|
addRule | Adds a new rule-based control to a project. |
deleteRule | Deletes an existing rule-based control. |
getRule | Retrieves summary information about a rule-based control. |
getRuleId | Gets the ID name of a rule-based control given its index. |
getPremise | Gets the properties of a premise in a rule-based control. |
setPremise | Sets the properties of a premise in a rule-based control. |
setPremiseIndex | Sets the index of an object in a premise of a rule-based control. |
setPremiseStatus | Sets the status being compared to in a premise of a rule-based control. |
setPremiseValue | Sets the value in a premise of a rule-based control. |
getThenAction | Gets the properties of a THEN action in a rule-based control. |
setThenAction | Sets the properties of a THEN action in a rule-based control. |
getElseAction | Gets the properties of an ELSE action in a rule-based control. |
setElseAction | Sets the properties of an ELSE action in a rule-based control. |
setRulePriority | Sets the priority of a rule-based control. |
addRule
Section titled “addRule”Adds a new rule-based control to a project.
addRule(rule: string): void;Parameters
| Parameter | Type | Description |
|---|---|---|
| rule | rule | text 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.
deleteRule
Section titled “deleteRule”Deletes an existing rule-based control.
deleteRule(index: number): void;Parameters
| Parameter | Type | Description |
|---|---|---|
| index | number | the index of the rule to be deleted (starting from 1). |
getRule
Section titled “getRule”Retrieves summary information about a rule-based control.
getRule(index: number): {premiseCount: number;thenActionCount: number;elseActionCount: number;priority: number;};Parameters
| Parameter | Type | Description |
|---|---|---|
| index | number | the rule’s index (starting from 1). |
Returns
Object
{ premiseCount: number; thenActionCount: number; elseActionCount: number; priority: number;}| Property | Type | Description |
|---|---|---|
| premiseCount | number | number of premises in the rule’s IF section. |
| thenActionCount | number | number of actions in the rule’s THEN section. |
| elseActionCount | number | number of actions in the rule’s ELSE section. |
| priority | number | the rule’s priority value. |
getRuleId
Section titled “getRuleId”Gets the ID name of a rule-based control given its index.
getRuleId(index: number): string;Parameters
| Parameter | Type | Description |
|---|---|---|
| index | number | the rule’s index (starting from 1). |
Returns
string
the rule’s ID name.
getPremise
Section titled “getPremise”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
| Parameter | Type | Description |
|---|---|---|
| ruleIndex | number | the rule’s index (starting from 1). |
| premiseIndex | number | 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;}| Property | Type | Description |
|---|---|---|
| logop | number | the premise’s logical operator ( IF = 1, AND = 2, OR = 3 ). |
| object | RuleObject | the type of object the premise refers to (see RuleObject). |
| objIndex | number | the index of the object (e.g. the index of a tank). |
| variable | RuleVariable | the object’s variable being compared (see RuleVariable). |
| relop | RuleOperator | the premise’s comparison operator (see RuleOperator). |
| status | RuleStatus | the status that the object’s status is compared to (see RuleStatus). |
| value | number | the value that the object’s variable is compared to. |
setPremise
Section titled “setPremise”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
| Parameter | Type | Description |
|---|---|---|
| ruleIndex | number | the rule’s index (starting from 1). |
| premiseIndex | number | the position of the premise in the rule’s list of premises (starting from 1). |
| logop | number | the premise’s logical operator ( IF = 1, AND = 2, OR = 3 ). |
| object | RuleObject | the type of object the premise refers to (see RuleObject). |
| objIndex | number | the index of the object (e.g. the index of a tank). |
| variable | RuleVariable | the object’s variable being compared (see RuleVariable). |
| relop | RuleOperator | the premise’s comparison operator (see RuleOperator). |
| status | RuleStatus | the status that the object’s status is compared to (see RuleStatus). |
| value | number | the value that the object’s variable is compared to. |
setPremiseIndex
Section titled “setPremiseIndex”Sets the index of an object in a premise of a rule-based control.
setPremiseIndex(ruleIndex: number, premiseIndex: number, objIndex: number): void;Parameters
| Parameter | Type | Description |
|---|---|---|
| ruleIndex | number | the rule’s index (starting from 1). |
| premiseIndex | number | the premise’s index (starting from 1). |
| objIndex | number | the index of the premise’s object (e.g. the index of a tank). |
setPremiseStatus
Section titled “setPremiseStatus”Sets the status being compared to in a premise of a rule-based control.
setPremiseStatus(ruleIndex: number, premiseIndex: number, status: RuleStatus): void;Parameters
| Parameter | Type | Description |
|---|---|---|
| ruleIndex | number | the rule’s index (starting from 1). |
| premiseIndex | number | the premise’s index (starting from 1). |
| status | RuleStatus | the status that the premise’s object status is compared to (see RuleStatus). |
setPremiseValue
Section titled “setPremiseValue”Sets the value in a premise of a rule-based control.
setPremiseValue(ruleIndex: number, premiseIndex: number, value: number): void;Parameters
| Parameter | Type | Description |
|---|---|---|
| ruleIndex | number | the rule’s index (starting from 1). |
| premiseIndex | number | the premise’s index (starting from 1). |
| value | number | The value that the premise’s variable is compared to. |
getThenAction
Section titled “getThenAction”Gets the properties of a THEN action in a rule-based control.
getThenAction(ruleIndex: number, actionIndex: number): {linkIndex: number;status: RuleStatus;setting: number;};Parameters
| Parameter | Type | Description |
|---|---|---|
| ruleIndex | number | the rule’s index (starting from 1). |
| actionIndex | number | the index of the THEN action to retrieve (starting from 1). |
Returns
Object
{ linkIndex: number; status: RuleStatus; setting: number;}| Property | Type | Description |
|---|---|---|
| linkIndex | number | the index of the link in the action (starting from 1). |
| status | RuleStatus | the status assigned to the link (see RuleStatus) |
| setting | number | the value assigned to the link’s setting. |
setThenAction
Section titled “setThenAction”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
| Parameter | Type | Description |
|---|---|---|
| ruleIndex | number | the rule’s index (starting from 1). |
| actionIndex | number | the index of the THEN action to modify (starting from 1). |
| linkIndex | number | the index of the link in the action. |
| status | RuleStatus | the new status assigned to the link (see RuleStatus). |
| setting | number | the new value assigned to the link’s setting. |
getElseAction
Section titled “getElseAction”Sets the properties of an ELSE action in a rule-based control.
getElseAction(ruleIndex: number, actionIndex: number): {linkIndex: number;status: RuleStatus;setting: number;};Parameters
| Parameter | Type | Description |
|---|---|---|
| ruleIndex | number | the rule’s index (starting from 1). |
| actionIndex | number | the index of the ELSE action to retrieve (starting from 1). |
Returns
Object
{ linkIndex: number; status: RuleStatus; setting: number;}| Property | Type | Description |
|---|---|---|
| linkIndex | number | the index of the link in the action (starting from 1). |
| status | RuleStatus | the status assigned to the link (see RuleStatus) |
| setting | number | the value assigned to the link’s setting. |
setElseAction
Section titled “setElseAction”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
| Parameter | Type | Description |
|---|---|---|
| ruleIndex | number | the rule’s index (starting from 1). |
| actionIndex | number | the index of the ELSE action being modified (starting from 1). |
| linkIndex | number | the index of the link in the action (starting from 1). |
| status | RuleStatus | the status assigned to the link (see RuleStatus) |
| setting | number | the value assigned to the link’s setting. |
setRulePriority
Section titled “setRulePriority”Sets the priority of a rule-based control.
setRulePriority(index: number, priority: number): void;Parameters
| Parameter | Type | Description |
|---|---|---|
| index | number | the rule’s index (starting from 1). |
| priority | number | the priority value assigned to the rule. |