Adding a list of actions to rules
Closed this issue · 2 comments
I am new to WNTR. I am learning how to add controls and rules to the model. The documentation mentions that it is possible to add multiple actions (a list) if using rules, however I was hoping to be able to add a list of actions (i.e. close / open several pipes at once) but I get a EPANET 200 error when doing so.
I have done this to attempt to create a list of actions:
list_action2=[]
for pipe in demais_links:
link=wn1.get_link(pipe)
act2=controls.ControlAction(link, 'status', 0)
list_action2.append(act2)
control3=controls.Rule(cond3_list[0], list_action2 , priority=4,name='tank1')
When I ask to print control 3 (see below), it does print exactly what I need (several pipes closed), however when I rum EpanetSimulator I get the error message.
control 3: IF TANK TB7 PRESSURE >= 1.0 THEN PIPE PipeForEmit15 STATUS IS CLOSED AND PIPE 14 STATUS IS CLOSED AND PIPE 7 STATUS IS CLOSED AND PIPE B13 STATUS IS CLOSED AND PIPE 25 STATUS IS CLOSED AND PIPE 9 STATUS IS CLOSED AND PIPE 13 STATUS IS CLOSED AND PIPE B9 STATUS IS CLOSED AND PIPE 11 STATUS IS CLOSED AND PIPE PipeForEmit13 STATUS IS CLOSED AND PIPE PipeForEmit21 STATUS IS CLOSED AND PIPE B10 STATUS IS CLOSED AND PIPE PipeForEmit2 STATUS IS CLOSED AND PIPE PipeForEmit10 STATUS IS CLOSED AND PIPE PipeForEmit11 STATUS IS CLOSED AND PIPE B19 STATUS IS CLOSED AND PIPE 8 STATUS IS CLOSED AND PIPE PipeForEmit20 STATUS IS CLOSED AND PIPE 10 STATUS IS CLOSED AND PIPE B18 STATUS IS CLOSED AND PIPE B4 STATUS IS CLOSED AND PIPE PipeForEmit19 STATUS IS CLOSED AND PIPE PipeForEmit22 STATUS IS CLOSED AND PIPE B8 STATUS IS CLOSED AND PIPE B0 STATUS IS CLOSED AND PIPE B20 STATUS IS CLOSED AND PIPE PipeForEmit14 STATUS IS CLOSED AND PIPE 28 STATUS IS CLOSED AND PIPE B12 STATUS IS CLOSED AND PIPE PipeForEmit6 STATUS IS CLOSED AND PIPE PipeForEmit12 STATUS IS CLOSED AND PIPE B3 STATUS IS CLOSED AND PIPE 12 STATUS IS CLOSED AND PIPE B11 STATUS IS CLOSED AND PIPE 24 STATUS IS CLOSED AND PIPE 30 STATUS IS CLOSED AND PIPE 23 STATUS IS CLOSED AND PIPE 27 STATUS IS CLOSED AND PIPE PipeForEmit5 STATUS IS CLOSED AND PIPE 29 STATUS IS CLOSED AND PIPE B17 STATUS IS CLOSED AND PIPE 6 STATUS IS CLOSED PRIORITY 4.
I have tested with 2 separate actions only and it does seams to work fine. Is that the case that rules will only work for up to 2 action in 2 pipes at the time?
Also, some of the pipes I am trying to change status, have initial status as CV. If I try to add an action to these pipes I also get the same error message. Is it not possible to change this status with an action?
I am using spyder 5.4.3
Many Thanks,
Daniela
I tested this out using Net1. The following code correctly adds a rule to the water network model using a list of actions and runs the EpanetSimulator with no errors:
import wntr
inp_file = 'networks/Net1.inp'
wn = wntr.network.WaterNetworkModel(inp_file)
action_list = []
for pipe in ['11', '22']:
link=wn.get_link(pipe)
act = wntr.network.controls.ControlAction(link, 'status', 0)
action_list.append(act)
cond = wntr.network.controls.SimTimeCondition(wn, '=', '12:00:00')
rule = wntr.network.controls.Rule(cond,
action_list,
priority = 4,
name = 'rule_name'
)
wn.add_control('rule1', rule)
print(rule)
sim = wntr.sim.EpanetSimulator(wn)
results = sim.run_sim()
However, the WNTR code uses the control rule name (rule1
) if a rule name (rule_name
) is not provided and that name (rule1
) cannot include a space. This can result in EPANET Error 200. This doesn't appear to be your issue, since your rule is named tank1
. Let us know if this resolves the issue.
@dbhart, can you resolve this issue by adding an underscore to the RULE name when witting an INP file?