pysal / region

A library for Spatially-Explicit Regionalization
BSD 3-Clause "New" or "Revised" License
14 stars 16 forks source link

Fix Tabu Local Searches in max-p #33

Closed renanxcortes closed 4 years ago

renanxcortes commented 4 years ago

Hello, everyone,

After digging deep into the code (by studying it and adding several print statements) to check what was happening, I managed to understand how each class is linked to each other.

This PR addresses directly https://github.com/pysal/region/issues/32 and https://github.com/pysal/region/issues/31 and fixes both issues.

So, the bugs were happening in the AZPBasicTabu and AZPReactiveTabu and are divided in two: "spatial constraints" and "threshold constraints". I explain here each solution:

Spatial constraints:

Threshold constraints:

Some extra comments:

Final comment:

After these fixes, I tried many scenarios and I didn't run into any weird solution. Therefore, I want to work with the Philosophy "Everyone is innocent until proven guilty". That is, I believe that max-p generates feasible solutions and it is innocent now unless someone raises an actual reproducible example with code with any of the issues that this PR attempts to solve. In this case, I'd be happy to help to try to solve it.

Best, Renan

renanxcortes commented 4 years ago

The last commit pushes a notebook (https://github.com/renanxcortes/region/blob/allow_strategy_inside_TabuClasses/region/notebooks/debug_code_MULTIPLE_TESTS.ipynb) showing that the approaches respect both issues in many different random selections and, therefore, reinforcing that these issues are fixed. I performed the tests in parallel.

This notebook can be deleted either in this PR before merging it or later.

sjsrey commented 4 years ago

Excellent work nailing these fixes!