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

net.sourceforge.cilib.entity.topologies.LBestTopology 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.entity.topologies;

import com.google.common.collect.UnmodifiableIterator;
import java.util.Iterator;
import java.util.NoSuchElementException;
import net.sourceforge.cilib.controlparameter.ConstantControlParameter;
import net.sourceforge.cilib.entity.Entity;

/**
 * 

* Implementation of the Local Best Neighbourhood topology. *

* References: *

  • * R.C. Eberhart, P. Simpson, and R. Drobbins, "Computational Intelligence PC Tools," * chapter 6, pp. 212-226. Academic Press Professional, 1996. *

* * @param The {@linkplain Entity} type. */ public class LBestTopology extends AbstractTopology { private static final long serialVersionUID = 93039445052676571L; /** * Default constructor. The default {@link #neighbourhoodSize} is 3. */ public LBestTopology() { this.neighbourhoodSize = ConstantControlParameter.of(3); } /** * Copy constructor.. */ public LBestTopology(LBestTopology copy) { super(copy); } /** * {@inheritDoc} */ @Override public LBestTopology getClone() { return new LBestTopology(this); } /** * {@inheritDoc} */ @Override protected Iterator neighbourhoodOf(final E e) { return new UnmodifiableIterator() { int count = 0; int ns = getNeighbourhoodSize(); int ts = size(); int index = (entities.indexOf(e) - (ns / 2) - 1 + ts) % ts; @Override public boolean hasNext() { return (count != ns); } @Override public E next() { if (!hasNext()) { throw new NoSuchElementException(); } return entities.get((index + ++count) % ts); } }; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy