diff --git a/README.md b/README.md index a185664..3d1302c 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,11 @@ - Package version + Package version - Supported Python versions + Supported Python versions diff --git a/docs/index.md b/docs/index.md index 3257aab..9924f0c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -31,11 +31,11 @@ hide: - Package version + Package version - Supported Python versions + Supported Python versions diff --git a/docs/release-notes.md b/docs/release-notes.md index f2ae557..1f4f4da 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -12,6 +12,23 @@ hide: [//]: # (--------------------------------------------------------------------------------------------------------------) +## [v0.1.1](https://github.com/dapensoft/pyorlib/releases/tag/0.1.1) March 2, 2024 { id="0.1.1" } + +
+ +##### Changed + +- The `print_info` and `print_solution` methods in the `Model` class have been enhanced to improve visibility and + provide deeper insights. +- The `get_pretty_string` method in the `Term` class has been refactored as an `@abstractmethod` for subclass + customization. +- Badges on the main page of the documentation and the readme file have been updated to improve visibility and align + with the package's color palette. +- The `git-committers` plugin in the `mkdocs.yml` file has been updated to exclude the `index.md`, `examples/index.md`, + and `api/index.md` files for consistency in the current configuration with the `git-revision-date-localized` plugin. + +[//]: # (--------------------------------------------------------------------------------------------------------------) + ## [v0.1.0](https://github.com/dapensoft/pyorlib/releases/tag/0.1.0) March 2, 2024 { id="0.1.0" }
diff --git a/mkdocs.yml b/mkdocs.yml index 4c5a35a..5146161 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -63,6 +63,10 @@ plugins: - git-committers: repository: dapensoft/pyorlib branch: master + exclude: + - examples/index.md + - api/index.md + - index.md - git-revision-date-localized: type: timeago enable_creation_date: true @@ -126,7 +130,7 @@ extra_javascript: nav: - PyORlib: index.md - Getting Started: getting-started.md - - Examples: + - Examples: - examples/index.md - A Transportation Model: examples/a-transportation-problem.md - API Reference: diff --git a/src/pyorlib/__init__.py b/src/pyorlib/__init__.py index ce58a19..7a24112 100644 --- a/src/pyorlib/__init__.py +++ b/src/pyorlib/__init__.py @@ -3,7 +3,7 @@ mathematical models in a standardized manner across different optimization packages. """ -__version__ = "0.1.0" +__version__ = "0.1.1" from .engines import Engine from .model import Model diff --git a/src/pyorlib/algebra/terms/constants/constant.py b/src/pyorlib/algebra/terms/constants/constant.py index 2478748..97a1f63 100644 --- a/src/pyorlib/algebra/terms/constants/constant.py +++ b/src/pyorlib/algebra/terms/constants/constant.py @@ -2,6 +2,7 @@ from typing import Any from ..term import Term +from ....core.constants import StdOutColors from ....enums import ValueType, TermType from ....exceptions import TermException from ....validators import ValueTypeValidator @@ -66,3 +67,16 @@ def __init__(self, name: str, value_type: ValueType, value: float): self._value: float = value """ The internal value of the constant. """ + + def get_pretty_string(self, float_precision: int = 6) -> str: # pragma: no cover + default, debug = StdOutColors.DEFAULT, StdOutColors.PURPLE + return "".join( + [ + f"Name: {debug}{self.name}{default} | ", + f"Type: {debug}{self.term_type.name.capitalize()}{default} | ", + f"Value type: {debug}{self.value_type.name.capitalize()}{default} | ", + f"Val:{debug} ", + "{0:.{prec}g} ".format(self.value, prec=float_precision), + f"{default}", + ] + ) diff --git a/src/pyorlib/algebra/terms/term.py b/src/pyorlib/algebra/terms/term.py index a9f59a7..d7776c6 100644 --- a/src/pyorlib/algebra/terms/term.py +++ b/src/pyorlib/algebra/terms/term.py @@ -4,7 +4,6 @@ from ..element import Element from ..expressions import Expression -from ...core.constants import StdOutColors from ...enums import TermType, ValueType from ...exceptions import TermException @@ -121,27 +120,14 @@ def __init__(self, term_type: TermType, value_type: ValueType): def _build_expression(self, expression: Any) -> Element: return Expression(expression=expression) - def get_pretty_string(self, float_precision: int = 6) -> str: # pragma: no cover + @abstractmethod + def get_pretty_string(self, float_precision: int = 6) -> str: """ Returns a formatted string representation of the term. :param float_precision: It represents the number of digits used in printing the solution and objective. :return: A formatted string representing the term. """ - default, debug = StdOutColors.DEFAULT, StdOutColors.PURPLE - return "".join( - [ - f"Name: {debug}{self.name}{default} | ", - f"Type: {debug}{self.term_type.name.capitalize()}{default} | ", - f"Value type: {debug}{self.value_type.name.capitalize()}{default} | ", - f"lb:{debug} ", - "{0:.{prec}g} ".format(self.lower_bound, prec=float_precision), - f"{default}| ub:{debug} ", - "{0:.{prec}g} ".format(self.upper_bound, prec=float_precision), - f"{default}| val:{debug} ", - "{0:.{prec}g} ".format(self.value, prec=float_precision), - f"{default}", - ] - ) + pass def __str__(self) -> str: # pragma: no cover return "".join( diff --git a/src/pyorlib/algebra/terms/variables/variable.py b/src/pyorlib/algebra/terms/variables/variable.py index b22815e..e826792 100644 --- a/src/pyorlib/algebra/terms/variables/variable.py +++ b/src/pyorlib/algebra/terms/variables/variable.py @@ -2,6 +2,7 @@ from math import inf from ..term import Term +from ....core.constants import StdOutColors from ....enums import ValueType, TermType from ....exceptions import TermException @@ -44,3 +45,20 @@ def __init__(self, name: str, value_type: ValueType, lower_bound: float = 0, upp raise TermException("Invalid lower bound for an integer variable term.") if value_type == ValueType.INTEGER and not upper_bound == inf and not float(upper_bound).is_integer(): raise TermException("Invalid upper bound for an integer variable term.") + + def get_pretty_string(self, float_precision: int = 6) -> str: # pragma: no cover + default, debug = StdOutColors.DEFAULT, StdOutColors.PURPLE + return "".join( + [ + f"Name: {debug}{self.name}{default} | ", + f"Type: {debug}{self.term_type.name.capitalize()}{default} | ", + f"Value type: {debug}{self.value_type.name.capitalize()}{default} | ", + f"Lb:{debug} ", + "{0:.{prec}g} ".format(self.lower_bound, prec=float_precision), + f"{default}| Ub:{debug} ", + "{0:.{prec}g} ".format(self.upper_bound, prec=float_precision), + f"{default}| Val:{debug} ", + "{0:.{prec}g} ".format(self.value, prec=float_precision), + f"{'(N/A) ' if self.value == -0.0 else ''}{default}", + ] + ) diff --git a/src/pyorlib/model/model.py b/src/pyorlib/model/model.py index 4d00cb7..05acfcd 100644 --- a/src/pyorlib/model/model.py +++ b/src/pyorlib/model/model.py @@ -445,49 +445,50 @@ def print_info(self, display_term_sets: bool = False) -> None: # pragma: no cov :param display_term_sets: Whether to display information about term sets. Defaults to False. :return: None. """ + default, debug = StdOutColors.DEFAULT, StdOutColors.PURPLE print(f"\n------ MODEL INFORMATION ------\n") print("Model properties:") - print(f"\tName: {StdOutColors.PURPLE}{self.name}{StdOutColors.DEFAULT}") + print(f"\tName: {debug}{self.name}{default}") print("Objective function:") print(f"\tExpression: {self.objective_expr}") - print(f"\tStatus: {StdOutColors.PURPLE}{self.solution_status.name}{StdOutColors.DEFAULT}") + print(f"\tStatus: {debug}{self.solution_status.name}{default}") print( - f"\tValue: {StdOutColors.PURPLE}", + f"\tValue: {debug}", ( "{0:.{prec}g}".format(self.objective_value, prec=self.float_precision) if self.objective_value is not None else "--" ), - f"{StdOutColors.DEFAULT}", + f"{default}", ) - print("Dimensions:") + print(f"Dimensions: {debug}{len(self.dimensions)}{default}") for name, size in self.dimensions.items(): print( - f"\tName: {StdOutColors.PURPLE}{name}{StdOutColors.DEFAULT} | ", - f"Val: {StdOutColors.PURPLE}{size}{StdOutColors.DEFAULT}", + f"\tName: {debug}{name}{default} | ", + f"Val: {debug}{size}{default}", ) - print("Terms:") + print(f"Terms: {debug}{len(self.terms)}{default}") for name, term in self.terms.items(): print(f"\t{term.get_pretty_string(float_precision=self.float_precision)}") if display_term_sets: - print("Terms Sets:") + print(f"Terms Sets: {debug}{len(self.term_sets)}{default}") for name, terms in self.term_sets.items(): - print(f"\tTerm: {StdOutColors.PURPLE}{name}{StdOutColors.DEFAULT}") + print(f"\tTerm: {debug}{name}{default}") for index, term in terms.items(): print( - f"\t\tIndex: {StdOutColors.PURPLE}{index}{StdOutColors.DEFAULT} | ", + f"\t\tIndex: {debug}{index}{default} | ", f"{term.get_pretty_string(float_precision=self.float_precision)}", ) - print("Constraints:") constraints = self.constraints + print(f"Constraints: {debug}{len(constraints)}{default}") for exp in constraints: try: print(f"\tExpression: {exp}") except RecursionError: - print("\tExpression: Unprintable expression") + print("\tExpression: Print Error") print() def print_solution(self) -> None: # pragma: no cover @@ -495,17 +496,18 @@ def print_solution(self) -> None: # pragma: no cover Prints the solution of the optimization problem. :return: None. """ + default, debug = StdOutColors.DEFAULT, StdOutColors.PURPLE print(f"\n------ MODEL SOLUTION ------\n") print("Objective function:") - print(f"\tStatus: {StdOutColors.PURPLE}{self.solution_status.name}{StdOutColors.DEFAULT}") + print(f"\tStatus: {debug}{self.solution_status.name}{default}") print( - f"\tValue: {StdOutColors.PURPLE}", + f"\tValue: {debug}", ( "{0:.{prec}g}".format(self.objective_value, prec=self.float_precision) if self.objective_value is not None else "--" ), - f"{StdOutColors.DEFAULT}", + f"{default}", ) solution_variables: Dict[str, Term] = { diff --git a/tests/algebra/terms/test_term.py b/tests/algebra/terms/test_term.py index 045b42e..1c95fce 100644 --- a/tests/algebra/terms/test_term.py +++ b/tests/algebra/terms/test_term.py @@ -36,7 +36,7 @@ def value(self) -> float: def raw(self) -> Any: pass - def validate(self) -> None: + def get_pretty_string(self, float_precision: int = 6) -> str: pass def __init__(self):