Example #1
0
def cold_ramp_up():
    '''
    Create three generators, one that must ramp up from cold. 
    Ensure that the generator ramps at within its limit.
    '''
    ramp_limit_SU = 20
    ramp_limit = 30
    generators = [
        make_cheap_gen(pmax=200),
        make_mid_gen(pmin=10,
                     rampratemax=ramp_limit,
                     startupramplimit=ramp_limit_SU),
        make_expensive_gen(pmin=1)
    ]
    initial = [{'power': 200}, {'status': 0}, {'status': 0}]

    power_system, times = solve_problem(
        generators, gen_init=initial, **make_loads_times(Pdt=[200, 230, 280]))

    ramp_rate_SU = value(generators[1].power(times[1])) - value(
        generators[1].power(times[0]))
    assert ramp_rate_SU <= ramp_limit_SU
    ramp_rate = value(generators[1].power(times[2])) - value(
        generators[1].power(times[1]))
    assert ramp_rate <= ramp_limit
Example #2
0
def hot_shut_down():
    '''
    Create three generators, one that must shut down from hot. 
    Ensure that the generator ramps within its limit.
    '''
    ramp_limit_SD = -30
    ramp_limit = -20
    generators = [
        make_cheap_gen(pmax=200),
        make_expensive_gen(pmin=20,
                           rampratemin=ramp_limit,
                           shutdownramplimit=ramp_limit_SD),
        make_mid_gen(pmin=1)
    ]
    initial = [{'power': 200}, {'power': 50}, {'power': 50}]

    power_system, times = solve_problem(generators,
                                        gen_init=initial,
                                        **make_loads_times(Pdt=[280, 150]))

    ramp_rate = value(generators[1].power(
        times[0])) - generators[1].initial_power
    assert ramp_limit <= ramp_rate

    ramp_rate_SD = value(generators[1].power(times[1])) - value(
        generators[1].power(times[0]))
    assert ramp_limit_SD == ramp_rate_SD
    assert value(generators[1].status(times[1])) == 0
def min_down_time():
    """
    Create three generators:
    * cheap with max power limit
    * with min down time
    * expensive
    Create load that is higher than the cheap limit all but t1.
    Ensure that the mid generator is OFF at t1 and t2, then turns on again.
    Ensure that the hi generator is ON for t2 to make up the difference.
    """
    generators = [
        make_cheap_gen(pmax=100),
        make_mid_gen(mindowntime=2, pmin=40),
        make_expensive_gen(),
    ]
    initial = [
        dict(power=100, status=True),
        dict(power=40, status=True, hoursinstatus=0),
        dict(status=False),
    ]

    _, times = solve_problem(generators,
                             gen_init=initial,
                             **make_loads_times(Pdt=[150, 10, 140, 140]))
    limgen_status = [value(generators[1].status(t)) for t in times]
    expensive_status_t2 = value(generators[2].status(times[2]))
    assert limgen_status == [1, 0, 0, 1] and expensive_status_t2 == 1
Example #4
0
def hot_shut_down():
    '''
    Create three generators, one that must shut down from hot.
    Ensure that the generator ramps within its limit.
    '''
    ramp_limit_SD = -30
    ramp_limit = -20
    generators = [
        make_cheap_gen(pmax=200),
        make_expensive_gen(pmin=20,
                           rampratemin=ramp_limit,
                           shutdownramplimit=ramp_limit_SD
                           ),
        make_mid_gen(pmin=1)]
    initial = [{'power': 200}, {'power': 50}, {'power': 50}]

    power_system, times = solve_problem(generators, gen_init=initial,
                                        **make_loads_times(Pdt=[280, 150]))

    ramp_rate = value(generators[1].power(times[0])) - generators[1].initial_power
    assert ramp_limit <= ramp_rate

    ramp_rate_SD = value(generators[1].power(times[1])) - value(generators[1].power(times[0]))
    assert ramp_limit_SD == ramp_rate_SD
    assert value(generators[1].status(times[1])) == 0
Example #5
0
def ramp_down():
    '''
    Create 2 gen, expensive one with ramp down limit.
    Create load that ramps down faster than limit at t1.
    Ensure that exp. unit is at its limit.
    '''
    ramp_limit = -80
    generators = [
        make_cheap_gen(),
        make_expensive_gen(rampratemin=ramp_limit)
    ]
    initial = [{'power': 250}, {'power': 250}]
    _, times = solve_problem(generators, gen_init=initial, **make_loads_times(Pdt=[550, 450]))
    ramp_rate = value(generators[1].power(times[1])) - value(generators[1].power(times[0]))
    assertAlmostEqual(ramp_rate, ramp_limit)
def ramp_up():
    """
    Create 2 gen, cheaper one with ramp up limit.
    Create load that ramps up faster than limit, at t1.
    Ensure that cheaper unit is at its limit.
    """
    ramp_limit = 80
    generators = [make_cheap_gen(rampratemax=ramp_limit), make_expensive_gen()]
    initial = [{"power": 250}, {"power": 250}]
    _, times = solve_problem(generators,
                             gen_init=initial,
                             **make_loads_times(Pdt=[250, 350]))
    print((generators[1]._parent_problem()))
    assert (value(generators[0].power(times[1])) -
            value(generators[0].power(times[0])) == ramp_limit)
Example #7
0
def ramp_down():
    '''
    Create 2 gen, expensive one with ramp down limit. 
    Create load that ramps down faster than limit at t1.
    Ensure that exp. unit is at its limit.
    '''
    ramp_limit = -80
    generators = [make_cheap_gen(), make_expensive_gen(rampratemin=ramp_limit)]
    initial = [{'power': 250}, {'power': 250}]
    _, times = solve_problem(generators,
                             gen_init=initial,
                             **make_loads_times(Pdt=[550, 450]))
    ramp_rate = value(generators[1].power(times[1])) - value(
        generators[1].power(times[0]))
    assertAlmostEqual(ramp_rate, ramp_limit)
Example #8
0
def three_buses():
    '''
    Create a three bus system
        -cheap gen and load on busA
        -mid gen and load on busB
        -expensive gen and load on busC
        -three lines connecting all three buses (triangle)
        -create congestion by setting a line limit
    Ensure that: 
        - the total load is met
        - the lmps are different
    '''
    pmax=50
    Pd=[105,225,302]
    generators=[
        make_cheap_gen(bus='A'),
        make_mid_gen(bus='B'),
        make_expensive_gen(bus='C'),
        ]    
    loads=[
        powersystems.Load(schedule=Series(Pd[0],singletime), bus='A'),
        powersystems.Load(schedule=Series(Pd[1],singletime), bus='B'),
        powersystems.Load(schedule=Series(Pd[2],singletime), bus='C')
        ]
    lines=[
        powersystems.Line(frombus='A', tobus='B'),
        powersystems.Line(frombus='A', tobus='C', pmax=pmax),
        powersystems.Line(frombus='B', tobus='C', pmax=pmax),
        ]
    power_system,times=solve_problem(generators, do_reset_config=False,
        times=singletime,loads=loads,lines=lines)
    num_lmps=len(set(b.price(times[0]) for b in power_system.buses))
    total_load = value(sum(b.Pload(times[0]) for b in power_system.buses))
    assert total_load==sum(Pd) and num_lmps>1
def min_up_time_longer():
    """
    Create two generators: cheap with max power limit, exp. with min up time and min power limits.
    Create load that increases over the cheap limit at t1 and then reduces back to constant.
    Ensure that the expensive generator is on at t1 and t2, then turns off.
    """
    generators = [
        make_cheap_gen(pmax=100),
        make_expensive_gen(minuptime=8, pmin=5)
    ]
    initial = [
        dict(power=80, status=True, hoursinstatus=1),
        dict(status=False, hoursinstatus=0),
    ]
    _, times = solve_problem(
        generators,
        gen_init=initial,
        **make_loads_times(Pdt=[85, 120, 80, 80, 70, 70, 70, 70, 80, 80]))
    limgen_status = [value(generators[1].status(t)) for t in times]
    # logging.critical(limgen_status)
    # logging.critical([(generators[1].startup(t),generators[1].shutdown(t)) for t in times])
    # logging.critical(problem.constraints['minuptime_g1t01'])
    assert limgen_status == [0, 1, 1, 1, 1, 1, 1, 1, 1, 0
                             ] or limgen_status == [
                                 1,
                                 1,
                                 1,
                                 1,
                                 1,
                                 1,
                                 1,
                                 1,
                                 0,
                                 0,
                             ]
Example #10
0
def ramp_down_initial():
    """
    Create 2 gen, expensive one with ramp down limit.
    Create load that ramps down faster than limit, at t0.
    Ensure that exp. unit is at its limit.
    """
    ramp_limit = -80
    generators = [make_cheap_gen(), make_expensive_gen(rampratemin=ramp_limit)]
    initial = [{"power": 250}, {"power": 250}]

    _, times = solve_problem(generators,
                             gen_init=initial,
                             **make_loads_times(Pdt=[300, 300]))
    ramp_rate = value(generators[1].power(times[0])) - value(
        generators[1].initial_power)
    assert ramp_rate == ramp_limit
Example #11
0
def power_minimum():
    """
    Create two generators, one cheap and one expensive, status on for both.
    Give the expensive one a min power limit.
    Ensure that the exp. unit is at its limit.
    """
    pmin = 10
    Pd = 221
    generators = [make_cheap_gen(), make_expensive_gen(pmin=pmin)]
    _, times = solve_problem(generators, **make_loads_times(Pd))
    assert value(generators[1].power(times[0])) == pmin
Example #12
0
def power_maximum():
    """
    Create two generators, one cheap and one expensive.
    Give the cheap one a maximum power limit lower than the load.
    Ensure that the cheaper unit is at its limit.
    """
    pmax = 100
    Pd = 221
    generators = [make_cheap_gen(pmax=pmax), make_expensive_gen()]
    _, times = solve_problem(generators, **make_loads_times(Pd))
    assert value(generators[0].power(times[0])) == pmax
Example #13
0
def cold_ramp_up():
    '''
    Create three generators, one that must ramp up from cold.
    Ensure that the generator ramps at within its limit.
    '''
    ramp_limit_SU = 20
    ramp_limit = 30
    generators = [
        make_cheap_gen(pmax=200),
        make_mid_gen(pmin=10, rampratemax=ramp_limit,
                     startupramplimit=ramp_limit_SU),
        make_expensive_gen(pmin=1)]
    initial = [{'power': 200}, {'status': 0}, {'status': 0}]

    power_system, times = solve_problem(generators, gen_init=initial,
                                        **make_loads_times(Pdt=[200, 230, 280]))

    ramp_rate_SU = value(generators[1].power(times[0])) - generators[1].initial_power
    assert ramp_rate_SU <= ramp_limit_SU
    ramp_rate = value(generators[1].power(times[2])) - value(generators[1].power(times[1]))
    assert ramp_rate <= ramp_limit
Example #14
0
def wind_shedding():
    """
    Create a sheddable wind generator and a situation that requires shedding.
    Ensure that the minimum power is shed.
    """
    lts = make_loads_times(Pdt=[85, 110, 80, 80])
    Pwind = pd.Series([60, 100, 120, 60], index=lts["times"].strings.values)

    generators = [
        Generator_nonControllable(schedule=Pwind, sheddingallowed=True),
        make_expensive_gen(),
    ]

    _, times = solve_problem(generators, **lts)
    assert value(generators[0].power(times[2])) == 80
    assert value(generators[0].power(times[3])) == 60
    assert sum(value(generators[1].power(t)) for t in times) == 25 + 10 + 20

    # this should work for stochastic generators
    # TODO - a real stochastic test case
    #   this one just tests deterministic solve
    user_config.deterministic_solve = True
    generators = [
        Generator_Stochastic(schedule=Pwind, sheddingallowed=True),
        make_expensive_gen(),
    ]
    _, times = solve_problem(generators, **lts)
    assert value(generators[0].power(times[2])) == 80
    assert value(generators[0].power(times[3])) == 60
    assert sum(value(generators[1].power(t)) for t in times) == 25 + 10 + 20
Example #15
0
def min_up_time():
    """
    Create two generators: cheap with max power limit, exp. with min up time and min power limits.
    Create load that increases over the cheap limit at t1 and then reduces back to constant.
    Ensure that the expensive generator is on at t1 and t2, then turns off.
    """
    generators = [
        make_cheap_gen(pmax=100),
        make_expensive_gen(minuptime=2, pmin=5)
    ]
    initial = [dict(power=80, status=True), dict(status=False)]
    _, times = solve_problem(generators,
                             gen_init=initial,
                             **make_loads_times(Pdt=[85, 120, 80, 80]))
    limgen_status = [value(generators[1].status(t)) for t in times]
    assert limgen_status == [0, 1, 1, 0] or limgen_status == [1, 1, 0, 0]
Example #16
0
def cubic_convex():
    '''
    Create a cubic, convex bid curve for one generators.
    Ensure that linearized cost is within +5% of the true cost
    '''
    Pd = 221
    a = 5
    b = 30
    c = .2
    d = .1
    user_config.breakpoints = 10

    generators = [Generator(costcurveequation='{}+{}P+{}P^2+{}P^3'.format(a, b, c, d))]
    _, times = solve_problem(generators, **make_loads_times(Pd))  # ,problem_filename='bidproblem.lp')
    cost = value(generators[0].bids.output(times[0], evaluate=True))
    actual_cost = a + b * Pd + c * Pd**2 + d * Pd**3
    assert actual_cost <= cost and cost <= 1.05 * actual_cost
Example #17
0
def start_up_cost():
    """
    Create two generators:
    * cheap with a max power
    * expensive with a start up cost.
    Create an increasing load.
    Ensure that the objective includes the startup cost.
    """
    startupcost = 9000
    generators = [
        make_cheap_gen(pmax=100),
        make_expensive_gen(pmin=10, startupcost=startupcost),
    ]
    initial = [dict(power=80, status=True), dict(status=False)]
    _, times = solve_problem(generators,
                             gen_init=initial,
                             **make_loads_times(Pdt=[80, 120]))
    assert value(generators[1].cost_startup(times[1])) == startupcost
Example #18
0
def shut_down_cost():
    """
    Create two generators, both on:
    * cheap with a max power
    * expensive with a start down cost and a min power.
    Create an decreasing load.
    Ensure that the objective includes the shutdown cost.
    """
    shutdowncost = 200
    generators = [
        make_cheap_gen(pmax=100),
        make_expensive_gen(shutdowncost=shutdowncost, pmin=20),
    ]
    initial = [dict(power=80, status=True), dict(power=20, status=True)]
    _, times = solve_problem(generators,
                             gen_init=initial,
                             **make_loads_times(Pdt=[150, 10]))
    assert value(generators[1].cost_shutdown(times[1])) == shutdowncost
Example #19
0
def cubic_convex():
    """
    Create a cubic, convex bid curve for one generators.
    Ensure that linearized cost is within +5% of the true cost
    """
    Pd = 221
    a = 5
    b = 30
    c = 0.2
    d = 0.1
    user_config.breakpoints = 10

    generators = [Generator(costcurveequation="{}+{}P+{}P^2+{}P^3".format(a, b, c, d))]
    _, times = solve_problem(
        generators, **make_loads_times(Pd)
    )  # ,problem_filename='bidproblem.lp')
    cost = value(generators[0].bids.output(times[0], evaluate=True))
    actual_cost = a + b * Pd + c * Pd ** 2 + d * Pd ** 3
    assert actual_cost <= cost and cost <= 1.05 * actual_cost
Example #20
0
def line_limit_high():
    '''
    Create a two bus system
        -cheap gen on busA
        -expensive gen and load on busB, 
        -line limit lower than load
    Ensure that: 
        - the line is at its limit 
        - the congestion price is equal to the diff. in LMPs
    '''
    pmax = 100
    generators = [make_cheap_gen(bus='A'), make_expensive_gen(bus='B')]

    lines = [powersystems.Line(pmax=pmax, frombus='A', tobus='B')]
    power_system, times = solve_problem(generators,
                                        do_reset_config=False,
                                        lines=lines,
                                        **make_loads_times(Pd=225, bus='B'))
    Pline = value(lines[0].power(times[0]))
    lmps = [b.price(times[0]) for b in power_system.buses]
    congestion_price = lines[0].price(times[0])
    assert Pline == pmax and congestion_price == (lmps[1] - lmps[0])
Example #21
0
def line_limit_low():
    """
    Create a two bus system
        -cheap gen on busA
        -expensive gen and load on busB,
        -line (from B to A) limit lower than load
    Ensure that:
        - the line is at its limit
        - the congestion price is equal to the diff. in LMPs
    """
    pmin = -100
    generators = [make_cheap_gen(bus="A"), make_expensive_gen(bus="B")]
    lines = [powersystems.Line(pmin=pmin, frombus="B", tobus="A")]
    power_system, times = solve_problem(
        generators,
        do_reset_config=False,
        lines=lines,
        **make_loads_times(Pd=225, bus="B")
    )
    Pline = value(lines[0].power(times[0]))
    lmps = [b.price(times[0]) for b in power_system.buses]
    congestion_price = lines[0].price(times[0])
    assert Pline == pmin and congestion_price == -1 * (lmps[1] - lmps[0])
Example #22
0
def line_limit_high():
    '''
    Create a two bus system
        -cheap gen on busA
        -expensive gen and load on busB, 
        -line limit lower than load
    Ensure that: 
        - the line is at its limit 
        - the congestion price is equal to the diff. in LMPs
    '''
    pmax=100
    generators=[
        make_cheap_gen(bus='A'),
        make_expensive_gen(bus='B')
    ]
    
    lines=[powersystems.Line(pmax=pmax, frombus='A', tobus='B')]
    power_system, times = solve_problem(generators, do_reset_config=False,
        lines=lines, **make_loads_times(Pd=225,bus='B'))
    Pline = value(lines[0].power(times[0]))
    lmps = [b.price(times[0]) for b in power_system.buses]
    congestion_price = lines[0].price(times[0])
    assert Pline == pmax and congestion_price == (lmps[1] - lmps[0])