diff options
Diffstat (limited to '')
-rw-r--r-- | README.md | 55 | ||||
-rw-r--r-- | src/act4e_mcdp_solution/__init__.py | 3 | ||||
-rw-r--r-- | src/act4e_mcdp_solution/solution.py | 15 | ||||
-rw-r--r-- | src/act4e_mcdp_solution/solver_dp.py | 29 | ||||
-rw-r--r-- | src/act4e_mcdp_solution/solver_mcdp.py | 34 |
5 files changed, 105 insertions, 31 deletions
@@ -39,7 +39,9 @@ If we tell you to update the library, use this: pip install -U ACT4E-mcdp -## Running the tests +## Make sure everything is OK + +### Downloading test cases Use this command to download the test cases: @@ -47,32 +49,55 @@ Use this command to download the test cases: Then you have available a few test cases in the directory `downloaded/`. -This is the command you use to run the solver: +### Running the DP solver + +This is the command you use to run the DP solver: - act4e-mcdp-solve \ - --solver act4e_mcdp_solution.MySolution \ + act4e-mcdp-solve-dp \ + --solver act4e_mcdp_solution.DPSolver \ --query FixFunMinRes \ - --model downloaded/lib1-parts.e03_splitter1.models.mcdpr1.yaml \ - --data '{f: 10}' + --model downloaded/lib1-parts.e03_splitter1.primitivedps.mcdpr1.yaml \ + --data '42' -In turn: +In brief: -* `--solver act4e_mcdp_solution.MySolution`: this selects your solver; +* `--solver act4e_mcdp_solution.DPSolver`: this selects the class for your solver; * `--query FixFunMinRes`: this selects `FixFunMinRes` (other choice: `FixResMaxFun`); -* `--model downloaded/lib1-parts.e03_splitter1.models.mcdpr1.yaml`: this selects the model to use for optimization; -* `--data '{f: 10}'`: this selects the query to give. It is a YAML dictionary with a key for each functionality name. +* `--model downloaded/lib1-parts.e03_splitter1.primitivedps.mcdpr1.yaml`: this selects the model to use for optimization; +* `--data '10'`: this selects the query to give. + +It is a YAML dictionary with a key for each functionality name. You will see the result in the logs: ``` -INFO query: {'f': Decimal('10')} -INFO solution: UpperSet(minima=[]) +INFO query: 10 +INFO solution: Interval(pessimistic=UpperSet(minima=[]), optimistic=UpperSet(minima=[])) ``` The template `act4e_mcdp_solution.MySolution` always returns an empty `UpperSet` (= infeasible). -At this point, you can start implementing your solver. -For testing, run `act4e-mcdp-solve` on different files. +### Running the MCDP solver + + +This is the command you use to run the MCDP solver: + + act4e-mcdp-solve-mcdp \ + --solver act4e_mcdp_solution.MCDPSolver \ + --query FixFunMinRes \ + --model downloaded/lib1-parts.e03_splitter1.models.mcdpr1.yaml \ + --data '{f: 42}' + +Note that for the MCDP solver we give a file of type `models.mcdpr1.yaml` instead of `primitivedps.mcdpr1.yaml`. + +For the data, we use a key-value pair with the functionality name and the value. + +You should see the output: + + query: {'f': Decimal('42')} + solution: Interval(pessimistic=UpperSet(minima=[]), optimistic=UpperSet(minima=[])) + +## Next steps -TODO: provide a exhaustive test case. +TODO: exhaustive test case diff --git a/src/act4e_mcdp_solution/__init__.py b/src/act4e_mcdp_solution/__init__.py index c3fe37e..cddc7c6 100644 --- a/src/act4e_mcdp_solution/__init__.py +++ b/src/act4e_mcdp_solution/__init__.py @@ -7,4 +7,5 @@ import logging logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) -from .solution import * +from .solver_dp import * +from .solver_mcdp import * diff --git a/src/act4e_mcdp_solution/solution.py b/src/act4e_mcdp_solution/solution.py deleted file mode 100644 index 4704807..0000000 --- a/src/act4e_mcdp_solution/solution.py +++ /dev/null @@ -1,15 +0,0 @@ -from typing import Any, Mapping - -from act4e_mcdp import NamedDP, SolverInterface, UpperSet, LowerSet - -__all__ = ["MySolution"] - - -class MySolution(SolverInterface): - def solve_FixFunMinRes(self, model: NamedDP, query: Mapping[str, Any]) -> UpperSet[Mapping[str, Any]]: - # returns the empty upper set - marking it as infeasible - return UpperSet([]) - - def solve_FixResMaxFun(self, model: NamedDP, query: Mapping[str, Any]) -> LowerSet[Mapping[str, Any]]: - # returns the empty upper set - marking it as infeasible - return LowerSet([]) diff --git a/src/act4e_mcdp_solution/solver_dp.py b/src/act4e_mcdp_solution/solver_dp.py new file mode 100644 index 0000000..8a4d58c --- /dev/null +++ b/src/act4e_mcdp_solution/solver_dp.py @@ -0,0 +1,29 @@ +from act4e_mcdp import DPSolverInterface, Interval, LowerSet, PrimitiveDP, UpperSet + +__all__ = [ + "DPSolver", +] + + +class DPSolver(DPSolverInterface): + def solve_dp_FixFunMinRes( + self, + dp: PrimitiveDP, + functionality_needed: object, + /, + resolution_optimistic: int = 0, + resolution_pessimistic: int = 0, + ) -> Interval[UpperSet[object]]: + optimistic = pessimistic = UpperSet([]) + return Interval(pessimistic=pessimistic, optimistic=optimistic) + + def solve_dp_FixResMaxFun( + self, + dp: PrimitiveDP, + resource_budget: object, + /, + resolution_optimistic: int = 0, + resolution_pessimistic: int = 0, + ) -> Interval[LowerSet[object]]: + optimistic = pessimistic = LowerSet([]) + return Interval(pessimistic=pessimistic, optimistic=optimistic) diff --git a/src/act4e_mcdp_solution/solver_mcdp.py b/src/act4e_mcdp_solution/solver_mcdp.py new file mode 100644 index 0000000..12ab619 --- /dev/null +++ b/src/act4e_mcdp_solution/solver_mcdp.py @@ -0,0 +1,34 @@ +from typing import Any, Mapping + +from act4e_mcdp import Interval, LowerSet, MCDPSolverInterface, NamedDP, UpperSet + +__all__ = [ + "MCDPSolver", +] + + +class MCDPSolver(MCDPSolverInterface): + def solve_mcdp_FixFunMinRes( + self, + graph: NamedDP, + functionality_needed: Mapping[str, Any], + /, + resolution_optimistic: int = 0, + resolution_pessimistic: int = 0, + ) -> Interval[UpperSet[Mapping[str, Any]]]: + value_as_tuple = tuple(functionality_needed[key] for key in graph.functionalities) + + optimistic = pessimistic = UpperSet([]) + return Interval(pessimistic=pessimistic, optimistic=optimistic) + + def solve_mcdp_FixResMaxFun( + self, + graph: NamedDP, + resources_budget: Mapping[str, Any], + /, + resolution_optimistic: int = 0, + resolution_pessimistic: int = 0, + ) -> Interval[LowerSet[Mapping[str, Any]]]: + value_as_tuple = tuple(resources_budget[key] for key in graph.resources) + optimistic = pessimistic = LowerSet([]) + return Interval(pessimistic=pessimistic, optimistic=optimistic) |