Skip to contents

This algorithm tries to transform an unfeasible solution that check connectivity constraint but not one or more size constraints. Even if the problem is feasible the algorithm doesn't ensure to succeed. [Experimental]

Usage

resolve_unfeasible(
  distances = NULL,
  contiguity = NULL,
  sizes = NULL,
  d = NULL,
  data = NULL,
  m = 0,
  M = Inf,
  standardQuant = FALSE,
  binarQual = FALSE,
  regionalisation,
  maxItTransfers = Inf,
  verbose = FALSE,
  ...
)

Arguments

distances

The distance matrix of the problem. This can be omitted if a distance function d and data context data are provided. If only distances is provided, all distances must be present. (distance matrix)

contiguity

A contiguity matrix or an igraph contiguity graph. If not provided, the problem is considered completely contiguous (all elements are neighbors of each other).

sizes

Represents the size of each element. By default, it is set to 1 for each element (the size of a cluster becomes its cardinal). All data must be positive or zero. (positive real numeric vector)

d

Distance function between elements. This can be omitted if distances is already indicated. If present, data must also be specified. Some classical distances are available, it is recommended to use them rather than a personal function for optimisation reasons :

  • "euclidean": Euclidean distance.

  • "manhattan" : Manhattan distance.

  • "minkowski" : Minkowski's distance. In that case a value for p >= 1 must be specified.

(function or string)

data

A data.frame where each row represents data related to an element. This can be omitted if d is omitted. Present variables can be quantitative or qualitative. If qualitative variables are present, some distances may not be used. Possibility of standardising variables and transforming qualitative variables into binary variables (one-hot encoding) using standardQuant and binarQual. (data.frame)

m

Minimum size constraint. Must be positive or zero and small enough for the problem to be feasible. Default is 0 (no constraint). (positive number)

M

Maximum size constraint. Must be positive, superior or equal to m and large enough for the problem to be feasible. Default is Inf (no constraint). (positive number)

standardQuant

TRUE if the variables in data should be standardised (i.e., centered and scaled), FALSE (default) otherwise. Standardisation is applied after the possible binarization of qualitative variables (see binarQual). (flag)

binarQual

TRUE if qualitative variables should be binarized (one-hot encoding), for example, to make the data set compatible with common distances or to standardize these variables. FALSE (default) otherwise. (flag)

regionalisation

A partition checking the contiguity constraint but not checking at least the min or the max size constraint.

maxItTransfers

positive integer indicating the maximum number of elements can be transferred.

verbose

Logical indicating whether to display progress messages. Default is TRUE.

...

used for development.

Examples

set.seed(123L)
grid  <- simple_grid(4L, 5L)
data <- grid$context
sizes <- grid$repartition$nbIndividuals
contiguity <- grid$contiguity

m <- 200.0
M <- 800.0

d <- "euclidean"

unfeasibleSolution <-
  c(1L, 2L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 4L,
    4L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L)

resolve_unfeasible(contiguity = contiguity,
                   sizes = sizes,
                   data = data,
                   d = d, m = m, M = M,
                   regionalisation = unfeasibleSolution,
                   verbose = FALSE)
#> $status
#> [1] "fully_resolved"
#> 
#> $itTransfers
#> [1] 6
#> 
#> $itFusions
#> [1] 0
#> 
#> $initialSmallRegions
#> [1] 1 3
#> 
#> $finalSmallRegions
#> NULL
#> 
#> $initialBigRegions
#> [1] 2 4
#> 
#> $finalBigRegions
#> NULL
#> 
#> $resolvedRegions
#> [1] 2 3 4 1
#> 
#> $initialRegionsSizes
#>   1   2   3   4 
#>  89 811 103 997 
#> 
#> $finalRegionsSizes
#>   1   2   3   4 
#> 315 727 274 684 
#> 
#> $regionalisation
#>  [1] 1 2 2 2 1 3 3 3 3 1 4 3 3 4 4 4 3 4 4 4
#> 
#> $initialNbClusters
#> [1] 4
#> 
#> $finalNbClusters
#> [1] 4
#>