diff --git a/.docker-compose/Dockerfile b/.docker-compose/Dockerfile index 62f8a78..593525a 100644 --- a/.docker-compose/Dockerfile +++ b/.docker-compose/Dockerfile @@ -6,6 +6,10 @@ RUN python -m pip install pulp RUN python -m pip install pydantic RUN python -m pip install daemonize RUN python -m pip install sqspy +RUN python -m pip install -U pytest +RUN python -m pip install pytest-cov +RUN python -m pip install pytest-stub +RUN python -m pip install pytest-mock RUN mkdir /app WORKDIR /app diff --git a/Dockerfile b/Dockerfile index 58839d7..4c2bfb4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,10 @@ RUN python -m pip install pulp RUN python -m pip install pydantic RUN python -m pip install daemonize RUN python -m pip install sqspy +RUN python -m pip install -U pytest +RUN python -m pip install pytest-cov +RUN python -m pip install pytest-stub +RUN python -m pip install pytest-mock RUN mkdir /app WORKDIR /app diff --git a/app/models/objective_function.py b/app/models/objective_function.py index 5081f1d..9bd332f 100644 --- a/app/models/objective_function.py +++ b/app/models/objective_function.py @@ -27,8 +27,6 @@ class ObjectiveFunction(BaseModel): else: for target in targets: target.drift = round(target.drift + amount, 2) - print(self.tif_targets) - print(self.tcc_targets) return amount def update_targets_drift(self, amount: float = 0.0): diff --git a/app/test/test_example.py b/app/test/test_example.py new file mode 100644 index 0000000..acdc04e --- /dev/null +++ b/app/test/test_example.py @@ -0,0 +1,60 @@ +# content of example.py +from pulp import LpProblem, LpVariable, LpMinimize, LpStatus, lpSum + + +def func(x): + return x + 1 + + +def test_pass(): + assert func(4) == 5 + + +def test_failure(): + assert func(3) == 5 + + +def yosh_loop(): + Items = [1, 2, 3, 4, 5] + tif = {1: 0.2, 2: 0.5, 3: 0.3, 4: 0.8, 5: 0.1} + iif = {1: 0.09, 2: 0.2, 3: 0.113, 4: 0.3, 5: 0.1} + drift = 0.0 + drift_limit = 0.2 + iif_target = 0.5 + tif_target = 0.9 + item_vars = LpVariable.dicts("Item", Items, cat="Binary") + result = 'Infeasible' + + while drift <= drift_limit: + prob = LpProblem("tif_tcc_test", LpMinimize) + prob += lpSum([(tif[i] + iif[i]) * item_vars[i] + for i in Items]), "TifTccSum" + prob += lpSum([item_vars[i] for i in Items]) == 3, "TotalItems" + prob += lpSum([tif[i] * item_vars[i] for i in Items + ]) >= tif_target - (tif_target * drift), 'TifMin' + prob += lpSum([tif[i] * item_vars[i] for i in Items + ]) <= tif_target + (tif_target * drift), 'TifMax' + prob += lpSum([iif[i] * item_vars[i] for i in Items + ]) >= iif_target - (iif_target * drift), 'TccMin' + prob += lpSum([iif[i] * item_vars[i] for i in Items + ]) <= iif_target + (iif_target * drift), 'TccMax' + + prob.solve() + + if LpStatus[prob.status] == "Infeasible": + for v in prob.variables(): + print(v.name, "=", v.varValue) + + drift += 0.02 + else: + for v in prob.variables(): + print(v.name, "=", v.varValue) + + result = LpStatus[prob.status] + break + + return result + + +def test_solver(): + assert yosh_loop() == 'Optimal'