/* * Copyright (c) 2006 Thomas Weise * * E-Mail : tweise@gmx.de * Creation Date : 2006-04-10 06:33:05 * Original Filename: org.dgpf.search.algorithms.ga.p2p.P2PCSGeneticEngine.java * Version : 2.1.7 * Last modification: 2006-06-22 * by: Thomas Weise * * License : GNU LESSER GENERAL PUBLIC LICENSE * Version 2.1, February 1999 * You should have received a copy of this license along * with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307, USA or download the license under * http://www.gnu.org/copyleft/lesser.html. * * Warranty : This software is provided "as is" without any * warranty; without even the implied warranty of * merchantability or fitness for a particular purpose. * See the Gnu Lesser General Public License for more * details. */ package org.dgpf.search.algorithms.ga.p2p; import java.io.Serializable; import java.net.InetAddress; import java.net.InetSocketAddress; import org.dgpf.search.algorithms.ga.SelectionAlgorithm; import org.dgpf.search.algorithms.ga.cs.CSGeneticEngine; import org.dgpf.search.api.Assigner; import org.dgpf.search.api.FitnessAccessor; import org.dgpf.search.api.Individual; import org.dgpf.search.api.IndividualComparator; import org.dgpf.search.api.NonDominatedList; import org.dgpf.search.api.SearchStateBag; import org.dgpf.search.api.SearchUtils; import org.dgpf.search.api.p2p.P2PState; import org.dgpf.search.api.p2p.SearchP2P; import org.sfc.collections.Arrays; import org.sfc.math.stochastic.Randomizer; import org.sfc.math.stochastic.statistics.StatisticInfoBag; import org.sfc.net.p2p.IPeerToPeer; import org.sfc.utils.Typesafe; /** *
* Instances of this class can form a peer-to-peer network of genetic
* engines working all on the same problem and evolving a distributed
* population using the island-hopping mechanism. Unlike the normal
* P2PGeneticEngine
, this engine does not process the tasks
* locally but let them be processed remotely in search servers.
*
* This is the highest scalable approach, it serves for problems that need * really a lot time to be simulated and allows different computer farms or * cluster cooperate on the other hand. *
* * @paramlt;1024
, the default port will be taken.
*/
public P2PCSGeneticEngine (final int p_port)
{
super();
this.m_port = ((p_port > 1023) ? p_port
: SearchUtils.DEFAULT_INDIVIDUAL_EXCHANGE_PORT);
}
/**
* Create a genetic engine.
* @param p_parameters The parameters object guiding the evolution process.
* @param p_ndl_size The size of the non-dominated list. Set this
* to -1
for don't care.
* @param p_port The port where the peer-to-peer service of the
* genetic engine should reside. If you leave this
* lt;1024
, the default port will be taken.
*/
public P2PCSGeneticEngine(final P2PGeneticParameterstrue
if and only if this
* initialization was called due to an
* deserialization process, false
if it
* is the normal initialization in the constructor.
*/
@Override
protected void initialize (final boolean p_deserialized)
{
super.initialize(p_deserialized);
if(p_deserialized) this.init_p2p();
}
/**
* Startup the search. This method will be called by start()
.
* @see #start()
*/
@Override
protected void do_start ()
{
super.do_start();
this.m_p2p.start();
}
/**
* This method is used to create the search state (and its accessor bag) to
* be used by this search engine.
* @return A new search state (and its accessor bag).
*/
@Override
protected SearchStateBagdo_abort
, which will subsequently be called
* automatically.
* @see #abort()
* @see #shutdown()
*/
@Override
protected void do_shutdown ()
{
super.do_shutdown();
this.m_p2p.shutdown();
}
/**
* This method aborts the activity. It is guaranteed to be called only once
* for aborting and once for shutdown.
* @see #abort()
* @see #shutdown()
*/
@Override
protected void do_abort ()
{
this.m_p2p.abort();
super.do_abort();
}
/**
* This hook allows you to insert some additional individuals by overriding
* existing ones.
* @param p_population The population array.
* @param p_count The count of individuals in the population array.
* @param p_comparator The comparator to be used for insertion.
* @return true
if and only if at least one new individual
* has been injected into the population, false
* otherwise.
*/
@Override
protected boolean insert_additional
(final Individual0
* and the worst at index p_count-1
.
* @param p_population The population array.
* @param p_count The population count.
* @param p_selection The selection algorithm to use.
* @param p_random A randomizer that can be used.
* @param p_ndl The non-dominated individual list.
* @param p_elp The elitism percentage.
*/
@Override
protected void select_additional
(final Individual* This method will be called every generation after the fitness has been * calculated and the state was updated, but before the genetic tasks are * entered in the task queue.
*/ @Override protected void inner_update () { P2PGeneticStatetrue
if and only if the peer was not yet known and
* has been added successfully.
*/
public final boolean add_peer (final InetAddress p_i,
final int p_port)
{
return this.m_p2p.add_peer(p_i, p_port);
}
/**
* Add a peer to the internal peer list.
* @param p_isa The internet address and port the peer is located at.
* @return true
if and only if the peer was not yet known and
* has been added successfully.
*/
public final boolean add_peer (final InetSocketAddress p_isa)
{
return this.m_p2p.add_peer(p_isa);
}
/**
* Remove a peer from the internal peer list.
* @param p_isa The internet address and port the peer is located at.
* @return true
if and only if the peer was known and
* has been removed successfully.
*/
public final boolean remove_peer (final InetSocketAddress p_isa)
{
return this.m_p2p.remove_peer(p_isa);
}
/**
* Wait for this object.
*/
@Override
public void wait_for ()
{
this.m_p2p.wait_for();
super.wait_for();
}
/**
* The human readable name of the search engine.
* @return The human readable name of the search engine.
*/
@Override
public String toString ()
{
return "P2P CS Genetic Engine (port " + this.m_port + ')';
}
}