Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def reset(self):
"""
Reset the _previous_values. This should be called before activating any control actions so that changes made
by the control actions can be tracked.
"""
self._changed = OrderedSet()
self._previous_values = OrderedDict()
for control in self._controls:
for action in control.actions():
obj, attr = action.target()
self._previous_values[(obj, attr)] = getattr(obj, attr)
def __init__(self, children=None, edges_between_children=None):
"""
Parameters
----------
children: list or collections.abc.Iterable of _Tree or networkx.Graph
edges_between_children: list or collections.abc.Iterable of _Edge
"""
self.children = OrderedSet()
self.edges_between_children = OrderedSet()
if children is not None:
self.children.update(children)
if edges_between_children is not None:
self.edges_between_children.update(edges_between_children)
def __init__(self, model):
super(LinkRegistry, self).__init__(model)
self._pipes = OrderedSet()
self._pumps = OrderedSet()
self._head_pumps = OrderedSet()
self._power_pumps = OrderedSet()
self._prvs = OrderedSet()
self._psvs = OrderedSet()
self._pbvs = OrderedSet()
self._tcvs = OrderedSet()
self._fcvs = OrderedSet()
self._gpvs = OrderedSet()
self._valves = OrderedSet()
def add(self, obj, attr, func):
if (obj, attr) not in self.update_functions:
self.update_functions[(obj, attr)] = OrderedSet()
self.update_functions[(obj, attr)].add(func)
def get_vars(self):
return OrderedSet([self])
def _collect_leaves(self):
self._vars = OrderedSet()
self._params = OrderedSet()
self._floats = OrderedSet()
for oper in self.operators():
for operand in oper.operands():
if operand.is_leaf():
if operand.is_variable_type():
self._vars.add(operand)
elif operand.is_parameter_type():
self._params.add(operand)
elif operand.is_float_type():
self._floats.add(operand)
elif operand.is_expression_type():
self._vars.update(operand.get_vars())
self._params.update(operand.get_params())
self._floats.update(operand.get_floats())
else:
raise ValueError('operand type not recognized: ' + str(operand))
def _collect_leaves(self):
self._vars = OrderedSet()
self._params = OrderedSet()
self._floats = OrderedSet()
for oper in self.operators():
for operand in oper.operands():
if operand.is_leaf():
if operand.is_variable_type():
self._vars.add(operand)
elif operand.is_parameter_type():
self._params.add(operand)
elif operand.is_float_type():
self._floats.add(operand)
elif operand.is_expression_type():
self._vars.update(operand.get_vars())
self._params.update(operand.get_params())
self._floats.update(operand.get_floats())
else:
raise ValueError('operand type not recognized: ' + str(operand))
def _register_constraint(self, con):
if type(con.expr) == ConditionalExpression:
self._register_conditional_constraint(con)
return None
ccon = self._evaluator.add_constraint()
con._c_obj = ccon
self._con_ccon_map[con] = ccon
leaf_ndx_map = OrderedDict()
referenced_vars = OrderedSet()
referenced_params = OrderedSet()
referenced_floats = OrderedSet()
ndx = 0
for v in con.expr.get_vars():
leaf_ndx_map[v] = ndx
ndx += 1
cvar = self._increment_var(v)
ccon.add_leaf(cvar)
referenced_vars.add(v)
for p in con.expr.get_params():
leaf_ndx_map[p] = ndx
ndx += 1
cparam = self._increment_param(p)
ccon.add_leaf(cparam)
referenced_params.add(p)
for f in con.expr.get_floats():
logger.debug('checking for isolated junctions and links')
for j in self._prev_isolated_junctions:
junction = self._wn.get_node(j)
junction._is_isolated = False
for l in self._prev_isolated_links:
link = self._wn.get_link(l)
link._is_isolated = False
node_indicator = np.ones(self._wn.num_nodes, dtype=self._int_dtype)
check_for_isolated_junctions(self._source_ids, node_indicator, self._internal_graph.indptr,
self._internal_graph.indices, self._internal_graph.data,
self._number_of_connections)
isolated_junction_ids = [i for i in range(len(node_indicator)) if node_indicator[i] == 1]
isolated_junctions = OrderedSet()
isolated_links = OrderedSet()
for j_id in isolated_junction_ids:
j = self._node_id_to_name[j_id]
junction = self._wn.get_node(j)
junction._is_isolated = True
isolated_junctions.add(j)
connected_links = self._wn.get_links_for_node(j)
for l in connected_links:
link = self._wn.get_link(l)
link._is_isolated = True
isolated_links.add(l)
if logger_level <= logging.DEBUG:
if len(isolated_junctions) > 0 or len(isolated_links) > 0:
logger.debug('isolated junctions: {0}'.format(isolated_junctions))
logger.debug('isolated links: {0}'.format(isolated_links))
wntr.sim.hydraulics.update_model_for_isolated_junctions_and_links(self._model, self._wn, self._model_updater,
def _register_constraint(self, con):
if type(con.expr) == ConditionalExpression:
self._register_conditional_constraint(con)
return None
ccon = self._evaluator.add_constraint()
con._c_obj = ccon
self._con_ccon_map[con] = ccon
leaf_ndx_map = OrderedDict()
referenced_vars = OrderedSet()
referenced_params = OrderedSet()
referenced_floats = OrderedSet()
ndx = 0
for v in con.expr.get_vars():
leaf_ndx_map[v] = ndx
ndx += 1
cvar = self._increment_var(v)
ccon.add_leaf(cvar)
referenced_vars.add(v)
for p in con.expr.get_params():
leaf_ndx_map[p] = ndx
ndx += 1
cparam = self._increment_param(p)
ccon.add_leaf(cparam)
referenced_params.add(p)
for f in con.expr.get_floats():
leaf_ndx_map[f] = ndx