added elitism to LTGA
This commit is contained in:
parent
cb357417a2
commit
2f82ea1f43
@ -35,6 +35,7 @@ public class LTGA implements InterfaceOptimizer, java.io.Serializable, Interface
|
|||||||
private AbstractOptimizationProblem problem = new BKnapsackProblem();
|
private AbstractOptimizationProblem problem = new BKnapsackProblem();
|
||||||
private AbstractEAIndividual template = null;
|
private AbstractEAIndividual template = null;
|
||||||
private int generationCycle = 500;
|
private int generationCycle = 500;
|
||||||
|
private boolean elitism = true;
|
||||||
|
|
||||||
public LTGA() {
|
public LTGA() {
|
||||||
}
|
}
|
||||||
@ -248,7 +249,15 @@ public class LTGA implements InterfaceOptimizer, java.io.Serializable, Interface
|
|||||||
this.problem.evaluatePopulationStart(this.population);
|
this.problem.evaluatePopulationStart(this.population);
|
||||||
Stack<Set<Integer>> linkageTree = buildLinkageTree();
|
Stack<Set<Integer>> linkageTree = buildLinkageTree();
|
||||||
Population newPop = new Population(this.popSize);
|
Population newPop = new Population(this.popSize);
|
||||||
|
if(elitism){
|
||||||
|
Population firstIndies = this.population.getBestNIndividuals(2, fitCrit);
|
||||||
|
Population firstNewIndies = buildNewIndies(firstIndies, linkageTree);
|
||||||
|
newPop.addAll(firstNewIndies);
|
||||||
|
}
|
||||||
for (int i = 0; i < (this.popSize / 2); i++) {
|
for (int i = 0; i < (this.popSize / 2); i++) {
|
||||||
|
if(this.elitism && i==0){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Population indies = this.population.getRandNIndividuals(2);
|
Population indies = this.population.getRandNIndividuals(2);
|
||||||
Population newIndies = buildNewIndies(indies, linkageTree);
|
Population newIndies = buildNewIndies(indies, linkageTree);
|
||||||
newPop.addAll(newIndies);
|
newPop.addAll(newIndies);
|
||||||
@ -335,6 +344,18 @@ public class LTGA implements InterfaceOptimizer, java.io.Serializable, Interface
|
|||||||
public void SetProblem(InterfaceOptimizationProblem problem) {
|
public void SetProblem(InterfaceOptimizationProblem problem) {
|
||||||
this.problem = (AbstractOptimizationProblem) problem;
|
this.problem = (AbstractOptimizationProblem) problem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getElitism(){
|
||||||
|
return this.elitism;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setElitism(boolean b){
|
||||||
|
this.elitism = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String elitismTipText(){
|
||||||
|
return "use elitism?";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InterfaceOptimizationProblem getProblem() {
|
public InterfaceOptimizationProblem getProblem() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user