Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.search.algorithms.ga.p2p.P2PGeneticParameters.java

Here you can find all the information about the file org.dgpf.search.algorithms.ga.p2p.P2PGeneticParameters.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-10 06:38:55
 * Original Filename: org.dgpf.search.algorithms.ga.p2p.P2PGeneticParameters.java
 * Version          : 2.0.1
 * Last modification: 2006-05-28
 *                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 org.dgpf.search.algorithms.ga.GeneticParameters;
import org.dgpf.search.algorithms.ga.p2p.adaptation.DefaultP2PGeneticAdapter;
import org.dgpf.search.api.AdaptationStrategy;
import org.dgpf.search.api.Assigner;
import org.dgpf.search.api.FitnessFunction;
import org.dgpf.search.api.SearchData;
import org.dgpf.search.api.p2p.P2PParameters;
import org.dgpf.search.api.p2p.P2PSearchUtils;
import org.sfc.math.stochastic.Randomizer;
import org.sfc.meta.MetaInformation;
import org.sfc.utils.Typesafe;

/**
 * <p>
 * The genetic parameters contain the dynamic control data of the evolution
 * enriched by peer-to-peer control data.
 * They might get modified often and reflect their changes to the genetic
 * engine.</p><p>
 * Genetic parameters might adapt dynamically to the state of the evolution.
 * Therefore, any given sheme can be applied, adaption could be done
 * algorithmic or manually.
 * </p>
 *
 * @param <Genotype>    The sort of genotype used to represent individuals.
 *                      This must be a serializable type.
 *
 * @author Thomas Weise
 */

public class P2PGeneticParameters<Genotype extends Serializable>
                                           extends GeneticParameters<Genotype>
  {
/**
 * The serial version uid.
 */

  private   static  final long    serialVersionUID        = 1;

  

/**
 * The meta information of the p2p genetic parameters.
 */

  public  static  final MetaInformation P2P_GENETIC_PARAMETERS_METAINFO  ;
  
  static
    {
    P2PSearchUtils.P2P_PARAMETERS.add_port(
            P2PGeneticParameters.class, true, false, null);
    
    P2P_GENETIC_PARAMETERS_METAINFO = new MetaInformation();
    }
  
/**
 * The peer-to-peer parameters to use.
 */

  private  P2PParameters m_p2p_parameters;

/**
 * Create a new p2p genetic parameter set.
 * @param p_data  The search data to assign to.
 */

  public P2PGeneticParameters (final SearchData p_data)
    {
    super(p_data);

    P2PParameters l_p;
    int           l_pc;

    if(this.m_p2p_parameters == null)
      {
      this.m_p2p_parameters = l_p = this.create_parameters(
                              p_data.get_fitness_function_count());

      l_pc = this.get_population_size();
      l_p.set_allowed_emigrants((int)(0.5d +
          (P2PGeneticUtils.DEFAULT_EMIGRATION_RATE*l_pc)));
      l_p.set_allowed_immigrants((int)(0.5d +
          (P2PGeneticUtils.DEFAULT_IMMIGRATION_RATE*l_pc)));
      }
    }


/**
 * Create the peer-to-peer parameter set to be used for this parameter set.
 * @param p_ff_count  The fitness function count.
 * @return  The new peer-to-peer parameters.
 */

  protected P2PParameters create_parameters(final int p_ff_count)
    {
    return new P2PParameters(p_ff_count);
    }

/**
 * Create a new p2p genetic parameter set.
 * @param p_functions   The fitness functions to be applied in this
 *                      evolution.
 */

  public P2PGeneticParameters(final FitnessFunction<Genotype,?>[] p_functions)
   {
   this(p_functions.length);
   }

/**
 * Create a new p2p genetic parameter set.
 * @param p_ff_count The count of fitness functions evaluated by this search.
 */

  public     P2PGeneticParameters (final int p_ff_count)
    {
    super(p_ff_count);
    this.m_p2p_parameters = this.create_parameters(p_ff_count);
    }

/**
 * Obtain the peer-to-peer parameters containing the control data of the
 * peer-to-peer node.
 * @return The peer-to-peer parameters containing the control data of the
 *         peer-to-peer node.
 */

  public  final P2PParameters get_p2p_parameters  ()
    {
    return this.m_p2p_parameters;
    }

/**
 * Assign the internal data of this search data to the data of
 * another one.
 * @param p_data  The simulation data  to assign to.
 */

  @Override
  public  void  assign  (final Object p_data)
    {
    P2PGeneticState<Genotype>      l_gs;
    P2PGeneticParameters<Genotype> l_gp;

    super.assign(p_data);

    if(p_data instanceof P2PGeneticState)
      {
      l_gs = Typesafe.cast(p_data);
      Assigner.assign(this.m_p2p_parameters, l_gs.get_p2p_state());
      }

    if(p_data instanceof P2PGeneticParameters)
      {
      l_gp = Typesafe.cast(p_data);
      Assigner.assign(this.m_p2p_parameters, l_gp.m_p2p_parameters);
      }
    }



/**
 * Set the adaptation strategy adjusting this search parameter set.
 * @param p_strategy  The new adaptation strategy to adjust this search
 *                    parameter set.
 */

  @Override
  public  final void  set_adaptation_strategy
                            (final AdaptationStrategy p_strategy)
    {
    super.set_adaptation_strategy(p_strategy);

    if(p_strategy instanceof DefaultP2PGeneticAdapter)
      {
      this.m_p2p_parameters.notify_strategy(
       ((DefaultP2PGeneticAdapter)p_strategy).get_p2p_adaptation_strategy());
      }
    }
  
/**
 * After setting the non-fitness-influencing parameters of this search
 * parameter set to the allowed maximum, call this method to alter the
 * configuration randomly.
 * @param p_r The randomizer to be used.
 */

  @Override
  public  void  configure_randomly  (final Randomizer p_r)
    {  
    P2PParameters l_p;
    int           l_i;
    
    super.configure_randomly(p_r);
    
    l_i = this.get_population_size();
    l_p = this.get_p2p_parameters();
       
    this.get_p2p_parameters().configure_randomly(p_r);
    l_p.set_allowed_emigrants(Math.max(1,
                            ((int)(Math.pow(p_r.nextDouble(), 3.9d)*l_i))));
    l_p.set_allowed_immigrants(Math.max(1,
                            ((int)(Math.pow(p_r.nextDouble(), 5.2d)*l_i))));
    }
  }

File Information:

file name:P2PGeneticParameters.java
package:org.dgpf.search.algorithms.ga.p2p
qualified name:org.dgpf.search.algorithms.ga.p2p.P2PGeneticParameters.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/search/algorithms/ga/p2p/P2PGeneticParameters.java
size:6.810 KB (6974 B)
uploaded: 2015-07-22 04:10:59 GMT+0000
last update: 2006-08-22 14:06:35 GMT+0000
last access: 2017-11-23 07:31:37 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-23 07:31:37 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo