PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ test_kmeans()

static void test_kmeans ( void  )
static

Definition at line 1721 of file cu_algorithm.c.

1722 {
1723  static int cluster_size = 100;
1724  static int num_clusters = 4;
1725  static double spread = 1.5;
1726  int N = cluster_size * num_clusters;
1727  LWGEOM **geoms;
1728  int i, j, k=0;
1729  int *r;
1730 
1731  geoms = lwalloc(sizeof(LWGEOM*) * N);
1732 
1733  for (j = 0; j < num_clusters; j++) {
1734  for (i = 0; i < cluster_size; i++)
1735  {
1736  double u1 = 1.0 * rand() / RAND_MAX;
1737  double u2 = 1.0 * rand() / RAND_MAX;
1738  double z1 = spread * j + sqrt(-2*log2(u1))*cos(2*M_PI*u2);
1739  double z2 = spread * j + sqrt(-2*log2(u1))*sin(2*M_PI*u2);
1740 
1741  LWPOINT *lwp = lwpoint_make2d(SRID_UNKNOWN, z1, z2);
1742  geoms[k++] = lwpoint_as_lwgeom(lwp);
1743  }
1744  }
1745 
1746  r = lwgeom_cluster_kmeans((const LWGEOM **)geoms, N, num_clusters, 0.0);
1747 
1748  // for (i = 0; i < k; i++)
1749  // {
1750  // printf("[%d] %s\n", r[i], lwgeom_to_ewkt(geoms[i]));
1751  // }
1752 
1753  /* Clean up */
1754  lwfree(r);
1755  for (i = 0; i < k; i++)
1756  lwgeom_free(geoms[i]);
1757  lwfree(geoms);
1758 
1759  return;
1760 }
char * r
Definition: cu_in_wkt.c:24
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
Definition: lwpoint.c:163
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
int * lwgeom_cluster_kmeans(const LWGEOM **geoms, uint32_t n, uint32_t k, double max_radius)
Take a list of LWGEOMs and a number of clusters and return an integer array indicating which cluster ...
Definition: lwkmeans.c:321
void lwfree(void *mem)
Definition: lwutil.c:242
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:344
void * lwalloc(size_t size)
Definition: lwutil.c:227
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:230

References lwalloc(), lwfree(), lwgeom_cluster_kmeans(), lwgeom_free(), lwpoint_as_lwgeom(), lwpoint_make2d(), r, and SRID_UNKNOWN.

Referenced by algorithms_suite_setup().

Here is the call graph for this function:
Here is the caller graph for this function: