예제 #1
0
def TEST_crowfail():
       
    from simulation_batch import SimulationBatch

    text = """# NetworkProbability data file
# bus bus_id fail_rate repair_rate
bus 101 0.0 10.0
bus 102 0.0 10.0
bus 103 0.0 10.0
# line name fbus tbus fail_rate repair_rate trans_fail
line a1 101 102 100000000000.0 10.0 0.0
line a2 102 103 0.0 10.0 0.0
# crow line1 line2 probability
crow a1 a2 0.5
"""

    count = 100000

    prob = NetworkProbability() 
    prob.read(StringIO(text))

    batch = SimulationBatch()
    for x in range(count):
        batch.add(prob.outages(str(x)))
    assert count == len(batch)

    batch.write_stats(sys.stdout)
예제 #2
0
파일: script.py 프로젝트: kerspoon/laos
def make_outages(prob, count):
    """func make_outages         :: NetworkProbability, Int -> SimulationBatch
       ----
       Monte Carlo sample the network for it's expected condition. 
       e.g. existing outages, weather & load forcast, etc.
    """
    batch = SimulationBatch()
    for x in range(count):
        batch.add(prob.outages(str(x)))
    EnsureEqual(count, batch.size())
    return batch
예제 #3
0
파일: script.py 프로젝트: kerspoon/laos
def make_failures(prob, count):
    """func make_failures        :: NetworkProbability, Int -> SimulationBatch
       ----
       Monte Carlo sample the network for unexpected changes. 
       e.g. new outages (failures), actual weather, actual load level, etc.
    """
    batch = SimulationBatch()
    for x in range(count):
        batch.add(prob.failures(str(x)))
    EnsureEqual(count, batch.size())
    return batch
예제 #4
0
def make_failures(prob, count):
    """func make_failures        :: NetworkProbability, Int -> SimulationBatch
       ----
       Monte Carlo sample the network for unexpected changes. 
       e.g. new outages (failures), actual weather, actual load level, etc.
    """
    batch = SimulationBatch()
    for x in range(count):
        batch.add(prob.failures(str(x)))
    EnsureEqual(count, batch.size())
    return batch
예제 #5
0
def make_outages(prob, count):
    """func make_outages         :: NetworkProbability, Int -> SimulationBatch
       ----
       Monte Carlo sample the network for it's expected condition. 
       e.g. existing outages, weather & load forcast, etc.
    """
    batch = SimulationBatch()
    for x in range(count):
        batch.add(prob.outages(str(x)))
    EnsureEqual(count, batch.size())
    return batch
예제 #6
0
파일: script.py 프로젝트: kerspoon/laos
def text_to_scenario(text):
    """func text_to_scenario     :: Str -> Scenario
       ----
       make `text` into a Scenario by reading as if a 
       single element batch file
    """
    
    with closing(StringIO(text)) as batch_stream:
        batch = SimulationBatch()
        batch.read(batch_stream)

    EnsureEqual(len(batch), 1) 
    return list(batch)[0]
예제 #7
0
def text_to_scenario(text):
    """func text_to_scenario     :: Str -> Scenario
       ----
       make `text` into a Scenario by reading as if a 
       single element batch file
    """

    with closing(StringIO(text)) as batch_stream:
        batch = SimulationBatch()
        batch.read(batch_stream)

    EnsureEqual(len(batch), 1)
    return list(batch)[0]
예제 #8
0
파일: tests.py 프로젝트: kerspoon/laos
def example5():

    clean_files()
    clean = False

    data = """
           [base] opf
           [dead_slack] opf
             remove generator g12
           [two_dead_slack] opf
             remove generator g12
             remove generator g13
           [three_dead_slack] opf
             remove generator g12
             remove generator g15
           [four_dead_slack] opf
             remove generator g13
             remove generator g12
           [five_dead_slack] opf
             remove generator g15
             remove generator g12
           [all_dead_slack] opf
             remove generator g12
             remove generator g13
             remove generator g15
           [rem_bus_1] opf
             remove bus 1
           [rem_li_a1] opf
             remove line a1
           [rem_gen_g1] opf
             remove generator g1
           [set_double] opf
             set all demand 2.0
           [set_half] opf
             set all demand 0.5
           """

    #data = """
    #       [fail_001] pf
    #         remove generator g32
    #         remove generator g13
    #"""

    batch = SimulationBatch()
    batch.read(StringIO(data))
    psat = read_psat("rts.m")

    for scenario in batch:
        report = simulate_scenario(psat, scenario, clean)
        print "result = '" + str(report_in_limits(report)) + "'"
예제 #9
0
파일: script.py 프로젝트: kerspoon/laos
def make_outage_cases(prob, count):
    """func make_outage_cases         :: NetworkProbability, Int -> SimulationBatch
       ----
       like `make_outages` but makes `count` *after* reducing.
       
       Monte Carlo sample the network for it's expected condition. 
       e.g. existing outages, weather & load forcast, etc.
    """
    batch = SimulationBatch()
    current = 0
    while len(batch) < count:
        batch.add(prob.outages(str(current)))
        current += 1
    EnsureEqual(count, len(batch))
    return batch
예제 #10
0
def make_outage_cases(prob, count):
    """func make_outage_cases         :: NetworkProbability, Int -> SimulationBatch
       ----
       like `make_outages` but makes `count` *after* reducing.
       
       Monte Carlo sample the network for it's expected condition. 
       e.g. existing outages, weather & load forcast, etc.
    """
    batch = SimulationBatch()
    current = 0
    while len(batch) < count:
        batch.add(prob.outages(str(current)))
        current += 1
    EnsureEqual(count, len(batch))
    return batch
예제 #11
0
def make_failure_cases(prob, count):
    """func make_failure_cases        :: NetworkProbability, Int -> SimulationBatch
       ----
       like `make_failures` but makes `count` *after* reducing.
       
       Monte Carlo sample the network for unexpected changes. 
       e.g. new outages (failures), actual weather, actual load level, etc.
    """
    batch = SimulationBatch()
    current = 0
    while len(batch) < count:
        batch.add(prob.failures(str(current)))
        current += 1
    EnsureEqual(count, len(batch))
    return batch
예제 #12
0
파일: script.py 프로젝트: kerspoon/laos
def make_failure_cases(prob, count):
       
    """func make_failure_cases        :: NetworkProbability, Int -> SimulationBatch
       ----
       like `make_failures` but makes `count` *after* reducing.
       
       Monte Carlo sample the network for unexpected changes. 
       e.g. new outages (failures), actual weather, actual load level, etc.
    """
    batch = SimulationBatch()
    current = 0
    while len(batch) < count:
        batch.add(prob.failures(str(current)))
        current += 1
    EnsureEqual(count, len(batch))
    return batch
예제 #13
0
파일: tests.py 프로젝트: kerspoon/laos
def test007():
    """batch and single should gave same results"""
    
    clean_files()

    psat = read_psat("rts2.m")
    # prob = read_probabilities("rts.net")
    # batch = make_outages(prob, 2)

    data = """
[batch0] opf
  remove generator g1
  remove generator g4
  remove generator g31
  set all demand 0.3987456
  result pass
[batch1] opf
  remove generator g22
  remove generator g24
  set all demand 0.6670332
  result fail
           """

    batch = SimulationBatch()
    batch.read(StringIO(data))

    batch_simulate(batch, psat, 10, False)

    with open("rts.bch", "w") as result_file:
        batch.write(result_file)

    for n, scenario in enumerate(batch):
        scenario.title = "single" + str(n)
        report = simulate_scenario(psat, scenario, False) 
        scenario.result = report_in_limits(report)
    
    with open("rts2.bch", "w") as result_file:
        batch.write(result_file)