Example #1
0
def upec(n_failures=100):
    """if we happen to have a stage one that kills the shunt bus then most bugs 
    go away. use this to get some data."""

    clean_files()
    clean = True

    data = """
           [upec] opf
             # remove generator g33
             # set all demand 0.7686144
             # remove bus 6
           """

    scenario = text_to_scenario(data)
    psat = read_psat("rts2.m")

    tmp_psat = scenario_to_psat(scenario, psat)
    report = single_simulate(tmp_psat, scenario.simtype, scenario.title)
    new_psat = report_to_psat(report, tmp_psat)

    prob = read_probabilities("rts.net")
    failure_batch = make_failures(prob, n_failures)

    failure_batch.scenarios.insert(0, Scenario("basecase"))
    batch_simulate(failure_batch, new_psat, 100, clean)

    filename = scenario.title + ".bch2"
    with open(filename, "w") as result_file:
        failure_batch.csv_write(result_file)
Example #2
0
def example3():
    """one random failure"""
    
    psat = read_psat("rts.m")
    prob = read_probabilities("rts.net")
    batch = make_failures(prob, 1)
    scenario = batch[0]
    report = simulate_scenario(psat, scenario)
    print "result =", report_in_limits(report), "."
Example #3
0
def example1(n=100):
    """make `n` outages, simulate them, and save the resulting batch"""

    psat = read_psat("rts.m")
    prob = read_probabilities("rts.net")
    batch = make_failures(prob, n)

    batch_simulate(batch, psat, 30)

    with open("rts.bch", "w") as result_file:
        batch.write(result_file)
Example #4
0
def generate_cases(n_outages=10, n_failures=1000, sim=True, full_sim=True):
    timer_begin = time.clock()
    timer_start = timer_begin
    print "[G] start simulation with %d states and %d contingencies." % (n_outages, n_failures)
    
    if full_sim: 
        Ensure(n_outages and n_failures and sim, "can only do full sim if we have everything")
        
    clean_files()    
    batch_size = 100 
    psat = read_psat("rts.m")
    prob = read_probabilities("rts.net")
    

    # create the base cases by sampling for outages 
    # simulate these and print to a file.
    # it should contain `n_outages` outages.
    
    summary_file = open("summary.txt", "w")
    
    mismatch_file = open("mismatch.txt", "w")
    print "Base Stats: mis= %f gen= %f load= %f lim ( %f < X < %f )" % psat.get_stats()
    mismatch_file.write(as_csv("title mismatch gen load min max".split()) + "\n")
    mismatch_file.write(as_csv(["base"] + list(psat.get_stats())) + "\n")
    
    try:
        if n_outages:
            outage_batch = make_outage_cases(prob, n_outages)
            if sim: batch_simulate(outage_batch, psat, batch_size, True, mismatch_file)
    
            with open("outage.txt", "w") as result_file:
                outage_batch.csv_write(result_file)
                
            print "-" * 80
            print "---- Outage Stats ----"
            outage_batch.write_stats(sys.stdout)
            summary_file.write("%s\n" % ("-"*80))
            summary_file.write("Outage Stats\n")
            summary_file.write("%s\n" % ("-"*80))
            outage_batch.write_stats(summary_file)

            timer_end = time.clock()
            timer_time = (timer_end - timer_start)
            print "[G] outages created in %d seconds." % int(math.ceil(timer_time))
            timer_start = time.clock()
        
        # do the same for one hour changes to the system.
        if n_failures:
            failure_batch = make_failure_cases(prob, n_failures)
            if sim: batch_simulate(failure_batch, psat, batch_size, True, mismatch_file)
    
            with open("failure.txt", "w") as result_file:
                failure_batch.csv_write(result_file)
    
            print "-" * 80
            print "---- Failure Stats ----"
            failure_batch.write_stats(sys.stdout)
            summary_file.write("Failure Stats\n")
            summary_file.write("%s\n" % ("-"*80))
            failure_batch.write_stats(summary_file)
            
            timer_end = time.clock()
            timer_time = (timer_end - timer_start)
            print "[G] failures created in %d seconds." % int(math.ceil(timer_time))
            timer_start = time.clock()
    
        # simulate each of the changes to each base case
        if full_sim: 
            simulate_cases(outage_batch, failure_batch, psat, summary_file, mismatch_file)
        
            timer_end = time.clock()
            timer_time = (timer_end - timer_start)
            print "[G] full sim  in %d seconds." % int(math.ceil(timer_time))
            timer_start = time.clock()
    finally:
        timer_end = time.clock()
        timer_time = (timer_end - timer_begin)
        print "[G] total time %d seconds." % int(math.ceil(timer_time))
Example #5
0
def generate_cases(n_outages=10, n_failures=1000, sim=True, full_sim=True):
    timer_begin = time.clock()
    timer_start = timer_begin
    print "[G] start simulation with %d states and %d contingencies." % (
        n_outages, n_failures)

    if full_sim:
        Ensure(n_outages and n_failures and sim,
               "can only do full sim if we have everything")

    clean_files()
    batch_size = 100
    psat = read_psat("rts.m")
    prob = read_probabilities("rts.net")

    # create the base cases by sampling for outages
    # simulate these and print to a file.
    # it should contain `n_outages` outages.

    summary_file = open("summary.txt", "w")

    mismatch_file = open("mismatch.txt", "w")
    print "Base Stats: mis= %f gen= %f load= %f lim ( %f < X < %f )" % psat.get_stats(
    )
    mismatch_file.write(
        as_csv("title mismatch gen load min max".split()) + "\n")
    mismatch_file.write(as_csv(["base"] + list(psat.get_stats())) + "\n")

    try:
        if n_outages:
            outage_batch = make_outage_cases(prob, n_outages)
            if sim:
                batch_simulate(outage_batch, psat, batch_size, True,
                               mismatch_file)

            with open("outage.txt", "w") as result_file:
                outage_batch.csv_write(result_file)

            print "-" * 80
            print "---- Outage Stats ----"
            outage_batch.write_stats(sys.stdout)
            summary_file.write("%s\n" % ("-" * 80))
            summary_file.write("Outage Stats\n")
            summary_file.write("%s\n" % ("-" * 80))
            outage_batch.write_stats(summary_file)

            timer_end = time.clock()
            timer_time = (timer_end - timer_start)
            print "[G] outages created in %d seconds." % int(
                math.ceil(timer_time))
            timer_start = time.clock()

        # do the same for one hour changes to the system.
        if n_failures:
            failure_batch = make_failure_cases(prob, n_failures)
            if sim:
                batch_simulate(failure_batch, psat, batch_size, True,
                               mismatch_file)

            with open("failure.txt", "w") as result_file:
                failure_batch.csv_write(result_file)

            print "-" * 80
            print "---- Failure Stats ----"
            failure_batch.write_stats(sys.stdout)
            summary_file.write("Failure Stats\n")
            summary_file.write("%s\n" % ("-" * 80))
            failure_batch.write_stats(summary_file)

            timer_end = time.clock()
            timer_time = (timer_end - timer_start)
            print "[G] failures created in %d seconds." % int(
                math.ceil(timer_time))
            timer_start = time.clock()

        # simulate each of the changes to each base case
        if full_sim:
            simulate_cases(outage_batch, failure_batch, psat, summary_file,
                           mismatch_file)

            timer_end = time.clock()
            timer_time = (timer_end - timer_start)
            print "[G] full sim  in %d seconds." % int(math.ceil(timer_time))
            timer_start = time.clock()
    finally:
        timer_end = time.clock()
        timer_time = (timer_end - timer_begin)
        print "[G] total time %d seconds." % int(math.ceil(timer_time))