Exemplo n.º 1
0
def test_attributes():
    md = ModelData(dict(testdata))

    attr = md.attributes(element_type='generator')

    attr_cmp = {
        'names': ['G1', 'G2'],
        'generator_type': {
            'G1': 'thermal',
            'G2': 'solar'
        },
        'connected_bus': {
            'G1': 'B1',
            'G2': 'B1'
        },
        'pg': {
            'G1': 100.0,
            'G2': 200.0
        },
        'qg': {
            'G1': 11.0,
            'G2': 22.0
        },
        'in_service': {
            'G1': True,
            'G2': True
        }
    }
    assert attr == attr_cmp
Exemplo n.º 2
0
def poly_cost_to_pw_cost(md: ModelData, num_points=10):
    gen_attrs = md.attributes(element_type='generator')
    p_cost = gen_attrs['p_cost']
    for gen_name, cost_dict in p_cost.items():
        assert cost_dict['cost_curve_type'] == 'polynomial'
        cost_dict['cost_curve_type'] = 'piecewise'
        poly_coefs = cost_dict['values']
        pw_values = list()
        p_min = gen_attrs['p_min'][gen_name]
        p_max = gen_attrs['p_max'][gen_name]
        for pt in np.linspace(p_min, p_max, num_points):
            cost = sum(coef*pt**exponent for exponent, coef in poly_coefs.items())
            pw_values.append((pt, cost))
        cost_dict['values'] = pw_values
Exemplo n.º 3
0
#  ___________________________________________________________________________

import pytest

from egret.data.model_data import ModelData
from egret.data.tests.test_model_data import testdata
from egret.model_library.unit_commitment.uc_utils import uc_time_helper

## these should be arbitary to mimic
## a pyomo RangeSet
TimePeriods = [3, 4, 5]

time_mapper = uc_time_helper(TimePeriods)

md_testdata = ModelData(testdata)
load_attrs = md_testdata.attributes(element_type='load')


def test_None():
    assert time_mapper(None) == dict()


def test_empty_dict():
    assert time_mapper(dict()) == dict()


def test_single_item_mapping():
    expected_result = {3: 11.0, 4: 111.0, 5: 111.1}
    assert time_mapper(load_attrs['Pl']['L1']) == expected_result