Example #1
0
    def __init__(self,
                 COP=None,
                 max_capacity=None,
                 Qmax=None,
                 taxation=None,
                 investment_cost=None,
                 **kwargs):
        super().__init__(**kwargs)

        with fs.namespace(self):
            Q = fs.VariableCollection(lb=0, ub=Qmax, name='Q')
            inv = fs.Variable(domain=fs.Domain.binary)

        self.production[Resources.heat] = Q
        self.consumption[Resources.power] = lambda t: Q(t) / COP
        #power_cons_tax = taxation('consumption', Resources.power)
        #Instead of using power_cons_tax in the lambda function I added 10 as a fixed cost
        self.cost = lambda t: self.consumption[Resources.power](t) * 10
        self.state_variables = lambda t: {Q(t)}
        self.inv = inv

        if max_capacity:
            self.max_capacity = max_capacity
            self.constraints += self.max_production
            self.investment_cost = inv * investment_cost
            self.static_variables = {inv}
        else:
            self.static_variables = {}
Example #2
0
    def __init__(self, **kwargs):
        super(Producer, self).__init__(**kwargs)

        with namespace(self):
            self.activity = VariableCollection('activity', lb=0)
        self.production[RESOURCE] = lambda t: 2 * self.activity(t)
        self.cost = lambda t: 3 * self.activity(t)
Example #3
0
    def __init__(self, **kwargs):
        super(Producer, self).__init__(**kwargs)

        with namespace(self):
            self.activity = VariableCollection('activity', lb=0)
        self.production[RESOURCE] = lambda t: 2 * self.activity(t)
        self.cost = lambda t: 3 * self.activity(t)
Example #4
0
    def __init__(self, startup_time=None, fuel=None, alpha=None, eta=None, 
                 Fmin=None, Fmax=None, fuel_cost=None, **kwargs):
        super().__init__(**kwargs)


        mode_names = ('off', 'starting', 'on')
        with fs.namespace(self):
            modes = OrderedDict(
                (n, VariableCollection(name=n, domain=fs.Domain.binary)) for n in mode_names)
            F_on = fs.VariableCollection(lb=0) # Fuel use if on

        self.consumption[fuel] = lambda t: F_on(t) * modes['on'](t) + modes['starting'](t) * Fmin
        self.production[Resources.heat] = lambda t: modes['on'] * F_on(t) * eta / (alpha + 1)
        self.production[Resources.power] = lambda t: alpha * self.production[Resources.heat](t)

        on_or_starting = lambda t: modes['on'](t) + modes['starting'](t)
        def mode_constraints(t):
            yield Constraint(
                sum(m(t) for m in modes.values()) == 1, desc='Exactly one mode at a time')

            recent_sum = sum(on_or_starting(t-tau-1) for tau in range(starting_time))
            yield Constraint(
                modes['on'](t) <= recent_sum / startup_time,
                desc="'on' mode is only allowed after startup_time in 'on' and 'starting'")

            yield Constraint(
                self.consumption[fuel](t) <= Fmax * modes['on'] + Fmin * modes['starting'],
                desc='Max fuel use')

        self.constraints += mode_constraints

        self.cost = lambda t: fuel_cost * self.consumption[fuel](t)
        self.state_variables = lambda t: {F_on(t)} | {var(t) for var in self.modes.values()}
Example #5
0
    def __init__(self, start_steps=None, fuel=None, alpha=None, eta=None, 
                 Fmin=None, Fmax=None, taxation=None, **kwargs):
        super().__init__(**kwargs)

        mode_names = ('off', 'starting', 'on')
        with fs.namespace(self):
            modes = OrderedDict(
                (n, VariableCollection(name=n, domain=fs.Domain.binary)) for n in mode_names)
            F_on = VariableCollection(lb=0, name='F_on') # Fuel use if on

        self.consumption[fuel] = lambda t: F_on(t) + modes['starting'](t) * Fmin
        self.production[Resources.heat] = lambda t: F_on(t) * eta / (alpha + 1)
        self.production[Resources.power] = lambda t: alpha * self.production[Resources.heat](t)

        self.cost = _CHP_cost_func(self, taxation, fuel)

        on_or_starting = lambda t: modes['on'](t) + modes['starting'](t)
        def mode_constraints(t):
            yield Constraint(
                fs.Eq(fs.Sum(m(t) for m in modes.values()), 1), desc='Exactly one mode at a time')

            if start_steps > 0:
                recent_sum = fs.Sum(on_or_starting(tau) for tau in self.iter_times(t, -(start_steps+1), 0))
                yield Constraint(
                    modes['on'](t) <= recent_sum / start_steps,
                    desc="'on' mode is only allowed after start_steps in 'on' and 'starting'")

            yield Constraint(
                self.consumption[fuel](t) <= Fmax * modes['on'](t) + Fmin * modes['starting'](t),
                desc='Max fuel use')

        self.constraints += mode_constraints

        self.state_variables = lambda t: {F_on(t)} | {var(t) for var in modes.values()}
Example #6
0
 def __init__(self, consumption, **kwargs):
     super(Consumer, self).__init__(**kwargs)
     
     with namespace(self):
         self.activity = VariableCollection('activity', lb=0)
     self.consumption[RESOURCE] = lambda t: self.activity(t) * 0.5
     cons = self.consumption[RESOURCE]
     self.constraints += lambda t: Constraint(fs.Eq(cons(t), consumption(t)), 'Consumption constraint')
Example #7
0
    def __init__(self, consumption, **kwargs):
        super(Consumer, self).__init__(**kwargs)

        with namespace(self):
            self.activity = VariableCollection('activity', lb=0)
        self.consumption[RESOURCE] = lambda t: self.activity(t) * 0.5
        cons = self.consumption[RESOURCE]
        self.constraints += lambda t: Constraint(
            cons(t) == consumption(t), 'Consumption constraint')
Example #8
0
    def __init__(self, COP=None, Qmax=None, power_cost=None, **kwargs):
        super(HeatPump, self).__init__(**kwargs)

        with fs.namespace(self):
            Q = fs.VariableCollection(lb=0, ub=Qmax)
        self.production[Resources.heat] = Q
        self.consumption[Resources.power] = lambda t: Q / COP

        self.cost = lambda t: power_cost * self.consumption[Resources.power](t)
        self.state_variables = lambda t: {Q(t)}
Example #9
0
    def __init__(self, COP=None, Qmax=None, power_cost=None, **kwargs):
        super(HeatPump, self).__init__(**kwargs)

        with fs.namespace(self):
            Q = fs.VariableCollection(lb=0, ub=Qmax)
        self.production[Resources.heat] = Q
        self.consumption[Resources.power] = lambda t: Q / COP

        self.cost = lambda t: power_cost * self.consumption[Resources.power](t)
        self.state_variables = lambda t: {Q(t)}
Example #10
0
    def __init__(self, fuel=None, eta=None, Fmax=None, fuel_cost=None, **kwargs):
        super().__init__(**kwargs)

        with fs.namespace(self):
            F = fs.VariableCollection(lb=0, ub=Fmax)
        self.consumption[fuel] = F
        self.production[Resources.heat] = lambda t: eta * F(t)

        self.cost = lambda t: fuel_cost * F(t)
        self.state_variables = lambda t: {F(t)}
Example #11
0
    def __init__(self, fuel=None, alpha=None, eta=None, Fmax=None, taxation=None, **kwargs):        
        super().__init__(**kwargs)

        with fs.namespace(self):
            F = VariableCollection(lb=0, ub=Fmax, name='F')

        self.consumption[fuel] = F
        self.production[Resources.heat] = lambda t: F(t) * eta / (alpha + 1)
        self.production[Resources.power] = lambda t: alpha * self.production[Resources.heat](t)

        self.state_variables = lambda t: {F(t)}
        self.cost = _CHP_cost_func(self, taxation, fuel)
Example #12
0
    def __init__(self, fuel=None, taxation=None, Fmax=None, eta=None, **kwargs):
        super().__init__(**kwargs)

        with fs.namespace(self):
            F = VariableCollection(lb=0, ub=Fmax, name='F')
        self.consumption[fuel] = F
        self.production[Resources.heat] = lambda t: eta * F(t)

        fuel_cons_tax = taxation('consumption', fuel, chp=False)
        self.cost = lambda t: self.consumption[fuel](t) * fuel_cons_tax

        self.state_variables = lambda t: {F(t)}
Example #13
0
    def __init__(self, COP=None, Qmax=None, taxation=None, **kwargs):
        super().__init__(**kwargs)

        with fs.namespace(self):
            Q = VariableCollection(lb=0, ub=Qmax, name='Q')
        self.production[Resources.heat] = Q
        self.consumption[Resources.power] = lambda t: Q(t) / COP

        power_cons_tax = taxation('consumption', Resources.power)
        self.cost = lambda t: self.consumption[Resources.power](t) * power_cons_tax

        self.state_variables = lambda t: {Q(t)}
Example #14
0
    def __init__(self, resource=None, max_import=None, max_export=None, price=None, **kwargs):
        super(Trade, self).__init__(**kwargs)

        with fs.namespace(self):
            net_import = fs.VariableCollection(lb=-max_export, ub=max_import)
        self.production[resource] = net_import

        if hasattr(price, '__getitem__'):
            self.cost = lambda t: price[t] * net_import(t)
        else:
            self.cost = lambda t: price * net_import(t)

        self.state_variables = lambda t: {net_import(t)}
Example #15
0
    def __init__(self,
                 resource=None,
                 max_flow=0,
                 max_energy=0,
                 loss_factor=0,
                 max_capacity=None,
                 investment_cost=None,
                 t_start='2016-01-01',
                 t_end='2016-01-02',
                 **kwargs):
        super().__init__(**kwargs)
        with fs.namespace(self):
            volume = fs.VariableCollection(lb=0, ub=max_energy, name='Storage')
            #cap = fs.Variable(lb=0, ub=max_capacity, name='cap')
            inv = fs.Variable(domain=fs.Domain.binary)

        self.test = {
            'resource': resource,
            'max_flow': max_flow,
            'max_energy': max_energy,
            'loss_factor': loss_factor,
            'max_capacity': max_capacity,
            'investment_cost': investment_cost
        }

        self.t_start = t_start
        self.t_end = t_end
        self.max_energy = max_energy
        self.volume = volume
        self.resource = resource
        self.consumption[self.resource] = lambda t: loss_factor * volume(t)
        self.max_flow = max_flow
        self.cost = lambda t: 0
        self.state_variables = lambda t: {volume(t)}

        self.accumulation[self.resource] = self.compute_accumulation
        self.constraints += self.max_change_constraints
        self.inv = inv

        if max_capacity:
            self.max_capacity = max_capacity
            self.investment_cost = inv * investment_cost
            self.constraints += self.max_volume
            self.timeindependent_constraint = fs.Eq(inv, 0)
            self.static_variables = {inv}
        else:
            self.static_variables = {}

        self.constraints += self.start_end_volume
        self.constraints += self.start_volume
Example #16
0
    def __init__(self, resource=None, capacity=None, price=None, **kwargs):
        super().__init__(**kwargs)

        with fs.namespace(self):
            quantity = VariableCollection(lb=0, ub=capacity, name='import')

        self.production[resource] = quantity

        if isinstance(price, numbers.Real):
            self.cost = lambda t: price * quantity(t)
        else:
            self.cost = lambda t: price[t] * quantity(t)

        self.state_variables = lambda t: {quantity(t)}
Example #17
0
    def __init__(self,
                 fuel=None,
                 alpha=None,
                 eta=None,
                 Fmax=None,
                 taxation=None,
                 investment_cost=None,
                 running_cost=0,
                 max_capacity=None,
                 **kwargs):
        super().__init__(**kwargs)
        try:
            if math.isnan(Fmax):
                Fmax = max_capacity
        except TypeError:
            import pdb
            pdb.set_trace()

        with fs.namespace(self):
            F = fs.VariableCollection(lb=0, ub=Fmax, name='F')
            inv = fs.Variable(domain=fs.Domain.binary, name='inv_chp')

        self.test = {
            'fuel': fuel,
            'alpha': alpha,
            'eta': eta,
            'Fmax': Fmax,
            'max_capacity': max_capacity,
            'taxation': taxation,
            'investment_cost': investment_cost
        }

        self.consumption[fuel] = F
        self.production[Resources.heat] = lambda t: F(t) * eta / (alpha + 1)
        self.production[
            Resources.power] = lambda t: alpha * F(t) * eta / (alpha + 1)
        self.cost = lambda t: F(
            t) * running_cost  #_CHP_cost_func(self, taxation, fuel)

        self.state_variables = lambda t: {F(t)}
        self.inv = inv

        if max_capacity:
            self.max_capacity = max_capacity
            self.constraints += self.max_production
            self.investment_cost = inv * investment_cost
            self.static_variables = {inv}
        else:
            self.static_variables = {}
Example #18
0
    def __init__(self,
                 startup_time=None,
                 fuel=None,
                 alpha=None,
                 eta=None,
                 Fmin=None,
                 Fmax=None,
                 fuel_cost=None,
                 **kwargs):
        super().__init__(**kwargs)

        mode_names = ('off', 'starting', 'on')
        with fs.namespace(self):
            modes = OrderedDict(
                (n, VariableCollection(name=n, domain=fs.Domain.binary))
                for n in mode_names)
            F_on = fs.VariableCollection(lb=0)  # Fuel use if on

        self.consumption[fuel] = lambda t: F_on(t) * modes['on'](t) + modes[
            'starting'](t) * Fmin
        self.production[Resources.heat] = lambda t: modes['on'] * F_on(
            t) * eta / (alpha + 1)
        self.production[Resources.power] = lambda t: alpha * self.production[
            Resources.heat](t)

        on_or_starting = lambda t: modes['on'](t) + modes['starting'](t)

        def mode_constraints(t):
            yield Constraint(sum(m(t) for m in modes.values()) == 1,
                             desc='Exactly one mode at a time')

            recent_sum = sum(
                on_or_starting(t - tau - 1) for tau in range(starting_time))
            yield Constraint(
                modes['on'](t) <= recent_sum / startup_time,
                desc=
                "'on' mode is only allowed after startup_time in 'on' and 'starting'"
            )

            yield Constraint(self.consumption[fuel](t) <=
                             Fmax * modes['on'] + Fmin * modes['starting'],
                             desc='Max fuel use')

        self.constraints += mode_constraints

        self.cost = lambda t: fuel_cost * self.consumption[fuel](t)
        self.state_variables = lambda t: {F_on(
            t)} | {var(t)
                   for var in self.modes.values()}
Example #19
0
    def __init__(self,
                 fuel=None,
                 eta=None,
                 Fmax=None,
                 fuel_cost=None,
                 **kwargs):
        super().__init__(**kwargs)

        with fs.namespace(self):
            F = fs.VariableCollection(lb=0, ub=Fmax)
        self.consumption[fuel] = F
        self.production[Resources.heat] = lambda t: eta * F(t)

        self.cost = lambda t: fuel_cost * F(t)
        self.state_variables = lambda t: {F(t)}
Example #20
0
    def __init__(self, resource=None, capacity=None, price=0, **kwargs):
        super().__init__(**kwargs)

        with fs.namespace(self):
            quantity = VariableCollection(lb=0,
                                          ub=capacity,
                                          name='export of {}'.format(resource))

        self.consumption[resource] = quantity

        if isinstance(price, numbers.Real):
            self.cost = lambda t: -price * quantity(t)
        else:
            self.cost = lambda t: -price[t] * quantity(t)

        self.state_variables = lambda t: {quantity(t)}
Example #21
0
    def __init__(self,
                 resource=None,
                 max_import=None,
                 max_export=None,
                 price=None,
                 **kwargs):
        super(Trade, self).__init__(**kwargs)

        with fs.namespace(self):
            net_import = fs.VariableCollection(lb=-max_export, ub=max_import)
        self.production[resource] = net_import

        if hasattr(price, '__getitem__'):
            self.cost = lambda t: price[t] * net_import(t)
        else:
            self.cost = lambda t: price * net_import(t)

        self.state_variables = lambda t: {net_import(t)}
Example #22
0
    def __init__(self,
                 resource=None,
                 capacity=None,
                 price=None,
                 CO2_factor=None,
                 **kwargs):
        super().__init__(**kwargs)

        with fs.namespace(self):
            quantity = VariableCollection(lb=0, ub=capacity, name='import')

        self.production[resource] = lambda t: quantity(t)
        self.production[Resources.CO2] = lambda t: quantity(t) * CO2_factor

        if isinstance(price, numbers.Real):
            self.cost = lambda t: price * quantity(t)
        else:
            self.cost = lambda t: price[t] * quantity(t)

        self.state_variables = lambda t: {quantity(t)}
 def __init__(self, consumption, variant, **kwargs):
     super(Consumer, self).__init__(**kwargs)
     
     self._cons_func = consumption
     with namespace(self):
         self.activity = fs.VariableCollection('activity', lb=0)
     self.consumption[RESOURCE] = lambda t: self.activity(t) * 0.5
     cons = self.consumption[RESOURCE]
     if variant == 0:
         self.constraints += lambda t: cons(t) == consumption(t)
     elif variant == 1:
         self.constraints += lambda t: (cons(t) == consumption(t), cons(t) == cons(t))
     elif variant == 2:
         self.constraints += (lambda t: cons(t) == consumption(t) for i in range(1))
     elif variant == 3:
         self.constraints += self._consumption_constraint
     elif variant == 4:
         self.constraints += lambda t: Constraint(cons(t) == consumption(t), 'Consumption')
     else:
         raise ValueError('variant {} not defined'.format(variant))
Example #24
0
    def __init__(self, consumption, variant, **kwargs):
        super(Consumer, self).__init__(**kwargs)

        self._cons_func = consumption
        with namespace(self):
            self.activity = fs.VariableCollection('activity', lb=0)
        self.consumption[RESOURCE] = lambda t: self.activity(t) * 0.5
        cons = self.consumption[RESOURCE]
        if variant == 0:
            self.constraints += lambda t: cons(t) == consumption(t)
        elif variant == 1:
            self.constraints += lambda t: (cons(t) == consumption(t), cons(t)
                                           == cons(t))
        elif variant == 2:
            self.constraints += (lambda t: cons(t) == consumption(t)
                                 for i in range(1))
        elif variant == 3:
            self.constraints += self._consumption_constraint
        elif variant == 4:
            self.constraints += lambda t: Constraint(
                cons(t) == consumption(t), 'Consumption')
        else:
            raise ValueError('variant {} not defined'.format(variant))
Example #25
0
    def __init__(self,
                 fuel=None,
                 taxation=None,
                 Fmax=None,
                 eta=None,
                 investment_cost=None,
                 running_cost=0,
                 max_capacity=None,
                 **kwargs):
        super().__init__(**kwargs)

        with fs.namespace(self):
            F = fs.VariableCollection(lb=0, ub=Fmax, name='F')
            inv = fs.Variable(domain=fs.Domain.binary)

        self.test = {
            'Fmax': Fmax,
            'eta': eta,
            'running_cost': running_cost,
            'max_capacity': max_capacity
        }

        self.consumption[fuel] = F
        self.production[Resources.heat] = lambda t: eta * F(t)
        self.cost = lambda t: self.consumption[fuel](t) * running_cost

        self.state_variables = lambda t: {F(t)}
        self.inv = inv

        if max_capacity:
            self.max_capacity = max_capacity
            self.constraints += self.max_production
            self.investment_cost = inv * investment_cost
            self.static_variables = {inv}
        else:
            self.static_variables = {}
Example #26
0
    def __init__(self,
                 start_steps=None,
                 fuel=None,
                 alpha=None,
                 eta=None,
                 capacity=None,
                 Fmin=None,
                 Fmax=None,
                 max_capacity=None,
                 taxation=None,
                 investment_cost=None,
                 **kwargs):
        super().__init__(**kwargs)

        mode_names = ('off', 'starting', 'on')
        with fs.namespace(self):
            modes = OrderedDict(
                (n, fs.VariableCollection(name=n, domain=fs.Domain.binary))
                for n in mode_names)
            F_on = fs.VariableCollection(lb=0, name='F_on')  # Fuel use if on
            inv = fs.Variable(domain=fs.Domain.binary)

        self.test = {
            'start_steps': start_steps,
            'fuel': fuel,
            'alpha': alpha,
            'eta': eta,
            'capacity': capacity,
            'Fmin': Fmin,
            'Fmax': Fmax,
            'max_capacity': max_capacity,
            'taxation': taxation,
            'investment_cost': investment_cost
        }
        self.inv = inv
        self.modes = modes

        if max_capacity:
            self.max_capacity = max_capacity
            Fmin = 0.2 * max_capacity * (1 + alpha) / eta
            Fmax = max_capacity * (1 + alpha) / eta
            self.investment_cost = inv * investment_cost
            self.constraints += self.max_production
            self.static_variables = {inv}
        elif capacity:
            Fmin = 0.2 * capacity * (1 + alpha) / eta
            Fmax = capacity * (1 + alpha) / eta
            self.static_variables = {}
            self.investment_cost = investment_cost
        else:
            self.static_variables = {}
            self.investment_cost = investment_cost

        self.consumption[fuel] = lambda t: F_on(t) + modes['starting'](t
                                                                       ) * Fmin
        self.production[Resources.heat] = lambda t: F_on(t) * eta / (alpha + 1)
        self.production[Resources.power] = lambda t: alpha * self.production[
            Resources.heat](t)

        self.cost = lambda t: self.consumption[fuel](
            t) * 0  #_CHP_cost_func(self, taxation, fuel)

        on_or_starting = lambda t: modes['on'](t) + modes['starting'](t)

        def mode_constraints(t):
            """ Yields mode constraints, if 'start_steps' is provided as 'n' the unit will have 
            to be 'starting' for 'n' time indices and can be turned to 'on' in the n+1 time index
            """
            yield Constraint(fs.Eq(fs.Sum(m(t) for m in modes.values()), 1),
                             desc='Exactly one mode at a time')

            if start_steps:
                recent_sum = fs.Sum(
                    on_or_starting(tau)
                    for tau in self.iter_times(t, -(start_steps), 0))
                yield Constraint(
                    modes['on'](t) <= recent_sum / (start_steps),
                    desc=
                    "'on' mode is only allowed after start_steps in 'on' and 'starting'"
                )

            yield Constraint(
                self.consumption[fuel](t) <=
                Fmax * modes['on'](t) + Fmin * modes['starting'](t),
                desc='Max fuel use when on or starting')

            yield Constraint(
                self.consumption[fuel](t) >= Fmin * modes['on'](t),
                desc='Min fuel use when on')

        self.constraints += mode_constraints
        self.state_variables = lambda t: {F_on(
            t)} | {var(t)
                   for var in modes.values()}