Skip to content

Commit

Permalink
Initial clean commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Guimbarda committed Feb 14, 2012
1 parent 41f8240 commit 64be16a
Show file tree
Hide file tree
Showing 2,592 changed files with 718,684 additions and 0 deletions.
48 changes: 48 additions & 0 deletions xnet/demos/pom.xml
@@ -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>
@@ -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;
}
}
@@ -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;
}
}

0 comments on commit 64be16a

Please sign in to comment.