Skip to content

Commit db4f4fa

Browse files
Merge pull request #25 from Ashrockzzz2003/24-bugs-in-integer-datatype-crossover-functions-algorithm-mu-lambda-strategy-random-range
Refactor docker-compose and enhance EA functions for bug fixes
2 parents 010afe8 + e82722f commit db4f4fa

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

docker-compose.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22
services:
33
runner_controller:
44
image: ghcr.io/evolutionary-algorithms-on-click/runner_controller_microservice:main
5+
# Comment the above line and uncomment the following lines
6+
# to build the image from the Dockerfile locally.
7+
# build:
8+
# context: .
9+
# dockerfile: Dockerfile
510
ports:
611
- "5002:5002"
712
environment:
813
DATABASE_URL : postgresql://root@host.docker.internal:26257/defaultdb?sslmode=disable
914
MINIO_ENDPOINT : host.docker.internal:9000
1015
MINIO_ACCESS_KEY_ID : <MINIO_ACCESS_KEY_ID>
1116
MINIO_SECRET_KEY : <MINIO_SECRET_KEY>
12-
RABBITMQ_URL : amqp://<user>:<password>@host.docker.internal:5672/
13-
FRONTEND_URL : http://host.docker.internal:3000
17+
RABBITMQ_URL : amqp://user:password@host.docker.internal:5672/
18+
FRONTEND_URL : http://localhost:3000
1419
HTTP_PORT : 5002
1520
AUTH_GRPC_ADDRESS : host.docker.internal:5001

modules/ea.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ func (ea *EA) validate() error {
5555
if err := util.ValidateAlgorithmName(ea.Algorithm); err != nil {
5656
return err
5757
}
58+
59+
// If randomrange not given or invalid, set to default.
60+
if len(ea.RandomRange) != 2 {
61+
ea.RandomRange = []float64{1, 5}
62+
} else if ea.RandomRange[0] >= ea.RandomRange[1] {
63+
ea.RandomRange = []float64{1, 5}
64+
}
65+
5866
// TODO: Validate remaining fields.
5967
return nil
6068
}
@@ -100,7 +108,7 @@ func (ea *EA) registerIndividual() string {
100108
case "floatingpoint":
101109
return fmt.Sprintf("toolbox.register(\"attr\", random.uniform, %f, %f)\n", ea.RandomRange[0], ea.RandomRange[1])
102110
case "integer":
103-
return fmt.Sprintf("toolbox.register(\"attr\", random.randint, %f, %f)\n", ea.RandomRange[0], ea.RandomRange[1])
111+
return fmt.Sprintf("toolbox.register(\"attr\", random.randint, %d, %d)\n", int(ea.RandomRange[0]), int(ea.RandomRange[1]))
104112
default:
105113
return ""
106114
}
@@ -190,6 +198,17 @@ func (ea *EA) plots() string {
190198
return plots
191199
}
192200

201+
func (ea *EA) crossoverFunction() string {
202+
switch ea.CrossoverFunction {
203+
case "cxUniform":
204+
return fmt.Sprintf("toolbox.register(\"mate\", tools.%s, indpb=%f)\n", ea.CrossoverFunction, ea.Indpb)
205+
case "cxUniformPartialyMatched":
206+
return fmt.Sprintf("toolbox.register(\"mate\", tools.%s, indpb=%f)\n", ea.CrossoverFunction, ea.Indpb)
207+
default:
208+
return fmt.Sprintf("toolbox.register(\"mate\", tools.%s)\n", ea.CrossoverFunction)
209+
}
210+
}
211+
193212
func (ea *EA) deCrossOverFunctions() string {
194213
return strings.Join([]string{
195214
"def cxBinomial(x, y, cr):",
@@ -336,9 +355,9 @@ func (ea *EA) Code() (string, error) {
336355
"\treturn y",
337356
}, "\n") + "\n\n"
338357
code += ea.deMutationFunction() + "\n\n"
358+
code += ea.deCrossOverFunctions() + "\n\n"
339359
}
340360

341-
code += ea.deCrossOverFunctions() + "\n\n"
342361
code += ea.CustomPop + "\n"
343362
code += ea.CustomMutation + "\n"
344363
code += ea.CustomSelection + "\n\n"
@@ -358,7 +377,7 @@ func (ea *EA) Code() (string, error) {
358377
code += fmt.Sprintf("F = %f\n", ea.ScalingFactor)
359378
code += fmt.Sprintf("toolbox.register(\"mate\", %s, cr=CR)\n", ea.CrossoverFunction)
360379
} else {
361-
code += fmt.Sprintf("toolbox.register(\"mate\", tools.%s)\n", ea.CrossoverFunction)
380+
code += ea.crossoverFunction() + "\n"
362381
}
363382
code += ea.selectionFunction() + "\n"
364383
code += "\ntoolbox.register(\"map\", futures.map)\n\n"

0 commit comments

Comments
 (0)