qiskit_optimization/problems/quadratic_program.py
def quadratic_constraint(
        self,
        linear: Union[ndarray, spmatrix, List[float], Dict[Union[int, str], float]] = None,
        quadratic: Union[
            ndarray,
            spmatrix,
            List[List[float]],
            Dict[Tuple[Union[int, str], Union[int, str]], float],
        ] = None,
        sense: Union[str, ConstraintSense] = "<=",
        rhs: float = 0.0,
        name: Optional[str] = None,
    ) -> QuadraticConstraint:
        """Adds a quadratic equality constraint to the quadratic program of the form:
            x * Q * x <= rhs.

        Args:
            linear: The linear coefficients of the constraint.
            quadratic: The quadratic coefficients of the constraint.
            sense: The sense of the constraint,
              - '==', '=', 'E', and 'EQ' denote 'equal to'.
              - '>=', '>', 'G', and 'GE' denote 'greater-than-or-equal-to'.
              - '<=', '<', 'L', and 'LE' denote 'less-than-or-equal-to'.
            rhs: The right hand side of the constraint.
            name: The name of the constraint.

        Returns:
            The added constraint.

        Raises:
            QiskitOptimizationError: if the constraint name already exists.
        """
        if name:
            if name in self.quadratic_constraints_index:
                raise QiskitOptimizationError(f"Quadratic constraint name already exists: {name}")
        else:
            k = self.get_num_quadratic_constraints()
            while f"q{k}" in self.quadratic_constraints_index:
                k += 1
            name = f"q{k}"
        self.quadratic_constraints_index[name] = len(self.quadratic_constraints)
        if linear is None:
            linear = {}
        if quadratic is None:
            quadratic = {}
        constraint = QuadraticConstraint(
            self, name, linear, quadratic, Constraint.Sense.convert(sense), rhs
        )
        self.quadratic_constraints.append(constraint)
        return constraint
Adds a quadratic equality constraint to the quadratic program of the form:
            x * Q * x <= rhs.

        Args:
            linear: The linear coefficients of the constraint.
            quadratic: The quadratic coefficients of the constraint.
            sense: The sense of the constraint,
              - '==', '=', 'E', and 'EQ' denote 'equal to'.
              - '>=', '>', 'G', and 'GE' denote 'greater-than-or-equal-to'.
              - '<=', '<', 'L', and 'LE' denote 'less-than-or-equal-to'.
            rhs: The right hand side of the constraint.
            name: The name of the constraint.

        Returns:
            The added constraint.

        Raises:
            QiskitOptimizationError: if the constraint name already exists.
        
Adds a quadratic equality constraint to the quadratic program of the form:
x * Q * x <= rhs.
Adds a quadratic equality constraint to the quadratic program of the form : x * Q * x < = rhs .
def quadratic_constraint(
        self,
        linear: Union[ndarray, spmatrix, List[float], Dict[Union[int, str], float]] = None,
        quadratic: Union[
            ndarray,
            spmatrix,
            List[List[float]],
            Dict[Tuple[Union[int, str], Union[int, str]], float],
        ] = None,
        sense: Union[str, ConstraintSense] = "<=",
        rhs: float = 0.0,
        name: Optional[str] = None,
    ) -> QuadraticConstraint:
        if name:
            if name in self.quadratic_constraints_index:
                raise QiskitOptimizationError(f"Quadratic constraint name already exists: {name}")
        else:
            k = self.get_num_quadratic_constraints()
            while f"q{k}" in self.quadratic_constraints_index:
                k += 1
            name = f"q{k}"
        self.quadratic_constraints_index[name] = len(self.quadratic_constraints)
        if linear is None:
            linear = {}
        if quadratic is None:
            quadratic = {}
        constraint = QuadraticConstraint(
            self, name, linear, quadratic, Constraint.Sense.convert(sense), rhs
        )
        self.quadratic_constraints.append(constraint)
        return constraint
def quadratic_constraint ( self , linear : Union [ ndarray , spmatrix , List [ float ] , Dict [ Union [ int , str ] , float ] ] = None , quadratic : Union [ ndarray , spmatrix , List [ List [ float ] ] , Dict [ Tuple [ Union [ int , str ] , Union [ int , str ] ] , float ] , ] = None , sense : Union [ str , ConstraintSense ] = "<=" , rhs : float = 0.0 , name : Optional [ str ] = None , ) -> QuadraticConstraint : if name : if name in self . quadratic_constraints_index : raise QiskitOptimizationError ( f"Quadratic constraint name already exists: {name}" ) else : k = self . get_num_quadratic_constraints ( ) while f"q{k}" in self . quadratic_constraints_index : k += 1 name = f"q{k}" self . quadratic_constraints_index [ name ] = len ( self . quadratic_constraints ) if linear is None : linear = { } if quadratic is None : quadratic = { } constraint = QuadraticConstraint ( self , name , linear , quadratic , Constraint . Sense . convert ( sense ) , rhs ) self . quadratic_constraints . append ( constraint ) return constraint
Adds a quadratic equality constraint to the quadratic program of the form:
x * Q * x <= rhs.
Adds a quadratic equality constraint to the quadratic program of the form : x * Q * x < = rhs .
"""Adds a quadratic equality constraint to the quadratic program of the form:
            x * Q * x <= rhs.

        Args:
            linear: The linear coefficients of the constraint.
            quadratic: The quadratic coefficients of the constraint.
            sense: The sense of the constraint,
              - '==', '=', 'E', and 'EQ' denote 'equal to'.
              - '>=', '>', 'G', and 'GE' denote 'greater-than-or-equal-to'.
              - '<=', '<', 'L', and 'LE' denote 'less-than-or-equal-to'.
            rhs: The right hand side of the constraint.
            name: The name of the constraint.

        Returns:
            The added constraint.

        Raises:
            QiskitOptimizationError: if the constraint name already exists.
        """
The added constraint.
The added constraint .
if the constraint name already exists.
if the constraint name already exists .
QiskitOptimizationError
self
linear
Union[ndarray, spmatrix, List[float], Dict[Union[int, str], float]]
The linear coefficients of the constraint.
The linear coefficients of the constraint .
quadratic
Union[
            ndarray,
            spmatrix,
            List[List[float]],
            Dict[Tuple[Union[int, str], Union[int, str]], float],
        ]
The quadratic coefficients of the constraint.
The quadratic coefficients of the constraint .
sense
Union[str, ConstraintSense]
The sense of the constraint,
'==', '=', 'E', and 'EQ' denote 'equal to'.
The sense of the constraint ' == ' ' = ' ' E ' and ' EQ ' denote ' equal to ' .
rhs
float
The right hand side of the constraint.
The right hand side of the constraint .
name
Optional[str]
The name of the constraint.
The name of the constraint .