コード例 #1
0
 def _generate_model(self):
     x = self._generate_base_model()
     model = self.model
     A, lb, ub, eq_index = self._get_dense_data()
     model.Amatrix = pmo.matrix_constraint(
         A, lb=lb, ub=ub, x=x, sparse=True)
     for i in eq_index:
         assert model.Amatrix[i].lb == \
             model.Amatrix[i].ub
         model.Amatrix[i].rhs = \
             model.Amatrix[i].lb
コード例 #2
0
ファイル: LP_compiled.py プロジェクト: Pyomo/pyomo
 def _generate_model(self):
     x = self._generate_base_model()
     model = self.model
     A, lb, ub, eq_index = self._get_dense_data()
     model.Amatrix = pmo.matrix_constraint(
         A, lb=lb, ub=ub, x=x, sparse=True)
     for i in eq_index:
         assert model.Amatrix[i].lb == \
             model.Amatrix[i].ub
         model.Amatrix[i].rhs = \
             model.Amatrix[i].lb
コード例 #3
0
 def _generate_model(self):
     variable_order = self._generate_base_model()
     model = self.model
     A, lb, ub, eq_index = self._get_dense_data()
     model.Amatrix = pmo.matrix_constraint(
         A, lb=lb, ub=ub,
         variable_order=variable_order,
         sparse=False)
     for i in eq_index:
         assert model.Amatrix[i].lb == \
             model.Amatrix[i].ub
         model.Amatrix[i].rhs = \
             model.Amatrix[i].lb
コード例 #4
0
def bounding_box(A, b, solver_name="gurobi"):
    """
    Find upper and lower bounds for each variable.

    Parameters
    ----------
    A : np.ndarray
        e.g. lhs of polytope for N-X secured network 
    b : np.ndarray
        e.g. rhs of polytope for N-X secured network 
    solver_name : str, default "gurobi"
        Solver

    Returns
    -------
    np.ndarray
        lower bounds
    np.ndarray
        upper bounds
    """
    dim = A.shape[1]

    model = pmo.block()

    variables = []
    for i in range(dim):
        setattr(model, f"x{i}", pmo.variable())
        variables.append(getattr(model, f"x{i}"))

    model.A = pmo.matrix_constraint(A, ub=b, x=variables, sparse=True)

    opt = pmo.SolverFactory(solver_name)

    lower_upper_bounds = []
    for sense in [pmo.minimize, pmo.maximize]:

        bounds = []
        for i in range(dim):
            model.objective = pmo.objective(getattr(model, f"x{i}"),
                                            sense=sense)
            result = opt.solve(model)
            assert str(result.solver.termination_condition) == "optimal"
            bounds.append(result["Problem"][0]["Lower bound"])
            del model.objective

        bounds = np.array(bounds).reshape(len(bounds), 1)
        lower_upper_bounds.append(bounds)

    return tuple(lower_upper_bounds)
コード例 #5
0
ファイル: compare_components.py プロジェクト: zy09838/pyomo
def build_matrix_constraint():
    """Build a constraint_list with no references to external
    objects so its size can be computed."""
    return matrix_constraint(A, rhs=b, x=X_kernel)
コード例 #6
0
ファイル: compare_components.py プロジェクト: Pyomo/pyomo
def build_matrix_constraint():
    """Build a constraint_list with no references to external
    objects so its size can be computed."""
    return matrix_constraint(A, rhs=b, x=X_kernel)