Esempio n. 1
0
def _relaxation_helper(model, md, include_soc, use_linear_relaxation):
    if not coramin_available:
        raise ImportError(
            'Cannot create relaxation unless coramin is available.')
    coramin.relaxations.relax(model,
                              in_place=True,
                              use_fbbt=True,
                              fbbt_options={
                                  'deactivate_satisfied_constraints': True,
                                  'max_iter': 2
                              })
    if not use_linear_relaxation:
        for b in coramin.relaxations.relaxation_data_objects(model,
                                                             descend_into=True,
                                                             active=True,
                                                             sort=True):
            if not isinstance(b,
                              coramin.relaxations.PWMcCormickRelaxationData):
                b.use_linear_relaxation = False
                b.rebuild()

    if include_soc:
        branch_attrs = md.attributes(element_type='branch')
        bus_pairs = zip_items(branch_attrs['from_bus'], branch_attrs['to_bus'])
        unique_bus_pairs = list(
            OrderedDict((val, None) for idx, val in bus_pairs.items()).keys())
        libbranch.declare_ineq_soc(
            model=model,
            index_set=unique_bus_pairs,
            use_outer_approximation=use_linear_relaxation)
Esempio n. 2
0
def create_soc_relaxation(model_data, use_linear_relaxation=True, include_feasibility_slack=False):
    model, md = _create_base_power_ac_model(model_data, include_feasibility_slack=include_feasibility_slack)
    if use_linear_relaxation:
        _relaxation_helper(model=model, md=md, include_soc=True, use_linear_relaxation=use_linear_relaxation)
    else:
        branch_attrs = md.attributes(element_type='branch')
        bus_pairs = zip_items(branch_attrs['from_bus'], branch_attrs['to_bus'])
        unique_bus_pairs = list(OrderedDict((val, None) for idx, val in bus_pairs.items()).keys())
        libbranch.declare_ineq_soc(model=model, index_set=unique_bus_pairs,
                                   use_outer_approximation=use_linear_relaxation)
    return model, md
Esempio n. 3
0
def create_atan_acopf_model(model_data, include_feasibility_slack=False):
    model, md = _create_base_power_ac_model(
        model_data, include_feasibility_slack=include_feasibility_slack)

    branch_attrs = md.attributes(element_type='branch')
    bus_pairs = zip_items(branch_attrs['from_bus'], branch_attrs['to_bus'])
    unique_bus_pairs = OrderedSet(val for val in bus_pairs.values())
    for fb, tb in unique_bus_pairs:
        assert (tb, fb) not in unique_bus_pairs

    graph = get_networkx_graph(md)
    ref_bus = md.data['system']['reference_bus']
    cycle_basis = networkx.algorithms.cycle_basis(graph, root=ref_bus)

    cycle_basis_bus_pairs = OrderedSet()
    for cycle in cycle_basis:
        for ndx in range(len(cycle) - 1):
            b1 = cycle[ndx]
            b2 = cycle[ndx + 1]
            assert (b1, b2) in unique_bus_pairs or (b2, b1) in unique_bus_pairs
            if (b1, b2) in unique_bus_pairs:
                cycle_basis_bus_pairs.add((b1, b2))
            else:
                cycle_basis_bus_pairs.add((b2, b1))
        b1 = cycle[-1]
        b2 = cycle[0]
        assert (b1, b2) in unique_bus_pairs or (b2, b1) in unique_bus_pairs
        if (b1, b2) in unique_bus_pairs:
            cycle_basis_bus_pairs.add((b1, b2))
        else:
            cycle_basis_bus_pairs.add((b2, b1))

    libbranch.declare_var_dva(model=model,
                              index_set=list(cycle_basis_bus_pairs),
                              initialize=0,
                              bounds=(-pi / 2, pi / 2))
    libbranch.declare_eq_dva_arctan(model=model,
                                    index_set=list(cycle_basis_bus_pairs))
    libbranch.declare_eq_dva_cycle_sum(model=model,
                                       cycle_basis=cycle_basis,
                                       valid_bus_pairs=cycle_basis_bus_pairs)
    libbranch.declare_ineq_soc(model=model,
                               index_set=list(unique_bus_pairs),
                               use_outer_approximation=False)
    libbranch.declare_ineq_soc_ub(model=model,
                                  index_set=list(unique_bus_pairs))

    return model, md
Esempio n. 4
0
def create_soc_relaxation(model_data, use_linear_relaxation=False):
    model, md = _create_base_relaxation(model_data)
    if use_linear_relaxation:
        if not coramin_available:
            raise ImportError(
                'Cannot create SOC relaxation with outer approximation unless coramin is available.'
            )
        model = coramin.relaxations.relax(model, in_place=True, use_fbbt=False)
    branch_attrs = md.attributes(element_type='branch')
    bus_pairs = zip_items(branch_attrs['from_bus'], branch_attrs['to_bus'])
    unique_bus_pairs = list(
        OrderedDict((val, None) for idx, val in bus_pairs.items()).keys())
    libbranch.declare_ineq_soc(model=model,
                               index_set=unique_bus_pairs,
                               use_outer_approximation=use_linear_relaxation)
    return model, md
Esempio n. 5
0
def create_relaxation_of_polar_acopf(model_data,
                                     include_soc=True,
                                     use_linear_relaxation=False):
    if not coramin_available:
        raise ImportError(
            'Cannot create polar relaxation unless coramin is available.')

    model, md = _create_base_relaxation(model_data)
    branches = dict(md.elements(element_type='branch'))
    bus_attrs = md.attributes(element_type='bus')
    branch_attrs = md.attributes(element_type='branch')
    bus_pairs = zip_items(branch_attrs['from_bus'], branch_attrs['to_bus'])
    unique_bus_pairs = list(
        OrderedDict((val, None) for idx, val in bus_pairs.items()).keys())

    # declare the polar voltages
    libbus.declare_var_vm(model,
                          bus_attrs['names'],
                          initialize=bus_attrs['vm'],
                          bounds=zip_items(bus_attrs['v_min'],
                                           bus_attrs['v_max']))

    va_bounds = {k: (-pi, pi) for k in bus_attrs['va']}
    libbus.declare_var_va(model,
                          bus_attrs['names'],
                          initialize=bus_attrs['va'],
                          bounds=va_bounds)

    # fix the reference bus
    ref_bus = md.data['system']['reference_bus']
    ref_angle = md.data['system']['reference_bus_angle']
    model.va[ref_bus].fix(radians(ref_angle))

    # relate c, s, and vmsq to vm and va
    libbus.declare_eq_vmsq(model=model,
                           index_set=bus_attrs['names'],
                           coordinate_type=CoordinateType.POLAR)
    libbranch.declare_eq_c(model=model,
                           index_set=unique_bus_pairs,
                           coordinate_type=CoordinateType.POLAR)
    libbranch.declare_eq_s(model=model,
                           index_set=unique_bus_pairs,
                           coordinate_type=CoordinateType.POLAR)

    # declare angle difference limits on interconnected buses
    libbranch.declare_ineq_angle_diff_branch_lbub(
        model=model,
        index_set=branch_attrs['names'],
        branches=branches,
        coordinate_type=CoordinateType.POLAR)

    fbbt(model, deactivate_satisfied_constraints=False)
    model = coramin.relaxations.relax(model, in_place=True, use_fbbt=False)
    if not use_linear_relaxation:
        for b in model.component_data_objects(pe.Block,
                                              descend_into=True,
                                              active=True,
                                              sort=True):
            if isinstance(b, (coramin.relaxations.BaseRelaxation,
                              coramin.relaxations.BaseRelaxationData)):
                if polynomial_degree(b.get_rhs_expr()) == 2:
                    if not isinstance(
                            b,
                        (coramin.relaxations.PWMcCormickRelaxation,
                         coramin.relaxations.PWMcCormickRelaxationData)):
                        b.use_linear_relaxation = False
                        b.rebuild()

    if include_soc:
        libbranch.declare_ineq_soc(
            model=model,
            index_set=unique_bus_pairs,
            use_outer_approximation=use_linear_relaxation)

    return model, md