Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.search.api.SearchTask.java

Here you can find all the information about the file org.dgpf.search.api.SearchTask.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-03-31 05:43:34
 * Original Filename: org.dgpf.search.api.SearchTask.java
 * Version          : 2.0.0
 * Last modification: 2006-05-08
 *                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.api;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import org.sfc.utils.Typesafe;

/**
 * This class contains the main search tasks.
 *
 * @param <Genotype>    The sort of genotype used to represent individuals.
 *                      This must be a serializable type.
 *                    
 * @author Thomas Weise
 */

public abstract class SearchTask<Genotype extends Serializable>
                                          extends Individual<Genotype>
  {
/**
 * The serial version uid.
 */

  private static final long serialVersionUID = 1;
  
/**
 * Create a new search task which can be used by a search involving
 * <code>p_fitness_count</code> fitness functions.
 * @param p_fitness_count The count of fitness functions that might be
 *                        applied to the individual.
 */

  SearchTask  (final int p_fitness_count)
    {
    super(p_fitness_count);
    }
  
/**
 * Execute the genetic task.
 * @param p_context The search context to use for execution.
 */

  public abstract  void  execute (final SearchContext<Genotype> p_context);
  
  

/**
 * With this method you are able to transmit the results of a processed
 * task to some object output stream. This method will only write the
 * required parts of the task.
 * @param p_oos   The object output stream to write to.
 * @param p_task  The task to be transmitted.
 * @param <T>     The genotype of the task.
 * @throws  IOException If io fails.
 */

  public static final <T extends Serializable>  void transmit_result(
                            final ObjectOutputStream p_oos,
                            final SearchTask<T>      p_task)
                    
      throws IOException
    {
    p_task.transmit(p_oos);
    }

/**
 * With this method you are able to receive the results of a processed task
 * from some object input stream. This method will only read the required
 * parts of the task.
 * @param p_ois   The object input stream to read from.
 * @param p_task  The task to to fill with the results..
 * @param <T>     The genotype of the task.
 * @throws  IOException             If io fails.
 * @throws  ClassNotFoundException  If the individuals genotype is
 *                                  invalid.
 */

  public static final <T extends Serializable>  void receive_result(
                            final ObjectInputStream  p_ois,
                            final SearchTask<T>      p_task)
        throws IOException, ClassNotFoundException
    {
    Individual<Serializable> l_x;
    l_x = Typesafe.cast(p_task);
    do_receive(l_x, p_ois);
    }

  
/**
 * This search task can be used to create and evaluate a completely new,
 * random individual.
 * 
 * @param <Genotype2>   The sort of genotype used to represent individuals.
 *                      This must be a serializable type.
 * 
 * @see SearchContext#create(Individual)
 * @author Thomas Weise
 */

  public static final class SearchNew<Genotype2 extends Serializable>
                                                extends SearchTask<Genotype2>
    {
/**
 * The serial version uid.
 */

    private static final long serialVersionUID = 1;
    
/**
 * Create a new "new individual"-task for a search involving
 * <code>p_fitness_count</code> fitness functions.
 * @param p_fitness_count The count of fitness functions that might be
 *                        applied to the individual.
 */

    public  SearchNew (final int p_fitness_count)
      {
      super(p_fitness_count);
      }
/**
 * Execute the genetic task.
 * @param p_context The search context to use for execution.
 */

    @Override
    public final void execute(final SearchContext<Genotype2> p_context)
      {
      p_context.create(this);
      }
    }
  
/**
 * This search task can be used to create and evaluate an individual which
 * is derived from an existing one by mutation.
 * 
 * @param <Genotype2>   The sort of genotype used to represent individuals.
 *                      This must be a serializable type.
 * 
 * @see SearchContext#mutate(Individual, Individual)
 * @author Thomas Weise
 */

  public static final class   SearchMutate<Genotype2 extends Serializable>
                      extends SearchTask<Genotype2>
    {
/**
 * The serial version uid.
 */

    private static final long serialVersionUID = 1;
    
/**
 * The parent individual.
 */

    private           Individual<Genotype2>  m_parent  ;
    
/**
 * Create a new "mutate individual"-task for a search involving
 * <code>p_fitness_count</code> fitness functions.
 * @param p_fitness_count The count of fitness functions that might be
 *                        applied to the individual.
 */

    public  SearchMutate (final int p_fitness_count)
      {
      super(p_fitness_count);
      }
    
/**
 * Set the parent which will be the individual to mutate.
 * @param p_parent  The parent individual to derive.
 */

    public  final void  set_parent  (final Individual<Genotype2> p_parent)
      {
      this.m_parent = p_parent;
      }
    
/**
 * Execute the genetic task.
 * @param p_context The search context to use for execution.
 */

    @Override
    public final void execute(final SearchContext<Genotype2> p_context)
      {
      p_context.mutate(this.m_parent, this);
      this.m_parent = null;
      }
    }
  
/**
 * This search task can be used to create and evaluate an individual which
 * is derived from two existing ones by crossover.
 * 
 * @param <Genotype2>   The sort of genotype used to represent individuals.
 *                      This must be a serializable type.
 * 
 * @see SearchContext#mutate(Individual, Individual)
 * @author Thomas Weise
 */

  public static final class   SearchCrossover<Genotype2 extends Serializable>
                      extends SearchTask<Genotype2>
    {
/**
 * The serial version uid.
 */

    private static final long serialVersionUID = 1;
    
/**
 * The first parent individual.
 */

    private           Individual<Genotype2>  m_parent_1  ;
/**
 * The second parent individual.
 */

    private           Individual<Genotype2>  m_parent_2  ;
    
    
/**
 * Create a new "crossover individuals"-task for a search involving
 * <code>p_fitness_count</code> fitness functions.
 * @param p_fitness_count The count of fitness functions that might be
 *                        applied to the individual.
 */

    public  SearchCrossover (final int p_fitness_count)
      {
      super(p_fitness_count);
      }
    
/**
 * Set the first parent which will be one of the individual to crossover.
 * @param p_parent  The parent individual to derive.
 */

    public  final void  set_parent_1 (final Individual<Genotype2> p_parent)
      {
      this.m_parent_1 = p_parent;
      }
    
/**
 * Set the second parent which will be one of the individual to crossover.
 * @param p_parent  The parent individual to derive.
 */

    public  final void  set_parent_2 (final Individual<Genotype2> p_parent)
      {
      this.m_parent_2 = p_parent;
      }    
    
/**
 * Execute the genetic task.
 * @param p_context The search context to use for execution.
 */

    @Override
    public final void execute(final SearchContext<Genotype2> p_context)
      {
      p_context.crossover(this.m_parent_1, this.m_parent_2, this);
      this.m_parent_1 = null;
      this.m_parent_2 = null;
      }
    }
  }

File Information:

file name:SearchTask.java
package:org.dgpf.search.api
qualified name:org.dgpf.search.api.SearchTask.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/search/api/SearchTask.java
size:8.529 KB (8734 B)
uploaded: 2015-07-22 04:11:00 GMT+0000
last update: 2006-05-08 13:46:19 GMT+0000
last access: 2017-11-20 19:01:00 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-20 19:01:00 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo