Example #1
0
 def info_lines(self, t):
     lines = self.lines
     return ['line info:',
             'connecting={}'.format(
                 zip(getattrL(lines, 'frombus'), getattrL(lines, 'tobus'))),
             'Pk={}'.format(self.get_values(lines, 'power', t)),
             'price={}'.format(self.line_prices[str(t)])]
Example #2
0
    def make_buses_list(self, loads, generators):
        """
        Create list of :class:`powersystems.Bus` objects
        from the load and generator bus names. Otherwise
        (as in ED,UC) create just one (system)
        :class:`powersystems.Bus` instance.

        :param loads: a list of :class:`powersystems.Load` objects
        :param generators: a list of :class:`powersystems.Generator` objects
        :returns: a list of :class:`powersystems.Bus` objects
        """
        busNameL = []
        busNameL.extend(getattrL(generators, 'bus'))
        busNameL.extend(getattrL(loads, 'bus'))
        busNameL = pd.Series(pd.unique(busNameL)).dropna().tolist()

        if len(busNameL) == 0:
            busNameL = [None]

        buses = []
        swingHasBeenSet = False

        for b, busNm in enumerate(busNameL):
            newBus = Bus(name=busNm, index=b)
            for gen in generators:
                if gen.bus == newBus.name:
                    newBus.generators.append(gen)
                if not swingHasBeenSet:
                    newBus.isSwing = swingHasBeenSet = True
            for ld in loads:
                if ld.bus == newBus.name:
                    newBus.loads.append(ld)
            buses.append(newBus)
        return buses
Example #3
0
 def create_constraints(self, times, buses):
     """create the constraints for a line over all times"""
     busNames = getattrL(buses, "name")
     iFrom, iTo = busNames.index(self.frombus), busNames.index(self.tobus)
     for t in times:
         line_flow_ij = self.power(t) == 1 / self.reactance * (buses[iFrom].angle(t) - buses[iTo].angle(t))
         self.add_constraint("line flow", t, line_flow_ij)
         self.add_constraint("line limit high", t, self.power(t) <= self.pmax)
         self.add_constraint("line limit low", t, self.pmin <= self.power(t))
     return
Example #4
0
 def info_buses(self, t):
     buses = self.buses
     out = ['bus info:',
            'name={}'.format(getattrL(buses, 'name')),
            'Pinj={}'.format([bus.Pgen(t, evaluate=True) -
                              bus.Pload(
                                  t, evaluate=True) for bus in buses]),
            'angle={}'.format(self.get_values(
                              buses, 'angle', t) if len(buses) > 1 else []),
            'LMP={}'.format(self.lmps[str(t)])]
     return out
Example #5
0
 def create_constraints(self, times, buses):
     '''create the constraints for a line over all times'''
     busNames = getattrL(buses, 'name')
     iFrom, iTo = busNames.index(self.frombus), busNames.index(self.tobus)
     for t in times:
         line_flow_ij = self.power(t) == \
             1 / self.reactance * (buses[iFrom].angle(t) -
                                   buses[iTo].angle(t))
         self.add_constraint('line flow', t, line_flow_ij)
         self.add_constraint(
             'line limit high', t, self.power(t) <= self.pmax)
         self.add_constraint(
             'line limit low', t, self.pmin <= self.power(t))
     return
Example #6
0
    def visualization(self, show_cost_also=False):
        ''' economic dispatch visualization of linearized incremental cost'''
        if not do_plotting:
            return
        t = self.times[0]
        price = self.lmps[str(t)][0]
        generators = self.generators
        loads = self.loads

        plotted_gens, names_gens, plotted_loads, names_loads = [], [], [], []
        minGen = min(getattrL(generators, 'pmin'))
        maxGen = max(getattrL(generators, 'pmax'))

        # save a plot of the price space - illustrating equal IC
        ax = plot.axes()
        for gen in generators:
            if gen.status(t):
                in_range, out_range = gen.bids.output_incremental_range()
                if gen.bids.is_pwl:
                    line, = plot.step(
                        in_range, out_range, where='pre', linestyle='-')
                else:
                    line, = plot.plot(in_range, out_range, linestyle='-', )
                plotted_gens.append(line)
                P = value(gen.power(t))
                IC = gen.incrementalcost(t)
                plot.plot(P, IC, '.', c=line.get_color(
                ), markersize=8, linewidth=2, alpha=0.7)
                names_gens.append(gen.name)
        if price is not None:
            grayColor = '.75'
            plot.plot([minGen, maxGen], [price, price], '--k', color=grayColor)
            plot.text(maxGen, price, '{p:0.2f} $/MWh'.format(
                p=price), color=grayColor, horizontalalignment='right')

        plot.xlabel('P [MWh]')
        if plotted_loads:
            plot.ylabel('Marginal Cost-Benifit [$/MWh]')
        else:
            plot.ylabel('Marginal Cost [$/MWh]')
        prettify_axes(ax)

        # plot.xlim(xmin=0,xmax=)
        ymin, _ = plot.ylim()
        if ymin < 0:
            plot.ylim(ymin=0)

        legendGens = plot.legend(plotted_gens, names_gens, fancybox=True,
                                 title='Generators:', loc='best')
        if plotted_loads:
            plot.legend(plotted_loads, names_loads,
                        fancybox=True, title='Loads:', loc='best')
            # add first legend to the axes manually bcs multiple legends get overwritten                        
            plot.gca().add_artist(legendGens)  

        self.savevisualization(filename=full_filename('dispatch.png'))

        if show_cost_also:
            # show a plot of the cost space, illustrating the linearization
            plot.figure()
            gensPlotted_price = plotted_gens
            plotted_gens, names_gens, plotted_loads, names_loads = [
            ], [], [], []
            for g, gen in enumerate(generators):
                if gen.status(t):
                    plotted_gens.append(gen.cost_model.plot(
                        P=value(gen.power(t)), 
                        linestyle='-', 
                        color=gensPlotted_price[g].get_color()
                        ))
                    names_gens.append(gen.name)
            for load in loads:
                if load.kind == 'bidding':
                    plotted_loads.append(load.bid(
                        t).plot(P=value(load.power(t)), linestyle=':'))
                    names_loads.append(load.name)
            plot.xlabel('P [MWh]')
            if plotted_loads:
                plot.ylabel('Cost-Benifit [$/h]')
            else:
                plot.ylabel('Cost [$/h]')
            legendGens = plot.legend(plotted_gens, names_gens, fancybox=True,
                                     title='Generators:', loc='best')
            if plotted_loads:
                plot.legend(plotted_loads, names_loads,
                            fancybox=True, title='Loads:', loc='best')
                plot.gca().add_artist(legendGens)  # add first legend to the axes manually bcs multiple legends get overwritten

            self.savevisualization(filename=full_filename('dispatch-cost.png'))