Skip to content

Commit

Permalink
Update docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
drknzz committed May 3, 2024
1 parent f3aa1da commit 741026b
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions pabutools/analysis/priceability_relaxation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import collections
from abc import ABC, abstractmethod
from numbers import Real

from mip import Model, xsum, minimize

Expand Down Expand Up @@ -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`.
Expand All @@ -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
Expand All @@ -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.
"""


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 741026b

Please sign in to comment.