/********************************************************************** # Copyright (c) EWA Systems Inc. 1998 - 2005 All Rights Reserved # No part of this program may be photocopied, reproduced, # or translated to another programming language without # the prior written consent of EWA Systems. **********************************************************************/ package com.ewasystems.opt.ga.test; import com.ewasystems.opt.ga.GeneticAlleleSet; import com.ewasystems.opt.ga.GeneticEngine; import com.ewasystems.opt.ga.GeneticGene; import com.ewasystems.opt.ga.GeneticProblem; import com.ewasystems.opt.ga.GeneticRunTask; /** *

Genetic Algorithm Test Case: Simpleton

*

Description: Maximize: (x1*x2*x3*x4*x5)/(x6*x7*x8*x9*x10) where (x1..x10)=[1..10]

*

Copyright: EWASystems Copyright (c) 1998 - 2005

*

Company: EWASystems

* @author Lincoln Evans-Beauchamp * @version 1.0 */ public class Simpleton extends GeneticProblem { /** * Problem Constructor */ public Simpleton() { super("Simpleton", "Maximize: (x1*x2*x3*x4*x5)/(x6*x7*x8*x9*x10) where (x1..x10)=[1..10]"); } /** * The Objective Function * @param gene The Genetic Gene to Test * @return double: The Genetic Gene's Fitness */ public double f(GeneticGene gene) { double fitness = 1d; for (int i=0; i<10; i++) { if (i<5) {fitness *= (double)((Integer)gene.getGeneValue(i)).intValue();} else {fitness /= (double)((Integer)gene.getGeneValue(i)).intValue();} } return fitness; } /** * Gets the Allele Set for the Problem * @return GeneticAlleleSet: The Allele Set */ public GeneticAlleleSet getAlleleSet() { GeneticAlleleSet gas = new GeneticAlleleSet(); Integer[] values = new Integer[10]; for (int i=1; i<=10; i++) {values[i-1] = new Integer(i);} gas.addCategoricalAllele("Integers 1 to 10", values, 10); return gas; } /** * Gets the Objective Type * @return int: The Objective Type */ public int getObjectiveType() {return OBJECTIVE_TYPE_MAX;} /** * Main for Running the Problem * @param args Not Used */ public static final void main(String[] args) { GeneticEngine ge = new GeneticEngine(); GeneticRunTask grt = ge.createGeneticTask(new Simpleton()); grt.getConfig().setMaxGenerations(4000); grt.getConfig().setShowFinalReport(true); grt.run(); } }