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

        Args:
            linear: The linear coefficients of the left-hand-side 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 or the sense is not
                valid.
        """
        if name:
            if name in self.linear_constraints_index:
                raise QiskitOptimizationError(f"Linear constraint's name already exists: {name}")
        else:
            k = self.get_num_linear_constraints()
            while f"c{k}" in self.linear_constraints_index:
                k += 1
            name = f"c{k}"
        self.linear_constraints_index[name] = len(self.linear_constraints)
        if linear is None:
            linear = {}
        constraint = LinearConstraint(self, name, linear, Constraint.Sense.convert(sense), rhs)
        self.linear_constraints.append(constraint)
        return constraint
Adds a linear equality constraint to the quadratic program of the form:
            linear * x sense rhs.

        Args:
            linear: The linear coefficients of the left-hand-side 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 or the sense is not
                valid.
        
Adds a linear equality constraint to the quadratic program of the form:
linear * x sense rhs.
Adds a linear equality constraint to the quadratic program of the form : linear * x sense rhs .
def linear_constraint(
        self,
        linear: Union[ndarray, spmatrix, List[float], Dict[Union[int, str], float]] = None,
        sense: Union[str, ConstraintSense] = "<=",
        rhs: float = 0.0,
        name: Optional[str] = None,
    ) -> LinearConstraint:
        if name:
            if name in self.linear_constraints_index:
                raise QiskitOptimizationError(f"Linear constraint's name already exists: {name}")
        else:
            k = self.get_num_linear_constraints()
            while f"c{k}" in self.linear_constraints_index:
                k += 1
            name = f"c{k}"
        self.linear_constraints_index[name] = len(self.linear_constraints)
        if linear is None:
            linear = {}
        constraint = LinearConstraint(self, name, linear, Constraint.Sense.convert(sense), rhs)
        self.linear_constraints.append(constraint)
        return constraint
def linear_constraint ( self , linear : Union [ ndarray , spmatrix , List [ float ] , Dict [ Union [ int , str ] , float ] ] = None , sense : Union [ str , ConstraintSense ] = "<=" , rhs : float = 0.0 , name : Optional [ str ] = None , ) -> LinearConstraint : if name : if name in self . linear_constraints_index : raise QiskitOptimizationError ( f"Linear constraint's name already exists: {name}" ) else : k = self . get_num_linear_constraints ( ) while f"c{k}" in self . linear_constraints_index : k += 1 name = f"c{k}" self . linear_constraints_index [ name ] = len ( self . linear_constraints ) if linear is None : linear = { } constraint = LinearConstraint ( self , name , linear , Constraint . Sense . convert ( sense ) , rhs ) self . linear_constraints . append ( constraint ) return constraint
Adds a linear equality constraint to the quadratic program of the form:
linear * x sense rhs.
Adds a linear equality constraint to the quadratic program of the form : linear * x sense rhs .
"""Adds a linear equality constraint to the quadratic program of the form:
            linear * x sense rhs.

        Args:
            linear: The linear coefficients of the left-hand-side 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 or the sense is not
                valid.
        """
The added constraint.
The added constraint .
if the constraint name already exists or the sense is not
valid.
if the constraint name already exists or the sense is not valid .
QiskitOptimizationError
self
linear
Union[ndarray, spmatrix, List[float], Dict[Union[int, str], float]]
The linear coefficients of the left-hand-side of the constraint.
The linear coefficients of the left - hand - side 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 .