ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ch...@apache.org
Subject [3/3] ignite git commit: IGNITE-6899: Adding GA Grid to Apache Ignite ML module.
Date Sun, 04 Mar 2018 15:08:05 GMT
IGNITE-6899: Adding GA Grid to Apache Ignite ML module.

This closes #3347


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/0cdded31
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/0cdded31
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/0cdded31

Branch: refs/heads/master
Commit: 0cdded31ecabfd34b47e55c51a8c1e1bf4f9d667
Parents: 932692e
Author: Turik Campbell <admin@techbysample.com>
Authored: Sun Mar 4 18:07:52 2018 +0300
Committer: Yury Babak <ybabak@gridgain.com>
Committed: Sun Mar 4 18:07:52 2018 +0300

----------------------------------------------------------------------
 examples/pom.xml                                |   9 +-
 .../ignite/examples/ml/genetic/change/Coin.java |  88 ++++
 .../OptimizeMakeChangeFitnessFunction.java      | 106 +++++
 .../change/OptimizeMakeChangeGAExample.java     | 207 +++++++++
 .../OptimizeMakeChangeTerminateCriteria.java    |  83 ++++
 .../helloworld/HelloWorldFitnessFunction.java   |  64 +++
 .../genetic/helloworld/HelloWorldGAExample.java | 120 +++++
 .../helloworld/HelloWorldTerminateCriteria.java |  88 ++++
 .../ignite/examples/ml/genetic/movie/Movie.java | 133 ++++++
 .../ml/genetic/movie/MovieFitnessFunction.java  | 105 +++++
 .../ml/genetic/movie/MovieGAExample.java        | 267 +++++++++++
 .../genetic/movie/MovieTerminateCriteria.java   |  88 ++++
 modules/ml/pom.xml                              |  13 +
 .../apache/ignite/ml/genetic/Chromosome.java    | 107 +++++
 .../apache/ignite/ml/genetic/CrossOverJob.java  | 142 ++++++
 .../apache/ignite/ml/genetic/CrossOverTask.java | 137 ++++++
 .../apache/ignite/ml/genetic/FitnessJob.java    | 101 +++++
 .../apache/ignite/ml/genetic/FitnessTask.java   | 103 +++++
 .../org/apache/ignite/ml/genetic/GAGrid.java    | 454 +++++++++++++++++++
 .../java/org/apache/ignite/ml/genetic/Gene.java |  86 ++++
 .../ignite/ml/genetic/IFitnessFunction.java     |  39 ++
 .../org/apache/ignite/ml/genetic/MutateJob.java |  94 ++++
 .../apache/ignite/ml/genetic/MutateTask.java    | 191 ++++++++
 .../ignite/ml/genetic/TruncateSelectionJob.java |  88 ++++
 .../ml/genetic/TruncateSelectionTask.java       | 173 +++++++
 .../ml/genetic/cache/GeneCacheConfig.java       |  52 +++
 .../ml/genetic/cache/PopulationCacheConfig.java |  53 +++
 .../ignite/ml/genetic/cache/package-info.java   |  21 +
 .../ml/genetic/functions/GAGridFunction.java    | 132 ++++++
 .../ml/genetic/functions/package-info.java      |  21 +
 .../apache/ignite/ml/genetic/package-info.java  |  21 +
 .../genetic/parameter/ChromosomeCriteria.java   |  50 ++
 .../ml/genetic/parameter/GAConfiguration.java   | 333 ++++++++++++++
 .../ml/genetic/parameter/GAGridConstants.java   |  37 ++
 .../genetic/parameter/ITerminateCriteria.java   |  39 ++
 .../ml/genetic/parameter/package-info.java      |  21 +
 .../ignite/ml/genetic/utils/GAGridUtils.java    | 124 +++++
 .../ignite/ml/genetic/utils/package-info.java   |  21 +
 .../org/apache/ignite/ml/IgniteMLTestSuite.java |   6 +-
 .../ml/genetic/GAGridCalculateFitnessTest.java  | 141 ++++++
 .../genetic/GAGridInitializePopulationTest.java | 153 +++++++
 .../ignite/ml/genetic/GAGridTestSuite.java      |  33 ++
 .../ml/genetic/PasswordFitnessFunction.java     |  61 +++
 43 files changed, 4400 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index a992820..cab1a89 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -7,9 +7,7 @@
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at
-
        http://www.apache.org/licenses/LICENSE-2.0
-
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -61,6 +59,11 @@
             <artifactId>ignite-indexing</artifactId>
             <version>${project.version}</version>
         </dependency>
+       <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-ml</artifactId>
+            <version>${project.version}</version>
+        </dependency>
 
         <dependency>
             <groupId>org.apache.ignite</groupId>
@@ -295,4 +298,4 @@
             </plugin>
         </plugins>
     </build>
-</project>
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/Coin.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/Coin.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/Coin.java
new file mode 100644
index 0000000..90f6e8f
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/Coin.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.ml.genetic.change;
+
+import java.io.Serializable;
+
+/**
+ * POJO to model a coin
+ */
+public class Coin implements Serializable {
+
+    public static enum CoinType {
+        PENNY, QUARTER, NICKEL, DIME
+    }
+
+    ;
+
+    /** number of coins */
+    private int numberOfCoins = 0;
+
+    private CoinType coinType = null;
+
+    /**
+     * @param coinType Type of coin
+     * @param numberOfCoins Number of coins
+     */
+    public Coin(CoinType coinType, int numberOfCoins) {
+        this.coinType = coinType;
+        this.numberOfCoins = numberOfCoins;
+    }
+
+    /**
+     * Retrieve the number of coins
+     *
+     * @return Number of coins
+     */
+    public int getNumberOfCoins() {
+        return numberOfCoins;
+    }
+
+    /**
+     * Set the number of coins
+     *
+     * @param numberOfCoins Number of coins
+     */
+    public void setNumberOfCoins(int numberOfCoins) {
+        this.numberOfCoins = numberOfCoins;
+    }
+
+    /**
+     * Retrieve Coin type
+     *
+     * @return Coin type
+     */
+    public CoinType getCoinType() {
+        return coinType;
+    }
+
+    /**
+     * Set Coin type
+     *
+     * @param coinType Coin Type
+     */
+    public void setCoinType(CoinType coinType) {
+        this.coinType = coinType;
+    }
+
+    @Override
+    public String toString() {
+        return "Coin [numberOfCoins=" + numberOfCoins + ", coinType=" + coinType + "]";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeFitnessFunction.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeFitnessFunction.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeFitnessFunction.java
new file mode 100644
index 0000000..faa113b
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeFitnessFunction.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.ml.genetic.change;
+
+import java.util.List;
+
+import org.apache.ignite.ml.genetic.Gene;
+import org.apache.ignite.ml.genetic.IFitnessFunction;
+
+/**
+ * This example demonstrates how to create a IFitnessFunction <br/>
+ *
+ * Your IFitness function will vary depending on your particular use case. <br/>
+ *
+ * For this fitness function, we simply want to calculate the value of  <br/>
+ *
+ * an individual solution relative to other solutions. <br/>
+ */
+
+public class OptimizeMakeChangeFitnessFunction implements IFitnessFunction {
+
+    int targetAmount = 0;
+
+    /**
+     * @param targetAmount Amount of change
+     */
+    public OptimizeMakeChangeFitnessFunction(int targetAmount) {
+        this.targetAmount = targetAmount;
+    }
+
+    /**
+     * Calculate fitness
+     *
+     * @param genes Genes
+     * @return Fitness value
+     */
+    public double evaluate(List<Gene> genes) {
+
+        int changeAmount = getAmountOfChange(genes);
+        int totalCoins = getTotalNumberOfCoins(genes);
+        int changeDifference = Math.abs(targetAmount - changeAmount);
+
+        double fitness = (99 - changeDifference);
+
+        if (changeAmount == targetAmount) {
+            fitness += 100 - (10 * totalCoins);
+        }
+
+        return fitness;
+
+    }
+
+    /**
+     * Calculate amount of change
+     *
+     * @param genes Genes
+     * @return Amount of change
+     */
+    private int getAmountOfChange(List<Gene> genes) {
+        Gene quarterGene = (Gene)genes.get(0);
+        Gene dimeGene = (Gene)genes.get(1);
+        Gene nickelGene = (Gene)genes.get(2);
+        Gene pennyGene = (Gene)genes.get(3);
+
+        int numQuarters = ((Coin)quarterGene.getValue()).getNumberOfCoins();
+        int numDimes = ((Coin)dimeGene.getValue()).getNumberOfCoins();
+        int numNickels = ((Coin)nickelGene.getValue()).getNumberOfCoins();
+        int numPennies = ((Coin)pennyGene.getValue()).getNumberOfCoins();
+
+        return (numQuarters * 25) + (numDimes * 10) + (numNickels * 5) + numPennies;
+    }
+
+    /**
+     * Return the total number of coins
+     *
+     * @param genes Genes
+     * @return Number of coins
+     */
+    private int getTotalNumberOfCoins(List<Gene> genes) {
+
+        int totalNumberOfCoins = 0;
+
+        for (Gene gene : genes) {
+            int numberOfCoins = ((Coin)gene.getValue()).getNumberOfCoins();
+            totalNumberOfCoins = totalNumberOfCoins + numberOfCoins;
+
+        }
+        return totalNumberOfCoins;
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeGAExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeGAExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeGAExample.java
new file mode 100644
index 0000000..ccd31cb
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeGAExample.java
@@ -0,0 +1,207 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.ml.genetic.change;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.Ignition;
+
+import org.apache.ignite.ml.genetic.Chromosome;
+import org.apache.ignite.ml.genetic.GAGrid;
+import org.apache.ignite.ml.genetic.Gene;
+import org.apache.ignite.ml.genetic.parameter.ChromosomeCriteria;
+import org.apache.ignite.ml.genetic.parameter.GAConfiguration;
+import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
+
+/**
+ * This example demonstrates how to use the GAGrid framework. <br/>
+ *
+ * This example is inspired by JGAP's "Minimize Make Change" example. <br/>
+ *
+ * In this example, the objective is to calculate the minimum number of coins that equal user specified amount of
+ * change
+ *
+ * ie: -DAMOUNTCHANGE
+ *
+ * mvn exec:java -Dexec.mainClass="org.apache.ignite.examples.ml.genetic.change.OptimizeMakeChangeGAExample"
+ * -DAMOUNTCHANGE=75
+ *
+ * <p> Remote nodes should always be started with special configuration file which enables P2P class loading: {@code
+ * 'ignite.{sh|bat} examples/config/example-ignite.xml'}.</p> <p> Alternatively you can run ExampleNodeStartup
+ * in another JVM which will start node with {@code examples/config/example-ignite.xml} configuration.</p>
+ */
+
+public class OptimizeMakeChangeGAExample {
+    private static Ignite ignite = null;
+    private static GAGrid gaGrid = null;
+    private static GAConfiguration gaConfig = null;
+
+    private static String sAmountChange = null;
+
+    private static IgniteLogger logger = null;
+
+    /**
+     * Executes example.
+     *
+     * Specify value for -DAMOUNTCHANGE JVM system variable
+     *
+     * @param args Command line arguments, none required.
+     */
+    public static void main(String args[]) {
+        System.setProperty("IGNITE_QUIET", "false");
+
+        sAmountChange = System.getProperty("AMOUNTCHANGE");
+
+        StringBuffer sbErrorMessage = new StringBuffer();
+        sbErrorMessage.append("AMOUNTCHANGE System property not set. Please provide a valid value between 1 and 99. ");
+        sbErrorMessage.append(" ");
+        sbErrorMessage.append("IE: -DAMOUNTCHANGE=75");
+
+        //Check if -DAMOUNTCHANGE JVM system variable is provided
+        if (sAmountChange == null) {
+            System.out.println(sbErrorMessage);
+            System.exit(1);
+        }
+
+        try {
+
+            //Create an Ignite instance as you would in any other use case.
+            ignite = Ignition.start("examples/config/example-ignite.xml");
+
+            logger = ignite.log();
+
+            // Create GAConfiguration
+            gaConfig = new GAConfiguration();
+
+            // set Gene Pool
+            List<Gene> genes = getGenePool();
+
+            // set selection method
+            gaConfig.setSelectionMethod(GAGridConstants.SELECTION_METHOD.SELECTON_METHOD_ELETISM);
+            gaConfig.setElitismCount(10);
+
+            // set the Chromosome Length to '4' since we have 4 coins.
+            gaConfig.setChromosomeLength(4);
+
+            // set population size
+            gaConfig.setPopulationSize(500);
+
+            // initialize gene pool
+            gaConfig.setGenePool(genes);
+
+            // set Truncate Rate
+            gaConfig.setTruncateRate(.10);
+
+            // set Cross Over Rate
+            gaConfig.setCrossOverRate(.50);
+
+            // set Mutation Rate
+            gaConfig.setMutationRate(.50);
+
+            // create and set Fitness function
+            OptimizeMakeChangeFitnessFunction function = new OptimizeMakeChangeFitnessFunction(new Integer(sAmountChange));
+            gaConfig.setFitnessFunction(function);
+
+            // create and set TerminateCriteria
+            OptimizeMakeChangeTerminateCriteria termCriteria = new OptimizeMakeChangeTerminateCriteria(ignite);
+
+            ChromosomeCriteria chromosomeCriteria = new ChromosomeCriteria();
+
+            List values = new ArrayList();
+
+            values.add("coinType=QUARTER");
+            values.add("coinType=DIME");
+            values.add("coinType=NICKEL");
+            values.add("coinType=PENNY");
+
+            chromosomeCriteria.setCriteria(values);
+
+            gaConfig.setChromosomeCriteria(chromosomeCriteria);
+            gaConfig.setTerminateCriteria(termCriteria);
+
+            // initialize GAGrid
+            gaGrid = new GAGrid(gaConfig, ignite);
+
+            logger.info("##########################################################################################");
+
+            logger.info("Calculating optimal set of coins where amount of change is " + sAmountChange);
+
+            logger.info("##########################################################################################");
+
+            Chromosome fittestChromosome = gaGrid.evolve();
+
+            Ignition.stop(true);
+            ignite = null;
+
+        }
+        catch (Exception e) {
+            System.out.println(e);
+        }
+
+    }
+
+    /**
+     * Helper routine to initialize Gene pool
+     *
+     * In typical usecase genes may be stored in database.
+     *
+     * @return List of Genes
+     */
+    private static List<Gene> getGenePool() {
+        List<Gene> list = new ArrayList();
+
+        Gene quarterGene1 = new Gene(new Coin(Coin.CoinType.QUARTER, 3));
+        Gene quarterGene2 = new Gene(new Coin(Coin.CoinType.QUARTER, 2));
+        Gene quarterGene3 = new Gene(new Coin(Coin.CoinType.QUARTER, 1));
+        Gene quarterGene4 = new Gene(new Coin(Coin.CoinType.QUARTER, 0));
+
+        Gene dimeGene1 = new Gene(new Coin(Coin.CoinType.DIME, 2));
+        Gene dimeGene2 = new Gene(new Coin(Coin.CoinType.DIME, 1));
+        Gene dimeGene3 = new Gene(new Coin(Coin.CoinType.DIME, 0));
+
+        Gene nickelGene1 = new Gene(new Coin(Coin.CoinType.NICKEL, 1));
+        Gene nickelGene2 = new Gene(new Coin(Coin.CoinType.NICKEL, 0));
+
+        Gene pennyGene1 = new Gene(new Coin(Coin.CoinType.PENNY, 4));
+        Gene pennyGene2 = new Gene(new Coin(Coin.CoinType.PENNY, 3));
+        Gene pennyGene3 = new Gene(new Coin(Coin.CoinType.PENNY, 2));
+        Gene pennyGene4 = new Gene(new Coin(Coin.CoinType.PENNY, 1));
+        Gene pennyGene5 = new Gene(new Coin(Coin.CoinType.PENNY, 0));
+
+        list.add(quarterGene1);
+        list.add(quarterGene2);
+        list.add(quarterGene3);
+        list.add(quarterGene4);
+        list.add(dimeGene1);
+        list.add(dimeGene2);
+        list.add(dimeGene3);
+        list.add(nickelGene1);
+        list.add(nickelGene2);
+        list.add(pennyGene1);
+        list.add(pennyGene2);
+        list.add(pennyGene3);
+        list.add(pennyGene4);
+        list.add(pennyGene5);
+
+        return list;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeTerminateCriteria.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeTerminateCriteria.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeTerminateCriteria.java
new file mode 100644
index 0000000..79601fe
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/change/OptimizeMakeChangeTerminateCriteria.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.ml.genetic.change;
+
+import java.util.List;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteLogger;
+
+import org.apache.ignite.ml.genetic.Chromosome;
+import org.apache.ignite.ml.genetic.Gene;
+import org.apache.ignite.ml.genetic.parameter.ITerminateCriteria;
+import org.apache.ignite.ml.genetic.utils.GAGridUtils;
+
+/**
+ * Terminate Condition implementation for OptimizeMakeChangeGATest <br/>
+ */
+public class OptimizeMakeChangeTerminateCriteria implements ITerminateCriteria {
+
+    private IgniteLogger igniteLogger = null;
+    private Ignite ignite = null;
+
+    /**
+     * @param ignite Ignite
+     */
+    public OptimizeMakeChangeTerminateCriteria(Ignite ignite) {
+        this.ignite = ignite;
+        this.igniteLogger = ignite.log();
+    }
+
+    /**
+     * @param fittestChromosome Most fit chromosome at for the nth generation
+     * @param averageFitnessScore Average fitness score as of the nth generation
+     * @param currentGeneration Current generation
+     * @return Boolean value
+     */
+    public boolean isTerminationConditionMet(Chromosome fittestChromosome, double averageFitnessScore,
+        int currentGeneration) {
+        boolean isTerminate = true;
+
+        igniteLogger.info("##########################################################################################");
+        igniteLogger.info("Generation: " + currentGeneration);
+        igniteLogger.info("Fittest is Chromosome Key: " + fittestChromosome);
+        igniteLogger.info("Chromsome: " + fittestChromosome);
+        printCoins(GAGridUtils.getGenesForChromosome(ignite, fittestChromosome));
+        igniteLogger.info("Avg Chromsome Fitness: " + averageFitnessScore);
+        igniteLogger.info("##########################################################################################");
+
+        if (!(currentGeneration > 5)) {
+            isTerminate = false;
+        }
+
+        return isTerminate;
+    }
+
+    /**
+     * Helper to print change detail
+     *
+     * @param genes List if Genes
+     */
+    private void printCoins(List<Gene> genes) {
+        for (Gene gene : genes) {
+            igniteLogger.info("Coin Type: " + ((Coin)gene.getValue()).getCoinType().toString());
+            igniteLogger.info("Number of Coins: " + ((Coin)gene.getValue()).getNumberOfCoins());
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldFitnessFunction.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldFitnessFunction.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldFitnessFunction.java
new file mode 100644
index 0000000..f5f1ee3
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldFitnessFunction.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.ml.genetic.helloworld;
+
+import java.util.List;
+import org.apache.ignite.ml.genetic.Gene;
+import org.apache.ignite.ml.genetic.IFitnessFunction;
+
+/**
+ * This example demonstrates how to create a IFitnessFunction
+ *
+ * Your IFitness function will vary depending on your particular use case.
+ *
+ * For this fitness function, we simply want to calculate the value of
+ *
+ * an individual solution relative to other solutions.
+ *
+ *
+ * To do this, we simply increase fitness score by '1' for each character
+ *
+ * that is correct position.
+ *
+ * For our solution, our genetic algorithm will continue until
+ *
+ * we achieve a fitness score of '11', as 'HELLO WORLD' contains '11' characters.
+ */
+
+public class HelloWorldFitnessFunction implements IFitnessFunction {
+
+    private String targetString = "HELLO WORLD";
+
+    /**
+     * Calculate fitness
+     *
+     * @param genes List of Genes
+     * @return Fitness value
+     */
+    public double evaluate(List<Gene> genes) {
+
+        double matches = 0;
+
+        for (int i = 0; i < genes.size(); i++) {
+            if (((Character)(genes.get(i).getValue())).equals(targetString.charAt(i))) {
+                matches = matches + 1;
+            }
+        }
+        return matches;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldGAExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldGAExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldGAExample.java
new file mode 100644
index 0000000..1799480
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldGAExample.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.ml.genetic.helloworld;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.Ignition;
+
+import org.apache.ignite.ml.genetic.Chromosome;
+import org.apache.ignite.ml.genetic.GAGrid;
+import org.apache.ignite.ml.genetic.Gene;
+import org.apache.ignite.ml.genetic.parameter.GAConfiguration;
+
+
+/**
+ * This example demonstrates how to use the GAGrid framework.
+ *
+ * In this example, we want to evolve a string of 11 characters such that the word 'HELLO WORLD'.
+ *
+ * is found.
+ *
+ *
+ * How To Run:
+ *
+ * mvn exec:java -Dexec.mainClass="org.apache.ignite.examples.ml.genetic.helloworld.HelloWorldGAExample"
+ *
+ * <p> Remote nodes should always be started with special configuration file which enables P2P class loading: {@code
+ * 'ignite.{sh|bat} examples/config/example-ignite.xml'}.</p> <p> Alternatively you can run ExampleNodeStartup
+ * in another JVM which will start node with {@code examples/config/example-ignite.xml} configuration.</p>
+ */
+
+public class HelloWorldGAExample {
+    private static Ignite ignite = null;
+    private static GAGrid gaGrid = null;
+    private static GAConfiguration gaConfig = null;
+
+    public static void main(String args[]) {
+        System.setProperty("IGNITE_QUIET", "false");
+
+        try {
+
+            //Create an Ignite instance as you would in any other use case.
+
+            ignite = Ignition.start("examples/config/example-ignite.xml");
+
+            // Create GAConfiguration
+            gaConfig = new GAConfiguration();
+
+            // set Gene Pool
+            List<Gene> genes = getGenePool();
+
+            // set the Chromosome Length to '11' since 'HELLO WORLD' contains 11 characters.
+            gaConfig.setChromosomeLength(11);
+
+            // initialize gene pool
+            gaConfig.setGenePool(genes);
+
+            // create and set Fitness function
+            HelloWorldFitnessFunction function = new HelloWorldFitnessFunction();
+            gaConfig.setFitnessFunction(function);
+
+            // create and set TerminateCriteria
+            HelloWorldTerminateCriteria termCriteria = new HelloWorldTerminateCriteria(ignite);
+            gaConfig.setTerminateCriteria(termCriteria);
+
+            ignite.log();
+
+            gaGrid = new GAGrid(gaConfig, ignite);
+            // evolve the population
+            Chromosome fittestChromosome = gaGrid.evolve();
+
+            Ignition.stop(true);
+            ignite = null;
+
+        }
+        catch (Exception e) {
+            System.out.println(e);
+        }
+
+    }
+
+    /**
+     * Helper routine to initialize Gene pool
+     *
+     * In typical usecase genes may be stored in database.
+     *
+     * @return List<Gene>
+     */
+    private static List<Gene> getGenePool() {
+        List<Gene> list = new ArrayList();
+
+        char[] chars = {
+            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
+            'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' '};
+
+        for (int i = 0; i < chars.length; i++) {
+            Gene gene = new Gene(new Character(chars[i]));
+            list.add(gene);
+        }
+        return list;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldTerminateCriteria.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldTerminateCriteria.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldTerminateCriteria.java
new file mode 100644
index 0000000..a0d6f93
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/helloworld/HelloWorldTerminateCriteria.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.ml.genetic.helloworld;
+
+import java.util.List;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteLogger;
+
+import org.apache.ignite.ml.genetic.Chromosome;
+import org.apache.ignite.ml.genetic.Gene;
+import org.apache.ignite.ml.genetic.parameter.ITerminateCriteria;
+import org.apache.ignite.ml.genetic.utils.GAGridUtils;
+
+/**
+ * Represents the terminate condition for HelloWorld Genetic algorithm
+ *
+ * Class terminates Genetic algorithm when fitnessScore > 10
+ */
+public class HelloWorldTerminateCriteria implements ITerminateCriteria {
+
+    private IgniteLogger igniteLogger = null;
+    private Ignite ignite = null;
+
+    /**
+     * @param ignite Ignite
+     */
+    public HelloWorldTerminateCriteria(Ignite ignite) {
+        this.ignite = ignite;
+        this.igniteLogger = ignite.log();
+    }
+
+    /**
+     * @param fittestChromosome Most fit chromosome at for the nth generation
+     * @param averageFitnessScore Average fitness score as of the nth generation
+     * @param currentGeneration Current generation
+     * @return Boolean value
+     */
+    public boolean isTerminationConditionMet(Chromosome fittestChromosome, double averageFitnessScore,
+        int currentGeneration) {
+        boolean isTerminate = true;
+
+        igniteLogger.info("##########################################################################################");
+        igniteLogger.info("Generation: " + currentGeneration);
+        igniteLogger.info("Fittest is Chromosome Key: " + fittestChromosome);
+        igniteLogger.info("Chromosome: " + fittestChromosome);
+        printPhrase(GAGridUtils.getGenesInOrderForChromosome(ignite, fittestChromosome));
+        igniteLogger.info("Avg Chromosome Fitness: " + averageFitnessScore);
+        igniteLogger.info("##########################################################################################");
+
+        if (!(fittestChromosome.getFitnessScore() > 10)) {
+            isTerminate = false;
+        }
+
+        return isTerminate;
+    }
+
+    /**
+     * Helper to print Phrase
+     *
+     * @param List of Genes
+     */
+    private void printPhrase(List<Gene> genes) {
+
+        StringBuffer sbPhrase = new StringBuffer();
+
+        for (Gene gene : genes) {
+            sbPhrase.append(((Character)gene.getValue()).toString());
+        }
+        igniteLogger.info(sbPhrase.toString());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/Movie.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/Movie.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/Movie.java
new file mode 100644
index 0000000..fd4afda
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/Movie.java
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.ml.genetic.movie;
+
+import java.util.List;
+
+/**
+ * POJO to model a movie.
+ */
+
+public class Movie {
+    /** name of movie */
+    private String name;
+    /** genre of movie */
+    private List genre;
+    /** rating of movie */
+    private String rating;
+
+    /** IMDB rating */
+    private double imdbRating;
+
+    /** year of movie */
+    private String year;
+
+    /**
+     * Get the year
+     *
+     * @return Year
+     */
+    public String getYear() {
+        return year;
+    }
+
+    /**
+     * Set the year
+     *
+     * @param year Year
+     */
+    public void setYear(String year) {
+        this.year = year;
+    }
+
+    /**
+     * Get the IMDB rating
+     *
+     * @return IMDB rating
+     */
+    public double getImdbRating() {
+        return imdbRating;
+    }
+
+    /**
+     * Set the IMDB rating
+     *
+     * @param imdbRating IMDB rating
+     */
+    public void setImdbRating(double imdbRating) {
+        this.imdbRating = imdbRating;
+    }
+
+    /**
+     * Get the name of movie
+     *
+     * @return Name of movie
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * Set the name of movie
+     *
+     * @param name Movie name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * @return List of genres
+     */
+    public List getGenre() {
+        return genre;
+    }
+
+    /**
+     * Set the genre
+     *
+     * @param genre Genre of movie
+     */
+    public void setGenre(List genre) {
+        this.genre = genre;
+    }
+
+    /**
+     * Get the rating of the movie
+     *
+     * @return Movie rating
+     */
+    public String getRating() {
+        return rating;
+    }
+
+    /**
+     * Set the rating of the movie
+     *
+     * @param rating Movie rating
+     */
+    public void setRating(String rating) {
+        this.rating = rating;
+    }
+
+    public String toString() {
+        return "Movie [name=" + name + ", genre=" + genre + ", rating=" + rating + ", imdbRating=" + imdbRating
+            + ", year=" + year + "]";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieFitnessFunction.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieFitnessFunction.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieFitnessFunction.java
new file mode 100644
index 0000000..9690d69
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieFitnessFunction.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.ml.genetic.movie;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.ignite.ml.genetic.Chromosome;
+import org.apache.ignite.ml.genetic.Gene;
+import org.apache.ignite.ml.genetic.IFitnessFunction;
+
+/**
+ * This example demonstrates how to create a IFitnessFunction
+ *
+ * Your IFitness function will vary depending on your particular use case.
+ *
+ * For this fitness function, we simply want to calculate the value of
+ *
+ * an individual solution relative to other solutions.
+ *
+ *
+ * To do this, we simply increase fitness score by number of times
+ *
+ * genre is found in list of movies.
+ *
+ * In addition, we increase score by fictional IMDB rating.
+ *
+ * If there are duplicate movies in selection, we automatically apply a '0'
+ *
+ * fitness score.
+ */
+
+public class MovieFitnessFunction implements IFitnessFunction {
+
+    private List<String> genres = null;
+
+    /**
+     * @param genres List of genres
+     */
+    public MovieFitnessFunction(List<String> genres) {
+        this.genres = genres;
+    }
+
+    /**
+     * Calculate fitness score
+     *
+     * @param genes List of Genes
+     * @return Fitness score
+     */
+    public double evaluate(List<Gene> genes) {
+
+        double score = 0;
+        List<String> dups = new ArrayList();
+        int badSolution = 1;
+
+        for (int i = 0; i < genes.size(); i++) {
+            Movie movie = (Movie)genes.get(i).getValue();
+            if (dups.contains(movie.getName())) {
+                badSolution = 0;
+            }
+            else {
+                dups.add(movie.getName());
+            }
+            double genreScore = getGenreScore(movie);
+            if (genreScore == 0) {
+                badSolution = 0;
+            }
+            score = (score + movie.getImdbRating()) + (genreScore);
+        }
+        return (score * badSolution);
+    }
+
+    /**
+     * helper to calculate genre score
+     *
+     * @param movie Move
+     * @return Genre score
+     */
+    private double getGenreScore(Movie movie) {
+        double genreScore = 0;
+
+        for (String genre : this.genres) {
+            if (movie.getGenre().contains(genre)) {
+                genreScore = genreScore + 1;
+            }
+        }
+        return genreScore;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieGAExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieGAExample.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieGAExample.java
new file mode 100644
index 0000000..79ec295
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieGAExample.java
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.ml.genetic.movie;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.Ignition;
+
+import org.apache.ignite.ml.genetic.Chromosome;
+import org.apache.ignite.ml.genetic.GAGrid;
+import org.apache.ignite.ml.genetic.Gene;
+import org.apache.ignite.ml.genetic.parameter.GAConfiguration;
+import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
+
+/**
+ * This example demonstrates how to use the GAGrid framework.
+ *
+ * In this example, we utilize GA Grid to calculate an optimal set of movies based on our interests in various genres
+ * (ie: Action, Comedy, and Romance)
+ *
+ *
+ * How To Run:
+ *
+ * mvn exec:java -Dexec.mainClass="org.apache.ignite.examples.ml.genetic.movie.MovieGAExample" -DGENRES=Action,Comedy
+ *
+ * <p> Remote nodes should always be started with special configuration file which enables P2P class loading: {@code
+ * 'ignite.{sh|bat} examples/config/example-ignite.xml'}.</p> <p> Alternatively you can run ExampleNodeStartup
+ * in another JVM which will start node with {@code examples/config/example-ignite.xml} configuration.</p>
+ */
+
+public class MovieGAExample {
+    private static Ignite ignite = null;
+    private static GAGrid gaGrid = null;
+    private static GAConfiguration gaConfig = null;
+
+    /**
+     * Executes example.
+     *
+     * Specify value for -DGENRES JVM system variable
+     *
+     * @param args Command line arguments, none required.
+     */
+
+    public static void main(String args[]) {
+        System.setProperty("IGNITE_QUIET", "false");
+
+        List genres = new ArrayList();
+        String sGenres = System.getProperty("GENRES");
+
+        StringBuffer sbErrorMessage = new StringBuffer();
+        sbErrorMessage.append("GENRES System property not set. Please provide GENRES information.");
+        sbErrorMessage.append(" ");
+        sbErrorMessage.append("IE: -DGENRES=Action,Comedy,Romance");
+
+        if (sGenres == null) {
+            System.out.println(sbErrorMessage);
+            System.exit(1);
+        }
+
+        StringTokenizer st = new StringTokenizer(sGenres, ",");
+
+        while (st.hasMoreElements()) {
+            String genre = st.nextToken();
+            genres.add(genre);
+        }
+
+        // Create GAConfiguration
+        gaConfig = new GAConfiguration();
+
+        // set Gene Pool
+        List<Gene> genes = getGenePool();
+
+        // Define Chromosome
+        gaConfig.setChromosomeLength(3);
+        gaConfig.setPopulationSize(100);
+        gaConfig.setGenePool(genes);
+        gaConfig.setTruncateRate(.10);
+        gaConfig.setCrossOverRate(.50);
+        gaConfig.setMutationRate(.50);
+        gaConfig.setSelectionMethod(GAGridConstants.SELECTION_METHOD.SELECTION_METHOD_TRUNCATION);
+
+        //Create fitness function
+        MovieFitnessFunction function = new MovieFitnessFunction(genres);
+
+        //set fitness function
+        gaConfig.setFitnessFunction(function);
+
+        try {
+
+            //Create an Ignite instance as you would in any other use case.
+            ignite = Ignition.start("examples/config/example-ignite.xml");
+
+            MovieTerminateCriteria termCriteria = new MovieTerminateCriteria(ignite);
+
+            gaConfig.setTerminateCriteria(termCriteria);
+
+            gaGrid = new GAGrid(gaConfig, ignite);
+
+            ignite.log();
+            Chromosome fittestChromosome = gaGrid.evolve();
+
+            Ignition.stop(true);
+            ignite = null;
+
+        }
+        catch (Exception e) {
+            System.out.println(e);
+        }
+
+    }
+
+    private static List<Gene> getGenePool() {
+        List list = new ArrayList();
+
+        Movie movie1 = new Movie();
+        movie1.setName("The Matrix");
+        movie1.setImdbRating(7);
+        List genre1 = new ArrayList();
+        genre1.add("SciFi");
+        genre1.add("Action");
+        movie1.setGenre(genre1);
+        movie1.setRating("PG-13");
+        movie1.setYear("1999");
+
+        Gene gene1 = new Gene(movie1);
+
+        Movie movie2 = new Movie();
+        movie2.setName("The Dark Knight");
+        movie2.setImdbRating(9.6);
+        List genre2 = new ArrayList();
+        genre2.add("Action");
+        movie2.setGenre(genre2);
+        movie2.setRating("PG-13");
+        movie2.setYear("2008");
+
+        Gene gene2 = new Gene(movie2);
+
+        Movie movie3 = new Movie();
+        movie3.setName("The Avengers");
+        movie3.setImdbRating(9.6);
+        movie3.setYear("2012");
+
+        List genre3 = new ArrayList();
+        genre3.add("Action");
+        movie3.setGenre(genre3);
+        movie3.setRating("PG-13");
+
+        Gene gene3 = new Gene(movie3);
+
+        Movie movie4 = new Movie();
+        movie4.setName("The Hangover");
+        movie4.setImdbRating(7.6);
+        List genre4 = new ArrayList();
+        genre4.add("Comedy");
+        movie4.setGenre(genre4);
+        movie4.setRating("R");
+        movie4.setYear("2009");
+
+        Gene gene4 = new Gene(movie4);
+
+        Movie movie5 = new Movie();
+        movie5.setName("The Hangover 2");
+        movie5.setImdbRating(9.6);
+        List genre5 = new ArrayList();
+        genre5.add("Comedy");
+        movie5.setGenre(genre5);
+        movie5.setRating("R");
+        movie5.setYear("2012");
+
+        Gene gene5 = new Gene(movie5);
+
+        Movie movie6 = new Movie();
+        movie6.setName("This Means War");
+        movie6.setImdbRating(6.4);
+        List genre6 = new ArrayList();
+        genre6.add("Comedy");
+        genre6.add("Action");
+        genre6.add("Romance");
+        movie6.setGenre(genre6);
+        movie6.setRating("PG-13");
+        movie6.setYear("2012");
+
+        Gene gene6 = new Gene(movie6);
+
+        Movie movie7 = new Movie();
+        movie7.setName("Hitch");
+        movie7.setImdbRating(10);
+        List genre7 = new ArrayList();
+        genre7.add("Comedy");
+        genre7.add("Romance");
+        movie7.setGenre(genre7);
+        movie7.setRating("PG-13");
+        movie7.setYear("2005");
+
+        Gene gene7 = new Gene(movie7);
+
+        Movie movie8 = new Movie();
+        movie8.setName("21 Jump Street");
+        movie8.setImdbRating(6.7);
+        List genre8 = new ArrayList();
+        genre8.add("Comedy");
+        genre8.add("Action");
+        movie8.setGenre(genre8);
+        movie8.setRating("R");
+        movie8.setYear("2012");
+
+        Gene gene8 = new Gene(movie8);
+
+        Movie movie9 = new Movie();
+        movie9.setName("Killers");
+        movie9.setImdbRating(5.1);
+        List genre9 = new ArrayList();
+        genre9.add("Comedy");
+        genre9.add("Action");
+        genre9.add("Romance");
+        movie9.setGenre(genre9);
+        movie9.setRating("PG-13");
+        movie9.setYear("2010");
+
+        Gene gene9 = new Gene(movie9);
+
+        Movie movie10 = new Movie();
+        movie10.setName("What to Expect When You're Expecting");
+        movie10.setImdbRating(5.1);
+        List genre10 = new ArrayList();
+        genre10.add("Comedy");
+        genre10.add("Romance");
+        movie10.setGenre(genre10);
+        movie10.setRating("PG-13");
+        movie10.setYear("2012");
+
+        Gene gene10 = new Gene(movie10);
+
+        list.add(gene1);
+        list.add(gene2);
+        list.add(gene3);
+        list.add(gene4);
+        list.add(gene5);
+        list.add(gene6);
+        list.add(gene7);
+        list.add(gene8);
+        list.add(gene9);
+        list.add(gene10);
+
+        return list;
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieTerminateCriteria.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieTerminateCriteria.java b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieTerminateCriteria.java
new file mode 100644
index 0000000..904c66d
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/ml/genetic/movie/MovieTerminateCriteria.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.examples.ml.genetic.movie;
+
+import java.util.List;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteLogger;
+
+import org.apache.ignite.ml.genetic.Chromosome;
+import org.apache.ignite.ml.genetic.Gene;
+import org.apache.ignite.ml.genetic.parameter.ITerminateCriteria;
+import org.apache.ignite.ml.genetic.utils.GAGridUtils;
+
+/**
+ * Represents the terminate condition for Movie Genetic algorithm  <br/>
+ *
+ * Class terminates Genetic algorithm when fitnessScore > 32  <br/>
+ */
+
+public class MovieTerminateCriteria implements ITerminateCriteria {
+
+    private IgniteLogger igniteLogger = null;
+    private Ignite ignite = null;
+
+    /**
+     * @param ignite
+     */
+    public MovieTerminateCriteria(Ignite ignite) {
+        this.ignite = ignite;
+        this.igniteLogger = ignite.log();
+
+    }
+
+    /**
+     * @param fittestChromosome Most fit chromosome at for the nth generation
+     * @param averageFitnessScore Average fitness score as of the nth generation
+     * @param currentGeneration Current generation
+     * @return Boolean value
+     */
+    public boolean isTerminationConditionMet(Chromosome fittestChromosome, double averageFitnessScore,
+        int currentGeneration) {
+        boolean isTerminate = true;
+
+        igniteLogger.info("##########################################################################################");
+        igniteLogger.info("Generation: " + currentGeneration);
+        igniteLogger.info("Fittest is Chromosome Key: " + fittestChromosome);
+        igniteLogger.info("Chromsome: " + fittestChromosome);
+        printMovies(GAGridUtils.getGenesForChromosome(ignite, fittestChromosome));
+        igniteLogger.info("##########################################################################################");
+
+        if (!(fittestChromosome.getFitnessScore() > 32)) {
+            isTerminate = false;
+        }
+
+        return isTerminate;
+    }
+
+    /**
+     * Helper to print change detail
+     *
+     * @param genes List of Genes
+     */
+    private void printMovies(List<Gene> genes) {
+        for (Gene gene : genes) {
+            igniteLogger.info("Name: " + ((Movie)gene.getValue()).getName().toString());
+            igniteLogger.info("Genres: " + ((Movie)gene.getValue()).getGenre().toString());
+            igniteLogger.info("IMDB Rating: " + ((Movie)gene.getValue()).getImdbRating());
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/modules/ml/pom.xml
----------------------------------------------------------------------
diff --git a/modules/ml/pom.xml b/modules/ml/pom.xml
index f8d56d7..f578cdf 100644
--- a/modules/ml/pom.xml
+++ b/modules/ml/pom.xml
@@ -47,8 +47,21 @@
             <type>test-jar</type>
             <scope>test</scope>
         </dependency>
+        
+        <dependency>
+	    <groupId>org.apache.ignite</groupId>
+	    <artifactId>ignite-indexing</artifactId>
+	    <version>${project.version}</version>
+        </dependency>
+
 
         <dependency>
+	    <groupId>org.apache.ignite</groupId>
+	    <artifactId>ignite-spring</artifactId>
+	    <version>${project.version}</version>
+        </dependency>
+       
+        <dependency>
             <groupId>it.unimi.dsi</groupId>
             <artifactId>fastutil</artifactId>
             <version>7.0.12</version>

http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/modules/ml/src/main/java/org/apache/ignite/ml/genetic/Chromosome.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/genetic/Chromosome.java b/modules/ml/src/main/java/org/apache/ignite/ml/genetic/Chromosome.java
new file mode 100644
index 0000000..03e949f
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/genetic/Chromosome.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.genetic;
+
+import java.util.Arrays;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+
+/**
+ * Represents a potential solution consisting of a fixed-length collection of genes. <br/>
+ *
+ * <p>
+ *
+ * NOTE: Chromosome resides in cache: GAGridConstants.POPULATION_CACHE. This cached is partitioned.
+ *
+ * </p>
+ */
+public class Chromosome {
+
+    private static final AtomicLong ID_GEN = new AtomicLong();
+
+    @QuerySqlField(index = true)
+    private double fitnessScore = -1;
+
+    /** Id (indexed). */
+    @QuerySqlField(index = true)
+    private Long id;
+
+    /** array of gene keys. */
+    private long[] genes;
+
+    /**
+     *
+     * @param genes Primary keys of Genes
+     */
+    public Chromosome(long[] genes) {
+        id = ID_GEN.incrementAndGet();
+        this.genes = genes;
+    }
+
+    /**
+     * Gets the fitnessScore
+     *
+     * @return This chromosome's fitness score
+     */
+    public double getFitnessScore() {
+        return fitnessScore;
+    }
+
+    /**
+     * Set the fitnessScore for this chromosome
+     *
+     * @param fitnessScore This chromosome's new fitness score
+     */
+    public void setFitnessScore(double fitnessScore) {
+        this.fitnessScore = fitnessScore;
+    }
+
+    /**
+     * Gets the gene keys (ie: primary keys) for this chromosome
+     *
+     * @return This chromosome's genes
+     */
+    public long[] getGenes() {
+        return genes;
+    }
+
+    /**
+     * Set the gene keys (ie: primary keys)
+     *
+     * @param genes This chromosome's new genes
+     */
+    public void setGenes(long[] genes) {
+        this.genes = genes;
+    }
+
+    /**
+     * Get the id (primary key) for this chromosome
+     *
+     * @return This chromosome's primary key
+     */
+    public Long id() {
+        return id;
+    }
+
+    @Override
+    public String toString() {
+        return "Chromosome [fitnessScore=" + fitnessScore + ", id=" + id + ", genes=" + Arrays.toString(genes) + "]";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/modules/ml/src/main/java/org/apache/ignite/ml/genetic/CrossOverJob.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/genetic/CrossOverJob.java b/modules/ml/src/main/java/org/apache/ignite/ml/genetic/CrossOverJob.java
new file mode 100644
index 0000000..74f81b8
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/genetic/CrossOverJob.java
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.genetic;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.compute.ComputeJobAdapter;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.resources.LoggerResource;
+import org.apache.ignite.transactions.Transaction;
+
+import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
+
+/**
+ * Responsible for performing 'crossover' genetic operation for 2 X 'parent' chromosomes.
+ *
+ * <p>
+ *
+ * It relies on the GAConfiguration.getCrossOverRate() to determine probability rate of crossover for pair of
+ * chromosome.
+ *
+ * <br/>
+ *
+ * CrossOverJob will randomly pick a start index j in Chromosome.getGenes[] and continue
+ *
+ * swapping until end of genes[] array.
+ *
+ * </p>
+ */
+public class CrossOverJob extends ComputeJobAdapter {
+
+    @IgniteInstanceResource
+    private Ignite ignite = null;
+
+    @LoggerResource
+    private IgniteLogger log = null;
+
+    /** primary key of 1st chromosome */
+    private Long key1;
+
+    /** primary key of 2nd chromosome */
+    private Long key2;
+
+    /** Cross over rate */
+    private double crossOverRate;
+
+    /**
+     * @param key1 Primary key for 1st chromosome
+     * @param key2 Primary key for 2nd chromosome
+     * @param crossOverRate CrossOver rate
+     */
+    public CrossOverJob(Long key1, Long key2, double crossOverRate) {
+        this.key1 = key1;
+        this.key2 = key2;
+        this.crossOverRate = crossOverRate;
+    }
+
+    /**
+     * helper routine to assist cross over
+     *
+     * @param newKeySwapArrayForChrome New gene keys to copy starting at updateIdx
+     * @param updateIdx Update Index
+     * @param genekeys Original gene Keys for a chromosome
+     * @return New Gene keys
+     */
+
+    private long[] crossOver(long[] newKeySwapArrayForChrome, int updateIdx, long[] genekeys) {
+        long[] newGeneKeys = genekeys.clone();
+
+        int k = 0;
+        for (int x = updateIdx; x < newGeneKeys.length; x++) {
+            newGeneKeys[x] = newKeySwapArrayForChrome[k];
+            k = k + 1;
+        }
+        return newGeneKeys;
+    }
+
+    /**
+     * Perform crossover operation
+     */
+    public Object execute() throws IgniteException {
+
+        if (this.crossOverRate > Math.random()) {
+
+            IgniteCache<Long, Chromosome> populationCache = ignite.cache(GAGridConstants.POPULATION_CACHE);
+
+            Transaction tx = ignite.transactions().txStart();
+
+            Chromosome chromosome1 = populationCache.localPeek(this.key1);
+            Chromosome chromosome2 = populationCache.localPeek(this.key2);
+
+            long[] genesforChrom1 = chromosome1.getGenes();
+            long[] genesforChrom2 = chromosome2.getGenes();
+
+            Random rn = new Random();
+
+            // compute index to start for copying respective genes
+            int geneIndexStartSwap = rn.nextInt(genesforChrom1.length);
+
+            long[] newKeySwapArrayForChrome1 =
+                Arrays.copyOfRange(genesforChrom2, geneIndexStartSwap, genesforChrom1.length);
+            long[] newKeySwapArrayForChrome2 =
+                Arrays.copyOfRange(genesforChrom1, geneIndexStartSwap, genesforChrom1.length);
+
+            long[] newGeneKeysForChrom1 = crossOver(newKeySwapArrayForChrome1, geneIndexStartSwap, genesforChrom1);
+            long[] newGeneKeysForChrom2 = crossOver(newKeySwapArrayForChrome2, geneIndexStartSwap, genesforChrom2);
+
+            chromosome1.setGenes(newGeneKeysForChrom1);
+            populationCache.put(chromosome1.id(), chromosome1);
+
+            chromosome2.setGenes(newGeneKeysForChrom2);
+            populationCache.put(chromosome2.id(), chromosome2);
+
+            tx.commit();
+
+        }
+
+        return null;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/modules/ml/src/main/java/org/apache/ignite/ml/genetic/CrossOverTask.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/genetic/CrossOverTask.java b/modules/ml/src/main/java/org/apache/ignite/ml/genetic/CrossOverTask.java
new file mode 100644
index 0000000..377ec3d
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/genetic/CrossOverTask.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.genetic;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeJobResultPolicy;
+import org.apache.ignite.compute.ComputeTaskAdapter;
+import org.apache.ignite.resources.IgniteInstanceResource;
+
+import org.apache.ignite.ml.genetic.parameter.GAConfiguration;
+import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
+
+/**
+ * Responsible for assigning 2 X 'parent' chromosomes to produce 2 X 'child' chromosomes.
+ *
+ * <p>
+ *
+ * CrossOverTask leverages  Ignite's data affinity capabilities for routing CrossOverJobs to primary <br/> IgniteNode
+ * where 'parent' chromosomes reside.
+ *
+ * </p>
+ */
+public class CrossOverTask extends ComputeTaskAdapter<List<Long>, Boolean> {
+
+    @IgniteInstanceResource
+    private Ignite ignite = null;
+
+    /** GAConfiguration */
+    private GAConfiguration config = null;
+
+    /**
+     * @param config GAConfiguration
+     */
+    public CrossOverTask(GAConfiguration config) {
+        this.config = config;
+    }
+
+    /**
+     * Map Jobs to nodes using data affinity.
+     *
+     * @param nodes Cluster Nodes
+     * @param chromosomeKeys Primary keys for respective chromosomes
+     * @return A map of nodes to jobs.
+     */
+    public Map map(List<ClusterNode> nodes, List<Long> chromosomeKeys) throws IgniteException {
+
+        Map<ComputeJob, ClusterNode> map = new HashMap<>();
+
+        Affinity affinity = ignite.affinity(GAGridConstants.POPULATION_CACHE);
+
+        Map<ClusterNode, Collection<Long>> nodeKeys = affinity.mapKeysToNodes(chromosomeKeys);
+
+        for (Map.Entry<ClusterNode, Collection<Long>> entry : nodeKeys.entrySet()) {
+            ClusterNode aNode = entry.getKey();
+            map = setupCrossOver(aNode, (List<Long>)entry.getValue(), map);
+        }
+        return map;
+    }
+
+    /**
+     * We return TRUE if success, else Exection is thrown.
+     *
+     * @param list ComputeJobResult
+     * @return Boolean value; if operationa was successful return true, otherwise Exception
+     */
+    public Boolean reduce(List<ComputeJobResult> list) throws IgniteException {
+        // TODO Auto-generated method stub
+        return Boolean.TRUE;
+    }
+
+    /**
+     * @param res ComputeJobResult
+     * @param rcvd List of ComputeJobResult
+     * @return ComputeJobResultPolicy
+     */
+    public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) {
+        IgniteException err = res.getException();
+
+        if (err != null)
+            return ComputeJobResultPolicy.FAILOVER;
+
+        // If there is no exception, wait for all job results.
+        return ComputeJobResultPolicy.WAIT;
+
+    }
+
+    /**
+     * Helper method to help assign ComputeJobs to respective ClusterNodes
+     *
+     * @param clusterNode
+     * @param keys Primary keys of Chromosomes
+     * @param map Nodes where jobs will be sent
+     * @return A map of ComputeJob/ClusterNode's
+     */
+
+    private Map<ComputeJob, ClusterNode> setupCrossOver(ClusterNode clusterNode, List<Long> keys,
+        Map<ComputeJob, ClusterNode> map) {
+        // Calculate number of Jobs = keys / 2
+        // as we desire pairs of Chromosomes to be swapped
+        int numberOfJobs = keys.size() / 2;
+        int k = 0;
+        for (int i = 0; i < numberOfJobs; i++) {
+            Long key1 = keys.get(k);
+            Long key2 = keys.get(k + 1);
+
+            CrossOverJob job = new CrossOverJob(key1, key2, this.config.getCrossOverRate());
+            map.put(job, clusterNode);
+            k = k + 2;
+        }
+        return map;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/modules/ml/src/main/java/org/apache/ignite/ml/genetic/FitnessJob.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/genetic/FitnessJob.java b/modules/ml/src/main/java/org/apache/ignite/ml/genetic/FitnessJob.java
new file mode 100644
index 0000000..064846e
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/genetic/FitnessJob.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.genetic;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.compute.ComputeExecutionRejectedException;
+import org.apache.ignite.compute.ComputeJobAdapter;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.resources.LoggerResource;
+import org.apache.ignite.transactions.Transaction;
+
+import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
+
+/**
+ * Responsible for performing fitness evaluation on an individual chromosome
+ */
+public class FitnessJob extends ComputeJobAdapter {
+
+    /**
+     * Chromosome primary Key
+     */
+    private Long key;
+
+    @IgniteInstanceResource
+    private Ignite ignite = null;
+
+    @LoggerResource
+    private IgniteLogger log = null;
+
+    /** IFitnessFunction */
+    private IFitnessFunction fitnessFuncton = null;
+
+    /**
+     * @param key Chromosome primary Key
+     * @param fitnessFunction Fitness function defined by developer
+     */
+    public FitnessJob(Long key, IFitnessFunction fitnessFunction) {
+        this.key = key;
+        this.fitnessFuncton = fitnessFunction;
+    }
+
+    /**
+     * Perform fitness operation utilizing IFitnessFunction
+     *
+     * Update chromosome's fitness value
+     *
+     * @return Fitness score
+     */
+    public Double execute() throws IgniteException {
+
+        IgniteCache<Long, Chromosome> populationCache = ignite.cache(GAGridConstants.POPULATION_CACHE);
+
+        IgniteCache<Long, Gene> geneCache = ignite.cache(GAGridConstants.GENE_CACHE);
+
+        Chromosome chromosome = populationCache.localPeek(key);
+
+        long[] geneKeys = chromosome.getGenes();
+
+        List<Gene> genes = new ArrayList();
+
+        for (int i = 0; i < geneKeys.length; i++) {
+            long aKey = geneKeys[i];
+            Gene aGene = geneCache.localPeek(aKey);
+            genes.add(aGene);
+        }
+
+        Double value = fitnessFuncton.evaluate(genes);
+
+        chromosome.setFitnessScore(value);
+
+        Transaction tx = ignite.transactions().txStart();
+
+        populationCache.put(chromosome.id(), chromosome);
+
+        tx.commit();
+
+        return value;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0cdded31/modules/ml/src/main/java/org/apache/ignite/ml/genetic/FitnessTask.java
----------------------------------------------------------------------
diff --git a/modules/ml/src/main/java/org/apache/ignite/ml/genetic/FitnessTask.java b/modules/ml/src/main/java/org/apache/ignite/ml/genetic/FitnessTask.java
new file mode 100644
index 0000000..58b69fa
--- /dev/null
+++ b/modules/ml/src/main/java/org/apache/ignite/ml/genetic/FitnessTask.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ml.genetic;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeJobResultPolicy;
+import org.apache.ignite.compute.ComputeTaskAdapter;
+import org.apache.ignite.resources.IgniteInstanceResource;
+
+import org.apache.ignite.ml.genetic.parameter.GAConfiguration;
+import org.apache.ignite.ml.genetic.parameter.GAGridConstants;
+
+/**
+ * Responsible for fitness operation
+ */
+public class FitnessTask extends ComputeTaskAdapter<List<Long>, Boolean> {
+
+    @IgniteInstanceResource
+    private Ignite ignite = null;
+
+    /** GAConfiguration **/
+    private GAConfiguration config = null;
+
+    /**
+     * @param config GAConfiguration
+     */
+    public FitnessTask(GAConfiguration config) {
+        this.config = config;
+    }
+
+    /**
+     * @param nodes List of ClusterNode
+     * @param chromosomeKeys List of chromosome keys
+     * @return Map of jobs to nodes
+     */
+    public Map map(List<ClusterNode> nodes, List<Long> chromosomeKeys) throws IgniteException {
+
+        Map<ComputeJob, ClusterNode> map = new HashMap<>();
+
+        Affinity affinity = ignite.affinity(GAGridConstants.POPULATION_CACHE);
+
+        for (Long key : chromosomeKeys) {
+
+            FitnessJob ajob = new FitnessJob(key, this.config.getFitnessFunction());
+
+            ClusterNode primary = affinity.mapKeyToNode(key);
+
+            map.put(ajob, primary);
+        }
+        return map;
+    }
+
+    /**
+     * @param list List of ComputeJobResult
+     * @return Boolean value
+     */
+    public Boolean reduce(List<ComputeJobResult> list) throws IgniteException {
+
+        return Boolean.TRUE;
+    }
+
+    /**
+     * @param res ComputeJobResult
+     * @param rcvd List of ComputeJobResult
+     * @return ComputeJobResultPolicy
+     */
+    public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) {
+        IgniteException err = res.getException();
+
+        if (err != null)
+            return ComputeJobResultPolicy.FAILOVER;
+
+        // If there is no exception, wait for all job results.
+        return ComputeJobResultPolicy.WAIT;
+
+    }
+}


Mime
View raw message