Skip to content

Constraint

Bases: QuadraticProgramElement

Abstract Constraint Class.

Source code in q3as/quadratic/problems/constraint.py
class Constraint(QuadraticProgramElement):
    """Abstract Constraint Class."""

    Sense = ConstraintSense

    def __init__(
        self, quadratic_program: Any, name: str, sense: ConstraintSense, rhs: float
    ) -> None:
        """Initializes the constraint.

        Args:
            quadratic_program: The parent QuadraticProgram.
            name: The name of the constraint.
            sense: The sense of the constraint.
            rhs: The right-hand-side of the constraint.
        """
        super().__init__(quadratic_program)
        self._name = name
        self._sense = sense
        self._rhs = rhs

    @property
    def name(self) -> str:
        """Returns the name of the constraint.

        Returns:
            The name of the constraint.
        """
        return self._name

    @property
    def sense(self) -> ConstraintSense:
        """Returns the sense of the constraint.

        Returns:
            The sense of the constraint.
        """
        return self._sense

    @sense.setter
    def sense(self, sense: ConstraintSense) -> None:
        """Sets the sense of the constraint.

        Args:
            sense: The sense of the constraint.
        """
        self._sense = sense

    @property
    def rhs(self) -> float:
        """Returns the right-hand-side of the constraint.

        Returns:
            The right-hand-side of the constraint.
        """
        return self._rhs

    @rhs.setter
    def rhs(self, rhs: float) -> None:
        """Sets the right-hand-side of the constraint.

        Args:
            rhs: The right-hand-side of the constraint.
        """
        self._rhs = rhs

    @abstractmethod
    def evaluate(self, x: Union[ndarray, List, Dict[Union[int, str], float]]) -> float:
        """Evaluate left-hand-side of constraint for given values of variables.

        Args:
            x: The values to be used for the variables.

        Returns:
            The left-hand-side of the constraint.
        """
        raise NotImplementedError()

name: str property

Returns the name of the constraint.

Returns:

Type Description
str

The name of the constraint.

rhs: float property writable

Returns the right-hand-side of the constraint.

Returns:

Type Description
float

The right-hand-side of the constraint.

sense: ConstraintSense property writable

Returns the sense of the constraint.

Returns:

Type Description
ConstraintSense

The sense of the constraint.

__init__(quadratic_program, name, sense, rhs)

Initializes the constraint.

Parameters:

Name Type Description Default
quadratic_program Any

The parent QuadraticProgram.

required
name str

The name of the constraint.

required
sense ConstraintSense

The sense of the constraint.

required
rhs float

The right-hand-side of the constraint.

required
Source code in q3as/quadratic/problems/constraint.py
def __init__(
    self, quadratic_program: Any, name: str, sense: ConstraintSense, rhs: float
) -> None:
    """Initializes the constraint.

    Args:
        quadratic_program: The parent QuadraticProgram.
        name: The name of the constraint.
        sense: The sense of the constraint.
        rhs: The right-hand-side of the constraint.
    """
    super().__init__(quadratic_program)
    self._name = name
    self._sense = sense
    self._rhs = rhs

evaluate(x) abstractmethod

Evaluate left-hand-side of constraint for given values of variables.

Parameters:

Name Type Description Default
x Union[ndarray, List, Dict[Union[int, str], float]]

The values to be used for the variables.

required

Returns:

Type Description
float

The left-hand-side of the constraint.

Source code in q3as/quadratic/problems/constraint.py
@abstractmethod
def evaluate(self, x: Union[ndarray, List, Dict[Union[int, str], float]]) -> float:
    """Evaluate left-hand-side of constraint for given values of variables.

    Args:
        x: The values to be used for the variables.

    Returns:
        The left-hand-side of the constraint.
    """
    raise NotImplementedError()