# spopt.region.MaxPHeuristic

class spopt.region.MaxPHeuristic(gdf, w, attrs_name, threshold_name, threshold, top_n=2, max_iterations_construction=99, max_iterations_sa=10, verbose=False, policy='single')

  The max-p-regions involves the aggregation of n areas into an unknown maximum number of homogeneous regions, while ensuring that each region is contiguious and satisfies a minimum threshold value imposed on a predefined spatially extensive attribute.

  Parameters:
    gdf `geopandas.GeoDataFrame`, required

      Geodataframe containing original data.

    w `libpysal.weights.W`, required

      Weights object created from given data.

    attrs_name `python:list`, required

      Strings for attribute names (cols of `geopandas.GeoDataFrame`).

    threshold_name `python:str`, required

      The name of the spatial extensive attribute variable.

    threshold{`python:int`, `python:float`}, required

      The threshold value.

    top_n `python:int`, required

      The number of top candidate regions to consider for enclave assignment.

    max_iterations_construction `python:int`

      Max number of iterations for construction phase.

    max_iterations_SA `python:int`

      Max number of iterations for customized simulated annealing.

    verbose bool

      Set to `True` for reporting solution progress/debugging. Default is `False`.

    policy `python:str`

      Defaults to `'single'` to attach infeasible components using a single linkage between the area in the infeasible component with the smallest nearest neighbor distance to an area in a feasible component. `'multiple'` adds joins for each area in an infeasible component and their nearest neighbor area in a feasible component. `'keep'` attempts to solve without modification (useful for debugging). `'drop'` removes areas in infeasible components before solving.

  Attributes:
    max_p `python:int`

      The number of regions.

    labels_`numpy.array`

      Region IDs for observations.

  Examples

      >>> import numpy
      >>> import libpysal
      >>> import geopandas as gpd
      >>> from spopt.region.maxp import MaxPHeuristic

  Read the data.

      >>> pth = libpysal.examples.get_path("mexicojoin.shp")
      >>> mexico = gpd.read_file(pth)
      >>> mexico["count"] = 1

  Create the weight.

      >>> w = libpysal.weights.Queen.from_dataframe(mexico)

  Define the columns of `geopandas.GeoDataFrame` to be spatially extensive attribute.

      >>> attrs_name = [f"PCGDP{year}" for year in range(1950, 2010, 10)]

  Define the spatial extensive attribute variable and the threshold value.

      >>> threshold_name = "count"
      >>> threshold = 4

  Run the max-p-regions algorithm.

      >>> model = MaxPHeuristic(mexico, w, attrs_name, threshold_name, threshold)
      >>> model.solve()

  Get the number of regions and region IDs for unit areas.

      >>> model.p
      >>> model.labels_

  __init__(gdf, w, attrs_name, threshold_name, threshold, top_n=2, max_iterations_construction=99, max_iterations_sa=10, verbose=False, policy='single')

  Methods

  `__init__`(gdf, w, attrs_name, threshold_name, ...) |
  `solve`() | Solve a max-p-regions problem and get back the results.

  solve()

    Solve a max-p-regions problem and get back the results.