Distance Matrix Testing

Posted By : Abhinav Kumar Singh | 08-Jan-2025

Optaplanner

Loading...

Testing A planned Solution

Testing a planning module that integrates with Timefold presents an exciting challenge. My project focuses on making it easier and faster to manage field workers so businesses can provide better service with fewer resources. By leveraging Timefold technology and advanced algorithms, this system removes the complexity of scheduling and routing field workers and optimizes every step of the process. In this blog, I'll share my experience testing the results saved in the distance matrix of a planning module that leveraged Timefold as the core optimization engine.

What is Timefold/optaplanner

Timefold, an advanced version of OptaPlanner, is a powerful AI constraint solver widely used for solving optimization problems, including the field works routing and planning and the Traveling Salesman Problem (TSP). Its ability to handle fleet scheduling, whether for trucks, airplanes, or field workers, makes it an invaluable tool for enterprises seeking efficiency.


Understanding the Distance Matrix and Its Role

The distance matrix is a fundamental component of route optimization. It contains precomputed distances or times between various locations, serving as the foundation for route calculations. For example, in a field workforce scheduling scenario, the distance matrix helps Timefold determine the optimal sequence for workers to visit locations to minimize travel time or distance. Timefold's optimization process relies heavily on the accuracy of this matrix, as any deviation can lead to suboptimal or even incorrect planning results. Therefore, testing the data within the distance matrix was a critical part of the QA process.


Testing Strategy

The testing process ensured that the calculated distances and their integration with the module were accurate, consistent, and met the specified constraints.

My approach to testing the distance matrix data involved the following steps:

1. Data Verification

The first step was to validate the source data used to generate the distance matrix. This included:

  • Ensuring the accuracy of latitude and longitude coordinates for all locations.
  • Verifying the consistency of distance values generated by the map integration (Google Maps API in this case).
  • Confirming that travel modes (e.g., driving, walking, biking) matched the requirements.

2. Boundary Testing

I tested the system with edge cases to verify the module's resilience. For example:

  • Locations that were extremely far apart or within very close proximity.
  • Scenarios where some locations were inaccessible due to some obstacles or other constraints.
  • Invalid or missing coordinates.

3. Integration Testing with Timefold

Since Timefold integrates seamlessly with Java applications, I verified that the distance matrix data was correctly consumed and interpreted by the planning engine. This included:

  • Checking that constraints (e.g., Shortest distance, parking, nearest polygon first) were honoured.
  • Ensuring shadow variables and incremental score calculation were working as intended.
  • Verifying that the optimization results were consistent across multiple runs.

4. Performance and Scalability Testing

To ensure the module could handle real-world scenarios, I tested the system with:

  • Increasing numbers of locations to simulate large-scale operations.
  • Various constraints and objectives to evaluate the planner's adaptability.

5. Comparison Testing

I compared Timefold's results with manual calculations and alternative routing solutions to validate the accuracy and efficiency of the output. This helped identify any discrepancies in the routing logic.

Key Findings

During testing, I uncovered several insights:

  • The accuracy of the distance matrix is paramount. Small inaccuracies in distances led to noticeable deviations in the optimization results.
  • Timefold's incremental score calculation significantly improved performance when handling large datasets.
  • Real-time map integration with Google Maps ensured up-to-date routing information, but API limits and rate throttling needed careful handling.
  • The use of advanced heuristics and metaheuristics (such as Tabu Search and Simulated Annealing) allowed Timefold to find optimal or near-optimal solutions efficiently.

    Conclusion

    Testing the distance matrix and its integration with a planning module using Timefold was a rewarding experience. It highlighted the importance of accurate data, robust integration, and thorough validation in achieving reliable and efficient optimization results. Timefold's flexibility and power make it a fantastic choice for solving complex scheduling and routing problems, and as a QA, ensuring its outputs are trustworthy is a critical responsibility.
    I hope this blog provides valuable insights for other QAs working on similar projects. Feel free to share your thoughts or ask questions in the comments section!