use of org.apache.ignite.ml.genetic.parameter.GAConfiguration in project ignite by apache.
the class OptimizeMakeChangeGAExample method main.
/**
* 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 = "75";
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");
sbErrorMessage.append("\n");
sbErrorMessage.append("Using default value: 75");
// Check if -DAMOUNTCHANGE JVM system variable is provided
if (System.getProperty("AMOUNTCHANGE") == null) {
System.out.println(sbErrorMessage);
} else {
sAmountChange = System.getProperty("AMOUNTCHANGE");
}
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);
}
}
use of org.apache.ignite.ml.genetic.parameter.GAConfiguration in project ignite by apache.
the class HelloWorldGAExample method main.
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);
}
}
use of org.apache.ignite.ml.genetic.parameter.GAConfiguration in project ignite by apache.
the class MovieGAExample method main.
/**
* 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 = "Action,Comedy,Romance";
StringBuffer sbErrorMessage = new StringBuffer();
sbErrorMessage.append("GENRES System property not set. Please provide GENRES information.");
sbErrorMessage.append(" ");
sbErrorMessage.append("IE: -DGENRES=Action,Comedy,Romance");
sbErrorMessage.append("\n");
sbErrorMessage.append("Using default value: Action,Comedy,Romance");
if (System.getProperty("GENRES") == null) {
System.out.println(sbErrorMessage);
} else {
sGenres = System.getProperty("GENRES");
}
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);
}
}
use of org.apache.ignite.ml.genetic.parameter.GAConfiguration in project ignite by apache.
the class GAGridCalculateFitnessTest method initialize.
/**
* Setup test
*/
@Before
public void initialize() {
try {
// Create an Ignite instance as you would in any other use case.
ignite = Ignition.start();
// Create GAConfiguration
gaConfig = new GAConfiguration();
// set Gene Pool
List<Gene> genes = this.getGenePool();
gaConfig.setGenePool(genes);
// set the Chromosome Length to '8' since password contains 8 characters.
gaConfig.setChromosomeLength(8);
// create and set Fitness function
PasswordFitnessFunction function = new PasswordFitnessFunction();
gaConfig.setFitnessFunction(function);
gaGrid = new GAGrid(gaConfig, ignite);
gaGrid.initializeGenePopulation();
gaGrid.initializePopulation();
} catch (Exception e) {
System.out.println(e);
}
}
use of org.apache.ignite.ml.genetic.parameter.GAConfiguration in project ignite by apache.
the class GAGridInitializePopulationTest method initialize.
@Before
public void initialize() {
try {
// Create an Ignite instance as you would in any other use case.
ignite = Ignition.start();
// Create GAConfiguration
gaConfig = new GAConfiguration();
// set Gene Pool
List<Gene> genes = this.getGenePool();
// set the Chromosome Length to '8' since password contains 8 characters.
gaConfig.setChromosomeLength(8);
gaConfig.setGenePool(genes);
gaGrid = new GAGrid(gaConfig, ignite);
} catch (Exception e) {
System.out.println(e);
}
}
Aggregations