Skip to content

odys.optimization.objective_terms.profit

Internal implementation detail. The expected-profit term: each scenario's profit weighted by its probability, times the term's weight. See Expected profit.

The expected-profit objective term.

ProfitTermFormulation

Bases: ObjectiveTermFormulation

Expected profit: the probability-weighted sum of every scenario's profit, times the term's weight.

Source code in src/odys/optimization/objective_terms/profit.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class ProfitTermFormulation(ObjectiveTermFormulation):
    """Expected profit: the probability-weighted sum of every scenario's profit, times the term's weight."""

    def __init__(self, term: ProfitTerm, inputs: ObjectiveTermInputs) -> None:
        """Initialize the term.

        Args:
            term: The profit term of the objective.
            inputs: The objective, the shared indexing, and the entity formulations.
        """
        super().__init__(inputs)
        self.term = term

    @classmethod
    def build(cls, inputs: ObjectiveTermInputs) -> Self | None:
        """Return the profit term's formulation, or None if the objective has no profit term."""
        term = inputs.objective.term_of(ProfitTerm)
        return None if term is None else cls(term, inputs)

    def expression(self) -> linopy.LinearExpression:
        """Return the weight times Σ_s probability_s · profit_s."""
        profit = per_scenario_profit(self.formulations)
        expected_profit = (profit * self.context.probabilities).sum(ModelDimension.Scenarios)
        weighted: linopy.LinearExpression = self.term.weight * expected_profit
        return weighted

__init__(term, inputs)

Initialize the term.

Parameters:

Name Type Description Default
term ProfitTerm

The profit term of the objective.

required
inputs ObjectiveTermInputs

The objective, the shared indexing, and the entity formulations.

required
Source code in src/odys/optimization/objective_terms/profit.py
16
17
18
19
20
21
22
23
24
def __init__(self, term: ProfitTerm, inputs: ObjectiveTermInputs) -> None:
    """Initialize the term.

    Args:
        term: The profit term of the objective.
        inputs: The objective, the shared indexing, and the entity formulations.
    """
    super().__init__(inputs)
    self.term = term

build(inputs) classmethod

Return the profit term's formulation, or None if the objective has no profit term.

Source code in src/odys/optimization/objective_terms/profit.py
26
27
28
29
30
@classmethod
def build(cls, inputs: ObjectiveTermInputs) -> Self | None:
    """Return the profit term's formulation, or None if the objective has no profit term."""
    term = inputs.objective.term_of(ProfitTerm)
    return None if term is None else cls(term, inputs)

expression()

Return the weight times Σ_s probability_s · profit_s.

Source code in src/odys/optimization/objective_terms/profit.py
32
33
34
35
36
37
def expression(self) -> linopy.LinearExpression:
    """Return the weight times Σ_s probability_s · profit_s."""
    profit = per_scenario_profit(self.formulations)
    expected_profit = (profit * self.context.probabilities).sum(ModelDimension.Scenarios)
    weighted: linopy.LinearExpression = self.term.weight * expected_profit
    return weighted