# EPANET: [RULES]

[RULES]

Purpose:

Defines rule-based controls which modify links based on a combination of conditions.

Format:

Each rule is a series of statements of the form:

RULE ruleID
IF condition_1
AND condition_2
OR condition_3
AND condition_4
etc.
THEN action_1
AND action_2
etc.
ELSE action_3
AND action_4
etc.
PRIORITY value

where:

ruleID | = | an ID label assigned to the rule
conditon_n | = | a condition clause
action_n | = | an action clause
PRIORITY | = | a priority value (e.g., a number from 1 to 5)

Remarks:

1. Only the RULE, IF and THEN portions of a rule are required; the other portions are optional.
2. When mixing AND and OR clauses, the OR operator has higher precedence than AND, i.e.,
   `IF A or B and C`
   is equivalent to
   `IF (A or B) and C`
   If the interpretation was meant to be
   `IF A or (B and C)`
   then this can be expressed using two rules as in
   `IF A THEN ...`
   `IF B and C THEN ...`
3. The PRIORITY value is used to determine which rule applies when two or more rules require that conflicting actions be taken on a link. A rule without a priority value always has a lower priority than one with a value. For two rules with the same priority value, the rule that appears first is given the higher priority.

Example:

[RULES]
RULE 1
IF TANK 1 LEVEL ABOVE 19.1
THEN PUMP 335 STATUS IS CLOSED
AND PIPE 330 STATUS IS OPEN
RULE 2
IF SYSTEM CLOCKTIME >= 8 AM
AND SYSTEM CLOCKTIME < 6 PM
AND TANK 1 LEVEL BELOW 12
THEN PUMP 335 STATUS IS OPEN
RULE 3
IF SYSTEM CLOCKTIME >= 6 PM
OR SYSTEM CLOCKTIME < 8 AM
AND TANK 1 LEVEL BELOW 14
THEN PUMP 335 STATUS IS OPEN