summaryrefslogtreecommitdiffstats
path: root/src/backend/optimizer/geqo/geqo_mutation.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:17:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:17:33 +0000
commit5e45211a64149b3c659b90ff2de6fa982a5a93ed (patch)
tree739caf8c461053357daa9f162bef34516c7bf452 /src/backend/optimizer/geqo/geqo_mutation.c
parentInitial commit. (diff)
downloadpostgresql-15-5e45211a64149b3c659b90ff2de6fa982a5a93ed.tar.xz
postgresql-15-5e45211a64149b3c659b90ff2de6fa982a5a93ed.zip
Adding upstream version 15.5.upstream/15.5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/backend/optimizer/geqo/geqo_mutation.c')
-rw-r--r--src/backend/optimizer/geqo/geqo_mutation.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/backend/optimizer/geqo/geqo_mutation.c b/src/backend/optimizer/geqo/geqo_mutation.c
new file mode 100644
index 0000000..2af0295
--- /dev/null
+++ b/src/backend/optimizer/geqo/geqo_mutation.c
@@ -0,0 +1,66 @@
+/*------------------------------------------------------------------------
+*
+* geqo_mutation.c
+*
+* TSP mutation routines
+*
+* src/backend/optimizer/geqo/geqo_mutation.c
+*
+*-------------------------------------------------------------------------
+*/
+
+/* contributed by:
+ =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
+ * Martin Utesch * Institute of Automatic Control *
+ = = University of Mining and Technology =
+ * utesch@aut.tu-freiberg.de * Freiberg, Germany *
+ =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
+ */
+
+/* this is adopted from Genitor : */
+/*************************************************************/
+/* */
+/* Copyright (c) 1990 */
+/* Darrell L. Whitley */
+/* Computer Science Department */
+/* Colorado State University */
+/* */
+/* Permission is hereby granted to copy all or any part of */
+/* this program for free distribution. The author's name */
+/* and this copyright notice must be included in any copy. */
+/* */
+/*************************************************************/
+
+#include "postgres.h"
+#include "optimizer/geqo_mutation.h"
+#include "optimizer/geqo_random.h"
+
+#if defined(CX) /* currently used only in CX mode */
+
+void
+geqo_mutation(PlannerInfo *root, Gene *tour, int num_gene)
+{
+ int swap1;
+ int swap2;
+ int num_swaps = geqo_randint(root, num_gene / 3, 0);
+ Gene temp;
+
+
+ while (num_swaps > 0)
+ {
+ swap1 = geqo_randint(root, num_gene - 1, 0);
+ swap2 = geqo_randint(root, num_gene - 1, 0);
+
+ while (swap1 == swap2)
+ swap2 = geqo_randint(root, num_gene - 1, 0);
+
+ temp = tour[swap1];
+ tour[swap1] = tour[swap2];
+ tour[swap2] = temp;
+
+
+ num_swaps -= 1;
+ }
+}
+
+#endif /* defined(CX) */