From 44720f8b8932d3c968abc8c61d4335e81a82e7ce Mon Sep 17 00:00:00 2001 From: "Bernhard J. Berger" <bernhard.berger@uni-bremen.de> Date: Fri, 21 Apr 2023 23:19:20 +0200 Subject: [PATCH] Fixed unit tests. --- ci/create-release.sh | 7 +- .../search/EvolutionaryAlgorithmSearch.java | 2 +- .../META-INF/definitions/data/constraints.dl | 13 - .../META-INF/definitions/data/si-units.ddl | 67 --- .../META-INF/definitions/optimisation/core.dl | 434 ------------------ .../src/main/resources/de/evoal/core/ea.dl | 201 ++++++++ .../evoal/core/api/utils/LanguageHelper.java | 6 +- .../META-INF/definitions/data/constraints.dl | 13 - .../META-INF/definitions/data/si-units.ddl | 67 --- .../META-INF/definitions/optimisation/core.dl | 434 ------------------ .../src/main/resources/de/evoal/core.dl | 346 ++++++++++++++ .../resources/de/evoal/core/constraints.dl | 15 + .../src/main/resources/de/evoal/core/si.ddl | 67 +++ .../utils/LanguageHelperRegressionTest.java | 2 - .../api/utils/LanguageHelperUnitTest.java | 33 +- .../core/api/utils/LanguageHelperTest.ol | 9 +- .../de/evoal/core/api/utils/definitions.dl | 2 +- .../META-INF/definitions/generator/main.dl | 250 ---------- .../src/main/resources/de/evoal/benchmark.dl | 11 + .../src/main/resources/de/evoal/generator.dl | 253 ++++++++++ 20 files changed, 925 insertions(+), 1307 deletions(-) delete mode 100644 src/core/de.evoal.core.ea/src/main/resources/META-INF/definitions/data/constraints.dl delete mode 100644 src/core/de.evoal.core.ea/src/main/resources/META-INF/definitions/data/si-units.ddl delete mode 100644 src/core/de.evoal.core.ea/src/main/resources/META-INF/definitions/optimisation/core.dl create mode 100644 src/core/de.evoal.core.ea/src/main/resources/de/evoal/core/ea.dl delete mode 100644 src/core/de.evoal.core.main/src/main/resources/META-INF/definitions/data/constraints.dl delete mode 100644 src/core/de.evoal.core.main/src/main/resources/META-INF/definitions/data/si-units.ddl delete mode 100644 src/core/de.evoal.core.main/src/main/resources/META-INF/definitions/optimisation/core.dl create mode 100644 src/core/de.evoal.core.main/src/main/resources/de/evoal/core.dl create mode 100644 src/core/de.evoal.core.main/src/main/resources/de/evoal/core/constraints.dl create mode 100644 src/core/de.evoal.core.main/src/main/resources/de/evoal/core/si.ddl delete mode 100644 src/core/de.evoal.generator.main/src/main/resources/META-INF/definitions/generator/main.dl create mode 100644 src/core/de.evoal.generator.main/src/main/resources/de/evoal/benchmark.dl create mode 100644 src/core/de.evoal.generator.main/src/main/resources/de/evoal/generator.dl diff --git a/ci/create-release.sh b/ci/create-release.sh index 211e2796..b8bb8189 100755 --- a/ci/create-release.sh +++ b/ci/create-release.sh @@ -1,9 +1,13 @@ #!/bin/bash -set -e -x + + + RELEASE_PLUGINS="generator.main surrogate.api surrogate.simple surrogate.svr approximative.density core.arff core.ea" + +rm -rf evoal mkdir -p evoal/plugins cp src/languages/de.evoal.languages.releng.site/target/de.evoal.languages.releng.site-*.zip "evoal/eclipse-update-site.zip" @@ -18,6 +22,7 @@ done rm evoal/modules/javax.inject* rm evoal/modules/javax.annotation-api-* rm evoal/modules/jsr305-* + # remove multiple definitions of CDI stuff rm evoal/modules/jboss-annotations-api* rm evoal/modules/jboss-interceptors-api* diff --git a/src/core/de.evoal.core.ea/src/main/java/de/evoal/core/ea/main/search/EvolutionaryAlgorithmSearch.java b/src/core/de.evoal.core.ea/src/main/java/de/evoal/core/ea/main/search/EvolutionaryAlgorithmSearch.java index 9870a088..f7787e6f 100644 --- a/src/core/de.evoal.core.ea/src/main/java/de/evoal/core/ea/main/search/EvolutionaryAlgorithmSearch.java +++ b/src/core/de.evoal.core.ea/src/main/java/de/evoal/core/ea/main/search/EvolutionaryAlgorithmSearch.java @@ -147,7 +147,7 @@ public class EvolutionaryAlgorithmSearch implements OptimisationAlgorithm { private void setup() { final OptimisationModel configuration = board.get(CoreBlackboardEntries.OPTIMISATION_CONFIGURATION); - final de.evoal.languages.model.base.Instance alterers = LanguageHelper.lookup(configuration.getAlgorithm().getAlgorithm(), "alterers"); + final de.evoal.languages.model.base.Instance alterers = LanguageHelper.lookup(configuration.getAlgorithm().getInstance(), "alterers"); for(final Attribute category: alterers.getAttributes()) { final String name = category.getDefinition().getName(); diff --git a/src/core/de.evoal.core.ea/src/main/resources/META-INF/definitions/data/constraints.dl b/src/core/de.evoal.core.ea/src/main/resources/META-INF/definitions/data/constraints.dl deleted file mode 100644 index 1ba8690e..00000000 --- a/src/core/de.evoal.core.ea/src/main/resources/META-INF/definitions/data/constraints.dl +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Sets the variance of some data. - * - * <b>Parameters:</b> - * <ol> - * <li>Reference to the data ...</li> - * </ol> - */ -def void variance(data reference, float variance); - -def void connection(data ref1, data ref2, float connection); - -def void constraint(expression exp, string category); diff --git a/src/core/de.evoal.core.ea/src/main/resources/META-INF/definitions/data/si-units.ddl b/src/core/de.evoal.core.ea/src/main/resources/META-INF/definitions/data/si-units.ddl deleted file mode 100644 index b7e8f297..00000000 --- a/src/core/de.evoal.core.ea/src/main/resources/META-INF/definitions/data/si-units.ddl +++ /dev/null @@ -1,67 +0,0 @@ -types: - cardinal type Newton description : "SI-Unit for force, measure in Newton[N=kg*m/s*s]." - with constraints: - value >= 0.0; - ; - - quotient type Meter description: "SI-Unit for lengths, measured in metres[m]." - with constraints: - value >= 0.0; - ; - - quotient type Second description: "SI-Unit for time, measured in seconds[s]." - with constraints: - value >= 0.0; - ; - - quotient type Kilogram description: "SI-Unit for mass, measured in kilogram[kg]." - with constraints: - value >= 0.0; - ; - - quotient type Ampere description: "SI-Unit for eletric current, measured in ampere[A]." - with constraints: - value >= 0.0; - ; - - quotient type Kelvin description: "SI-Unit for thermodynamic temperature, measured in kelvin[K]." - with constraints: - value >= 0.0; - ; - - quotient type Mole description: "SI-Unit for amount of substance, measure in mole[mol]." - with constraints: - value >= 0.0; - ; - - quotient type Candela description: "SI-Unit for luminous intensity, measured in candela[cd]." - with constraints: - value >= 0.0; - ; - - quotient type Hertz description: "SI-Unit for frequency, measured in hertz[Hz=1/s]." - with constraints: - value >= 0.0; - ; - - quotient type Speed description: "SI-Unit for frequency, measured in metre per second[m/s]." - with constraints: - value >= 0.0; - ; - - quotient type Pascal description: "SI-Unit for pressure, measure in Pascal[Pa=kg/m*s*s]." - with constraints: - value >= 0.0; - ; - - cardinal type Celsius description: "SI-Unit for temperature relative to 273.15 K, measured in Celsius[°C=K]" - with constraints: - value >= -273.15; - ; - - quotient type Area description: "SI-Unit for areas, measured in square meter[m*m]" - with constraints: - value >= 0.0; - ; - - \ No newline at end of file diff --git a/src/core/de.evoal.core.ea/src/main/resources/META-INF/definitions/optimisation/core.dl b/src/core/de.evoal.core.ea/src/main/resources/META-INF/definitions/optimisation/core.dl deleted file mode 100644 index 91189620..00000000 --- a/src/core/de.evoal.core.ea/src/main/resources/META-INF/definitions/optimisation/core.dl +++ /dev/null @@ -1,434 +0,0 @@ -/** - * Root element for an evolutionary algorithm configuration. - */ -type configuration { - /** - * A freely selectable name for the configuration. - */ - name : string; - - /** - * The algorithm configuration. - */ - algorithm : instance algorithm; - - /** - * Configuration of statistics to measure and to write. - */ - statistics : instance statistics; -} - -abstract type algorithm {} - -type 'evolutionary-algorithm' extends 'algorithm' { - 'number-of-generations' : int; - 'size-of-population' : int; - 'maximum-age' : int; - maximize : boolean; - - genotype : array instance chromosome; - - initialization : instance 'initial-population'; - handlers : array instance 'handler'; - selectors : instance selectors; - alterers : instance alterers; - - fitness : instance 'fitness-function'; - comparator : instance comparator; -} - -abstract type chromosome { - genes : array instance gene; -} - -type 'bit-chromosome' extends chromosome { - scale : int; -} - -type 'gray-chromosome' extends 'bit-chromosome' { - scale : int; -} - -type 'double-chromosome' extends chromosome { -} - -type 'integer-chromosome' extends chromosome { -} - -type gene { content : data; } - -abstract type comparator {} - -type 'weighted-sum' extends comparator { - weights : array float; -} - -type pareto extends comparator { -} - -/** - * Abstract base class for functions to map the individual to the target values. - */ -abstract type 'fitness-function' {} - -/** - * Abstract base class for all fitness functions that call a subsequent fitness function during calculation. - */ -abstract type 'decorated-fitness-function' extends 'fitness-function' { - /** - * Fitness function we are calling during the fitness calculation. - */ - function : instance 'fitness-function'; -} - -type 'malus' extends 'decorated-fitness-function' { -} - -/** - * Fitness function that calculates the difference between a fitness value and a - * target value to optimize to:<br/> - * - * <mathml> - * <math> - * <mrow> - * <mi>f</mi> - * <mi>i</mi> - * <mi>t</mi> - * <mi>n</mi> - * <mi>e</mi> - * <mi>s</mi> - * <mi>s</mi> - * <mo>=</mo> - * <mi>f</mi> - * <mi>u</mi> - * <mi>n</mi> - * <mi>c</mi> - * <mi>t</mi> - * <mi>i</mi> - * <mi>o</mi> - * <mi>n</mi> - * <mo form="prefix" stretchy="false">(</mo> - * <mi>i</mi> - * <mi>n</mi> - * <mi>d</mi> - * <mo form="postfix" stretchy="false">)</mo> - * <mo>−</mo> - * <mi>t</mi> - * <mi>a</mi> - * <mi>r</mi> - * <mi>g</mi> - * <mi>e</mi> - * <mi>t</mi> - * </mrow> - * </math> - * </mathml> - */ -type distance extends 'decorated-fitness-function' { - target : array instance variable; -} - -type variable { - name : data; - val : literal; -} - -abstract type 'goal-function' extends 'fitness-function' { - 'maps-to' : array data; -} - -/** - * Calculating fitness value by using a surrogate function:<br/> - * - * <mathml> - * <math> - * <mrow> - * <mi>f</mi> - * <mi>i</mi> - * <mi>t</mi> - * <mi>n</mi> - * <mi>e</mi> - * <mi>s</mi> - * <mi>s</mi> - * <mo>=</mo> - * <mi>s</mi> - * <mi>u</mi> - * <mi>r</mi> - * <mi>r</mi> - * <mi>o</mi> - * <mi>g</mi> - * <mi>a</mi> - * <mi>t</mi> - * <mi>e</mi> - * <mo form="prefix" stretchy="false">(</mo> - * <mi>i</mi> - * <mi>n</mi> - * <mi>d</mi> - * <mo form="postfix" stretchy="false">)</mo> - * </mrow> - * </math> - * </mathml> - */ -type surrogate extends 'goal-function' { -} - -/** - * Calculating fitness value by using a known function:<br/> - * - * <mathml> - * <math> - * <mrow> - * <mi>f</mi> - * <mi>i</mi> - * <mi>t</mi> - * <mi>n</mi> - * <mi>e</mi> - * <mi>s</mi> - * <mi>s</mi> - * <mo>=</mo> - * <mi>n</mi> - * <mi>o</mi> - * <mi>r</mi> - * <mi>m</mi> - * <mi>a</mi> - * <mi>l</mi> - * <mo form="prefix" stretchy="false">(</mo> - * <mi>i</mi> - * <mi>n</mi> - * <mi>d</mi> - * <mo form="postfix" stretchy="false">)</mo> - * </mrow> - * </math> - * </mathml> - */ -type normal extends 'fitness-function' { -} - -abstract type 'initial-population' {} - -type 'random-population' extends 'initial-population' { -} - -abstract type handler {} - -type 'constraint-handler' extends handler { - category : string; - calculation : instance normal | 'standard-deviation'; - 'constraint-handling' : instance 'kill-at-birth' | 'malus-for-fitness'; -} - -type 'standard-deviation' { - factor : float; -} - -type 'kill-at-birth' { - 'repair-strategy' : instance 'repair-strategy'; -} - -abstract type 'repair-strategy' {} - -type 'repair-with-random' extends 'repair-strategy' {} - -type 'malus-for-fitness' { - smoothing : float; -} - -type selectors { - survivor : instance selector; - offspring : instance selector; -} - -abstract type selector { -} - -type 'elite-selector' extends selector { - 'size-factor' : float; - 'non-elite-selector' : instance selector; -} - -type 'boltzmann-selector' extends selector { - beta : float; -} - -type 'exponential-rank-selector' extends selector { -} - -type 'linear-rank-selector' extends selector { - nminus : int; -} - -type 'monte-carlo-selector' extends selector { -} - -type 'probability-selector' extends selector { -} - -type 'stochastic-universal-selector' extends selector { -} - -type 'tournament-selector' extends selector { - 'size-factor' : float; -} - -type 'truncation-selector' extends selector { - 'worst-rank' : int; -} - -type alterers { - crossover : array instance crossover; - mutator : array instance mutator ; -} - -abstract type crossover {} - -type 'mean-alterer' extends crossover { - probability : float; -} - -type 'correlation-mean-alterer' extends crossover { - probability : float; -} - -type 'partial-matched-alterer' extends crossover { - probability : float; -} - -type 'correlation-partial-matched-alterer' extends crossover { - probability : float; -} - -type 'line-crossover' extends crossover { - probability : float; - position : float; -} - -type 'correlation-line-crossover' extends crossover { - probability : float; - position : float; -} - -type 'multi-point-crossover' extends crossover { - probability : float; - count : int; -} - -type 'correlation-multi-point-crossover' extends crossover { - probability : float; - count : int; -} - -type 'single-point-crossover' extends crossover { - probability : float; -} - -type 'correlation-single-point-crossover' extends crossover { - probability : float; -} - -type 'uniform-crossover' extends crossover { - 'crossover-probability' : float; - 'swap-probability' : float; -} - -type 'correlation-uniform-crossover' extends crossover { - 'crossover-probability' : float; - 'swap-probability' : float; -} - -abstract type mutator { -} - -type 'gaussian-mutator' extends mutator { - probability : float; -} - -type 'correlation-gaussian-mutator' extends mutator { - probability : float; - threshold : float; -} - -type 'swap-mutator' extends mutator { - probability : float; -} - -type 'correlation-swap-mutator' extends mutator { - probability : float; - threshold : float; -} - -type 'bit-flip-mutator' extends mutator { - probability : float; -} - -type 'correlation-bit-flip-mutator' extends mutator { - probability : float; - threshold : float; -} - -type statistics { - writer : array instance 'statistics-writer'; -} - -abstract type 'statistics-writer' { -} - -/** - * Creates a file named '<tt>constraint-statistics.csv</tt>' containing - * information on each generation and constraint violations: - * - * <ul> - * <li>generation</li> - * <li>for each constraint: - * <ul> - * <li>number of violating individuals</li> - * <li>sum of differences</li> - * <li>min of differences</li> - * <li>avg of differences</li> - * <li>max of differences</li> - * </ul> - * </li> - * </ul> - */ -type 'constraint-statistics' extends 'statistics-writer' {} - -/** - * Creates a file named '<tt>fitness-by-individual.csv</tt>' containing for each individual - * of each generation the following information: - * - * <ul> - * <li>generation</li> - * <li>index of individual</li> - * <li>fitness value of each predicted value of the individual</li> - * </ul> - */ -type 'fitness-per-individual' extends 'statistics-writer' {} - -/** - * Creates a file named '<tt>individuals.csv</tt>' containing for each individual - * the following information: - * - * <ul> - * <li>generation</li> - * <li>index of individual</li> - * <li>text representation of individual</li> - * <li>age</li> - * <li>each property value of the individual</li> - * </ul> - */ -type individuals extends 'statistics-writer' {} - -/** - * Does not write any statistics. Can be used to disable statistics output. - */ -type none extends 'statistics-writer' {} - -/** - * Creates a file named '<tt>prediction-by-individual.csv</tt>' containing the - * predicted value(s) of each individual for each generation of the EA run: - * - * <ul> - * <li>generation</li> - * <li>index of individual</li> - * <li>each predicted value of the individual</li> - * </ul> - */ -type 'prediction-per-individual' extends 'statistics-writer' {} diff --git a/src/core/de.evoal.core.ea/src/main/resources/de/evoal/core/ea.dl b/src/core/de.evoal.core.ea/src/main/resources/de/evoal/core/ea.dl new file mode 100644 index 00000000..e35a4a30 --- /dev/null +++ b/src/core/de.evoal.core.ea/src/main/resources/de/evoal/core/ea.dl @@ -0,0 +1,201 @@ +import "definitions" from de.evoal.core; + +module de.evoal.core.ea { + type 'evolutionary-algorithm' extends 'algorithm' { + 'number-of-generations' : int; + 'size-of-population' : int; + 'maximum-age' : int; + + genotype : array instance chromosome; + + handlers : array instance 'handler'; + selectors : instance selectors; + alterers : instance alterers; + + fitness : instance 'optimisation-function'; + } + + abstract type chromosome { + genes : array instance gene; + } + + type 'bit-chromosome' extends chromosome { + scale : int; + } + + type 'gray-chromosome' extends 'bit-chromosome' { + scale : int; + } + + type 'double-chromosome' extends chromosome { + } + + type 'integer-chromosome' extends chromosome { + } + + type gene { content : data; } + + type pareto extends comparator { + } + + abstract type handler {} + + type 'constraint-handler' extends handler { + category : string; + calculation : instance 'constraint-calculation'; + 'constraint-handling' : instance 'constraint-handling'; + } + + abstract type 'constraint-calculation' { + } + + type 'standard-deviation' extends 'constraint-calculation' { + factor : float; + } + + abstract type 'constraint-handling' {} + + type 'kill-at-birth' extends 'constraint-handling'{ + 'repair-strategy' : instance 'repair-strategy'; + } + + abstract type 'repair-strategy' {} + + type 'repair-with-random' extends 'repair-strategy' {} + + type 'malus-for-fitness' extends 'constraint-handling' { + smoothing : float; + } + + type selectors { + survivor : instance selector; + offspring : instance selector; + } + + abstract type selector { + } + + type 'elite-selector' extends selector { + 'size-factor' : float; + 'non-elite-selector' : instance selector; + } + + type 'boltzmann-selector' extends selector { + beta : float; + } + + type 'exponential-rank-selector' extends selector { + } + + type 'linear-rank-selector' extends selector { + nminus : int; + } + + type 'monte-carlo-selector' extends selector { + } + + type 'probability-selector' extends selector { + } + + type 'stochastic-universal-selector' extends selector { + } + + type 'tournament-selector' extends selector { + 'size-factor' : float; + } + + type 'truncation-selector' extends selector { + 'worst-rank' : int; + } + + type alterers { + crossover : array instance crossover; + mutator : array instance mutator ; + } + + abstract type crossover {} + + type 'mean-alterer' extends crossover { + probability : float; + } + + type 'correlation-mean-alterer' extends crossover { + probability : float; + } + + type 'partial-matched-alterer' extends crossover { + probability : float; + } + + type 'correlation-partial-matched-alterer' extends crossover { + probability : float; + } + + type 'line-crossover' extends crossover { + probability : float; + position : float; + } + + type 'correlation-line-crossover' extends crossover { + probability : float; + position : float; + } + + type 'multi-point-crossover' extends crossover { + probability : float; + count : int; + } + + type 'correlation-multi-point-crossover' extends crossover { + probability : float; + count : int; + } + + type 'single-point-crossover' extends crossover { + probability : float; + } + + type 'correlation-single-point-crossover' extends crossover { + probability : float; + } + + type 'uniform-crossover' extends crossover { + 'crossover-probability' : float; + 'swap-probability' : float; + } + + type 'correlation-uniform-crossover' extends crossover { + 'crossover-probability' : float; + 'swap-probability' : float; + } + + abstract type mutator { + } + + type 'gaussian-mutator' extends mutator { + probability : float; + } + + type 'correlation-gaussian-mutator' extends mutator { + probability : float; + threshold : float; + } + + type 'swap-mutator' extends mutator { + probability : float; + } + + type 'correlation-swap-mutator' extends mutator { + probability : float; + threshold : float; + } + + type 'bit-flip-mutator' extends mutator { + probability : float; + } + + type 'correlation-bit-flip-mutator' extends mutator { + probability : float; + threshold : float; + } +} \ No newline at end of file diff --git a/src/core/de.evoal.core.main/src/main/java/de/evoal/core/api/utils/LanguageHelper.java b/src/core/de.evoal.core.main/src/main/java/de/evoal/core/api/utils/LanguageHelper.java index d26a3336..ffa77ee2 100644 --- a/src/core/de.evoal.core.main/src/main/java/de/evoal/core/api/utils/LanguageHelper.java +++ b/src/core/de.evoal.core.main/src/main/java/de/evoal/core/api/utils/LanguageHelper.java @@ -83,9 +83,11 @@ public final class LanguageHelper { } private static Object convertToJava(final Object current, final Type type) { - if(current instanceof Literal) { + if(type instanceof InstanceType) { + return (Instance)current; + } else if(type instanceof LiteralType) { return readLiteral(current, type); - } else if(current instanceof Array) { + } else if(type instanceof ArrayType) { return readArray(current, type); } diff --git a/src/core/de.evoal.core.main/src/main/resources/META-INF/definitions/data/constraints.dl b/src/core/de.evoal.core.main/src/main/resources/META-INF/definitions/data/constraints.dl deleted file mode 100644 index 1ba8690e..00000000 --- a/src/core/de.evoal.core.main/src/main/resources/META-INF/definitions/data/constraints.dl +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Sets the variance of some data. - * - * <b>Parameters:</b> - * <ol> - * <li>Reference to the data ...</li> - * </ol> - */ -def void variance(data reference, float variance); - -def void connection(data ref1, data ref2, float connection); - -def void constraint(expression exp, string category); diff --git a/src/core/de.evoal.core.main/src/main/resources/META-INF/definitions/data/si-units.ddl b/src/core/de.evoal.core.main/src/main/resources/META-INF/definitions/data/si-units.ddl deleted file mode 100644 index b7e8f297..00000000 --- a/src/core/de.evoal.core.main/src/main/resources/META-INF/definitions/data/si-units.ddl +++ /dev/null @@ -1,67 +0,0 @@ -types: - cardinal type Newton description : "SI-Unit for force, measure in Newton[N=kg*m/s*s]." - with constraints: - value >= 0.0; - ; - - quotient type Meter description: "SI-Unit for lengths, measured in metres[m]." - with constraints: - value >= 0.0; - ; - - quotient type Second description: "SI-Unit for time, measured in seconds[s]." - with constraints: - value >= 0.0; - ; - - quotient type Kilogram description: "SI-Unit for mass, measured in kilogram[kg]." - with constraints: - value >= 0.0; - ; - - quotient type Ampere description: "SI-Unit for eletric current, measured in ampere[A]." - with constraints: - value >= 0.0; - ; - - quotient type Kelvin description: "SI-Unit for thermodynamic temperature, measured in kelvin[K]." - with constraints: - value >= 0.0; - ; - - quotient type Mole description: "SI-Unit for amount of substance, measure in mole[mol]." - with constraints: - value >= 0.0; - ; - - quotient type Candela description: "SI-Unit for luminous intensity, measured in candela[cd]." - with constraints: - value >= 0.0; - ; - - quotient type Hertz description: "SI-Unit for frequency, measured in hertz[Hz=1/s]." - with constraints: - value >= 0.0; - ; - - quotient type Speed description: "SI-Unit for frequency, measured in metre per second[m/s]." - with constraints: - value >= 0.0; - ; - - quotient type Pascal description: "SI-Unit for pressure, measure in Pascal[Pa=kg/m*s*s]." - with constraints: - value >= 0.0; - ; - - cardinal type Celsius description: "SI-Unit for temperature relative to 273.15 K, measured in Celsius[°C=K]" - with constraints: - value >= -273.15; - ; - - quotient type Area description: "SI-Unit for areas, measured in square meter[m*m]" - with constraints: - value >= 0.0; - ; - - \ No newline at end of file diff --git a/src/core/de.evoal.core.main/src/main/resources/META-INF/definitions/optimisation/core.dl b/src/core/de.evoal.core.main/src/main/resources/META-INF/definitions/optimisation/core.dl deleted file mode 100644 index 91189620..00000000 --- a/src/core/de.evoal.core.main/src/main/resources/META-INF/definitions/optimisation/core.dl +++ /dev/null @@ -1,434 +0,0 @@ -/** - * Root element for an evolutionary algorithm configuration. - */ -type configuration { - /** - * A freely selectable name for the configuration. - */ - name : string; - - /** - * The algorithm configuration. - */ - algorithm : instance algorithm; - - /** - * Configuration of statistics to measure and to write. - */ - statistics : instance statistics; -} - -abstract type algorithm {} - -type 'evolutionary-algorithm' extends 'algorithm' { - 'number-of-generations' : int; - 'size-of-population' : int; - 'maximum-age' : int; - maximize : boolean; - - genotype : array instance chromosome; - - initialization : instance 'initial-population'; - handlers : array instance 'handler'; - selectors : instance selectors; - alterers : instance alterers; - - fitness : instance 'fitness-function'; - comparator : instance comparator; -} - -abstract type chromosome { - genes : array instance gene; -} - -type 'bit-chromosome' extends chromosome { - scale : int; -} - -type 'gray-chromosome' extends 'bit-chromosome' { - scale : int; -} - -type 'double-chromosome' extends chromosome { -} - -type 'integer-chromosome' extends chromosome { -} - -type gene { content : data; } - -abstract type comparator {} - -type 'weighted-sum' extends comparator { - weights : array float; -} - -type pareto extends comparator { -} - -/** - * Abstract base class for functions to map the individual to the target values. - */ -abstract type 'fitness-function' {} - -/** - * Abstract base class for all fitness functions that call a subsequent fitness function during calculation. - */ -abstract type 'decorated-fitness-function' extends 'fitness-function' { - /** - * Fitness function we are calling during the fitness calculation. - */ - function : instance 'fitness-function'; -} - -type 'malus' extends 'decorated-fitness-function' { -} - -/** - * Fitness function that calculates the difference between a fitness value and a - * target value to optimize to:<br/> - * - * <mathml> - * <math> - * <mrow> - * <mi>f</mi> - * <mi>i</mi> - * <mi>t</mi> - * <mi>n</mi> - * <mi>e</mi> - * <mi>s</mi> - * <mi>s</mi> - * <mo>=</mo> - * <mi>f</mi> - * <mi>u</mi> - * <mi>n</mi> - * <mi>c</mi> - * <mi>t</mi> - * <mi>i</mi> - * <mi>o</mi> - * <mi>n</mi> - * <mo form="prefix" stretchy="false">(</mo> - * <mi>i</mi> - * <mi>n</mi> - * <mi>d</mi> - * <mo form="postfix" stretchy="false">)</mo> - * <mo>−</mo> - * <mi>t</mi> - * <mi>a</mi> - * <mi>r</mi> - * <mi>g</mi> - * <mi>e</mi> - * <mi>t</mi> - * </mrow> - * </math> - * </mathml> - */ -type distance extends 'decorated-fitness-function' { - target : array instance variable; -} - -type variable { - name : data; - val : literal; -} - -abstract type 'goal-function' extends 'fitness-function' { - 'maps-to' : array data; -} - -/** - * Calculating fitness value by using a surrogate function:<br/> - * - * <mathml> - * <math> - * <mrow> - * <mi>f</mi> - * <mi>i</mi> - * <mi>t</mi> - * <mi>n</mi> - * <mi>e</mi> - * <mi>s</mi> - * <mi>s</mi> - * <mo>=</mo> - * <mi>s</mi> - * <mi>u</mi> - * <mi>r</mi> - * <mi>r</mi> - * <mi>o</mi> - * <mi>g</mi> - * <mi>a</mi> - * <mi>t</mi> - * <mi>e</mi> - * <mo form="prefix" stretchy="false">(</mo> - * <mi>i</mi> - * <mi>n</mi> - * <mi>d</mi> - * <mo form="postfix" stretchy="false">)</mo> - * </mrow> - * </math> - * </mathml> - */ -type surrogate extends 'goal-function' { -} - -/** - * Calculating fitness value by using a known function:<br/> - * - * <mathml> - * <math> - * <mrow> - * <mi>f</mi> - * <mi>i</mi> - * <mi>t</mi> - * <mi>n</mi> - * <mi>e</mi> - * <mi>s</mi> - * <mi>s</mi> - * <mo>=</mo> - * <mi>n</mi> - * <mi>o</mi> - * <mi>r</mi> - * <mi>m</mi> - * <mi>a</mi> - * <mi>l</mi> - * <mo form="prefix" stretchy="false">(</mo> - * <mi>i</mi> - * <mi>n</mi> - * <mi>d</mi> - * <mo form="postfix" stretchy="false">)</mo> - * </mrow> - * </math> - * </mathml> - */ -type normal extends 'fitness-function' { -} - -abstract type 'initial-population' {} - -type 'random-population' extends 'initial-population' { -} - -abstract type handler {} - -type 'constraint-handler' extends handler { - category : string; - calculation : instance normal | 'standard-deviation'; - 'constraint-handling' : instance 'kill-at-birth' | 'malus-for-fitness'; -} - -type 'standard-deviation' { - factor : float; -} - -type 'kill-at-birth' { - 'repair-strategy' : instance 'repair-strategy'; -} - -abstract type 'repair-strategy' {} - -type 'repair-with-random' extends 'repair-strategy' {} - -type 'malus-for-fitness' { - smoothing : float; -} - -type selectors { - survivor : instance selector; - offspring : instance selector; -} - -abstract type selector { -} - -type 'elite-selector' extends selector { - 'size-factor' : float; - 'non-elite-selector' : instance selector; -} - -type 'boltzmann-selector' extends selector { - beta : float; -} - -type 'exponential-rank-selector' extends selector { -} - -type 'linear-rank-selector' extends selector { - nminus : int; -} - -type 'monte-carlo-selector' extends selector { -} - -type 'probability-selector' extends selector { -} - -type 'stochastic-universal-selector' extends selector { -} - -type 'tournament-selector' extends selector { - 'size-factor' : float; -} - -type 'truncation-selector' extends selector { - 'worst-rank' : int; -} - -type alterers { - crossover : array instance crossover; - mutator : array instance mutator ; -} - -abstract type crossover {} - -type 'mean-alterer' extends crossover { - probability : float; -} - -type 'correlation-mean-alterer' extends crossover { - probability : float; -} - -type 'partial-matched-alterer' extends crossover { - probability : float; -} - -type 'correlation-partial-matched-alterer' extends crossover { - probability : float; -} - -type 'line-crossover' extends crossover { - probability : float; - position : float; -} - -type 'correlation-line-crossover' extends crossover { - probability : float; - position : float; -} - -type 'multi-point-crossover' extends crossover { - probability : float; - count : int; -} - -type 'correlation-multi-point-crossover' extends crossover { - probability : float; - count : int; -} - -type 'single-point-crossover' extends crossover { - probability : float; -} - -type 'correlation-single-point-crossover' extends crossover { - probability : float; -} - -type 'uniform-crossover' extends crossover { - 'crossover-probability' : float; - 'swap-probability' : float; -} - -type 'correlation-uniform-crossover' extends crossover { - 'crossover-probability' : float; - 'swap-probability' : float; -} - -abstract type mutator { -} - -type 'gaussian-mutator' extends mutator { - probability : float; -} - -type 'correlation-gaussian-mutator' extends mutator { - probability : float; - threshold : float; -} - -type 'swap-mutator' extends mutator { - probability : float; -} - -type 'correlation-swap-mutator' extends mutator { - probability : float; - threshold : float; -} - -type 'bit-flip-mutator' extends mutator { - probability : float; -} - -type 'correlation-bit-flip-mutator' extends mutator { - probability : float; - threshold : float; -} - -type statistics { - writer : array instance 'statistics-writer'; -} - -abstract type 'statistics-writer' { -} - -/** - * Creates a file named '<tt>constraint-statistics.csv</tt>' containing - * information on each generation and constraint violations: - * - * <ul> - * <li>generation</li> - * <li>for each constraint: - * <ul> - * <li>number of violating individuals</li> - * <li>sum of differences</li> - * <li>min of differences</li> - * <li>avg of differences</li> - * <li>max of differences</li> - * </ul> - * </li> - * </ul> - */ -type 'constraint-statistics' extends 'statistics-writer' {} - -/** - * Creates a file named '<tt>fitness-by-individual.csv</tt>' containing for each individual - * of each generation the following information: - * - * <ul> - * <li>generation</li> - * <li>index of individual</li> - * <li>fitness value of each predicted value of the individual</li> - * </ul> - */ -type 'fitness-per-individual' extends 'statistics-writer' {} - -/** - * Creates a file named '<tt>individuals.csv</tt>' containing for each individual - * the following information: - * - * <ul> - * <li>generation</li> - * <li>index of individual</li> - * <li>text representation of individual</li> - * <li>age</li> - * <li>each property value of the individual</li> - * </ul> - */ -type individuals extends 'statistics-writer' {} - -/** - * Does not write any statistics. Can be used to disable statistics output. - */ -type none extends 'statistics-writer' {} - -/** - * Creates a file named '<tt>prediction-by-individual.csv</tt>' containing the - * predicted value(s) of each individual for each generation of the EA run: - * - * <ul> - * <li>generation</li> - * <li>index of individual</li> - * <li>each predicted value of the individual</li> - * </ul> - */ -type 'prediction-per-individual' extends 'statistics-writer' {} diff --git a/src/core/de.evoal.core.main/src/main/resources/de/evoal/core.dl b/src/core/de.evoal.core.main/src/main/resources/de/evoal/core.dl new file mode 100644 index 00000000..5e4fe142 --- /dev/null +++ b/src/core/de.evoal.core.main/src/main/resources/de/evoal/core.dl @@ -0,0 +1,346 @@ +module de.evoal.core { + + /** + * The algorithm-independent problem description. + */ + type problem { + /** + * Name of the problem (used for referencing from the algorithm). + */ + name : string; + + /** + * Description of the optimisation space. + */ + 'optimisation-space' : array data; + + /** + * Optional search space description. + */ + 'search-space' : array data; + + /** + * An optional optimisation function if known that maps between the + * search and the optimisation space. + */ + 'function' : instance 'optimisation-function'; + + /** + * Do we have to search for a maximum or a minimum? + */ + maximise : boolean; + } + + /** + * Abstract base type for functions mapping a solution from the search to + * the optimisation space. + */ + abstract type 'optimisation-function' { + } + + /** + * Abstract base class for optimisation functions that call a subsequent optimisation + * function during calculation. + */ + abstract type 'decorated-optimisation-function' extends 'optimisation-function' { + /** + * Fitness function we are calling during the fitness calculation. + */ + function : instance 'optimisation-function'; + } + + /** + * Place-holder for an unknown optimisation function. + */ + type 'unknown-function' extends 'optimisation-function' {} + + /** + * Optimisation function that calculates the difference between a optimisation + * value and a target value to optimise to:<br/> + * + * <mathml> + * <math> + * <mrow> + * <mi>r</mi> + * <mi>e</mi> + * <mi>u</mi> + * <mi>l</mi> + * <mi>t</mi> + * <mo>=</mo> + * <mi>f</mi> + * <mi>u</mi> + * <mi>n</mi> + * <mi>c</mi> + * <mi>t</mi> + * <mi>i</mi> + * <mi>o</mi> + * <mi>n</mi> + * <mo form="prefix" stretchy="false">(</mo> + * <mi>c</mi> + * <mi>a</mi> + * <mi>n</mi> + * <mi>d</mi> + * <mi>i</mi> + * <mi>d</mi> + * <mi>a</mi> + * <mi>t</mi> + * <mi>e</mi> + * <mo form="postfix" stretchy="false">)</mo> + * <mo>−</mo> + * <mi>t</mi> + * <mi>a</mi> + * <mi>r</mi> + * <mi>g</mi> + * <mi>e</mi> + * <mi>t</mi> + * </mrow> + * </math> + * </mathml> + */ + type 'optimisation-distance' extends 'decorated-optimisation-function' { + /** + * The target to search for. This value may be unset if the value is set + * by EvoAl itself during evaluation. + */ + target : array instance variable; + } + + /** + * A binding of a variable. + */ + type variable { + /** + * The data to bind. + */ + name : data; + + /** + * The actual value. + */ + val : literal; + } + + + /** + * Abstract base type for optimisation algorithms. + */ + abstract type algorithm { + /** + * Source for initial candidates. + */ + 'initialisation' : instance 'initial-population'; + + /** + * The optimisation function to use. + */ + 'function' : instance 'fitness-function'; + + /** + * Comparator to use for comparing results of the optimisation function. + */ + 'comparator' : instance comparator; + } + + /** + * Comparator for comparing optimisation function results to each other. + */ + abstract type comparator {} + + /** + * Comparator that calculates a weighted sum for multi-dimensional optimisation + * values. + */ + type 'weighted-sum' extends comparator { + /** + * Weights for summing the dimensions. + */ + weights : array float; + } + + /** + * Comparator for a single number-based fitness value (such as a double). + */ + type 'numeric-comparator' extends comparator { + } + + /** + * A fitness function during the optimisation (not at the problem-level). + */ + abstract type 'fitness-function' {} + + /** + * Abstract base class for all fitness functions that call a subsequent fitness + * function during calculation. + */ + abstract type 'decorated-fitness-function' extends 'fitness-function' { + /** + * Fitness function we are calling during the fitness calculation. + */ + function : instance 'optimisation-function'; + } + + /** + * Modifies the fitness value based on constraint violation. + */ + type 'malus' extends 'decorated-fitness-function' { + } + + /** + * Fitness function that calculates the difference between a fitness value and a + * target value to optimize to:<br/> + * + * <mathml> + * <math> + * <mrow> + * <mi>f</mi> + * <mi>i</mi> + * <mi>t</mi> + * <mi>n</mi> + * <mi>e</mi> + * <mi>s</mi> + * <mi>s</mi> + * <mo>=</mo> + * <mi>f</mi> + * <mi>u</mi> + * <mi>n</mi> + * <mi>c</mi> + * <mi>t</mi> + * <mi>i</mi> + * <mi>o</mi> + * <mi>n</mi> + * <mo form="prefix" stretchy="false">(</mo> + * <mi>i</mi> + * <mi>n</mi> + * <mi>d</mi> + * <mo form="postfix" stretchy="false">)</mo> + * <mo>−</mo> + * <mi>t</mi> + * <mi>a</mi> + * <mi>r</mi> + * <mi>g</mi> + * <mi>e</mi> + * <mi>t</mi> + * </mrow> + * </math> + * </mathml> + */ + type 'fitness-distance' extends 'decorated-fitness-function' { + /** + * The target to search for. This value may be unset if the value is set + * by EvoAl itself during evaluation. + */ + target : array instance variable; + } + + /** + * Calculating fitness value by using a surrogate function:<br/> + * + * <mathml> + * <math> + * <mrow> + * <mi>f</mi> + * <mi>i</mi> + * <mi>t</mi> + * <mi>n</mi> + * <mi>e</mi> + * <mi>s</mi> + * <mi>s</mi> + * <mo>=</mo> + * <mi>s</mi> + * <mi>u</mi> + * <mi>r</mi> + * <mi>r</mi> + * <mi>o</mi> + * <mi>g</mi> + * <mi>a</mi> + * <mi>t</mi> + * <mi>e</mi> + * <mo form="prefix" stretchy="false">(</mo> + * <mi>i</mi> + * <mi>n</mi> + * <mi>d</mi> + * <mo form="postfix" stretchy="false">)</mo> + * </mrow> + * </math> + * </mathml> + */ + type surrogate extends 'fitness-function' { + } + + /** + * Abstract base type for initial population strategies. + */ + abstract type 'initial-population' {} + + /** + * Chooses the initial population randomly from the search space. The selection + * process respects the boundaries defined at the data definition-level. + */ + type 'random-population' extends 'initial-population' { + } + + abstract type 'statistics-writer' { + } + + /** + * Creates a file named '<tt>constraint-statistics.csv</tt>' containing + * information on each generation and constraint violations: + * + * <ul> + * <li>generation</li> + * <li>for each constraint: + * <ul> + * <li>number of violating individuals</li> + * <li>sum of differences</li> + * <li>min of differences</li> + * <li>avg of differences</li> + * <li>max of differences</li> + * </ul> + * </li> + * </ul> + */ + type 'constraint-statistics' extends 'statistics-writer' {} + + /** + * Creates a file named '<tt>fitness-by-individual.csv</tt>' containing for each individual + * of each generation the following information: + * + * <ul> + * <li>generation</li> + * <li>index of individual</li> + * <li>fitness value of each predicted value of the individual</li> + * </ul> + */ + type 'fitness-per-individual' extends 'statistics-writer' {} + + /** + * Creates a file named '<tt>individuals.csv</tt>' containing for each individual + * the following information: + * + * <ul> + * <li>generation</li> + * <li>index of individual</li> + * <li>text representation of individual</li> + * <li>age</li> + * <li>each property value of the individual</li> + * </ul> + */ + type individuals extends 'statistics-writer' {} + + /** + * Does not write any statistics. Can be used to disable statistics output. + */ + type none extends 'statistics-writer' {} + + /** + * Creates a file named '<tt>prediction-by-individual.csv</tt>' containing the + * predicted value(s) of each individual for each generation of the EA run: + * + * <ul> + * <li>generation</li> + * <li>index of individual</li> + * <li>each predicted value of the individual</li> + * </ul> + */ + type 'prediction-per-individual' extends 'statistics-writer' {} +} diff --git a/src/core/de.evoal.core.main/src/main/resources/de/evoal/core/constraints.dl b/src/core/de.evoal.core.main/src/main/resources/de/evoal/core/constraints.dl new file mode 100644 index 00000000..c7b85a33 --- /dev/null +++ b/src/core/de.evoal.core.main/src/main/resources/de/evoal/core/constraints.dl @@ -0,0 +1,15 @@ +module de.evoal.core.constrainst { + /** + * Sets the variance of some data. + * + * <b>Parameters:</b> + * <ol> + * <li>Reference to the data ...</li> + * </ol> + */ + def void variance(data reference, float variance); + + def void connection(data ref1, data ref2, float connection); + + def void constraint(expression exp, string category); +} \ No newline at end of file diff --git a/src/core/de.evoal.core.main/src/main/resources/de/evoal/core/si.ddl b/src/core/de.evoal.core.main/src/main/resources/de/evoal/core/si.ddl new file mode 100644 index 00000000..b16797ce --- /dev/null +++ b/src/core/de.evoal.core.main/src/main/resources/de/evoal/core/si.ddl @@ -0,0 +1,67 @@ +module de.evoal.core.si { + types: + cardinal type Newton description : "SI-Unit for force, measure in Newton[N=kg*m/s*s]." + with constraints: + value >= 0.0; + ; + + quotient type Meter description: "SI-Unit for lengths, measured in metres[m]." + with constraints: + value >= 0.0; + ; + + quotient type Second description: "SI-Unit for time, measured in seconds[s]." + with constraints: + value >= 0.0; + ; + + quotient type Kilogram description: "SI-Unit for mass, measured in kilogram[kg]." + with constraints: + value >= 0.0; + ; + + quotient type Ampere description: "SI-Unit for eletric current, measured in ampere[A]." + with constraints: + value >= 0.0; + ; + + quotient type Kelvin description: "SI-Unit for thermodynamic temperature, measured in kelvin[K]." + with constraints: + value >= 0.0; + ; + + quotient type Mole description: "SI-Unit for amount of substance, measure in mole[mol]." + with constraints: + value >= 0.0; + ; + + quotient type Candela description: "SI-Unit for luminous intensity, measured in candela[cd]." + with constraints: + value >= 0.0; + ; + + quotient type Hertz description: "SI-Unit for frequency, measured in hertz[Hz=1/s]." + with constraints: + value >= 0.0; + ; + + quotient type Speed description: "SI-Unit for frequency, measured in metre per second[m/s]." + with constraints: + value >= 0.0; + ; + + quotient type Pascal description: "SI-Unit for pressure, measure in Pascal[Pa=kg/m*s*s]." + with constraints: + value >= 0.0; + ; + + cardinal type Celsius description: "SI-Unit for temperature relative to 273.15 K, measured in Celsius[°C=K]" + with constraints: + value >= -273.15; + ; + + quotient type Area description: "SI-Unit for areas, measured in square meter[m*m]" + with constraints: + value >= 0.0; + ; +} \ No newline at end of file diff --git a/src/core/de.evoal.core.main/src/test/java/de/evoal/core/api/utils/LanguageHelperRegressionTest.java b/src/core/de.evoal.core.main/src/test/java/de/evoal/core/api/utils/LanguageHelperRegressionTest.java index 6a727174..b79aef00 100644 --- a/src/core/de.evoal.core.main/src/test/java/de/evoal/core/api/utils/LanguageHelperRegressionTest.java +++ b/src/core/de.evoal.core.main/src/test/java/de/evoal/core/api/utils/LanguageHelperRegressionTest.java @@ -96,7 +96,5 @@ public class LanguageHelperRegressionTest { final Array array2 = (Array) array.getValues().get(0); Assertions.assertEquals(10, array2.getValues().size()); } - } - } diff --git a/src/core/de.evoal.core.main/src/test/java/de/evoal/core/api/utils/LanguageHelperUnitTest.java b/src/core/de.evoal.core.main/src/test/java/de/evoal/core/api/utils/LanguageHelperUnitTest.java index bbb3a76a..6784c76d 100644 --- a/src/core/de.evoal.core.main/src/test/java/de/evoal/core/api/utils/LanguageHelperUnitTest.java +++ b/src/core/de.evoal.core.main/src/test/java/de/evoal/core/api/utils/LanguageHelperUnitTest.java @@ -11,11 +11,11 @@ public class LanguageHelperUnitTest { @Test public void testLoading() { final OptimisationModel model = de.evoal.core.junit.dsl.LanguageHelper.loadFromClasspath("de/evoal/core/api/utils/LanguageHelperTest.ol"); -// final Instance instance = model.getInstance(); - // TODO FIXME -// Assertions.assertNotNull(instance); + final Instance instance = model.getProblem().getInstance(); + + Assertions.assertNotNull(instance); } -/* + @Test public void testLookupForNullInstance() { Assertions.assertThrows(IllegalStateException.class, () -> lookup(null, "child")); @@ -24,7 +24,7 @@ public class LanguageHelperUnitTest { @Test public void testLookupForNullPath() { final OptimisationModel model = de.evoal.core.junit.dsl.LanguageHelper.loadFromClasspath("de/evoal/core/api/utils/LanguageHelperTest.ol"); - final Instance instance = model.getInstance(); + final Instance instance = model.getProblem().getInstance(); Assertions.assertThrows(IllegalArgumentException.class, () -> lookup(instance, null)); } @@ -32,7 +32,7 @@ public class LanguageHelperUnitTest { @Test public void testLookupForEmptyPath() { final OptimisationModel model = de.evoal.core.junit.dsl.LanguageHelper.loadFromClasspath("de/evoal/core/api/utils/LanguageHelperTest.ol"); - final Instance instance = model.getInstance(); + final Instance instance = model.getProblem().getInstance(); final Object result = lookup(instance, ""); @@ -43,7 +43,7 @@ public class LanguageHelperUnitTest { @Test public void testLookupForExistingChild() { final OptimisationModel model = de.evoal.core.junit.dsl.LanguageHelper.loadFromClasspath("de/evoal/core/api/utils/LanguageHelperTest.ol"); - final Instance instance = model.getInstance(); + final Instance instance = model.getProblem().getInstance(); final Object result = lookup(instance, "child"); @@ -57,7 +57,7 @@ public class LanguageHelperUnitTest { @Test public void testLookupName() { final OptimisationModel model = de.evoal.core.junit.dsl.LanguageHelper.loadFromClasspath("de/evoal/core/api/utils/LanguageHelperTest.ol"); - final Instance instance = model.getInstance(); + final Instance instance = model.getProblem().getInstance(); final Object result = lookup(instance, "name"); @@ -68,7 +68,7 @@ public class LanguageHelperUnitTest { @Test public void testLookupChildOfLiteral() { final OptimisationModel model = de.evoal.core.junit.dsl.LanguageHelper.loadFromClasspath("de/evoal/core/api/utils/LanguageHelperTest.ol"); - final Instance instance = model.getInstance(); + final Instance instance = model.getProblem().getInstance(); Assertions.assertThrows(IllegalStateException.class, () -> lookup(instance, "child.string-field.non-existing")); } @@ -76,7 +76,7 @@ public class LanguageHelperUnitTest { @Test public void testLookupNonExistingChild() { final OptimisationModel model = de.evoal.core.junit.dsl.LanguageHelper.loadFromClasspath("de/evoal/core/api/utils/LanguageHelperTest.ol"); - final Instance instance = model.getInstance(); + final Instance instance = model.getProblem().getInstance(); Assertions.assertThrows(IllegalStateException.class, () -> lookup(instance, "child.non-existing")); } @@ -84,7 +84,7 @@ public class LanguageHelperUnitTest { @Test public void testLookupBooleanField() { final OptimisationModel model = de.evoal.core.junit.dsl.LanguageHelper.loadFromClasspath("de/evoal/core/api/utils/LanguageHelperTest.ol"); - final Instance instance = model.getInstance(); + final Instance instance = model.getProblem().getInstance(); final Object result = lookup(instance, "child.boolean-field"); @@ -96,7 +96,7 @@ public class LanguageHelperUnitTest { @Test public void testLookupFlotField() { final OptimisationModel model = de.evoal.core.junit.dsl.LanguageHelper.loadFromClasspath("de/evoal/core/api/utils/LanguageHelperTest.ol"); - final Instance instance = model.getInstance(); + final Instance instance = model.getProblem().getInstance(); final Object result = lookup(instance, "child.float-field"); @@ -108,7 +108,7 @@ public class LanguageHelperUnitTest { @Test public void testLookupIntegerField() { final OptimisationModel model = de.evoal.core.junit.dsl.LanguageHelper.loadFromClasspath("de/evoal/core/api/utils/LanguageHelperTest.ol"); - final Instance instance = model.getInstance(); + final Instance instance = model.getProblem().getInstance(); final Object result = lookup(instance, "child.integer-field"); @@ -120,7 +120,7 @@ public class LanguageHelperUnitTest { @Test public void testLookupStringField() { final OptimisationModel model = de.evoal.core.junit.dsl.LanguageHelper.loadFromClasspath("de/evoal/core/api/utils/LanguageHelperTest.ol"); - final Instance instance = model.getInstance(); + final Instance instance = model.getProblem().getInstance(); final Object result = lookup(instance, "child.string-field"); @@ -132,7 +132,7 @@ public class LanguageHelperUnitTest { @Test public void testLookup1DArrayField() { final OptimisationModel model = de.evoal.core.junit.dsl.LanguageHelper.loadFromClasspath("de/evoal/core/api/utils/LanguageHelperTest.ol"); - final Instance instance = model.getInstance(); + final Instance instance = model.getProblem().getInstance(); final Object result = lookup(instance, "child.array-1D-float"); @@ -149,7 +149,7 @@ public class LanguageHelperUnitTest { @Test public void testLookup2DArrayField() { final OptimisationModel model = de.evoal.core.junit.dsl.LanguageHelper.loadFromClasspath("de/evoal/core/api/utils/LanguageHelperTest.ol"); - final Instance instance = model.getInstance(); + final Instance instance = model.getProblem().getInstance(); final Object result = lookup(instance, "child.array-2D-int"); @@ -179,5 +179,4 @@ public class LanguageHelperUnitTest { Assertions.assertEquals(42, array2[0]); } - */ } diff --git a/src/core/de.evoal.core.main/src/test/resources/de/evoal/core/api/utils/LanguageHelperTest.ol b/src/core/de.evoal.core.main/src/test/resources/de/evoal/core/api/utils/LanguageHelperTest.ol index 731d710f..a0e767fc 100644 --- a/src/core/de.evoal.core.main/src/test/resources/de/evoal/core/api/utils/LanguageHelperTest.ol +++ b/src/core/de.evoal.core.main/src/test/resources/de/evoal/core/api/utils/LanguageHelperTest.ol @@ -1,7 +1,7 @@ -import de.evoal.core.api.utils.regressions.definitions; +import "definitions" from de.evoal.core.api.utils.definitions; -declare -parent { + +declare 'p' as parent { child := A { 'boolean-field' := true; 'float-field' := 1.3; @@ -9,10 +9,9 @@ parent { 'string-field' := "FOOBAR"; 'array-1D-float' := [4.2, 3.1, 1.0]; 'array-2D-int' := [ - [ 1, 2, 3, 4, 5], [ 3, 2, 1], [42] ]; }; -} \ No newline at end of file +} documenting := []; \ No newline at end of file diff --git a/src/core/de.evoal.core.main/src/test/resources/de/evoal/core/api/utils/definitions.dl b/src/core/de.evoal.core.main/src/test/resources/de/evoal/core/api/utils/definitions.dl index fde56c23..0ce286a3 100644 --- a/src/core/de.evoal.core.main/src/test/resources/de/evoal/core/api/utils/definitions.dl +++ b/src/core/de.evoal.core.main/src/test/resources/de/evoal/core/api/utils/definitions.dl @@ -1,4 +1,4 @@ -module de.evoal.core.api.utils.regressions.definitions { +module de.evoal.core.api.utils.definitions { type 'parent' { child : instance A; } diff --git a/src/core/de.evoal.generator.main/src/main/resources/META-INF/definitions/generator/main.dl b/src/core/de.evoal.generator.main/src/main/resources/META-INF/definitions/generator/main.dl deleted file mode 100644 index bd4485c1..00000000 --- a/src/core/de.evoal.generator.main/src/main/resources/META-INF/definitions/generator/main.dl +++ /dev/null @@ -1,250 +0,0 @@ -/** - * In mathematical optimisation, the Ackley function is a non-convex function - * used as a performance test problem for optimisation algorithms. It was proposed - * by David Ackley in his 1987 PhD dissertation. ... <a href="https://en.wikipedia.org/wiki/Ackley_function">Wikipedia</a>. - * - * <math display="block"> - * <mrow> - * <mi>f</mi> - * <mo form="prefix" stretchy="false">(</mo> - * <mi>w</mi> - * <mi>r</mi> - * <mi>i</mi> - * <mi>t</mi> - * <msub> - * <mi>e</mi> - * <mn>0</mn> - * </msub> - * <mo form="postfix" stretchy="false">)</mo> - * <mo>=</mo> - * <mo>−</mo> - * <mi>a</mi> - * <mo>⋅</mo> - * <mi>e</mi> - * <mi>x</mi> - * <mi>p</mi> - * <mo form="prefix" stretchy="false">(</mo> - * <mo>−</mo> - * <mi>b</mi> - * <msqrt> - * <mrow> - * <mfrac> - * <mn>1</mn> - * <mi>n</mi> - * </mfrac> - * <mrow> - * <munderover> - * <mo movablelimits="false">∑</mo> - * <mrow> - * <mi>i</mi> - * <mo>=</mo> - * <mn>1</mn> - * </mrow> - * <mi>n</mi> - * </munderover> - * </mrow> - * <mi>r</mi> - * <mi>e</mi> - * <mi>a</mi> - * <msub> - * <mi>d</mi> - * <mi>i</mi> - * </msub> - * </mrow> - * </msqrt> - * <mo form="postfix" stretchy="false">)</mo> - * <mo>−</mo> - * <mi>e</mi> - * <mi>x</mi> - * <mi>p</mi> - * <mo form="prefix" stretchy="false">(</mo> - * <mfrac> - * <mn>1</mn> - * <mi>n</mi> - * </mfrac> - * <mrow> - * <munderover> - * <mo movablelimits="false">∑</mo> - * <mrow> - * <mi>i</mi> - * <mo>=</mo> - * <mn>1</mn> - * </mrow> - * <mi>n</mi> - * </munderover> - * </mrow> - * <mi>c</mi> - * <mi>o</mi> - * <mi>s</mi> - * <mo form="prefix" stretchy="false">(</mo> - * <mi>c</mi> - * <mo>⋅</mo> - * <mi>r</mi> - * <mi>e</mi> - * <mi>a</mi> - * <msub> - * <mi>d</mi> - * <mi>i</mi> - * </msub> - * <mo form="postfix" stretchy="false">)</mo> - * <mo form="postfix" stretchy="false">)</mo> - * <mo>+</mo> - * <mi>a</mi> - * <mo>+</mo> - * <mi>e</mi> - * <mi>x</mi> - * <mi>p</mi> - * <mo form="prefix" stretchy="false">(</mo> - * <mn>1</mn> - * <mo form="postfix" stretchy="false">)</mo> - * </mrow> - * </math> - * - * According to this specification, the function only generates a single output - * variable out of a n input variables. - */ -type ackley { - /** - * The constant a is set to 20 in the original Ackley function. - */ - a : float; - - /** - * The constant b is set to 0.2 in the original Ackley function. - */ - b : float; - - /** - * The constant c is set to 2π in the original Ackley function. - */ - c : float; -} - -/** - * In mathematical optimisation, the Rastrigin function is a non-convex function - * used as a performance test problem for optimisation algorithms. ... <a href="https://en.wikipedia.org/wiki/Rastrigin_function">Wikipedia</a> - * - * <math display="block"> - * <mrow> - * <mi>w</mi> - * <mi>r</mi> - * <mi>i</mi> - * <mi>t</mi> - * <msub> - * <mi>e</mi> - * <mn>0</mn> - * </msub> - * <mo>=</mo> - * <mi>a</mi> - * <mo>⋅</mo> - * <mi>n</mi> - * <mo>+</mo> - * <mrow> - * <munderover> - * <mo movablelimits="false">∑</mo> - * <mrow> - * <mi>i</mi> - * <mo>=</mo> - * <mn>1</mn> - * </mrow> - * <mi>n</mi> - * </munderover> - * </mrow> - * <mo form="prefix" stretchy="false">(</mo> - * <mi>r</mi> - * <mi>e</mi> - * <mi>a</mi> - * <msubsup> - * <mi>d</mi> - * <mi>i</mi> - * <mn>2</mn> - * </msubsup> - * <mo>−</mo> - * <mi>A</mi> - * <mo>⋅</mo> - * <mi>c</mi> - * <mi>o</mi> - * <mi>s</mi> - * <mo form="prefix" stretchy="false">(</mo> - * <mn>2</mn> - * <mi>π</mi> - * <mo>⋅</mo> - * <mi>r</mi> - * <mi>e</mi> - * <mi>a</mi> - * <msub> - * <mi>d</mi> - * <mi>i</mi> - * </msub> - * <mo form="postfix" stretchy="false">)</mo> - * <mo form="postfix" stretchy="false">)</mo> - * </mrow> - * </math> - * - */ -type rastrigin { - /** - * Constant a, which is typically 10. - */ - a : float; -} - -/** - * TODO Document me - */ -type 'weighted-sphere' { -} - -/** - * TODO Document me - */ -type 'rosenbrock' { -} - -/** - * Adds constant values for the specified data. - */ -type constants { - /** - * The constant values to append. - */ - constants : array float; -} - - -type 'multivariate-normal-distribution' { - means : array float; - covariance : array array float; -} - -/** - * Adds normally distributed noise to data. For each data to noise, you can - * specify a separate distribution. - */ -type 'normally-distributed-noise' { - /** - * The different distributions to use. Make sure it matches the size of - * the data the function writes. - */ - distributions : array instance distribution; -} - -/** - * A distribution specification. - */ -type distribution { - /** - * The distribution's expected value. - */ - 'μ' : float; - - /** - * The distribution's standard deviation. - */ - 'σ' : float; -} - - -type 'constraint-validation' { - -} diff --git a/src/core/de.evoal.generator.main/src/main/resources/de/evoal/benchmark.dl b/src/core/de.evoal.generator.main/src/main/resources/de/evoal/benchmark.dl new file mode 100644 index 00000000..98aa7491 --- /dev/null +++ b/src/core/de.evoal.generator.main/src/main/resources/de/evoal/benchmark.dl @@ -0,0 +1,11 @@ +import "definitions" from de.evoal.core; +import "definitions" from de.evoal.generator; + +module de.evoal.benchmark { + /** + * Known optimisation functions for benchmarking purposes. + */ + type 'benchmark-function' extends 'optimisation-function' { + benchmark : instance benchmark; + } +} \ No newline at end of file diff --git a/src/core/de.evoal.generator.main/src/main/resources/de/evoal/generator.dl b/src/core/de.evoal.generator.main/src/main/resources/de/evoal/generator.dl new file mode 100644 index 00000000..94ed9912 --- /dev/null +++ b/src/core/de.evoal.generator.main/src/main/resources/de/evoal/generator.dl @@ -0,0 +1,253 @@ +module de.evoal.generator { + abstract type benchmark{} + + /** + * In mathematical optimisation, the Ackley function is a non-convex function + * used as a performance test problem for optimisation algorithms. It was proposed + * by David Ackley in his 1987 PhD dissertation. ... <a href="https://en.wikipedia.org/wiki/Ackley_function">Wikipedia</a>. + * + * <math display="block"> + * <mrow> + * <mi>f</mi> + * <mo form="prefix" stretchy="false">(</mo> + * <mi>w</mi> + * <mi>r</mi> + * <mi>i</mi> + * <mi>t</mi> + * <msub> + * <mi>e</mi> + * <mn>0</mn> + * </msub> + * <mo form="postfix" stretchy="false">)</mo> + * <mo>=</mo> + * <mo>−</mo> + * <mi>a</mi> + * <mo>⋅</mo> + * <mi>e</mi> + * <mi>x</mi> + * <mi>p</mi> + * <mo form="prefix" stretchy="false">(</mo> + * <mo>−</mo> + * <mi>b</mi> + * <msqrt> + * <mrow> + * <mfrac> + * <mn>1</mn> + * <mi>n</mi> + * </mfrac> + * <mrow> + * <munderover> + * <mo movablelimits="false">∑</mo> + * <mrow> + * <mi>i</mi> + * <mo>=</mo> + * <mn>1</mn> + * </mrow> + * <mi>n</mi> + * </munderover> + * </mrow> + * <mi>r</mi> + * <mi>e</mi> + * <mi>a</mi> + * <msub> + * <mi>d</mi> + * <mi>i</mi> + * </msub> + * </mrow> + * </msqrt> + * <mo form="postfix" stretchy="false">)</mo> + * <mo>−</mo> + * <mi>e</mi> + * <mi>x</mi> + * <mi>p</mi> + * <mo form="prefix" stretchy="false">(</mo> + * <mfrac> + * <mn>1</mn> + * <mi>n</mi> + * </mfrac> + * <mrow> + * <munderover> + * <mo movablelimits="false">∑</mo> + * <mrow> + * <mi>i</mi> + * <mo>=</mo> + * <mn>1</mn> + * </mrow> + * <mi>n</mi> + * </munderover> + * </mrow> + * <mi>c</mi> + * <mi>o</mi> + * <mi>s</mi> + * <mo form="prefix" stretchy="false">(</mo> + * <mi>c</mi> + * <mo>⋅</mo> + * <mi>r</mi> + * <mi>e</mi> + * <mi>a</mi> + * <msub> + * <mi>d</mi> + * <mi>i</mi> + * </msub> + * <mo form="postfix" stretchy="false">)</mo> + * <mo form="postfix" stretchy="false">)</mo> + * <mo>+</mo> + * <mi>a</mi> + * <mo>+</mo> + * <mi>e</mi> + * <mi>x</mi> + * <mi>p</mi> + * <mo form="prefix" stretchy="false">(</mo> + * <mn>1</mn> + * <mo form="postfix" stretchy="false">)</mo> + * </mrow> + * </math> + * + * According to this specification, the function only generates a single output + * variable out of a n input variables. + */ + type ackley extends benchmark { + /** + * The constant a is set to 20 in the original Ackley function. + */ + 'a' : float; + + /** + * The constant b is set to 0.2 in the original Ackley function. + */ + b : float; + + /** + * The constant c is set to 2π in the original Ackley function. + */ + 'c' : float; + } + + /** + * In mathematical optimisation, the Rastrigin function is a non-convex function + * used as a performance test problem for optimisation algorithms. ... <a href="https://en.wikipedia.org/wiki/Rastrigin_function">Wikipedia</a> + * + * <math display="block"> + * <mrow> + * <mi>w</mi> + * <mi>r</mi> + * <mi>i</mi> + * <mi>t</mi> + * <msub> + * <mi>e</mi> + * <mn>0</mn> + * </msub> + * <mo>=</mo> + * <mi>a</mi> + * <mo>⋅</mo> + * <mi>n</mi> + * <mo>+</mo> + * <mrow> + * <munderover> + * <mo movablelimits="false">∑</mo> + * <mrow> + * <mi>i</mi> + * <mo>=</mo> + * <mn>1</mn> + * </mrow> + * <mi>n</mi> + * </munderover> + * </mrow> + * <mo form="prefix" stretchy="false">(</mo> + * <mi>r</mi> + * <mi>e</mi> + * <mi>a</mi> + * <msubsup> + * <mi>d</mi> + * <mi>i</mi> + * <mn>2</mn> + * </msubsup> + * <mo>−</mo> + * <mi>A</mi> + * <mo>⋅</mo> + * <mi>c</mi> + * <mi>o</mi> + * <mi>s</mi> + * <mo form="prefix" stretchy="false">(</mo> + * <mn>2</mn> + * <mi>π</mi> + * <mo>⋅</mo> + * <mi>r</mi> + * <mi>e</mi> + * <mi>a</mi> + * <msub> + * <mi>d</mi> + * <mi>i</mi> + * </msub> + * <mo form="postfix" stretchy="false">)</mo> + * <mo form="postfix" stretchy="false">)</mo> + * </mrow> + * </math> + * + */ + type rastrigin extends benchmark { + /** + * Constant a, which is typically 10. + */ + 'a' : float; + } + + /** + * TODO Document me + */ + type 'weighted-sphere' extends benchmark { + } + + /** + * TODO Document me + */ + type 'rosenbrock' extends benchmark { + } + + /** + * Adds constant values for the specified data. + */ + type constants { + /** + * The constant values to append. + */ + constants : array float; + } + + + type 'multivariate-normal-distribution' { + means : array float; + covariance : array array float; + } + + /** + * Adds normally distributed noise to data. For each data to noise, you can + * specify a separate distribution. + */ + type 'normally-distributed-noise' { + /** + * The different distributions to use. Make sure it matches the size of + * the data the function writes. + */ + distributions : array instance distribution; + } + + /** + * A distribution specification. + */ + type distribution { + /** + * The distribution's expected value. + */ + 'μ' : float; + + /** + * The distribution's standard deviation. + */ + 'σ' : float; + } + + + type 'constraint-validation' { + } +} \ No newline at end of file -- GitLab