Interface Variable

All Superinterfaces:
Copyable<Variable>, Defined, Named, Serializable
All Known Implementing Classes:
AbstractVariable, BinaryIntegerVariable, BinaryVariable, Grammar, Permutation, Program, RealVariable, Subset

public interface Variable extends Copyable<Variable>, Serializable, Defined, Named
Interface for decision variables.

Implementations are encouraged to also override Object.equals(Object) and Object.hashCode(). These are used, for example, to exclude duplicate solutions from populations.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.moeaframework.core.Defined

    Defined.ConstructorComparator
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    decode(String value)
    Parses and loads the value of this variable from a string.
    Encodes the value of this variable as a string.
    static String
    getNameOrDefault(Variable variable, int index)
    Returns the name of the variable, using either the name assigned to the variable or deriving the name from its index.
    void
    Randomly assign the value of this variable.
    Returns a human-readable representation of this value.

    Methods inherited from interface org.moeaframework.core.Copyable

    copy

    Methods inherited from interface org.moeaframework.core.Defined

    getDefinition

    Methods inherited from interface org.moeaframework.core.Named

    getName
  • Method Details

    • randomize

      void randomize()
      Randomly assign the value of this variable.
    • toString

      String toString()
      Returns a human-readable representation of this value.
      Overrides:
      toString in class Object
      Returns:
      the value of this variable formatted as a string
    • encode

      String encode()
      Encodes the value of this variable as a string. This should reflect the internal representation of the value and not necessarily the actual value. For example, a binary-encoded integer should display the bits and not the integer value.

      Implementations should make an effort to display the value in a meaningful format, but that is not required. Instead, use toString() if a human-readable format is required.

      This method along with decode(String) are used primarily for storing values in text files. To make parsing easier, the resulting string must:

      1. Only contain ASCII characters
      2. Contain no whitespace (no spaces, tabs, newlines, etc.)
      Returns:
      the encoded value as a string
      Throws:
      VariableEncodingException - if an error occurred while encoding this variable
    • decode

      void decode(String value)
      Parses and loads the value of this variable from a string. This must be able to process any string produced by encode().
      Parameters:
      value - the value as a string
      Throws:
      VariableEncodingException - if an error occurred while decoding this variable
    • getNameOrDefault

      static String getNameOrDefault(Variable variable, int index)
      Returns the name of the variable, using either the name assigned to the variable or deriving the name from its index.
      Parameters:
      variable - the variable
      index - the index of the variable
      Returns:
      the name of the variable