How thought-eater/tabu-search-tasf works
1. This repo has two main execution surfaces over the same core logic: a CLI entrypoint for long-running simulations/experiments, and a Spring Boot API for CRUD, route queries, simulation state, and solver control. Both sit on top of the same domain model and Tabu Search solver.
2. The architectural center is the logistics network model: airports, flights, shipment requests, route assignments, and complete solutions. Flights are mutable and shared across routes so capacity is tracked in-place; that makes resetLoads() and careful state management a required boundary before each solve/replan run.
3. Input data comes from real text files rather than synthetic generation. AirportsLoader, RealFlightLoader, and EnviosDataLoader parse aeropuertos.txt, planes_vuelo.txt, and the _envios_*.txt shipment files into the domain model. RealNetworkBuilder assembles these into the directed flight network used by the solver.
4. The solver subsystem is a Tabu Search implementation centered in TabuSearchSolver and configured by TabuSearchConfig. It builds an initial greedy solution, explores reroute neighborhoods, tracks forbidden moves in a tabu list, and periodically intensifies or diversifies the search. Replanning (replanify) is a special shorter run triggered by flight cancellations.
5. The solver’s key constraint is route feasibility against flight capacity and delivery deadlines. Fitness is a penalty-based objective: infeasible routes are worst, late deliveries are next, and delay magnitude is penalized after that. The objective and search behavior are tightly coupled to the mutable flight-load state.
6. Multi-day routing is handled inside the network layer by creating cached virtual next-day flight instances. That matters architecturally because capacity must be preserved across repeated route searches, not just on the original scheduled flights.
7. The CLI program in Main drives four simulation modes: E1 period simulation, E2 real-time replanning, E3 collapse simulation, and EXP batch experimentation. These modes differ mainly in time budget, randomness, request scaling, and whether cancellation events are injected, but they all use the same solver and network builder.
8. The API layer is organized by resource/controller boundaries: airports, flights, shipments, routes, simulation, and solver. Controllers return DTOs, not raw domain objects, and ApiMapper bridges between persistence/domain models and response/request shapes. CorsConfig and ApiExceptionHandler provide API cross-cutting behavior.
9. Persistence is database-backed and migration-driven. The migrations/ directory defines airports, flights, shipments, shipment-flight assignments, and solver control tables, with seed/adjustment migrations layered on top. The service/db package contains row/insert models plus SimulationDbRepository, which is the database access boundary used by the simulation and solver-control services.
10. ShipmentImportService, SimulationDataService, SolverState, and the service/solver package form the application/service layer. This is where imported shipments are turned into solver inputs, simulation status is tracked, and solver control settings are read or updated independently of the raw controllers.
11. Important repository-level boundaries are explicit: DTOs are separated from domain objects, loaders are separated from solver logic, and the persistence schema is separated from the in-memory graph. That separation is what makes the same codebase support both offline batch runs and interactive API-driven operations.
12. Tooling and deployment are lightweight but important: Java 17 + Maven are the primary runtime/build stack, Dockerfiles and compose.yaml support containerized execution, and scripts/init_db.sh suggests a database bootstrap path for the migration-driven persistence layer.
13. Tests are mostly integration-focused. There are controller/service/solver tests under src/test, plus a nonstandard smoke-test runner in src/main/java/pe/edu/pucp/tasf/test/RunnerTest.java, which indicates the project is validated by end-to-end execution against the real data files rather than isolated unit tests alone.
14. For an architecture diagram, the key flows are: text-file and DB inputs into loaders/repositories, loaders/builders into the shared logistics network, the network into the Tabu solver, and solver outputs back out to either CLI reports/CSV or API DTO responses. The mutable-flight state and database migration layer are the two most important implementation boundaries to reflect.
Main entry points: TabuSearchSolver.java Tabu solver · RoutesController.java API controllers · LogisticsNetwork.java Network model · TabuSolverOrchestratorService.java Solver orch
Components 19
CLI
Long-running simulation and experiment entrypoints
- Main · Runs E1, E2, E3, and EXP simulation modes
src/main/java/pe/edu/pucp/tasf/Main.java
API
Spring Boot controllers and HTTP-facing contracts
- API controllers · Airport, flight, shipment, routes, simulation, and solver endpoints
src/main/java/pe/edu/pucp/tasf/api/controller/RoutesController.java - DTO layer · HTTP-facing request and response shapes
src/main/java/pe/edu/pucp/tasf/api/dto/RoutesSolveResponse.java
Core model
Shared logistics network and tabu search solver
- Network model · Airports, flights, shipment requests, route assignments, and solutions
src/main/java/pe/edu/pucp/tasf/model/LogisticsNetwork.java - Flight state · Shared flight objects track in-place load across route searches
src/main/java/pe/edu/pucp/tasf/model/Flight.java - Route solution · Represents complete shipment routing and feasibility outcome
src/main/java/pe/edu/pucp/tasf/model/Solution.java - Tabu solver · Greedy init, tabu list, intensify/diversify, and replanning
src/main/java/pe/edu/pucp/tasf/algorithm/TabuSearchSolver.java - Solver config · Tuning and execution parameters for tabu search runs
src/main/java/pe/edu/pucp/tasf/algorithm/TabuSearchConfig.java
Inputs
Text-file loaders and network assembly
- Network builder · Builds the real logistics network from parsed inputs
src/main/java/pe/edu/pucp/tasf/util/RealNetworkBuilder.java - Text loaders · Parses airports, flights, and shipment text files
src/main/java/pe/edu/pucp/tasf/io/RealFlightLoader.java
Persistence
Database schema, rows, and repository boundary
- DB repo · Database boundary used by simulation and solver-control services
src/main/java/pe/edu/pucp/tasf/service/db/SimulationDbRepository.java - Migrations · Creates and seeds airports, flights, shipments, assignments, and solver control tables
migrations/0001_create_airports_table.up.sql
Services
Application services, orchestration, and mapping
- API mapper · Bridges domain, persistence, and DTO representations
src/main/java/pe/edu/pucp/tasf/service/ApiMapper.java - Simulation svc · Coordinates shipment import, simulation data, and state tracking
src/main/java/pe/edu/pucp/tasf/service/SimulationDataService.java - Import service · Turns shipment text data into solver-ready records
src/main/java/pe/edu/pucp/tasf/service/ShipmentImportService.java - Solver orch · Runs solver workflows from API and simulation control
src/main/java/pe/edu/pucp/tasf/service/solver/TabuSolverOrchestratorService.java - Solver state · Tracks solver control status independent of controllers
src/main/java/pe/edu/pucp/tasf/service/SolverState.java
Ops
Containerization, database bootstrap, and testing
- Runtime ops · Containerization and database initialization support
Dockerfile - Tests · Controller, service, and solver integration coverage plus smoke runner
src/test/java/pe/edu/pucp/tasf/api/controller/RoutesControllerIntegrationTest.java
Connections 24
- Main → Network builder: builds network · CLI modes assemble the real network before solving
- Main → Tabu solver: runs solver · Simulation modes invoke the shared tabu search engine
- Text loaders → Network builder: parsed by · Text files are parsed into domain inputs consumed by the builder
- Network builder → Network model: creates · Builder assembles the logistics network graph
- Network model → Flight state: contains · Network owns shared flight instances with mutable loads
- Network model → Route solution: yields · Solver works over complete solution objects
- Tabu solver → Solver config: configured by · Search behavior comes from TabuSearchConfig
- Tabu solver → Network model: searches · Solver explores routes within the logistics network
- Tabu solver → Route solution: produces · Solver returns feasible or penalized route solutions
- Tabu solver → Flight state: updates capacity · Search mutates flight loads and requires resets before reruns
- API controllers → DTO layer: returns · Controllers expose DTOs instead of raw domain objects
- API controllers → API mapper: uses · HTTP resources delegate object conversion to the mapper
- API controllers → Solver orch: coordinates · Route and solver endpoints trigger orchestration workflows
- API controllers → Simulation svc: queries · Simulation endpoints read current simulation state
- API mapper → Network model: maps domain · Mapper bridges network and shipment representations
- Simulation svc → Import service: imports · Simulation layer ingests shipment files into records
- Simulation svc → Solver state: tracks · Service maintains solver/control status
- Solver orch → Tabu solver: executes · Orchestrator invokes tabu search and replanning runs
- Solver orch → DB repo: reads/writes · Solver control and simulation outcomes use the DB boundary
- DB repo → Migrations: backed by · Repository operates on the migrated schema
- Runtime ops → Migrations: boots db · Bootstrap scripts support migration-driven initialization
- Tests → API controllers: covers · Integration tests exercise controller boundaries
- Tests → Solver orch: covers · Tests validate solver orchestration behavior
- Tests → Main: covers · Smoke runner and end-to-end executions validate CLI flows