![JAR search and dependency download from the Maven repository](/logo.png)
com.github.chen0040.gp.lgp.gp.PopulationInitialization Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-genetic-programming Show documentation
Show all versions of java-genetic-programming Show documentation
Genetic Programming in Java, including packages on Linear Genetic Programming
package com.github.chen0040.gp.lgp.gp;
import com.github.chen0040.gp.lgp.LGP;
import com.github.chen0040.gp.lgp.enums.LGPInitializationStrategy;
import com.github.chen0040.gp.lgp.helpers.InstructionHelper;
import com.github.chen0040.gp.lgp.program.*;
import com.github.chen0040.gp.services.RandEngine;
import com.github.chen0040.data.exceptions.NotImplementedException;
import java.util.List;
/**
* Created by xschen on 7/5/2017.
*/
public class PopulationInitialization {
public static void apply(List programs, LGP manager) {
RandEngine randEngine = manager.getRandEngine();
if(manager.getProgramInitializationStrategy() == LGPInitializationStrategy.ConstantLength){
initializeWithConstantLength(programs, manager, randEngine);
} else if(manager.getProgramInitializationStrategy() == LGPInitializationStrategy.VariableLength) {
initializeWithVariableLength(programs, manager, randEngine);
} else {
throw new NotImplementedException();
}
}
// Xianshun says:
// specified here is a variable length initialization that selects initial program
// lengths from a uniform distribution within a specified range of m_iInitialMinProgLength - m_iIinitialMaxProgLength
// the method is recorded in chapter 7 section 7.6 page 164 of Linear Genetic Programming 2004
// Xianshun says:
// the program generated in this way will have program length as small as
// iMinProgLength and as large as iMaxProgLength
// the program length is distributed uniformly between iMinProgLength and iMaxProgLength
private static void initializeWithVariableLength(List programs, LGP manager, RandEngine randEngine) {
int popSize = manager.getPopulationSize();
for(int i=0; i < popSize; ++i) {
Program lgp= new Program();
initialize(lgp, manager, randEngine, randEngine.nextInt(manager.getPopInitMinProgramLength(), manager.getPopInitMaxProgramLength()));
programs.add(lgp);
}
}
// Xianshun says:
// the program generated in this way will have program length as small as
// iMinProgLength and as large as iMaxProgLength
// the program length is distributed uniformly between iMinProgLength and iMaxProgLength
private static void initializeWithConstantLength(List programs, LGP manager, RandEngine randEngine) {
int popSize = manager.getPopulationSize();
for(int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy