# Generic Constraints

To represent generic constraints on real-valued functions, this class can parse String expressions in prefix notation of the form:

> <expr> ::= <constant-operator> | <functional-operator> "(" <arguments> ")"
> <arguments> ::= <expr> | <expr> "," <arguments>

Setting the constraint string: Constant operators have an arity of zero. Examples are:
(pi,0) (X,0) (1.0,0)
Functional operators have an arity greater zero. Examples are:
(sum,1) (prod,1) (abs,1) (sin,1) (pow2,1) (pow3,1) (sqrt,1) (neg,1) (cos,1) (exp,1)
(+,2) (-,2) (/,2) (*,2)

Additionally, any numerical strings can also be used; they are parsed to numeric constants. The literal n is parsed to the current number of problem dimensions.
Notice that only the sum and prod operators may receive the literal X as input, standing for the full solution vector. Access to single solution components is possible by writing x0...x9 for a problem with 10 dimensions.

Thus you may write +(-(5,sum(X)),+sin(/(x0,pi))) and select 'lessEqZero' as relation to require valid solutions to fulfill 5-sum(X)+sin(x0/pi)<=0.

Typical relations concerning constraints allow for g(x)<=0, g(x)==0, or g(x)>=0 for constraint g. Notice that equal-to-zero constraints are converted to g(x)==0 <=> |g(x)-epsilon|<=0 for customizable small values of epsilon.

The handling method defines how EvA 2 copes with the constraint. Simplest variant is an additive penalty which is scaled by the penalty factor and then added directly to the fitness of an individual. This will work for any optimization strategy, but results will depend on the selection of penalty factors. Multiplicative penalty works analogously with the difference of being multiplied with the raw fitness.
In the variant called specific tag, the constraint violation is stored in an extra field of any individual and may be regarded by the optimization strategy. However, not all strategies provide simple mechanisms of incorporating this specific tag.