def list_constraints(self):
     """Return a list of strings containing constraint expressions."""
     if IHas2SidedConstraints.providedBy(self.parent):
         return self._eq.list_constraints() + \
                self._ineq.list_constraints() + \
                self.parent.list_2sided_constraints()
     else:
         return self._eq.list_constraints() + self._ineq.list_constraints()
 def list_constraints(self):
     """Return a list of strings containing constraint expressions."""
     if IHas2SidedConstraints.providedBy(self.parent):
         return self._eq.list_constraints() + \
                self._ineq.list_constraints() + \
                self.parent.list_2sided_constraints()
     else:
         return self._eq.list_constraints() + self._ineq.list_constraints()
 def list_constraint_targets(self):
     """Returns a list of outputs suitable for calc_gradient()."""
     if IHas2SidedConstraints.providedBy(self.parent):
         return self._eq.list_eq_constraint_targets() + \
                self._ineq.list_ineq_constraint_targets() + \
                self.parent.list_2sided_constraint_targets()
     else:
         return self._eq.list_eq_constraint_targets() + \
                self._ineq.list_ineq_constraint_targets()
 def list_constraint_targets(self):
     """Returns a list of outputs suitable for calc_gradient()."""
     if IHas2SidedConstraints.providedBy(self.parent):
         return self._eq.list_eq_constraint_targets() + \
                self._ineq.list_ineq_constraint_targets() + \
                self.parent.list_2sided_constraint_targets()
     else:
         return self._eq.list_eq_constraint_targets() + \
                self._ineq.list_ineq_constraint_targets()
    def add_constraint(self, expr_string, name=None, scope=None, linear=False):
        """Adds a constraint in the form of a boolean expression string
        to the driver.

        expr_string: str
            Expression string containing the constraint.

        name: str (optional)
            Name to be used to refer to the constraint rather than its
            expression string.

        scope: object (optional)
            The object to be used as the scope when evaluating the expression.

        linear: bool
            Set this to True to define this constraint is linear. Behavior
            depends on whether and how your optimizer supports it. Deault is
            False or nonlinear constraint.
        """
        try:
            lhs, rel, rhs = _parse_constraint(expr_string)
        except Exception as err:
            self.parent.raise_exception(str(err), type(err))
        if rel == '=':
            self._eq._add_eq_constraint(lhs,
                                        rhs,
                                        name=name,
                                        scope=scope,
                                        linear=linear)
        elif isinstance(rhs, tuple):
            if not IHas2SidedConstraints.providedBy(self.parent):
                msg = 'Double-sided constraints are not supported on ' + \
                      'this driver.'
                self.parent.raise_exception(msg, AttributeError)
            self.parent.add_2sided_constraint(rhs[0],
                                              lhs,
                                              rhs[1],
                                              rel,
                                              name=name,
                                              scope=scope,
                                              linear=linear)
        else:
            self._ineq._add_ineq_constraint(lhs,
                                            rel,
                                            rhs,
                                            name=name,
                                            scope=scope,
                                            linear=linear)
    def add_constraint(self, expr_string, name=None, scope=None, linear=False,
                       jacs=None):
        """Adds a constraint in the form of a boolean expression string
        to the driver.

        expr_string: str
            Expression string containing the constraint.

        name: str (optional)
            Name to be used to refer to the constraint rather than its
            expression string.

        scope: object (optional)
            The object to be used as the scope when evaluating the expression.

        linear: bool
            Set this to True to define this constraint is linear. Behavior
            depends on whether and how your optimizer supports it. Deault is
            False or nonlinear constraint.

        jacs: dict
            Dictionary of user-defined functions that return the flattened
            Jacobian of this constraint with repsect to the parameters of
            the driver, as indicated by the dictionary keys. Default is None
            to let OpenMDAO determine the derivatives.
        """
        try:
            lhs, rel, rhs = _parse_constraint(expr_string)
        except Exception as err:
            self.parent.raise_exception(str(err), type(err))
        if rel == '=':
            self._eq._add_eq_constraint(lhs, rhs, name=name, scope=scope,
                                        linear=linear, jacs=jacs)
        elif isinstance(rhs, tuple):
            if not IHas2SidedConstraints.providedBy(self.parent):
                msg = 'Double-sided constraints are not supported on ' + \
                      'this driver.'
                self.parent.raise_exception(msg, AttributeError)
            self.parent.add_2sided_constraint(rhs[0], lhs, rhs[1], rel,
                                              name=name, scope=scope,
                                              linear=linear, jacs=jacs)
        else:
            self._ineq._add_ineq_constraint(lhs, rel, rhs, name=name, scope=scope,
                                            linear=linear, jacs=jacs)
    def add_existing_constraint(self, scope, constraint, name=None):
        """Adds an existing Constraint object to the driver.

        scope: container object where constraint expression will
            be evaluated.

        constraint: Constraint object

        name: str (optional)
            Name to be used to refer to the constraint rather than its
            expression string.
        """
        if constraint.comparator == '=':
            self._eq.add_existing_constraint(scope, constraint, name)
        else:
            self._ineq.add_existing_constraint(scope, constraint, name)
            if IHas2SidedConstraints.providedBy(self.parent):
                self.parent.add_existing_2sided_constraint(scope, constraint,
                                                           name)
    def add_existing_constraint(self, scope, constraint, name=None):
        """Adds an existing Constraint object to the driver.

        scope: container object where constraint expression will
            be evaluated.

        constraint: Constraint object

        name: str (optional)
            Name to be used to refer to the constraint rather than its
            expression string.
        """
        if constraint.comparator == '=':
            self._eq.add_existing_constraint(scope, constraint, name)
        else:
            self._ineq.add_existing_constraint(scope, constraint, name)
            if IHas2SidedConstraints.providedBy(self.parent):
                self.parent.add_existing_2sided_constraint(
                    scope, constraint, name)
 def clear_constraints(self):
     """Removes all constraints."""
     self._eq.clear_constraints()
     self._ineq.clear_constraints()
     if IHas2SidedConstraints.providedBy(self.parent):
         self.parent.clear_2sided_constraints()
 def clear_constraints(self):
     """Removes all constraints."""
     self._eq.clear_constraints()
     self._ineq.clear_constraints()
     if IHas2SidedConstraints.providedBy(self.parent):
         self.parent.clear_2sided_constraints()