PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ test_kmeans()

static void test_kmeans ( void  )
static

Definition at line 1728 of file cu_algorithm.c.

1729{
1730 static int cluster_size = 100;
1731 static int num_clusters = 4;
1732 static double spread = 1.5;
1733 int N = cluster_size * num_clusters;
1734 LWGEOM **geoms;
1735 int i, j, k=0;
1736 int *r;
1737
1738 geoms = lwalloc(sizeof(LWGEOM*) * N);
1739
1740 for (j = 0; j < num_clusters; j++) {
1741 for (i = 0; i < cluster_size; i++)
1742 {
1743 double u1 = 1.0 * rand() / RAND_MAX;
1744 double u2 = 1.0 * rand() / RAND_MAX;
1745 double z1 = spread * j + sqrt(-2*log2(u1))*cos(2*M_PI*u2);
1746 double z2 = spread * j + sqrt(-2*log2(u1))*sin(2*M_PI*u2);
1747
1748 LWPOINT *lwp = lwpoint_make2d(SRID_UNKNOWN, z1, z2);
1749 geoms[k++] = lwpoint_as_lwgeom(lwp);
1750 }
1751 }
1752
1753 r = lwgeom_cluster_kmeans((const LWGEOM **)geoms, N, num_clusters, 0.0);
1754
1755 // for (i = 0; i < k; i++)
1756 // {
1757 // printf("[%d] %s\n", r[i], lwgeom_to_ewkt(geoms[i]));
1758 // }
1759
1760 /* Clean up */
1761 lwfree(r);
1762 for (i = 0; i < k; i++)
1763 lwgeom_free(geoms[i]);
1764 lwfree(geoms);
1765
1766 return;
1767}
char * r
Definition cu_in_wkt.c:24
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition lwgeom.c:372
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
void * lwalloc(size_t size)
Definition lwutil.c:227
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:248
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
Definition lwpoint.c:163
#define SRID_UNKNOWN
Unknown SRID value.
Definition liblwgeom.h:215

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: