Exemple #1
0
def test_schedule():
    print('Running AbstractModel.test_schedule()')

    test_mtn = TransactiveNode()

    #   Create a test market test_mkt
    test_mkt = Market()

    #   Create a sample time interval ti
    dt = datetime.now()
    at = dt
    # NOTE: Function Hours() corrects behavior of Matlab hours().
    dur = timedelta(hours=1)
    mkt = test_mkt
    mct = dt
    # NOTE: Function Hours() corrects behavior of Matlab hours().
    st = datetime.combine(date.today(), time()) + timedelta(hours=20)
    ti = TimeInterval(at, dur, mkt, mct, st)

    print(ti)

    #   Save the time interval
    test_mkt.timeIntervals = [ti]

    #   Assign a marginal price in the time interval
    test_mkt.check_marginal_prices(test_mtn)

    #   Create a Neighbor test object and give it a default maximum power value
    # test_obj = Neighbor()

    #   Create a corresponding Neighbor.
    test_mdl = Neighbor()
    test_mdl.maximumPower = 100

    #   Make sure that the model and object cross-reference one another
    # test_obj.model = test_mdl
    # test_mdl.object = test_obj

    #   Run a test with a Neighbor object
    print('- running test with a Neighbor:')

    try:
        test_mdl.schedule(test_mkt)
        print('  - the method encountered no errors')
    except RuntimeWarning:
        print('  - ERRORS ENCOUNTERED')

    assert len(test_mdl.scheduledPowers
               ) == 1, '  - the method did not store a scheduled power'
    assert len(test_mdl.reserveMargins
               ) == 1, '  - the method did not store a reserve margin'
    assert len(test_mdl.activeVertices
               ) == 1, '  - the method did not store an active vertex'

    # Run a test again with a LocalAsset.
    # test_obj = LocalAsset()

    test_mdl = LocalAsset()
    # test_obj.model = test_mdl
    # test_mdl.object = test_obj
    test_mdl.maximumPower = 100
    test_mdl.scheduleCalculated = True

    print('- running test with a LocalAsset:')

    try:
        test_mdl.schedule(test_mkt)
        print('  - the method encountered no errors')
    except RuntimeWarning:
        print('  - ERRORS ENCOUNTERED')

    assert len(test_mdl.scheduledPowers
               ) == 1, '  - the method did not store a scheduled power'
    assert len(test_mdl.reserveMargins
               ) == 1, '  - the method did not store a reserve margin'
    assert len(test_mdl.activeVertices
               ) == 1, '  - the method did not store an active vertex'

    # Success
    print('test_schedule() ran to completion.\n')
Exemple #2
0
def test_update_costs():
    print('Running AbstractModel.test_update_costs()')

    test_mtn = TransactiveNode()

    #   Create a test market test_mkt
    test_mkt = Market()

    #   Create a sample time interval ti
    dt = datetime.now()
    at = dt
    #   NOTE: Function Hours() corrects behavior of Matlab hours().
    dur = timedelta(hours=1)
    mkt = test_mkt
    mct = dt
    st = datetime.combine(date.today(), time()) + timedelta(hours=20)
    ti = TimeInterval(at, dur, mkt, mct, st)

    #   Save the time interval
    test_mkt.timeIntervals = [ti]

    #   Assign a marginal price in the time interval
    test_mkt.check_marginal_prices(test_mtn)

    #   Create a Neighbor test object and give it a default maximum power value
    # test_obj = Neighbor()
    #     test_obj.maximumPower = 100

    #   Create a corresponding Neighbor.
    test_mdl = Neighbor()

    #   Make sure that the model and object cross-reference one another
    # test_obj.model = test_mdl
    # test_mdl.object = test_obj

    test_mdl.scheduledPowers = [
        IntervalValue(test_mdl, ti, test_mkt, MeasurementType.ScheduledPower,
                      100)
    ]
    test_mdl.activeVertices = [
        IntervalValue(test_mdl, ti, test_mkt, MeasurementType.ActiveVertex,
                      Vertex(0.05, 0, 100))
    ]

    #   Run a test with a Neighbor object
    print('- running test with a Neighbor:')
    try:
        test_mdl.update_costs(test_mkt)
        print('  - the method encountered no errors')
    except RuntimeWarning:
        print('  - ERRORS ENCOUNTERED')

    assert len(test_mdl.productionCosts
               ) == 1, '  - the method did not store a production cost'
    assert len(
        test_mdl.dualCosts) == 1, '  - the method did not store a dual cost'
    assert test_mdl.totalProductionCost == sum([x.value for x in test_mdl.productionCosts]), \
            '  - the method did not store a total production cost'
    assert test_mdl.totalDualCost == sum([x.value for x in test_mdl.dualCosts]), \
            '  - the method did not store a total dual cost'

    # Run a test again with a LocalAsset.
    # test_obj = LocalAsset()
    test_mdl = LocalAsset()
    # test_obj.model = test_mdl
    # test_mdl.object = test_obj
    test_mdl.maximumPower = 100

    test_mdl.scheduledPowers = [
        IntervalValue(test_mdl, ti, test_mkt, MeasurementType.ScheduledPower,
                      100)
    ]
    test_mdl.activeVertices = [
        IntervalValue(test_mdl, ti, test_mkt, MeasurementType.ActiveVertex,
                      Vertex(0.05, 0, 100))
    ]

    print('- running test with a LocalAsset:')

    try:
        test_mdl.update_costs(test_mkt)
        print('  - the method encountered no errors')
    except RuntimeWarning:
        print('  - ERRORS ENCOUNTERED')

    assert len(test_mdl.productionCosts
               ) == 1, '  - the method did not store a production cost'
    assert len(
        test_mdl.dualCosts) == 1, '  - the method did not store a dual cost'
    assert test_mdl.totalProductionCost == sum([x.value for x in test_mdl.productionCosts]), \
            '  - the method did not store a total production cost'
    assert test_mdl.totalDualCost == sum([x.value for x in test_mdl.dualCosts]), \
            '  - the method did not store a total dual cost'

    # Success
    print('test_update_costs() ran to completion.\n')