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

net.sourceforge.cilib.util.functions.Populations Maven / Gradle / Ivy

Go to download

A library of composable components enabling simpler Computational Intelligence

There is a newer version: 0.8
Show newest version
/**           __  __
 *    _____ _/ /_/ /_    Computational Intelligence Library (CIlib)
 *   / ___/ / / / __ \   (c) CIRG @ UP
 *  / /__/ / / / /_/ /   http://cilib.net
 *  \___/_/_/_/_.___/
 */
package net.sourceforge.cilib.util.functions;

import fj.F;
import fj.F2;
import fj.data.List;
import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm;
import net.sourceforge.cilib.entity.Entity;
import net.sourceforge.cilib.entity.Topology;
import net.sourceforge.cilib.pso.particle.Particle;
import net.sourceforge.cilib.pso.particle.ParticleBehavior;

public final class Populations {
    /**
     * Returns an empty population of the given population type;
     */
    public static 

F emptyPopulation() { return new F() { @Override public P f(P a) { P tmp = (P) a.getClone(); tmp.getTopology().clear(); return tmp; } }; } /** * Converts a swarm into a list of single entity populations. */ public static

F> populationToAlgorithms() { return new F>() { @Override public List

f(final P a) { return Populations.entitiesToAlgorithms().f((Topology) a.getTopology(), a); } }; } /** * Converts a single entity to a population of the given type. */ public static

F2 entityToAlgorithm() { return new F2() { @Override public P f(E e, P p) { P tmp = (P) p.getClone(); tmp.getTopology().clear(); ((Topology) tmp.getTopology()).add(e); return tmp; } }; } /** * Converts a list of entities into single entity populations. */ public static

F2, P, List

> entitiesToAlgorithms() { return new F2, P, List

>() { @Override public List

f(Iterable a, P b) { return List.iterableList(a).map(Populations.entityToAlgorithm().flip().f(b)); } }; } /** * Makes sure a swarm has a neighbourhood best and the correct particle behavior. * * @param pb The particle behavior to give each entity in the swarm. * * @return The enforced swarm. */ public static

F enforceTopology(final ParticleBehavior pb) { return new F() { @Override public P f(P a) { P tmp = (P) a.getClone(); if (!tmp.getTopology().isEmpty() && tmp.getTopology().get(0) instanceof Particle) { for (Entity e : tmp.getTopology()) { Particle p = (Particle) e; p.setParticleBehavior(pb); } } return tmp; } }; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy