Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.search.algorithms.ga.cs.CSGeneticEngine.java

Here you can find all the information about the file org.dgpf.search.algorithms.ga.cs.CSGeneticEngine.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2006 Thomas Weise
 * 
 * E-Mail           : tweise@gmx.de
 * Creation Date    : 2006-04-12 10:13:33
 * Original Filename: org.dgpf.search.algorithms.ga.cs.CSGeneticEngine.java
 * Version          : 2.1.4
 * Last modification: 2006-07-15
 *                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.cs;

import java.io.Serializable;
import java.net.InetSocketAddress;

import org.dgpf.search.algorithms.ga.GeneticEngine;
import org.dgpf.search.algorithms.ga.GeneticParameters;
import org.dgpf.search.api.cs.SearchClient;
import org.sfc.net.cs.IClient;

/**
 * This genetic engine uses the client-server model to distribute the
 * computational load. This model is often also refered as master-slave
 * model. Basically, the selection is done on the client and reproduction
 * as well as simulation is distributed to a set of servers.
 * 
 * This special Genetic Engine unleashes the parallelization potential of
 * Genetic Algorithms by distributing computational load of reproduction
 * and evaluation of the individuals to servers in a network. This allows
 * you to process populations of complicated individuals (taking long to be
 * evaluated) in reasonable time in parallel. Check also the peer-to-peer /
 * client-server hybrid engine in the <code>org.dgpf.ga.p2p</code> package.
 *
 * @param <Genotype>    The sort of genotype used to represent individuals.
 *                      This must be a serializable type.
 *
 * @see org.dgpf.search.algorithms.ga.p2p.P2PCSGeneticEngine
 *
 * @author Thomas Weise
 */

public class CSGeneticEngine<Genotype extends Serializable> 
                                      extends GeneticEngine<Genotype>
                                      implements  IClient
  {
/**
 * The search client to be used to distribute the computational load.
 */

  private final SearchClient<Genotype>  m_client  ;

/**
 * Create a new genetic engine without providing additional information or
 * parameters. This constructor will be used only for loading a snapshot
 * immediately afterwards.
 */

  public CSGeneticEngine()
    {
    super();
    this.m_client = new SearchClient<Genotype>(this.get_task_queue(), this);
    this.add_compound_activity(this.m_client);
    }
  
/**
 * Create a client-server 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 <code>-1</code> for don't care.
 */

  public CSGeneticEngine(final GeneticParameters<Genotype> p_parameters,
                         final int                         p_ndl_size)
    {
    super(p_parameters, p_ndl_size);
    this.m_client = new SearchClient<Genotype>(this.get_task_queue(), this);
    }
  
/**
 * <p>
 * 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.</p><p>
 * You may use it to update worker threads.</p>
 */

  @Override
  protected void  inner_update  ()
    {
    if(this.is_running())
      {
      this.m_client.transmit_settings(
            this.get_parameters().create_context_parameters());
      }
    }
  
/**
 * Startup the search. This method will be called by <code>start()</code>.
 * @see #start()
 */

  @Override
  protected void  do_start  ()
    {
    super.do_start();
    this.m_client.start();
    }
  
  
/**
 * Perform a shutdown. It is guaranteed to be called only once for shutdown.
 * This method should only perform the actions needed to shutdown the
 * network of activities. The closing of the activity itself will be done
 * by <code>do_abort</code>, which will subsequently be called
 * automatically.
 * @see #abort()
 * @see #shutdown()
 */

  @Override
  protected void  do_shutdown ()
    {
    super.do_shutdown();
    this.m_client.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  ()
    {
    super.do_abort();
    this.m_client.abort();
    }
  
/**
 * Wait for this object.
 */

  @Override
  public  void  wait_for  ()
    {    
    this.m_client.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 "Client-Server Genetic Engine";
    }
  
/**
 * Add a new server to the list of servers to use.
 * @param p_addr  The internet socket address of the server.
 */

  public final void add_server(final InetSocketAddress p_addr)
    {
    this.m_client.add_server(p_addr);
    }
  

/**
 * Obtain the count of servers running.
 * @return The count of servers running.
 */

  public  final int get_server_count()
    {
    return this.m_client.get_server_count();
    }
  }

File Information:

file name:CSGeneticEngine.java
package:org.dgpf.search.algorithms.ga.cs
qualified name:org.dgpf.search.algorithms.ga.cs.CSGeneticEngine.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/search/algorithms/ga/cs/CSGeneticEngine.java
size:5.806 KB (5946 B)
uploaded: 2015-07-22 04:10:59 GMT+0000
last update: 2006-07-15 09:36:23 GMT+0000
last access: 2017-11-18 06:33:19 GMT+0000

statistics online since 2006-01-02.   RSS Feed
Contact us by sending an email to tweise@gmx.de to receive further information, to report errors, or to join our project.
All content on this site (http://dgpf.sourceforge.net/) is LGPL-licensed.
http://dgpf.sourceforge.net/scripts/source/source.php last modified at 2015-07-22 04:10:53 GMT+0000 served at 2017-11-18 06:33:19 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo