All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sourceforge.cilib.pso.crossover.parentupdate.BoltzmannParentReplacementStrategy Maven / Gradle / Ivy

Go to download

A library of composable components enabling simpler Computational Intelligence

The newest version!
/**           __  __
 *    _____ _/ /_/ /_    Computational Intelligence Library (CIlib)
 *   / ___/ / / / __ \   (c) CIRG @ UP
 *  / /__/ / / / /_/ /   http://cilib.net
 *  \___/_/_/_/_.___/
 */
package net.sourceforge.cilib.pso.crossover.parentupdate;

import com.google.common.collect.Lists;
import java.util.Arrays;
import java.util.List;
import net.sourceforge.cilib.pso.particle.Particle;
import net.sourceforge.cilib.util.selection.recipes.BoltzmannSelector;

/**
 * This ParentReplacementStrategy uses Boltzmann selection to determine if an
 * offspring replaces a parent.
 */
public class BoltzmannParentReplacementStrategy extends ParentReplacementStrategy {
    private BoltzmannSelector selector;

    public BoltzmannParentReplacementStrategy() {
        this.selector = new BoltzmannSelector();
    }

    @Override
    public List f(List parents, List offspring) {
        List particles = Lists.newArrayList();

        for (int i = 0; i < Math.min(parents.size(), offspring.size()); i++) {
            particles.add(selector.on(Arrays.asList(parents.get(i), offspring.get(i))).select());
        }

        particles.addAll(parents.subList(particles.size(), parents.size()));

        return particles;
    }

    public void setBoltzmannSelector(BoltzmannSelector selector) {
        this.selector = selector;
    }

    public BoltzmannSelector getBoltzmannSelector() {
        return selector;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy