From 741026b707343c02769faf3b3066049a84463d71 Mon Sep 17 00:00:00 2001 From: drknzz Date: Fri, 3 May 2024 07:07:33 +0200 Subject: [PATCH] Update docstrings --- pabutools/analysis/priceability_relaxation.py | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/pabutools/analysis/priceability_relaxation.py b/pabutools/analysis/priceability_relaxation.py index 0f43fea7..e61426fa 100644 --- a/pabutools/analysis/priceability_relaxation.py +++ b/pabutools/analysis/priceability_relaxation.py @@ -6,6 +6,7 @@ import collections from abc import ABC, abstractmethod +from numbers import Real from mip import Model, xsum, minimize @@ -76,7 +77,7 @@ def add_stability_constraint(self, mip_model: Model) -> None: """ @abstractmethod - def get_beta(self, mip_model: Model): + def get_beta(self, mip_model: Model) -> Real | dict: """ Get the value of beta from the model. This method implicitly saves internally the value of beta variable from `mip_model`. @@ -85,6 +86,12 @@ def get_beta(self, mip_model: Model): ---------- mip_model : Model The stable-priceability MIP model. + + Returns + ------- + Real | dict + The value of beta from the model. + """ @abstractmethod @@ -96,6 +103,12 @@ def get_relaxed_cost(self, project: Project) -> float: ---------- project : :py:class:`~pabutools.election.instance.Project` The project to get the relaxed cost for. + + Returns + ------- + float + Relaxed cost of the project. + """ @@ -124,7 +137,7 @@ def add_stability_constraint(self, mip_model: Model) -> None: <= c.cost * beta + x_vars[c] * self.INF ) - def get_beta(self, mip_model: Model): + def get_beta(self, mip_model: Model) -> Real | dict: beta = mip_model.var_by_name(name="beta") self._saved_beta = beta.x return self._saved_beta @@ -158,7 +171,7 @@ def add_stability_constraint(self, mip_model: Model) -> None: <= c.cost + beta + x_vars[c] * self.INF ) - def get_beta(self, mip_model: Model): + def get_beta(self, mip_model: Model) -> Real | dict: beta = mip_model.var_by_name(name="beta") self._saved_beta = beta.x return self._saved_beta @@ -199,7 +212,7 @@ def add_stability_constraint(self, mip_model: Model) -> None: <= c.cost + beta[c] + x_vars[c] * self.INF ) - def get_beta(self, mip_model: Model): + def get_beta(self, mip_model: Model) -> Real | dict: beta = {c: mip_model.var_by_name(name=f"beta_{c.name}") for c in self.C} return_beta = collections.defaultdict(int) for c in self.C: @@ -258,7 +271,7 @@ def add_stability_constraint(self, mip_model: Model) -> None: <= c.cost + beta_global + beta[c] + x_vars[c] * self.INF ) - def get_beta(self, mip_model: Model): + def get_beta(self, mip_model: Model) -> Real | dict: beta_global = mip_model.var_by_name(name="beta") beta = {c: mip_model.var_by_name(name=f"beta_{c.name}") for c in self.C} return_beta = collections.defaultdict(int)