Ejemplo n.º 1
0
        results = self.extract_results()
        n_level_satisfied = sum(1 for x in results['storage.HQ.H']
                                if _min <= x <= _max)
        q_pump_integral = sum(results['Q_pump'])
        q_pump_sum_changes = np.sum(np.diff(results['Q_pump'])**2)
        self.intermediate_results.append(
            (priority, n_level_satisfied, q_pump_integral, q_pump_sum_changes))

    def post(self):
        # Call super() class to not overwrite default behaviour
        super().post()
        for priority, n_level_satisfied, q_pump_integral, q_pump_sum_changes \
                in self.intermediate_results:
            print('\nAfter finishing goals of priority {}:'.format(priority))
            print('Level goal satisfied at {} of {} time steps'.format(
                n_level_satisfied, len(self.times())))
            print('Integral of Q_pump = {:.2f}'.format(q_pump_integral))
            print('Sum of squares of changes in Q_pump: {:.2f}'.format(
                q_pump_sum_changes))

    # Any solver options can be set here
    def solver_options(self):
        options = super().solver_options()
        solver = options['solver']
        options[solver]['print_level'] = 1
        return options


# Run
run_optimization_problem(Example)
Ejemplo n.º 2
0
                      label='Slootvaart Pump 2',
                      linewidth=2,
                      color='r')
        ymin, ymax = axarr[4].get_ylim()
        axarr[4].set_ylim(-0.05 * (ymax - ymin), ymax * 1.1)
        axarr[4].xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))

        f.autofmt_xdate()

        # Shrink each axis by 20% and put a legend to the right of the axis
        for i in range(len(axarr)):
            box = axarr[i].get_position()
            axarr[i].set_position(
                [box.x0, box.y0, box.width * 0.8, box.height])
            axarr[i].legend(loc='center left',
                            bbox_to_anchor=(1, 0.5),
                            frameon=False)

        # Output Plot
        f.set_size_inches(8, 9)
        plt.savefig(os.path.join(self._output_folder, 'overall_results.png'),
                    bbox_inches='tight',
                    pad_inches=0.1)

        # Plot the working area with the operating points of the pump.
        plot_operating_points(self, self._output_folder)


# Run
run_optimization_problem(Wieringermeer_afd1_afd2, base_folder='..')