From d131042441187b676b94cefd08818950f44f3b8e Mon Sep 17 00:00:00 2001 From: ModischFabrications Date: Sat, 30 Mar 2024 03:24:08 +0100 Subject: [PATCH] massive rework & cleanup; implement pydantic validation and extend checks, simplify tests with matrixes, remove cumbersome test fixtures, use simple typing, create and update SolverSettings, rework n_max checks to properly respect calculation times, major performance upgrade to bruteforce solver (closes #66), fix and include gapfill solver, prepare structure for #68 metrics --- app/constants.py | 22 +++- app/main.py | 15 +-- app/solver/data/Job.py | 74 +++++------ app/solver/data/Result.py | 17 +-- app/solver/solver.py | 187 +++++++++++++++------------- tests/res/in/testjob_cuts.json | 10 -- tests/res/in/testjob_equal.json | 10 -- tests/res/in/testjob_l.json | 22 ---- tests/res/in/testjob_m.json | 18 --- tests/res/in/testjob_zero_cuts.json | 10 -- tests/solver/data/test_Job.py | 24 ++-- tests/solver/data/test_Result.py | 53 +++++--- tests/solver/data/test_json.py | 6 +- tests/solver/test_large.py | 77 ++++++++---- tests/solver/test_solver.py | 18 ++- tests/solver/test_special.py | 54 ++++---- tests/test_fixtures.py | 25 ---- tests/test_main.py | 2 + 18 files changed, 312 insertions(+), 332 deletions(-) delete mode 100644 tests/res/in/testjob_cuts.json delete mode 100644 tests/res/in/testjob_equal.json delete mode 100644 tests/res/in/testjob_l.json delete mode 100644 tests/res/in/testjob_m.json delete mode 100644 tests/res/in/testjob_zero_cuts.json diff --git a/app/constants.py b/app/constants.py index de49de1..8f606c6 100644 --- a/app/constants.py +++ b/app/constants.py @@ -1,5 +1,19 @@ -version = "v1.0.0" +from pydantic import BaseModel -# solver parameter -n_max_precise = 9 # 10 takes 30s on a beefy desktop, 9 only 1.2s -n_max = 500 # around 1 million with n^2 +# used for git tags +version = "v1.0.1" + + +class SolverSettings(BaseModel): + bruteforce_max_combinations: int + n_max: int + + +# TODO should be startup parameter +solverSettings = SolverSettings( + # Desktop with Ryzen 2700X: + # (4, 3, 2)=1260 => 0.1s, (4, 3, 3)=4200 => 0.8s, (5, 3, 3)=9240 => 8s + bruteforce_max_combinations=5000, + # that is already unusable x100, but the solver takes it easily + n_max=2000 +) diff --git a/app/main.py b/app/main.py index bc75f42..a4e337f 100644 --- a/app/main.py +++ b/app/main.py @@ -6,8 +6,7 @@ from starlette.requests import Request from starlette.responses import HTMLResponse, PlainTextResponse -from app.constants import version, n_max_precise, n_max - +from app.constants import version, solverSettings # don't mark /app as a sources root or pycharm will delete the "app." prefix # that's needed for pytest to work correctly from app.solver.data.Job import Job @@ -84,15 +83,9 @@ def get_debug(): @app.get("/constants", response_class=HTMLResponse) -def get_debug(): - static_answer = ( - "Constants:" - "