Esempio n. 1
0
def run_example(config):
    # misc.
    datetime_index = pd.date_range(config['date_from'],
                                   config['date_to'],
                                   freq='60min')

    # model creation and solving
    logging.info('Starting optimization')

    es = EnergySystem(timeindex=datetime_index)

    NodesFromCSV(file_nodes_flows=os.path.join(config['scenario_path'],
                                               config['nodes_flows']),
                 file_nodes_flows_sequences=os.path.join(
                     config['scenario_path'], config['nodes_flows_sequences']),
                 delimiter=',')

    om = OperationalModel(es)
    om.receive_duals()
    om.solve(solver=config['solver'], solve_kwargs={'tee': config['verbose']})

    logging.info('Done! \n Check the results')

    # create pandas dataframe with results
    results = ResultsDataFrame(energy_system=es)

    rdict = {'objective': es.results.objective, 'time_series': results}

    return rdict
Esempio n. 2
0
def run_example(config):
    # misc.
    datetime_index = pd.date_range(config['date_from'],
                                   config['date_to'],
                                   freq='60min')

    # model creation and solving
    logging.info('Starting optimization')

    es = EnergySystem(timeindex=datetime_index)

    NodesFromCSV(file_nodes_flows=os.path.join(
                             config['scenario_path'],
                             config['nodes_flows']),
                 file_nodes_flows_sequences=os.path.join(
                             config['scenario_path'],
                             config['nodes_flows_sequences']),
                 delimiter=',')

    om = OperationalModel(es)
    om.receive_duals()
    om.solve(solver=config['solver'], solve_kwargs={'tee': config['verbose']})

    logging.info('Done! \n Check the results')

    # create pandas dataframe with results
    results = ResultsDataFrame(energy_system=es)

    rdict = {
        'objective': es.results.objective,
        'time_series': results
    }

    return rdict
Esempio n. 3
0
def run_investment_example(solver='cbc', verbose=True, nologg=False):
    if not nologg:
        logger.define_logging()

    # %% model creation and solving
    date_from = '2050-01-01 00:00:00'
    date_to = '2050-01-01 23:00:00'

    datetime_index = pd.date_range(date_from, date_to, freq='60min')

    es = EnergySystem(timeindex=datetime_index)

    data_path = os.path.join(os.path.dirname(__file__), 'data')

    NodesFromCSV(file_nodes_flows=os.path.join(data_path, 'nodes_flows.csv'),
                 file_nodes_flows_sequences=os.path.join(
                     data_path, 'nodes_flows_seq.csv'),
                 delimiter=',')

    stopwatch()

    om = OperationalModel(es)

    logging.info('OM creation time: ' + stopwatch())

    om.receive_duals()

    om.solve(solver=solver, solve_kwargs={'tee': verbose})

    logging.info('Optimization time: ' + stopwatch())

    results = ResultsDataFrame(energy_system=es)

    results_path = os.path.join(os.path.expanduser("~"), 'csv_invest')

    if not os.path.isdir(results_path):
        os.mkdir(results_path)

    results.to_csv(os.path.join(results_path, 'results.csv'))

    logging.info("The results can be found in {0}".format(results_path))
    logging.info("Read the documentation (outputlib) to learn how" +
                 " to process the results.")
    logging.info("Or search the web to learn how to handle a MultiIndex" +
                 "DataFrame with pandas.")

    logging.info('Done!')
Esempio n. 4
0
def run_example(config):
    # creation of an hourly datetime_index
    datetime_index = pd.date_range(config['date_from'],
                                   config['date_to'],
                                   freq='60min')

    # model creation and solving
    logging.info('Starting optimization')

    # initialisation of the energy system
    es = EnergySystem(timeindex=datetime_index)

    # adding all nodes and flows to the energy system
    # (data taken from csv-file)
    NodesFromCSV(file_nodes_flows=os.path.join(config['scenario_path'],
                                               config['nodes_flows']),
                 file_nodes_flows_sequences=os.path.join(
                     config['scenario_path'], config['nodes_flows_sequences']),
                 delimiter=',')

    # creation of a least cost model from the energy system
    om = OperationalModel(es)
    om.receive_duals()

    # solving the linear problem using the given solver
    om.solve(solver=config['solver'], solve_kwargs={'tee': config['verbose']})

    logging.info("Done!")

    # create pandas dataframe with results
    results = ResultsDataFrame(energy_system=es)

    # write results for selected busses to single csv files
    results.bus_balance_to_csv(bus_labels=['R1_bus_el', 'R2_bus_el'],
                               output_path=config['results_path'])

    logging.info("The results can be found in {0}".format(
        config['results_path']))
    logging.info("Read the documentation (outputlib) to learn how" +
                 " to process the results.")

    rdict = {'objective': es.results.objective, 'time_series': results}

    return rdict
Esempio n. 5
0
def simulate(es=None, **arguments):
    """Creates the optimization model, solves it and writes back results to
    energy system object

    Parameters
    ----------
    es : :class:`oemof.solph.network.EnergySystem` object
        Energy system holding nodes, grouping functions and other important
        information.
    **arguments : key word arguments
        Arguments passed from command line
    """

    om = OperationalModel(es)

    logging.info('OM creation time: ' + stopwatch())

    om.receive_duals()

    om.solve(solver=arguments['--solver'], solve_kwargs={'tee': True})

    logging.info('Optimization time: ' + stopwatch())

    return om
Esempio n. 6
0
if read_only:
    logging.info("Reading scenario tables.")
else:
    create_objects_from_dataframe_collection()

logging.info("Creating nodes.")

de21.create_nodes()

logging.info("Creating OperationalModel")

om = OperationalModel(de21)

logging.info('OM created. Starting optimisation using {0}'.format(solver))

om.receive_duals()

om.solve(solver=solver, solve_kwargs={'tee': True})

logging.info('Optimisation done.')

results = ResultsDataFrame(energy_system=de21)

if not os.path.isdir('results'):
    os.mkdir('results')
date = '2017_03_21'
file_name = ('scenario_' + de21.name + date + '_' + 'results_complete.csv')

results_path = 'results'

results.to_csv(os.path.join(results_path, file_name))