How to use the wntr.sim.aml.expr.Float function in wntr

To help you get started, we’ve selected a few wntr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github USEPA / WNTR / wntr / sim / aml / aml.py View on Github external
ndx = 0
        derivs = list()
        for expr in con.expr._conditions:
            referenced_vars.update(expr.get_vars())
            referenced_params.update(expr.get_params())
            referenced_floats.update(expr.get_floats())
        for expr in con.expr._exprs:
            referenced_vars.update(expr.get_vars())
            referenced_params.update(expr.get_params())
            referenced_floats.update(expr.get_floats())
        for expr in con.expr._exprs:
            _deriv = expr.reverse_sd()
            derivs.append(_deriv)
            for v in referenced_vars:
                if v not in _deriv:
                    _deriv[v] = Float(0)
                elif type(_deriv[v]) in native_numeric_types:
                    _deriv[v] = Float(_deriv[v])
                referenced_floats.update(_deriv[v].get_floats())

        for v in referenced_vars:
            leaf_ndx_map[v] = ndx
            ndx += 1
            cvar = self._increment_var(v)
            ccon.add_leaf(cvar)
        for v in referenced_params:
            leaf_ndx_map[v] = ndx
            ndx += 1
            cvar = self._increment_param(v)
            ccon.add_leaf(cvar)
        for v in referenced_floats:
            leaf_ndx_map[v] = ndx
github USEPA / WNTR / wntr / sim / aml / expr.py View on Github external
if type(lb) not in native_numeric_types or type(ub) not in native_numeric_types:
            raise ValueError('inequality can only accept both lb and ub arguments if both are floats or ints.')

    if lb is None:
        lb = -math.inf
    if ub is None:
        ub = math.inf

    if type(lb) in native_numeric_types:
        lb = Float(lb)
    else:
        body -= lb
        lb = Float(0)

    if type(ub) in native_numeric_types:
        ub = Float(ub)
    else:
        body -= ub
        ub = Float(0)

    if type(body) in native_numeric_types:
        return lb.value <= body <= ub.value

    if body.is_leaf():
        expr = expression()
    else:
        expr = expression(body)
    new_operator = InequalityOperator(body.last_node(), lb=lb, ub=ub)
    expr.append_operator(new_operator)
    return expr
github USEPA / WNTR / wntr / sim / aml / expr.py View on Github external
def __rsub__(self, other):
        assert type(other) in native_numeric_types
        if other == 0:
            return -self
        return Float(other) - self
github USEPA / WNTR / wntr / sim / aml / expr.py View on Github external
def _binary_operation_helper(self, other, cls):
        if type(other) in native_numeric_types:
            other = Float(other)
        new_operator = cls(self.last_node(), other.last_node())
        expr = expression(self)
        for oper in other.operators():
            expr.append_operator(oper)
        expr.append_operator(new_operator)
        return expr
github USEPA / WNTR / wntr / sim / aml / expr.py View on Github external
expr: ExpressionBase
    """
    if lb is not None and ub is not None:
        if type(lb) not in native_numeric_types or type(ub) not in native_numeric_types:
            raise ValueError('inequality can only accept both lb and ub arguments if both are floats or ints.')

    if lb is None:
        lb = -math.inf
    if ub is None:
        ub = math.inf

    if type(lb) in native_numeric_types:
        lb = Float(lb)
    else:
        body -= lb
        lb = Float(0)

    if type(ub) in native_numeric_types:
        ub = Float(ub)
    else:
        body -= ub
        ub = Float(0)

    if type(body) in native_numeric_types:
        return lb.value <= body <= ub.value

    if body.is_leaf():
        expr = expression()
    else:
        expr = expression(body)
    new_operator = InequalityOperator(body.last_node(), lb=lb, ub=ub)
    expr.append_operator(new_operator)
github USEPA / WNTR / wntr / sim / aml / aml.py View on Github external
ccon.add_leaf(cparam)
            referenced_params.add(p)
        for f in con.expr.get_floats():
            leaf_ndx_map[f] = ndx
            ndx += 1
            cfloat = self._increment_float(f)
            ccon.add_leaf(cfloat)
            referenced_floats.add(f)
        fn_rpn = con.expr.get_rpn(leaf_ndx_map)
        for term in fn_rpn:
            ccon.add_fn_rpn_term(term)
        jac = con.expr.reverse_sd()
        for v in con.expr.get_vars():
            jac_v = jac[v]
            if type(jac_v) in native_numeric_types:
                jac_v = Float(jac_v)
            for f in jac_v.get_floats():
                if f not in leaf_ndx_map:
                    leaf_ndx_map[f] = ndx
                    ndx += 1
                    cfloat = self._increment_float(f)
                    ccon.add_leaf(cfloat)
                    referenced_floats.add(f)
            jac_rpn = jac_v.get_rpn(leaf_ndx_map)
            cvar = self._var_cvar_map[v]
            for term in jac_rpn:
                ccon.add_jac_rpn_term(cvar, term)
        self._vars_referenced_by_con[con] = referenced_vars
        self._params_referenced_by_con[con] = referenced_params
        self._floats_referenced_by_con[con] = referenced_floats
github USEPA / WNTR / wntr / sim / aml / expr.py View on Github external
----------
    if_statement: ExpressionBase
    then_statement: ExpressionBase
    else_statement: ExpressionBase

    Returns
    -------
    expr: ExpressionBase
    """
    if type(if_statement) in native_numeric_types or type(if_statement) in native_boolean_types:
        if if_statement:
            return then_statement
        else:
            return else_statement
    if type(then_statement) in native_numeric_types:
        then_statement = Float(then_statement)
    if type(else_statement) in native_numeric_types:
        else_statement = Float(else_statement)
    assert if_statement.is_relational()
    expr = expression(if_statement)
    new_operator = IfElseOperator(if_statement.last_node(), then_statement.last_node(), else_statement.last_node())
    for oper in then_statement.operators():
        expr.append_operator(oper)
    for oper in else_statement.operators():
        expr.append_operator(oper)
    expr.append_operator(new_operator)
    return expr
github USEPA / WNTR / wntr / sim / aml / expr.py View on Github external
def diff_down(self, val_dict, der_dict):
        der = der_dict[self]
        der_dict[self._operand] += der * if_else(if_statement=inequality(body=val_dict[self._operand], lb=0),
                                                 then_statement=Float(1), else_statement=Float(-1))
github USEPA / WNTR / wntr / sim / aml / expr.py View on Github external
Returns
    -------
    expr: ExpressionBase
    """
    if lb is not None and ub is not None:
        if type(lb) not in native_numeric_types or type(ub) not in native_numeric_types:
            raise ValueError('inequality can only accept both lb and ub arguments if both are floats or ints.')

    if lb is None:
        lb = -math.inf
    if ub is None:
        ub = math.inf

    if type(lb) in native_numeric_types:
        lb = Float(lb)
    else:
        body -= lb
        lb = Float(0)

    if type(ub) in native_numeric_types:
        ub = Float(ub)
    else:
        body -= ub
        ub = Float(0)

    if type(body) in native_numeric_types:
        return lb.value <= body <= ub.value

    if body.is_leaf():
        expr = expression()
    else: