Skip to content

Other structures

Value from a poset

ValueFromPoset dataclass

Bases: Generic[T]

A value in a particular poset (a "typed" value).

Depending on the poset, we have different types:

Attributes:

Name Type Description
value str | Decimal | tuple

The value \(x \in \posA\)

poset Poset[T]

The poset \(\posA\)

Source code in src/act4e_mcdp/primitivedps.py
@dataclass(frozen=True)
class ValueFromPoset(Generic[T]):
    r"""
    A value in a particular poset (a "typed" value).

    Depending on the poset, we have different types:

    - For [FinitePoset][act4e_mcdp.posets.FinitePoset] the values are strings.
    - For [Numbers][act4e_mcdp.posets.Numbers] the values are instances of Decimal.
    - For [PosetProduct][act4e_mcdp.posets.PosetProduct] the values are tuples of values.


    Attributes:
        value (str | Decimal | tuple): The value $x \in \posA$
        poset: The poset $\posA$

    """

    value: T
    poset: Poset[T]

Structures used in solution

UpperSet dataclass

Bases: Generic[T]

Describes a finitely-supported upper set of elements of type T.

Attributes:

Name Type Description
minimals list[T]

A list of elements of type T, which are the minimal elements of the set.

Source code in src/act4e_mcdp/posets.py
@dataclass
class UpperSet(Generic[T]):
    """
    Describes a finitely-supported **upper set** of elements of type T.

    Attributes:
        minimals: A list of elements of type T, which are the minimal elements of the set.

    """

    minimals: list[T]

    @classmethod
    def from_points(
        cls,
        P: Poset[T],
        points: "Collection[T]",
    ) -> "UpperSet[T]":
        """Returns the lower set generated by the points."""
        minimals = P.minimals(points)
        return cls(minimals=list(minimals))

    @classmethod
    def principal(cls, value: T) -> "UpperSet[T]":
        return cls(minimals=[value])

    @classmethod
    def empty(cls) -> "UpperSet[T]":
        return cls(minimals=[])

    @classmethod
    def product(cls, sets: "Collection[UpperSet[T]]") -> "UpperSet[tuple[T, ...]]":
        """Computes the product of upper sets"""
        minimals_sets: list[list[T]] = [_.minimals for _ in sets]
        from itertools import product

        minimals: list[tuple[T, ...]] = list(product(*minimals_sets))
        return cls(minimals=minimals)  # type: ignore

    @classmethod
    def union(cls, sets: "Collection[UpperSet[T]]", P: Poset[T]) -> "UpperSet[T]":
        # Computes the union of upper sets in the Poset P

        all_elements: set[T] = set()
        for s in sets:
            all_elements.update(s.minimals)

        minimal_elements = P.minimals(all_elements)

        return cls(minimals=list(minimal_elements))

    @classmethod
    def close(cls, p: Poset[T], x: "UpperSet[T]", y: "UpperSet[T]", /, *, atol: float, rtol: float) -> bool:
        assert isinstance(x, UpperSet), x
        assert isinstance(y, UpperSet), y
        return close_seq(p, x.minimals, y.minimals, atol=atol, rtol=rtol)

from_points(P, points) classmethod

Returns the lower set generated by the points.

Source code in src/act4e_mcdp/posets.py
@classmethod
def from_points(
    cls,
    P: Poset[T],
    points: "Collection[T]",
) -> "UpperSet[T]":
    """Returns the lower set generated by the points."""
    minimals = P.minimals(points)
    return cls(minimals=list(minimals))

product(sets) classmethod

Computes the product of upper sets

Source code in src/act4e_mcdp/posets.py
@classmethod
def product(cls, sets: "Collection[UpperSet[T]]") -> "UpperSet[tuple[T, ...]]":
    """Computes the product of upper sets"""
    minimals_sets: list[list[T]] = [_.minimals for _ in sets]
    from itertools import product

    minimals: list[tuple[T, ...]] = list(product(*minimals_sets))
    return cls(minimals=minimals)  # type: ignore

LowerSet dataclass

Bases: Generic[T]

Describes a finitely-supported lower set of elements of type T.

Attributes:

Name Type Description
maximals list[T]

A list of elements of type T, which are the minimal elements of the set.

Source code in src/act4e_mcdp/posets.py
@dataclass
class LowerSet(Generic[T]):
    """
    Describes a finitely-supported **lower set** of elements of type T.

    Attributes:
        maximals: A list of elements of type T, which are the minimal elements of the set.

    """

    maximals: list[T]

    @classmethod
    def from_points(cls, P: Poset[T], points: "Collection[T]") -> "LowerSet[T]":
        """Returns the lower set generated by the points."""
        maximals = P.maximals(points)
        return cls(maximals=list(maximals))

    @classmethod
    def principal(cls, value: T) -> "LowerSet[T]":
        return cls(maximals=[value])

    @classmethod
    def empty(cls) -> "LowerSet[T]":
        return cls(maximals=[])

    @classmethod
    def product(cls, sets: "Collection[LowerSet[T]]") -> "LowerSet[tuple[T, ...]]":
        maximals_sets: list[list[T]] = [_.maximals for _ in sets]
        from itertools import product

        maximals = list(product(*maximals_sets))
        return cls(maximals=maximals)  # type: ignore

    @classmethod
    def union(cls, sets: "Collection[LowerSet[T]]", P: Poset[T]) -> "LowerSet[tuple[T, ...]]":
        # Computes the union of upper sets in the Poset P

        all_elements: set[T] = set()
        for s in sets:
            all_elements.update(s.maximals)

        maximal_elements = P.maximals(all_elements)

        return cls(maximals=list(maximal_elements))  # type: ignore

    @classmethod
    def close(cls, p: Poset[T], x: "LowerSet[T]", y: "LowerSet[T]", /, *, atol: float, rtol: float) -> bool:
        assert isinstance(x, LowerSet), x
        assert isinstance(y, LowerSet), y
        return close_seq(p, x.maximals, y.maximals, atol=atol, rtol=rtol)

from_points(P, points) classmethod

Returns the lower set generated by the points.

Source code in src/act4e_mcdp/posets.py
@classmethod
def from_points(cls, P: Poset[T], points: "Collection[T]") -> "LowerSet[T]":
    """Returns the lower set generated by the points."""
    maximals = P.maximals(points)
    return cls(maximals=list(maximals))

Interval dataclass

Bases: Generic[T]

Describes an optimistic-pessimistic interval for a quantity of type T.

The two values can be the same if there is no uncertainty.

Attributes:

Name Type Description
pessimistic T

The pessimistic value

optimistic T

The optimistic value

Source code in src/act4e_mcdp/posets.py
@dataclass(kw_only=True)
class Interval(Generic[T]):
    """
    Describes an optimistic-pessimistic interval for a quantity of type T.

    The two values can be the same if there is no uncertainty.

    Attributes:
        pessimistic: The pessimistic value
        optimistic: The optimistic value

    """

    pessimistic: T
    optimistic: T

    @classmethod
    def degenerate(cls, value: T) -> "Interval[T]":
        return cls(pessimistic=value, optimistic=value)