From 42d23bb59879bb94b8e8098bad001c5cd027f029 Mon Sep 17 00:00:00 2001 From: Celeste Ma Date: Sun, 26 May 2024 10:58:03 +0800 Subject: [PATCH] Bumped version to 0.1.1. Component limits now can be None to specify no limit. --- README.md | 2 ++ pyproject.toml | 3 ++- src/reiuji/designer/base/constraints.py | 12 ++++++++---- .../designer/overhauled/turbine_dynamo/designer.py | 2 +- .../designer/overhauled/turbine_rotor/designer.py | 2 +- src/reiuji/designer/qmd/decelerator/designer.py | 2 +- src/reiuji/designer/qmd/linear/designer.py | 2 +- src/reiuji/designer/qmd/nucleosynthesis/designer.py | 2 +- src/reiuji/designer/qmd/synchrotron/designer.py | 2 +- 9 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f5c14e0..e261efe 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,5 @@ pip install reiuji-nuclearcraft ## Usage Reiuji has a command line interface that can be found [here](https://github.com/MtCelesteMa/reiuji-cli). + +There is also a web app in the works. diff --git a/pyproject.toml b/pyproject.toml index f4375af..ed27f84 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "reiuji_nuclearcraft" -version = "0.1.0" +version = "0.1.1" dependencies = [ "pydantic", "ortools", @@ -33,4 +33,5 @@ namespaces = false [project.urls] Homepage = "https://github.com/MtCelesteMa/reiuji" +Repository = "https://github.com/MtCelesteMa/reiuji" "Bug Tracker" = "https://github.com/MtCelesteMa/reiuji/issues" diff --git a/src/reiuji/designer/base/constraints.py b/src/reiuji/designer/base/constraints.py index 4b9c1d6..61448f6 100644 --- a/src/reiuji/designer/base/constraints.py +++ b/src/reiuji/designer/base/constraints.py @@ -139,13 +139,16 @@ def to_model( class QuantityConstraint(Constraint): """Limits the number of a specific component type in the sequence.""" - def __init__(self, component_full_name: str, max_quantity: int, min_quantity: int = 0) -> None: + def __init__(self, component_full_name: str, max_quantity: int | None = None, min_quantity: int | None = None) -> None: self.component_full_name = component_full_name self.max_quantity = max_quantity - self.min_quantity = min_quantity + self.min_quantity = min_quantity if isinstance(min_quantity, int) else 0 def is_satisfied(self, seq: core.multi_sequence.MultiSequence[Component]) -> bool: - return sum([1 for component in seq if component.full_name == self.component_full_name]) <= self.max_quantity + count = sum([1 for component in seq if component.full_name == self.component_full_name]) + if count < self.min_quantity or (isinstance(self.max_quantity, int) and count > self.max_quantity): + return False + return True def to_model( self, @@ -159,4 +162,5 @@ def to_model( model.Add(component == component_id).OnlyEnforceIf(is_equal[i]) model.Add(component != component_id).OnlyEnforceIf(is_equal[i].Not()) model.Add(sum(is_equal) >= self.min_quantity) - model.Add(sum(is_equal) <= self.max_quantity) + if isinstance(self.max_quantity, int): + model.Add(sum(is_equal) <= self.max_quantity) diff --git a/src/reiuji/designer/overhauled/turbine_dynamo/designer.py b/src/reiuji/designer/overhauled/turbine_dynamo/designer.py index 2937f15..7453af4 100644 --- a/src/reiuji/designer/overhauled/turbine_dynamo/designer.py +++ b/src/reiuji/designer/overhauled/turbine_dynamo/designer.py @@ -18,7 +18,7 @@ def __init__( x_symmetry: bool = False, y_symmetry: bool = False, components: list[Component] | None = None, - component_limits: dict[str, tuple[int, int]] | None = None + component_limits: dict[str, tuple[int | None, int | None]] | None = None ) -> None: super().__init__(components=components if not isinstance(components, type(None)) else OVERHAULED_TURBINE_DYNAMO_COMPONENTS) self.side_length = side_length diff --git a/src/reiuji/designer/overhauled/turbine_rotor/designer.py b/src/reiuji/designer/overhauled/turbine_rotor/designer.py index 9efbbd9..3911d70 100644 --- a/src/reiuji/designer/overhauled/turbine_rotor/designer.py +++ b/src/reiuji/designer/overhauled/turbine_rotor/designer.py @@ -16,7 +16,7 @@ def __init__( optimal_expansion: float, *, components: list[Component] | None = None, - component_limits: dict[str, tuple[int, int]] | None = None + component_limits: dict[str, tuple[int | None, int | None]] | None = None ) -> None: super().__init__(components=components if not isinstance(components, type(None)) else OVERHAULED_TURBINE_ROTOR_COMPONENTS) self.length = length diff --git a/src/reiuji/designer/qmd/decelerator/designer.py b/src/reiuji/designer/qmd/decelerator/designer.py index a001729..84679be 100644 --- a/src/reiuji/designer/qmd/decelerator/designer.py +++ b/src/reiuji/designer/qmd/decelerator/designer.py @@ -28,7 +28,7 @@ def __init__( heat_neutral: bool = True, internal_symmetry: bool = False, components: list[Component] | None = None, - component_limits: dict[str, tuple[int, int]] | None = None + component_limits: dict[str, tuple[int | None, int | None]] | None = None ) -> None: super().__init__(components=components if not isinstance(components, type(None)) else QMD_ACCELERATOR_COMPONENTS) self.side_length = side_length diff --git a/src/reiuji/designer/qmd/linear/designer.py b/src/reiuji/designer/qmd/linear/designer.py index 1be1e3c..8a39e1e 100644 --- a/src/reiuji/designer/qmd/linear/designer.py +++ b/src/reiuji/designer/qmd/linear/designer.py @@ -27,7 +27,7 @@ def __init__( y_symmetry: bool = False, z_symmetry: bool = False, components: list[Component] | None = None, - component_limits: dict[str, tuple[int, int]] | None = None + component_limits: dict[str, tuple[int | None, int | None]] | None = None ) -> None: super().__init__(components=components if not isinstance(components, type(None)) else QMD_LINEAR_ACCELERATOR_COMPONENTS) self.length = length diff --git a/src/reiuji/designer/qmd/nucleosynthesis/designer.py b/src/reiuji/designer/qmd/nucleosynthesis/designer.py index 59d53b5..f2b99c1 100644 --- a/src/reiuji/designer/qmd/nucleosynthesis/designer.py +++ b/src/reiuji/designer/qmd/nucleosynthesis/designer.py @@ -17,7 +17,7 @@ def __init__( x_symmetry: bool = False, z_symmetry: bool = False, components: list[Component] | None = None, - component_limits: dict[str, tuple[int, int]] | None = None + component_limits: dict[str, tuple[int | None, int | None]] | None = None ) -> None: super().__init__(components=components if not isinstance(components, type(None)) else QMD_NUCLEOSYNTHESIS_COMPONENTS) self.recipe_heat = recipe_heat diff --git a/src/reiuji/designer/qmd/synchrotron/designer.py b/src/reiuji/designer/qmd/synchrotron/designer.py index 388bdbc..f35b08d 100644 --- a/src/reiuji/designer/qmd/synchrotron/designer.py +++ b/src/reiuji/designer/qmd/synchrotron/designer.py @@ -27,7 +27,7 @@ def __init__( heat_neutral: bool = True, internal_symmetry: bool = False, components: list[Component] | None = None, - component_limits: dict[str, tuple[int, int]] | None = None + component_limits: dict[str, tuple[int | None, int | None]] | None = None ) -> None: super().__init__(components=components if not isinstance(components, type(None)) else QMD_ACCELERATOR_COMPONENTS) self.side_length = side_length