Example #1
0
def init_store(power_system, times, data):
    '''create the store before the first stage'''
    wipe_storage()
    storage = get_storage()
    generators = power_system.generators()

    # store the problem info read from the spreadsheets
    for key, df in data.iteritems():
        if key != 'scenario_values':
            for k, v in (df.dtypes == object).iterkv():
                if v:
                    df[k] = df[k].fillna('')

        key = 'data_' + key
        storage[key] = df

    stages = len(times)  # stage_times
    est_Nt = len(data['timeseries'])
    t = [times[0].initialTime]

    # store first stage initial state
    storage.append('power',
                   gen_time_dataframe(generators, t,
                                      values=[[gen.initial_power for gen in generators]]),
                   expectedrows=est_Nt)

    storage.append('status',
                   gen_time_dataframe(generators, t,
                                      values=[[gen.initial_status for gen in generators]]),
                   expectedrows=est_Nt)

    storage['hrsinstatus'] = gen_time_dataframe(generators, t,
                                                values=[[gen.initial_status_hours for gen in generators]])

    # setup empty containers for variables
    storage['load_shed'] = Series()
    storage['gen_shed'] = Series()
    storage['expected_cost'] = DataFrame()
    storage['observed_cost'] = DataFrame()
    storage['expected_status'] = DataFrame()
    storage['expected_power'] = DataFrame()
    storage['expected_fuelcost'] = DataFrame()
    storage['observed_fuelcost'] = DataFrame()

    # setup one-per-stage results
    storage['solve_time'] = Series(index=range(stages))
    storage['mipgap'] = Series(index=range(stages))

    # store configuration
    storage['configuration'] = Series(user_config)

    storage['version'] = Series({
        'minpower': pkg_resources.get_distribution('minpower').version,
        # try storing version number of the current working directory
        'problem': _get_problem_version(),
    })

    return storage
Example #2
0
def init_store(power_system, times, data):
    '''create the store before the first stage'''
    wipe_storage()
    storage = get_storage()
    generators = power_system.generators()

    # store the problem info read from the spreadsheets
    for key, df in data.iteritems():
        if key != 'scenario_values': 
            for k, v in (df.dtypes == object).iterkv():
                if v: df[k] = df[k].fillna('')
        
        key = 'data_' + key
        storage[key] = df

    stages = len(times)  # stage_times
    est_Nt = len(data['timeseries'])
    t = [times[0].initialTime]

    # store first stage initial state
    storage.append('power', 
        gen_time_dataframe(generators, t,
            values=[[gen.initial_power for gen in generators]]),
        expectedrows=est_Nt)
        
    storage.append('status',
        gen_time_dataframe(generators, t,
            values=[[gen.initial_status for gen in generators]]),
        expectedrows=est_Nt)
        
    storage['hrsinstatus'] = gen_time_dataframe(generators, t,
        values=[[gen.initial_status_hours for gen in generators]])

    # setup empty containers for variables
    storage['load_shed'] = Series()
    storage['gen_shed'] = Series()
    storage['expected_cost'] = DataFrame()
    storage['observed_cost'] = DataFrame()
    storage['expected_status'] = DataFrame()
    storage['expected_power'] = DataFrame()
    storage['expected_fuelcost'] = DataFrame()
    storage['observed_fuelcost'] = DataFrame()

    # setup one-per-stage results
    storage['solve_time'] = Series(index=range(stages))
    storage['mipgap'] = Series(index=range(stages))

    # store configuration
    storage['configuration'] = Series(user_config)

    storage['version'] = Series({
        'minpower': pkg_resources.get_distribution('minpower').version,
        # try storing version number of the current working directory
        'problem': _get_problem_version(),
    })

    return storage
Example #3
0
 def gen_time_df(self, method, non_overlap=True, evaluate=False,
                 generators=None):
     times = self.times_non_overlap if non_overlap else self.times
     if generators is None:
         generators = self.generators
     return gen_time_dataframe(generators, times,
         [self.get_values(generators, method, t, evaluate) for t in times])
Example #4
0
def store_state(power_system, times, sln=None):
    storage = get_storage()
    generators = power_system.generators()

    stg = sln.stage_number
    table_append(storage, 'power', sln.generators_power)
    table_append(storage, 'status', sln.generators_status)
    table_append(storage, 'load_shed', sln.load_shed_timeseries)
    table_append(storage, 'gen_shed', sln.gen_shed_timeseries)

    tEnd = times.last_non_overlap()
    storage['hrsinstatus'] = gen_time_dataframe(
        generators, [tEnd],
        values=[[gen.finalstatus['hoursinstatus'] for gen in generators]])

    _add_tbl_val(storage, 'solve_time', stg, sln.solve_time)
    _add_tbl_val(storage, 'mipgap', stg, sln.mipgap)

    if sln._resolved:
        table_append(storage, 'observed_cost', sln.observed_totalcost)
        table_append(storage, 'observed_fuelcost', sln.observed_fuelcost)
        table_append(storage, 'expected_cost', sln.expected_totalcost)
        table_append(storage, 'expected_fuelcost', sln.expected_fuelcost)
        table_append(storage, 'expected_power', sln.expected_power)
        table_append(storage, 'expected_status', sln.expected_status)
    else:
        table_append(storage, 'expected_cost', sln.totalcost_generation)
        table_append(storage, 'expected_fuelcost', sln.fuelcost)


#    # DEBUGGING
#    from pandas.util.testing import assert_frame_equal
#    try:
#        gens = storage['data_generators'].copy()
#        gens.index = ['g{}'.format(g) for g in gens.index]
#        status = storage['status'].ix[1:]
#        power = storage['power'][status.columns].ix[status.index]
#        cost = storage['observed_cost'][status.columns].ix[status.index]
#        fuelcost = storage['observed_fuelcost'][status.columns].ix[status.index]
#        stcost = cost - fuelcost

#
#        pcheck = (power * status)
#        ccheck = (cost * status)
#        stcheck = (stcost * status)
#        assert_frame_equal(pcheck, power)
#        assert_frame_equal(ccheck, cost)
#        assert_frame_equal(stcheck, stcost)
#        assert(((stcost < gens.startupcost - 1e-5) & (stcost > 1e-5) ).sum().sum() == 0)
#
#    except AssertionError:
#        raise

    return storage
Example #5
0
def store_state(power_system, times, sln=None):
    storage = get_storage()
    generators = power_system.generators()

    stg = sln.stage_number
    table_append(storage, 'power', sln.generators_power)
    table_append(storage, 'status', sln.generators_status)
    table_append(storage, 'load_shed', sln.load_shed_timeseries)
    table_append(storage, 'gen_shed', sln.gen_shed_timeseries)

    tEnd = times.last_non_overlap()
    storage['hrsinstatus'] = gen_time_dataframe(generators, [tEnd],
                                                values=[
                                                [gen.finalstatus['hoursinstatus'] for gen in generators]
                                                ])

    _add_tbl_val(storage, 'solve_time', stg, sln.solve_time)
    _add_tbl_val(storage, 'mipgap', stg, sln.mipgap)

    if sln._resolved:
        table_append(storage, 'observed_cost', sln.observed_totalcost)
        table_append(storage, 'observed_fuelcost', sln.observed_fuelcost)
        table_append(storage, 'expected_cost', sln.expected_totalcost)
        table_append(storage, 'expected_fuelcost', sln.expected_fuelcost)
        table_append(storage, 'expected_power', sln.expected_power)
        table_append(storage, 'expected_status', sln.expected_status)
    else:
        table_append(storage, 'expected_cost', sln.totalcost_generation)
        table_append(storage, 'expected_fuelcost', sln.fuelcost)

#    # DEBUGGING
#    from pandas.util.testing import assert_frame_equal
#    try: 
#        gens = storage['data_generators'].copy()
#        gens.index = ['g{}'.format(g) for g in gens.index]
#        status = storage['status'].ix[1:]
#        power = storage['power'][status.columns].ix[status.index]
#        cost = storage['observed_cost'][status.columns].ix[status.index]
#        fuelcost = storage['observed_fuelcost'][status.columns].ix[status.index]
#        stcost = cost - fuelcost

#        
#        pcheck = (power * status)
#        ccheck = (cost * status)
#        stcheck = (stcost * status)
#        assert_frame_equal(pcheck, power)
#        assert_frame_equal(ccheck, cost)
#        assert_frame_equal(stcheck, stcost)
#        assert(((stcost < gens.startupcost - 1e-5) & (stcost > 1e-5) ).sum().sum() == 0)
#        
#    except AssertionError:
#        raise
        
    return storage
Example #6
0
    def gen_time_df(self, method, scenario, non_overlap=True, evaluate=False,
                    generators=None):
        if generators is None:
            generators = self.generators

        if evaluate:
            getval = lambda gen, t: value(
                getattr(gen, method)(t, scenario, evaluate=True))
        else:
            getval = lambda gen, t: value(getattr(gen, method)(t, scenario))

        times = self.times_non_overlap if non_overlap else self.times
        return gen_time_dataframe(generators, times,
                                  [[getval(gen, t) for t in times] for gen in generators])