Learn R Programming

rgeoda (version 0.0.6)

maxp_sa: A simulated annealing algorithm to solve the max-p-region problem

Description

The max-p-region problem is a special case of constrained clustering where a finite number of geographical areas are aggregated into the maximum number of regions (max-p-regions), such that each region is geographically connected and the clusters could maximize internal homogeneity.

Usage

maxp_sa(
  w,
  data,
  bound_vals,
  min_bound,
  cooling_rate,
  sa_maxit = 1,
  iterations = 99,
  initial_regions = vector("numeric"),
  distance_method = "euclidean",
  random_seed = 123456789,
  cpu_threads = 6
)

Arguments

w

An instance of Weight class

data

A list of numeric vectors of selected variable

bound_vals

A numeric vector of selected bounding variable

min_bound

A minimum value that the sum value of bounding variable int each cluster should be greater than

cooling_rate

The cooling rate of a simulated annealing algorithm. Defaults to 0.85

sa_maxit

(optional): The number of iterations of simulated annealing. Defaults to 1

iterations

(optional): The number of iterations of SA algorithm. Defaults to 99.

initial_regions

(optional): The initial regions that the local search starts with. Default is empty. means the local search starts with a random process to "grow" clusters

distance_method

(optional) The distance method used to compute the distance betwen observation i and j. Defaults to "euclidean". Options are "euclidean" and "manhattan"

random_seed

(optional) The seed for random number generator. Defaults to 123456789.

cpu_threads

(optional) The number of cpu threads used for parallel computation

Value

A list of numeric vectors represents a group of clusters

Examples

Run this code
# NOT RUN {
guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda")
guerry <- geoda_open(guerry_path)
queen_w <- queen_weights(guerry)
guerry_df <- as.data.frame(guerry) # use as data.frame
data <- guerry_df[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')]
bound_vals <- guerry_df['Pop1831'][,1]
min_bound <- 3236.67 # 10% of Pop1831
maxp_clusters <- maxp_sa(queen_w, data, bound_vals, min_bound, cooling_rate=0.85, sa_maxit=1)
maxp_clusters
# }

Run the code above in your browser using DataLab