Rule-Based Control Functions
These functions are used for working with rule-based controls.
| Function | Versions | Description |
|---|---|---|
addRule | 2.2+ | Adds a new rule-based control to a project. |
deleteRule | 2.2+ | Deletes an existing rule-based control. |
getRule | 2.2+ | Retrieves summary information about a rule-based control. |
getRuleId | 2.2+ | Gets the ID name of a rule-based control given its index. |
getPremise | 2.2+ | Gets the properties of a premise in a rule-based control. |
setPremise | 2.2+ | Sets the properties of a premise in a rule-based control. |
setPremiseIndex | 2.2+ | Sets the index of an object in a premise of a rule-based control. |
setPremiseStatus | 2.2+ | Sets the status being compared to in a premise of a rule-based control. |
setPremiseValue | 2.2+ | Sets the value in a premise of a rule-based control. |
getThenAction | 2.2+ | Gets the properties of a THEN action in a rule-based control. |
setThenAction | 2.2+ | Sets the properties of a THEN action in a rule-based control. |
getElseAction | 2.2+ | Gets the properties of an ELSE action in a rule-based control. |
setElseAction | 2.2+ | Sets the properties of an ELSE action in a rule-based control. |
setRulePriority | 2.2+ | Sets the priority of a rule-based control. |
getRuleEnabled | 2.3+ | Checks whether a rule-based control is enabled. |
setRuleEnabled | 2.3+ | Enables or disables a rule-based control. |
addRule 2.2+
Section titled “addRule ”Adds a new rule-based control to a project.
addRule(rule: string): void;Parameters
| Parameter | Type | Description |
|---|---|---|
| rule | string | 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 2.2+
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 2.2+
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 2.2+
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 2.2+
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 2.2+
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 2.2+
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 2.2+
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 2.2+
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 2.2+
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 2.2+
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 2.2+
Section titled “getElseAction ”Gets 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 2.2+
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 2.2+
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. |
getRuleEnabled 2.3+
Section titled “getRuleEnabled ”Checks whether a rule-based control is enabled. Disabled rules are kept in the project but skipped during simulation.
getRuleEnabled(index: number): number;Parameters
| Parameter | Type | Description |
|---|---|---|
| index | number | the rule’s index (starting from 1). |
Returns
Number
1 if the rule is enabled, 0 if disabled.
setRuleEnabled 2.3+
Section titled “setRuleEnabled ”Enables or disables a rule-based control without deleting it.
setRuleEnabled(index: number, enabled: number): void;Parameters
| Parameter | Type | Description |
|---|---|---|
| index | number | the rule’s index (starting from 1). |
| enabled | number | 1 to enable the rule, 0 to disable it. |