MOEA Framework 2.12
API Specification

org.moeaframework.util.grammar
Class ContextFreeGrammar

java.lang.Object
  extended by org.moeaframework.util.grammar.ContextFreeGrammar

public class ContextFreeGrammar
extends Object

A context-free grammar. The rule at index 0 is the starting rule when building derivation trees.

See Also:
Rule

Constructor Summary
ContextFreeGrammar()
          Constructs an empty grammar.
 
Method Summary
 void add(Rule rule)
          Adds a rule to this grammar.
 String build(int[] array)
          Returns the grammar derivation using the construction rules of Grammatical Evolution on the specified codon array; or null if the codon array failed to produce a valid derivation Whenever the derivation encounters a rule with multiple productions, the production used to expand the rule is chosen using this codon array.
 Rule get(int index)
          Returns the rule at the specified index.
 Rule get(Symbol symbol)
          Returns the rule for the specified symbol; or null if no rule with the specified symbol exists.
 int getWrapLimit()
          Returns the maximum number of times the builder will wrap around the codon array before failing to produce a valid derivation.
 boolean isValid()
          Returns true if this grammar is valid; false otherwise.
 void remove(Rule rule)
          Removes a rule from this grammar.
 void setWrapLimit(int wrapLimit)
          Sets the maximum number of times the builder will wrap around the codon array before failing to produce a valid derivation.
 int size()
          Returns the number of rules contained in this grammar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContextFreeGrammar

public ContextFreeGrammar()
Constructs an empty grammar.

Method Detail

getWrapLimit

public int getWrapLimit()
Returns the maximum number of times the builder will wrap around the codon array before failing to produce a valid derivation.

Returns:
the maximum number of times the builder will wrap around the codon array before failing to produce a valid derivation

setWrapLimit

public void setWrapLimit(int wrapLimit)
Sets the maximum number of times the builder will wrap around the codon array before failing to produce a valid derivation.

Parameters:
wrapLimit - the maximum number of times the builder will wrap around the codon array before failing to produce a valid derivation

add

public void add(Rule rule)
Adds a rule to this grammar.

Parameters:
rule - the rule to be added

remove

public void remove(Rule rule)
Removes a rule from this grammar.

Parameters:
rule - the rule to be removed

size

public int size()
Returns the number of rules contained in this grammar.

Returns:
the number of rules contained in this grammar

get

public Rule get(int index)
Returns the rule at the specified index.

Parameters:
index - the index of the rule to be returned
Returns:
the rule at the specified index
Throws:
IndexOutOfBoundsException - if index is out of range ((index < 0) || (index >= size())

get

public Rule get(Symbol symbol)
Returns the rule for the specified symbol; or null if no rule with the specified symbol exists.

Parameters:
symbol - the symbol of the rule to be returned
Returns:
the rule for the specified symbol; or null if no rule with the specified symbol exists

build

public String build(int[] array)
Returns the grammar derivation using the construction rules of Grammatical Evolution on the specified codon array; or null if the codon array failed to produce a valid derivation Whenever the derivation encounters a rule with multiple productions, the production used to expand the rule is chosen using this codon array.

Parameters:
array - the codon array
Returns:
the grammar derivation using the construction rules of Grammatical Evolution on the specified codon array; or null if the codon array failed to produce a valid derivation
Throws:
GrammarException - if the codon array is empty

isValid

public boolean isValid()
Returns true if this grammar is valid; false otherwise. A grammar is valid if it is non-empty and all non-terminal symbols are defined by a rule in the grammar.

Returns:
true if this grammar is valid; false otherwise

MOEA Framework 2.12
API Specification

Copyright 2009-2016 MOEA Framework. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage. Visit us on Github!