Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.search.algorithms.hc.local.LocalHCEngine.java

Here you can find all the information about the file org.dgpf.search.algorithms.hc.local.LocalHCEngine.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-05-10 10:01:23
 * Original Filename: org.dgpf.search.algorithms.hc.local.LocalHCEngine.java
 * Version          : 1.0.2
 * 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.hc.local;

import java.io.Serializable;

import org.dgpf.search.algorithms.hc.HCEngine;
import org.dgpf.search.algorithms.hc.HCParameters;
import org.dgpf.search.api.SearchDefinition;
import org.dgpf.search.api.SearchTaskQueue;
import org.dgpf.search.api.SearchWorkerThread;
import org.sfc.collections.Arrays;
import org.sfc.events.EventPropagator;
import org.sfc.utils.Typesafe;

/**
 * The search engine implementing a hill climbing algorithm that runs
 * locally.
 * @param <Genotype> The genotype of the elements to be evolved.
 * @author Thomas Weise
 */

public class LocalHCEngine<Genotype extends Serializable>
                                    extends HCEngine<Genotype>
  {
/**
 * The search definition used by this engine.
 */

  private final SearchDefinition<Genotype>      m_definition  ;
/**
 * The search worker threads used by this engine.
 */

  private       SearchWorkerThread<Genotype>[]  m_swt ;
  
/**
 * Create a new hill climbing engine that runs locally without providing
 * additional information or parameters. This method will be used when
 * loading a snapshot mostly.
 * @param p_definition  The definition of the evolution process.
 */

  public LocalHCEngine  (final SearchDefinition<Genotype>  p_definition)
    {
    super();
    this.m_definition = p_definition;
    }

/**
 * Create a hill climbing engine that runs locally.
 * @param p_parameters  The parameters object guiding the evolution process.
 * @param p_definition  The definition of 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 LocalHCEngine  (final HCParameters<Genotype>      p_parameters,
                         final SearchDefinition<Genotype>  p_definition,
                         final int                         p_ndl_size)
    {
    super(p_parameters, p_ndl_size);
    this.m_definition = p_definition;
    this.init_threads(p_definition);
    }
  


/**
 * Initialize the worker threads.
 * @param p_def The search definition to be used for initializing the
 *              threads.
 */

  private final void init_threads(final SearchDefinition<Genotype> p_def)
    {
    SearchWorkerThread<Genotype>[]  l_swt;
    int                             l_i;
    EventPropagator                 l_ep;
    SearchTaskQueue<Genotype>       l_stq;
    HCParameters<Genotype>          l_gp;


    l_i   = this.compute_population_size();
    l_swt = Arrays.create(SearchWorkerThread.class, l_i);
    l_ep  = this.get_event_propagator();
    l_stq = this.get_task_queue();

    for(--l_i; l_i >= 0; l_i--)
      {
      l_swt[l_i] = new SearchWorkerThread<Genotype>(
                                          this, l_stq,
                                          p_def.create_context(l_ep));
      }

    l_gp = Typesafe.cast(this.get_parameters());

    for(l_i = (l_swt.length-1); l_i >= 0; l_i--)
      {
      l_swt[l_i].update_context(l_gp);
      }

    this.m_swt = l_swt;
    }
  

/**
 * This method is called to initialize the search engine. You must all
 * initialization code here.
 * @param p_deserialized  <code>true</code> if and only if this
 *                        initialization was called due to an
 *                        deserialization process, <code>false</code> 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_threads(this.m_definition);
    }
  

/**
 * Startup the search. This method will be called by <code>start()</code>.
 * @see #start()
 */

  @Override
  protected void  do_start  ()
    {    
    SearchWorkerThread<Genotype>[]  l_swt;
    int                             l_i;

    super.do_start();

    l_swt = this.m_swt;
    for(l_i = (l_swt.length-1); l_i >= 0; l_i--)
      {
      l_swt[l_i].start();
      }
    }
  

/**
 * 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  ()
    {
    SearchWorkerThread<Genotype>[]  l_swt;
    int                             l_i;

    super.do_abort();

    l_swt = this.m_swt;
    for(l_i = (l_swt.length-1); l_i >= 0; l_i--)
      {
      l_swt[l_i].abort();
      }
    }
  

/**
 * Wait for this object.
 */

  @Override
  public  void  wait_for  ()
    {
    SearchWorkerThread<Genotype>[]  l_swt;
    int                             l_i;
    
    l_swt = this.m_swt;

    for(l_i = (l_swt.length-1); l_i >= 0; l_i--)
      {
      l_swt[l_i].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 "Local Hill Climbing Engine";
    }
  }

File Information:

file name:LocalHCEngine.java
package:org.dgpf.search.algorithms.hc.local
qualified name:org.dgpf.search.algorithms.hc.local.LocalHCEngine.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/search/algorithms/hc/local/LocalHCEngine.java
size:6.153 KB (6301 B)
uploaded: 2015-07-22 04:10:59 GMT+0000
last update: 2006-07-15 09:36:43 GMT+0000
last access: 2017-11-24 00:19:34 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-24 00:19:34 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo