Definition Language

The definition language lets EvoAl extenders specify their extension for the domain-specific languages. For this purpose, it provides capabilities to describe types and functions and allows you to define constants. The files follow the standard file structure and have the file ending .dl. Whether you must define constants, functions or types—or all—depends on the extension you create.

Constants

A constant is a non-changeable value that can be used in any DSL, e.g. the constant π. π is a value that can come in handy in many situations. Therefore, we can define it using the following specification in a definition module:

module de.evoal.core.math {
  const real PI := 3.1415926535;
}

This example specifies the module de.evoal.core.math, which must be stored in de/evoal/core/math.dl. As described in the common file syntax page, we can also use the name π itself:

module de.evoal.core.math {
  const real 'π' := 3.1415926535;
}

The keyword const tells EvoAl that a constant definition follows. Then, we have to specify the type—real in this case—of the constant. Existing types are described in the following types section. Afterwards, the constant’s name is defined, followed by the constant value.

Types

In EvoAl, data is typed, meaning every expression has a type. EvoAl pre-defines a limited set of basic data types to use: boolean, int, real, string, and void. Additionally, every type can be used in an array as well as shown in the following example:

import "definitions" from de.evoal.core.math;

module com.example {

	const boolean booleanValue := true;

	const int integerValue := 1;
	
	const real realValue := 2.0;
	
	const string stringValue := "Hello EvoAl";
			
	const array array int twoDimensional := [
		[1, 2],
		[3, 4]
	];

    // the example is continued below
}

Furthermore, it is possible to use a self-defined structure type by using instance <structured type name> and self-defined data. An attribute of type path takes a path expression, e.g. features : path;. We will explain these data types in the corresponding sections on structure types and the Data Description Language.

Functions

In some cases, EvoAl allows you to define functions, for instance, goodness-of-fit measures for the surrogate training. A function definition starts with the keyword def. After that, a function has a return type, which may be void if your method does not return a value. Afterwards, you specify the function’s name and the list of parameters (enclosed by parentheses).

  // ...
  def void 'my-function'(expression parameter);

  // the example is continued below

The shown code-snipped defines a function called my-function of type void that expects a single parameter. In this case, the parameter is expected to be an expression of some type that the function will interpret.

Structured types

A type allows you to specify structured data. It is comparable to classes from object-oriented programming languages (except for no methods) or structures.

  // ...

  abstract type shape {
    x : int := 0;
    y : int := 0;
  }

  type circle extends shape {
    circumference : real := 2 * 'π' * 4.0;
  }

  // the example is continued below

The example above defines an abstract type named shape in the module com.example. The abstract modifier tells EvoAl that this type cannot be used in one of the other DSL files. Instead, it can be referenced by other type definitions. The shape defines two integer attributes, called x and y and assigns them a default value.

In the example, the type circle extends the shape. This means the circle inherits all attributes of shape and adds the circumference attribute. In this case, the default value is more complex and uses the constant 'π' from module de.evoal.core.math.

An attribute of type instance shape accepts an instance of shape or of a type that extends it, e.g. circle {}. The instance is part of the instance that holds it: an attribute instance T or array instance T is a containment, so a configuration or a model is a tree of instances. Likewise, an attribute of type enum E accepts only the literals of the enum E, and an array attribute applies these rules to each element. EvoAl checks values that are instances, literals or arrays when it loads a configuration and stops with an error that names the file and the attribute, e.g. for a string where an enum literal is expected.

Annotations

Types, enumerations, functions, the parameters of functions and attributes can carry annotations, written in front of the declaration as @<type> { … }. An annotation is an instance of a DL type, e.g. the constraints of de.evoal.core.constraints:

  import "definitions" from 'de.evoal.core.constraints';

  // ...
  @Literature { keys := ["harik1997learning"]; }
  def void 'building-block'(@MinimumNumberOfElements { bound := 2; } array data features);

  type circle extends shape {
    @LowerBoundary { boundary := 0.0; }
    radius : real;
  }

@LowerBoundary restricts the values of the attribute, @MinimumNumberOfElements the argument of every call of 'building-block': an annotation on a parameter is checked for every call against the argument, e.g. 'building-block'([data 'x:0']) stops EvoAl with the file, the line, the function and the parameter. A requirement on data (@RequiresScale, @RequiresRepresentation, @RequiresBoundaries) on a parameter starts its path at the data of the argument, so features := path "." checks the data itself, e.g. the features of correlation must be at least ordinal. @Literature names the sources of a type or function by their BibTeX keys; a type also has the literature of its super types. The full entries are in META-INF/evoal/credits.bib of the plugin (or of a module it depends on), and every optimisation run lists the literature of the types and functions its configuration uses (see Literature of a run). The documentation of a type names the source briefly, e.g. “(Harik and Goldberg 1997, section 2)”.

Constraint annotations

These annotations of de.evoal.core.constraints are checked when EvoAl loads a configuration, before the run starts:

Annotation On A valid value
@LowerBoundary { boundary := b; inclusive := i; } a number, or every element of an array >= b (inclusive := true, the default) or > b
@UpperBoundary { boundary := b; inclusive := i; } a number, or every element of an array <= b (inclusive := true, the default) or < b
@MinimumNumberOfElements { bound := n; } an array has at least n elements
@MaximumNumberOfElements { bound := n; } an array has at most n elements
@Scale { scale := 'measurement-scale.cardinal'; } an attribute no check; states the scale of measurement of the attribute (see below)
@MultiVariateConstraint { 'expression' := …; } a type the expression is true, e.g. self.'c1' + self.'c2' >= 4.0; it can use path expressions, e.g. !exists(path "c1") OR … for an optional attribute
@RequiresScale { minimum := …; features := path "…"; } a type every data the path selects has at least the scale minimum (nominal < ordinal < cardinal < quotient); data without a scale is nominal, typed data has the scale of its type
@RequiresRepresentation { representations := […]; features := path "…"; } a type every data the path selects is real, integer, boolean or string data as listed
@RequiresBoundaries { lower := …; upper := …; features := path "…"; } a type every data the path selects has the required @LowerBoundary/@UpperBoundary; the range of the representation does not count, but boolean data is always bounded
@Requires { selection := path "…"; } a type the path selects at least one object
@Excludes { selection := path "…"; } a type the path selects nothing
@RequiresFitnessComponents { minimum := n; maximum := m; } a type the fitness has at least n (default 1) and at most m (no limit if not set) components; checked when the run builds its fitness pipeline, see below

The annotations on a type are checked for every instance of the type and of its subtypes. The requirement annotations state what a component needs from the data it works on or from the other components of a configuration, e.g.:

@RequiresRepresentation { representations := ['representation.real']; features := path "/algorithm/problem/searchSpace"; }
@RequiresScale { minimum := 'measurement-scale.cardinal'; features := path "/algorithm/problem/searchSpace"; }
type 'particle-swarm-optimisation' extends 'algorithm' { … }

@RequiresBoundaries { lower := true; upper := true; features := path "/algorithm/problem/searchSpace"; }
@Requires { selection := path "../mover[arpso-mover]"; }
type 'arpso-swarm' extends 'swarm' { … }

A configuration that violates one stops with the file, the line, the path of the instance and the data or the selection, e.g. “‘particle-swarm-optimisation’ needs data of at least cardinal scale, but ‘x:1’ is ordinal”. Alternatives of @Requires are a union in the path; several annotations on a type must all hold.

An attribute that is optional and has no default has no value when a configuration does not set it, so self.'a' cannot be read then. exists(path "a") tells whether it has a value, and AND/OR stop at the operand that decides the result, e.g. for CMA-ES:

@MultiVariateConstraint { 'expression' := !exists(path "parent-number") OR !exists(path "population-size")
                                          OR 2 * self.'parent-number' <= self.'population-size'; }
type 'cma-es' extends 'algorithm' { … }

The number of fitness components follows from the goals of the problem and the steps of the 'fitness-pipeline' (a scalarisation such as 'weighted-sum' makes one), so @RequiresFitnessComponents is checked when an optimisation run builds its fitness pipeline, before the algorithm starts, for every configuration of the algorithm, e.g. the roulette wheel selection needs exactly one component and 'nsga2-selection' at least two.

The value is computed from the configuration, so formulas and constants are allowed (2.0 / 4.0 is checked as 0.5). An attribute that a configuration does not set is not checked there; its DL default is checked against the annotations where it is declared. A value that is only known during the run (e.g. data) is not checked; EvoAl reports this as an info.

Every constraint annotation has a severity that states how serious a violation is:

severity Meaning When EvoAl loads a configuration
Severity.error (the default) the value cannot work, e.g. a parameter the library rejects EvoAl stops with an error that names the file, the line and the attribute
Severity.warning the value works but is likely a mistake EvoAl prints a warning and the run continues
@LowerBoundary { boundary := 0.0; severity := Severity.warning; }
offset : real;

The step 'constraint-validation' of the generator language checks the same annotations on every generated row and chooses its reaction by the severity.

Annotations of model attributes

When a DL type describes a model that is searched (structured data data 'x' of instance T in the search space, see Optimisers), the annotations of its attributes also describe the values the search draws:

  • @LowerBoundary/@UpperBoundary on a number are the range of its random values; without them the range of int or real is used.
  • @MinimumNumberOfElements/@MaximumNumberOfElements on an array are the number of its elements; an array of a model needs @MaximumNumberOfElements.
  • @Scale states the scale of measurement (nominal < ordinal < cardinal < quotient) that the scale of DDL data states; an attribute without @Scale is nominal, an attribute of an enum has the scale of its enum.

Path expressions

A path expression selects objects of the configuration tree, starting at the instance it is evaluated for, in the style of XPath: path "../mover[arpso-mover]". The path is a string because // starts a comment and / is the division in the expressions.

Step Selects
. the object itself
.. the containing object
/ (at the start) the root: the module of the file, in every language
// all objects below, including the object itself
name the child name: an attribute of a DL instance, or a property of a language construct
* all children
[T] the selected instances of the DL type T or one of its subtypes; after a step (criteria[T]) or as a step of its own ([T]/criteria)
[exactly T] the selected instances of exactly the type T
p1 \| p2 the union of the selections of both paths
(p) a group
(p)* p zero or more times
(p)+ p one or more times
  • Names can be quoted ('maximum-iterations') and mean the same as without quotes; inside a path, unquoted names can contain -. Groups and repetitions follow the property paths of SPARQL 1.1; * directly after a closing parenthesis is the repetition, elsewhere it selects all children. A group directly after a step repeats from that step.
  • A DL instance has its DL attributes as children; an attribute that the instance does not set has its DL default. A language construct has its properties as children, e.g. algorithm of an OL module, problem of the configure block, searchSpace of the problem, writes of a generator step. The configure block has both: the DL attributes of its algorithm and the properties definition, problem, attributes and documentation. A DL attribute of an algorithm type with one of these names would hide the property; no such attribute exists.
  • A step into an array selects its elements, a reference to data selects the data. * and // follow only what an object contains, not references such as problem. A value (e.g. a number) has no parent.
  • A path selects every object once, a value as often as it is reached. A type name that no DL module of the configuration declares is an error.

Examples:

Path Selects
path "/algorithm/problem/searchSpace" the search variables of the problem the configuration is bound to, also if the problem is declared in another module
path "../features" the data of the attribute features of the containing instance
path "(..)+[double-chromosome]" the enclosing 'double-chromosome', at any depth (e.g. for an EA operator inside another operator)
path "/algorithm/stopping-criteria([any-of]/criteria)*[iteration-count]" the 'iteration-count's among the stopping criteria, also inside (nested) 'any-of's, but not inside an 'all-of'

In a @MultiVariateConstraint, the functions count, exists, min and max of de.evoal.core.constraints take the selection of a path, e.g. the rule of 'linear-decrease':

@MultiVariateConstraint {
    'expression' := count(path "/algorithm/stopping-criteria([any-of]/criteria)*[iteration-count]") = 0
                    OR self.'iterations' <= min(path "/algorithm/stopping-criteria([any-of]/criteria)*[iteration-count]/maximum-iterations");
}
type 'linear-decrease' extends 'decreasing-strategy' { … }

EvoAl checks the paths when it loads a configuration: a syntax error or an unknown type name is reported with its position in the path. The IDE does not know path expressions yet.

Documentation

Like well-known programming languages like Java, EvoAl interprets multi-line comments in front declarations (constants, functions, types, and attributes) as the declaration’s documentation. Documenting your definition files will help users to use your extensions since they will see the documentation as a tooltip. Thus, we suggest you to document your extensions properly.