Beispiel #1
0
def load_state():
    storage = get_storage()
    user_config.update(storage['configuration'].to_dict())

    # set up the times
    startidx = int(storage['times'][0].strip('t'))
    times = TimeIndex(storage['times'].index, startidx)
    intervalhrs = (times.strings.index[1] -
                   times.strings.index[0]).total_seconds() / 3600.0
    times._int_division = user_config.hours_commitment / intervalhrs
    times._int_overlap = user_config.hours_overlap / intervalhrs
    if len(times) <= times._int_division:
        # dont set overlap for last stage
        times._int_overlap = 0

    # create power_system
    power_system, times, scenario_tree = parse_standalone(storage, times)
    generators = power_system.generators()

    # set up initial state
    t = times.initialTime
    status = correct_status(storage['status']).ix[t]
    for gen in generators:
        g = str(gen)
        gen.set_initial_condition(power=storage['power'][g][t],
                                  status=status[g],
                                  hoursinstatus=storage['hrsinstatus'][g][t])

    return power_system, times, scenario_tree
Beispiel #2
0
def load_state():
    storage = get_storage()
    user_config.update(storage['configuration'].to_dict())

    # set up the times
    startidx = int(storage['times'][0].strip('t'))
    times = TimeIndex(storage['times'].index, startidx)
    intervalhrs = (times.strings.index[1] - times.strings.index[0]
                   ).total_seconds() / 3600.0
    times._int_division = user_config.hours_commitment / intervalhrs
    times._int_overlap = user_config.hours_overlap / intervalhrs
    if len(times) <= times._int_division:
        # dont set overlap for last stage
        times._int_overlap = 0

    # create power_system
    power_system, times, scenario_tree = parse_standalone(storage, times)
    generators = power_system.generators()

    # set up initial state
    t = times.initialTime
    status = correct_status(storage['status']).ix[t]
    for gen in generators:
        g = str(gen)
        gen.set_initial_condition(
            power=storage['power'][g][t],
            status=status[g],
            hoursinstatus=storage['hrsinstatus'][g][t])

    return power_system, times, scenario_tree
Beispiel #3
0
def solve_problem(
    datadir='.',
    shell=True,
    problemfile=False,
    csv=True,
):
    """
    Solve a optimization problem specified by spreadsheets in a directory.
    Read in data, create and solve the problem, and return solution.
    The problem type is determined by the data.
    All options are set within `user_config`.
    """
    user_config.directory = datadir

    pid = user_config.pid if user_config.pid else os.getpid()

    _set_store_filename(pid)
    _setup_logging(pid)

    if user_config.standalone_restart:
        store = get_storage()
        debugger = user_config.debugger  # preserve debugger state
        user_config.update(store['configuration'])
        user_config.debugger = debugger
        user_config.standalone_restart = True  # preserve restart state
        store.close()

    logging.debug(dict(user_config))

    start_time = timer.time()
    logging.debug('Minpower reading {}'.format(datadir))
    generators, loads, lines, times, scenario_tree, data = get_data.parsedir()
    logging.debug('data read')
    power_system = powersystems.PowerSystem(generators, loads, lines)

    logging.debug('power system initialized')
    if times.spanhrs <= user_config.hours_commitment + user_config.hours_overlap:
        solution = create_solve_problem(power_system, times, scenario_tree)
    else:  # split into multiple stages and solve
        if user_config.standalone:
            stage_solutions, stage_times = solve_multistage_standalone(
                power_system, times, scenario_tree, data)
        else:
            stage_solutions, stage_times = solve_multistage(
                power_system, times, scenario_tree, data)
        solution = results.make_multistage_solution(power_system, stage_times,
                                                    stage_solutions)

    if shell:
        if user_config.output_prefix or user_config.pid:
            stdout = sys.stdout
            sys.stdout = StreamToLogger()
            solution.show()
            sys.stdout = stdout
        solution.show()
    if csv and not user_config.standalone:
        solution.saveCSV()
    if user_config.visualization:
        solution.visualization()
    logging.info('total time: {}s'.format(timer.time() - start_time))

    if user_config.on_complete_script:
        os.system(user_config.on_complete_script)

    return solution
Beispiel #4
0
def solve_problem(datadir='.',
        shell=True,
        problemfile=False,
        csv=True,
        ):
    """
    Solve a optimization problem specified by spreadsheets in a directory.
    Read in data, create and solve the problem, and return solution.
    The problem type is determined by the data.
    All options are set within `user_config`.
    """
    user_config.directory = datadir
    
    pid = user_config.pid if user_config.pid else os.getpid()
        
    _set_store_filename(pid)
    _setup_logging(pid)

    if user_config.standalone_restart:
        store = get_storage()
        debugger = user_config.debugger  # preserve debugger state
        user_config.update(store['configuration'])
        user_config.debugger = debugger
        user_config.standalone_restart = True  # preserve restart state
        store.close()

    logging.debug(dict(user_config))
    
    start_time = timer.time()
    logging.debug('Minpower reading {}'.format(datadir))
    generators, loads, lines, times, scenario_tree, data = get_data.parsedir()
    logging.debug('data read')
    power_system = powersystems.PowerSystem(generators,loads,lines)

    logging.debug('power system initialized')
    if times.spanhrs <= user_config.hours_commitment + user_config.hours_overlap:
        solution = create_solve_problem(power_system, times, scenario_tree)
    else: #split into multiple stages and solve
        if user_config.standalone:
            stage_solutions, stage_times = solve_multistage_standalone(
                power_system, times, scenario_tree, data)
        else:
            stage_solutions, stage_times = solve_multistage(
                power_system, times, scenario_tree, data)
        solution = results.make_multistage_solution(
            power_system, stage_times, stage_solutions)

    if shell:
        if user_config.output_prefix or user_config.pid:
            stdout = sys.stdout
            sys.stdout = StreamToLogger()
            solution.show()
            sys.stdout = stdout
        solution.show()
    if csv and not user_config.standalone: solution.saveCSV()
    if user_config.visualization: solution.visualization()
    logging.info('total time: {}s'.format(timer.time()-start_time))

    if user_config.on_complete_script:
        os.system(user_config.on_complete_script)

    return solution