From 7f89d81e6f8a5ce82d42c3b852b5219edaa4b86c Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Wed, 7 May 2014 18:38:27 +0100 Subject: Removed reflection for now, added fitness orientation support --- src/jcgp/backend/population/Chromosome.java | 4 +- src/jcgp/backend/population/Mutable.java | 53 +++++++++++++++++++++++++ src/jcgp/backend/population/MutableElement.java | 53 ------------------------- src/jcgp/backend/population/Node.java | 6 +-- src/jcgp/backend/population/Output.java | 6 +-- 5 files changed, 61 insertions(+), 61 deletions(-) create mode 100644 src/jcgp/backend/population/Mutable.java delete mode 100644 src/jcgp/backend/population/MutableElement.java (limited to 'src/jcgp/backend/population') diff --git a/src/jcgp/backend/population/Chromosome.java b/src/jcgp/backend/population/Chromosome.java index 0dfa801..673bb26 100644 --- a/src/jcgp/backend/population/Chromosome.java +++ b/src/jcgp/backend/population/Chromosome.java @@ -283,12 +283,12 @@ public class Chromosome implements Comparable { /** * This method is useful for mutating chromosomes. It returns any - * random {@code MutableElement} out of the chromosome with equal + * random {@code Mutable} out of the chromosome with equal * probability. * * @return a random element that can be mutated - node or output. */ - public MutableElement getRandomMutableElement() { + public Mutable getRandomMutable() { // choose output or node int index = resources.getRandomInt(outputs.length + (resources.rows() * resources.columns())); diff --git a/src/jcgp/backend/population/Mutable.java b/src/jcgp/backend/population/Mutable.java new file mode 100644 index 0000000..3ce7065 --- /dev/null +++ b/src/jcgp/backend/population/Mutable.java @@ -0,0 +1,53 @@ +package jcgp.backend.population; + +/** + * {@code Mutable} declares the expected behaviour of any + * part of a chromosome that is mutable, more specifically + * nodes or outputs. Inputs are not mutable since they don't have + * connections or functions. + *

+ * This interface provides a way to deal with mutable elements + * generically without having to specify whether they are nodes + * or outputs. In this way a random mutable element can be picked and + * dealt with more easily, facilitating mutations. + * + * @author Eduardo Pedroni + * + */ +public interface Mutable { + + /** + * This method sets the indexed connection to the specified new connection. + * Implementing classes may choose to ignore the given index (such as in the + * case of outputs, which only have one connection). + * + * @param index the connection index to set. + * @param newConnection the chromosome element to connect to. + */ + public void setConnection(int index, Connection newConnection); + + /** + * Asserts if the specified element is a copy of the elements + * this is called on.
+ * This method returns true if and only if: + * + *

+ * The relationship computed by this method is: + * + * @param element the mutable element to compare to. + * @return true if {@code element} is a copy of this element. + */ + boolean copyOf(Mutable element); + +} diff --git a/src/jcgp/backend/population/MutableElement.java b/src/jcgp/backend/population/MutableElement.java deleted file mode 100644 index 5782a99..0000000 --- a/src/jcgp/backend/population/MutableElement.java +++ /dev/null @@ -1,53 +0,0 @@ -package jcgp.backend.population; - -/** - * {@code MutableElement} declares the expected behaviour of any - * part of a chromosome that is mutable, more specifically - * nodes or outputs. Inputs are not mutable since they don't have - * connections or functions. - *

- * This interface provides a way to deal with mutable elements - * generically without having to specify whether they are nodes - * or outputs. In this way a random mutable element can be picked and - * dealt with more easily, facilitating mutations. - * - * @author Eduardo Pedroni - * - */ -public interface MutableElement { - - /** - * This method sets the indexed connection to the specified new connection. - * Implementing classes may choose to ignore the given index (such as in the - * case of outputs, which only have one connection). - * - * @param index the connection index to set. - * @param newConnection the chromosome element to connect to. - */ - public void setConnection(int index, Connection newConnection); - - /** - * Asserts if the specified element is a copy of the elements - * this is called on.
- * This method returns true if and only if: - * - *

- * The relationship computed by this method is: - * - * @param element the mutable element to compare to. - * @return true if {@code element} is a copy of this element. - */ - boolean copyOf(MutableElement element); - -} diff --git a/src/jcgp/backend/population/Node.java b/src/jcgp/backend/population/Node.java index 704b24e..3bcf3da 100644 --- a/src/jcgp/backend/population/Node.java +++ b/src/jcgp/backend/population/Node.java @@ -10,7 +10,7 @@ import jcgp.backend.function.Function; * contains a function and a number of connections. * The node outputs the result of performing its function * on the values of its connections. Nodes therefore - * implement both {@code MutableElement} and {@code Connection} + * implement both {@code Mutable} and {@code Connection} * since they can be mutated but also connected to. * Nodes are constructed with a fixed number of connections * (determined by the maximum arity of the function set) @@ -20,7 +20,7 @@ import jcgp.backend.function.Function; * @author Eduardo Pedroni * */ -public class Node implements MutableElement, Connection { +public class Node implements Mutable, Connection { private Function function; private Connection[] connections; @@ -124,7 +124,7 @@ public class Node implements MutableElement, Connection { } @Override - public boolean copyOf(MutableElement element) { + public boolean copyOf(Mutable element) { // both cannot be the same instance if (this != element) { // element must be instance of node diff --git a/src/jcgp/backend/population/Output.java b/src/jcgp/backend/population/Output.java index ab693e2..938741b 100644 --- a/src/jcgp/backend/population/Output.java +++ b/src/jcgp/backend/population/Output.java @@ -12,7 +12,7 @@ import java.util.ArrayList; * @author Eduardo Pedroni * */ -public class Output implements MutableElement { +public class Output implements Mutable { private Connection source; private Chromosome chromosome; @@ -56,7 +56,7 @@ public class Output implements MutableElement { * is simply ignored and the output source is * set. * - * @see jcgp.backend.population.MutableElement#setConnection(int, jcgp.backend.population.Connection) + * @see jcgp.backend.population.Mutable#setConnection(int, jcgp.backend.population.Connection) */ @Override public void setConnection(int index, Connection newConnection) { @@ -66,7 +66,7 @@ public class Output implements MutableElement { } @Override - public boolean copyOf(MutableElement m) { + public boolean copyOf(Mutable m) { // both cannot be the same instance if (this != m) { // element must be instance of output -- cgit v1.2.3