Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Luis Guimbarda
committed
Feb 14, 2012
1 parent
41f8240
commit 64be16a
Showing
2,592 changed files
with
718,684 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<parent> | ||
<groupId>com.xtructure.xnet</groupId> | ||
<artifactId>xnet</artifactId> | ||
<version>0.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.xtructure.xnet.demos</groupId> | ||
<artifactId>demos</artifactId> | ||
<packaging>jar</packaging> | ||
<name>demos</name> | ||
<url>http://www.xtructure.com</url> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.xtructure.xnet.xart</groupId> | ||
<artifactId>xart</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.xtructure.xnet.xbatch</groupId> | ||
<artifactId>xbatch</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.xtructure.xnet.xevolution</groupId> | ||
<artifactId>xevolution</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.xtructure.xnet.xneat</groupId> | ||
<artifactId>xneat</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.xtructure.xnet.xsim</groupId> | ||
<artifactId>xsim</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.xtructure.xnet.xutil</groupId> | ||
<artifactId>xutil</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
85 changes: 85 additions & 0 deletions
85
xnet/demos/src/main/java/com/xtructure/xnet/demos/arith/ArithmeticCrossoverOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright 2012 Michael Roberts | ||
* All rights reserved. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
package com.xtructure.xnet.demos.arith; | ||
|
||
import static com.xtructure.xutil.valid.ValidateUtils.isEqualTo; | ||
import static com.xtructure.xutil.valid.ValidateUtils.validateArg; | ||
|
||
import com.xtructure.xevolution.genetics.GeneticsFactory; | ||
import com.xtructure.xevolution.genetics.Genome; | ||
import com.xtructure.xevolution.operator.CrossoverOperator; | ||
import com.xtructure.xevolution.operator.impl.AbstractOperator; | ||
import com.xtructure.xutil.RandomUtil; | ||
|
||
/** | ||
* The Class ArithmeticCrossoverOperator. | ||
* | ||
* @author Luis Guimbarda | ||
*/ | ||
public class ArithmeticCrossoverOperator extends AbstractOperator<String> | ||
implements CrossoverOperator<String> { | ||
|
||
/** | ||
* Instantiates a new arithmetic crossover operator. | ||
* | ||
* @param geneticsFactory | ||
* the genetics factory | ||
*/ | ||
public ArithmeticCrossoverOperator(GeneticsFactory<String> geneticsFactory) { | ||
super(geneticsFactory); | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* | ||
* @see com.xtructure.xevolution.operator.CrossoverOperator#crossover(int, | ||
* com.xtructure.xevolution.genetics.Genome, | ||
* com.xtructure.xevolution.genetics.Genome) | ||
*/ | ||
@Override | ||
public Genome<String> crossover(int idNumber, Genome<String> genome1, | ||
Genome<String> genome2) throws OperationFailedException { | ||
validateArg("genome1 data is expected length", genome1.getData() | ||
.length(), isEqualTo(ArithmeticGenomeDecoder.EXPRESSION_LENGTH)); | ||
validateArg("genome2 data is expected length", genome2.getData() | ||
.length(), isEqualTo(ArithmeticGenomeDecoder.EXPRESSION_LENGTH)); | ||
String chromosome1 = genome1.getData(); | ||
String chromosome2 = genome2.getData(); | ||
int index = RandomUtil | ||
.nextInteger(ArithmeticGenomeDecoder.EXPRESSION_LENGTH); | ||
String pre1 = chromosome1.substring(0, index); | ||
String post1 = chromosome1.substring(index); | ||
String pre2 = chromosome2.substring(0, index); | ||
String post2 = chromosome2.substring(index); | ||
Genome<String> child = null; | ||
if (RandomUtil.eventOccurs(0.5)) { | ||
child = getGeneticsFactory().createGenome(idNumber, pre1 + post2); | ||
} else { | ||
child = getGeneticsFactory().createGenome(idNumber, pre2 + post1); | ||
} | ||
child.validate(); | ||
return child; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
xnet/demos/src/main/java/com/xtructure/xnet/demos/arith/ArithmeticEvaluationStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2012 Michael Roberts | ||
* All rights reserved. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
package com.xtructure.xnet.demos.arith; | ||
|
||
import com.xtructure.xevolution.evolution.EvaluationStrategy; | ||
import com.xtructure.xevolution.evolution.impl.AbstractEvaluationStrategy; | ||
import com.xtructure.xevolution.genetics.Genome; | ||
|
||
/** | ||
* The Class ArithmeticEvaluationStrategy. | ||
* | ||
* @author Luis Guimbarda | ||
*/ | ||
public class ArithmeticEvaluationStrategy extends | ||
AbstractEvaluationStrategy<String, Integer> implements | ||
EvaluationStrategy<String, Integer> { | ||
|
||
/** The target. */ | ||
private final int target; | ||
|
||
/** | ||
* Instantiates a new arithmetic evaluation strategy. | ||
* | ||
* @param target | ||
* the target | ||
*/ | ||
public ArithmeticEvaluationStrategy(int target) { | ||
super(new ArithmeticGenomeDecoder()); | ||
this.target = target; | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* | ||
* @see | ||
* com.xtructure.xevolution.evolution.EvaluationStrategy#simulate(com.xtructure | ||
* .xevolution.genetics.Genome) | ||
*/ | ||
@Override | ||
public double simulate(Genome<String> genome) { | ||
int num = getGenomeDecoder().decode(genome); | ||
double fitness = 1.0 / (1 + Math.abs(target - num)); | ||
genome.setAttribute(Genome.FITNESS_ATTRIBUTE_ID, fitness); | ||
return fitness; | ||
} | ||
} |
Oops, something went wrong.