Example #1
0
def def_bilinear_dynamic_cost(bl, var_in='p_in', var_out='p_out'):
    """
    Method for adding bilinear dynamic cost to a block associated to variables 'var_in', 'var_out'.

    Names of costs are 'cost_in' 'cost_out' and are not tunable for the moment.
    Final instantaneous cost expression is called "inst_cost"

    :param bl: Block
    :param str var_in: Name of the input variable
    :param str var_out: Name of the input variable
    :return: Expression
    """

    # bl.cost_in  = Param(bl.time, default=0, mutable=True,
    #                     doc=f'buying cost of variable {var_in} with respect to time')
    # bl.cost_out = Param(bl.time, default=0, mutable=True,
    #                     doc=f'selling cost of variable {var_out} with respect to time')

    from lms2.base.base_units import fix_profile

    fix_profile(bl, flow_name='cost_in',  index_name='cost_in_index',  profile_name='cost_in_value',
                doc_index=f'index for the dynamic cost related to variable {var_in}',
                doc_value=f'values for dynamic cost related to variable {var_in}')
    fix_profile(bl, flow_name='cost_out', index_name='cost_out_index', profile_name='cost_out_value',
                doc_index=f'index for the dynamic cost related to variable {var_out}',
                doc_value=f'values for dynamic cost related to variable {var_out}')

    def _instant_cost(m, t):
        return (m.find_component(var_out)[t] * m.cost_out[t] - m.find_component(var_in)[t] * m.cost_in[t])/3600

    return Expression(bl.time, rule=_instant_cost,
                      doc=f'instantaneous bilinear and dynamic cost, associated with variable {var_in} and {var_out}')
Example #2
0
def def_linear_dyn_cost(m, var_name='p'):
    """
    Method for adding a linear dynamic cost associated to variable 'p', to a block
    Final instantaneous cost expression is called "inst_cost"

    .. math::
        m.instantcost(t) = m.var(t) \\times m.cost(t), \ \\forall t \\in m.time

    :param m: Block
    :param str var_name: Names of the expensive variable
    :return: pyomo Expression
    """
    from lms2.base.base_units import fix_profile

    fix_profile(m,
                flow_name='cost',
                index_name='cost_index',
                profile_name='cost_value')

    def _instant_cost(m, t):
        return m.find_component(var_name)[t] * m.cost[t] / 3600

    return Expression(
        m.time,
        rule=_instant_cost,
        doc=
        f'instantaneous linear cost (euros/s), associated with variable {var_name}'
    )
Example #3
0
    def __init__(self, *args, flow_name='p', **kwds):
        from lms2.base.base_units import fix_profile
        from pyomo.environ import Var

        super().__init__(*args, flow_name=flow_name, **kwds)

        fix_profile(self,
                    flow_name='pp',
                    profile_name='profile_value',
                    index_name='profile_index')
        self.u = Var(
            self.time,
            within=Binary,
            doc='binary, equals to 1 when the load is ON, 0 otherwise.')

        @self.Constraint(self.time, doc='curtailement constraint')
        def _curtailing(m, t):
            return m.p[t], m.u[t] * m.pp[t]
Example #4
0
def def_bilinear_dynamic_cost(bl, var_in='p_in', var_out='p_out'):
    """
    Method for adding bilinear dynamic cost to a block associated to variables 'var_in', 'var_out'.

    Names of costs are 'cost_in' 'cost_out' and are not tunable for the moment.
    Final instantaneous cost expression is called "inst_cost"

    .. warning :: should only be used for convex cost ! i.e.  cost_out > -cost_in

    :param bl: Block
    :param str var_in: Name of the input variable
    :param str var_out: Name of the input variable
    :return: Expression
    """

    from lms2.base.base_units import fix_profile

    fix_profile(
        bl,
        flow_name='cost_in',
        index_name='cost_in_index',
        profile_name='cost_in_value',
        doc_index=f'index for the dynamic cost related to variable {var_in}',
        doc_value=f'values for dynamic cost related to variable {var_in}')
    fix_profile(
        bl,
        flow_name='cost_out',
        index_name='cost_out_index',
        profile_name='cost_out_value',
        doc_index=f'index for the dynamic cost related to variable {var_out}',
        doc_value=f'values for dynamic cost related to variable {var_out}')

    def _instant_cost(m, t):
        return (m.find_component(var_out)[t] * m.cost_out[t] -
                m.find_component(var_in)[t] * m.cost_in[t]) / 3600

    return Expression(
        bl.time,
        rule=_instant_cost,
        doc=
        f'instantaneous bilinear and dynamic cost, associated with variable {var_in} and {var_out}'
    )
Example #5
0
    def __init__(self, *args, flow_name='p', **kwds):

        from lms2 import fix_profile
        from pyomo.core import Binary
        from pyomo.environ import Param, Var, Set

        super().__init__(*args, flow_name=flow_name, **kwds)

        def _bound_u(m, t):
            if m.window.bounds()[0] <= t <= m.window.bounds()[-1]:
                return 0, 1
            else:
                return 0, 0

        fix_profile(self,
                    flow_name='pp',
                    profile_name='profile_value',
                    index_name='profile_index')

        self.w1 = Param()
        self.w2 = Param()
        self.window = Set(doc='time window where load can be turned ON.')

        self.u = Var(
            self.time,
            bounds=_bound_u,
            within=Binary,
            doc='binary, equals to 1 when the load is turned ON, 0 otherwise.')

        @self.Constraint(doc='the load is turned on only once')
        def _turned_on(m):
            return sum([m.u[t] for t in m.time]) == 1

        @self.Constraint(
            self.time,
            doc='the load is contraint to be off outside the time range')
        def _bound_p(m, t):
            if m.window.bounds()[0] <= t <= m.window.bounds()[-1]:
                return Constraint.Skip
            else:
                return 0, m.p[t], 0