Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.search.api.p2p.P2PState.java

Here you can find all the information about the file org.dgpf.search.api.p2p.P2PState.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-26 05:03:51
 * Original Filename: org.dgpf.search.api.p2p.P2PState.java
 * Version          : 2.0.2
 * Last modification: 2006-05-29
 *                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.p2p;

import org.dgpf.search.api.SearchUtils;
import org.sfc.math.stochastic.statistics.StatisticInfo;
import org.sfc.math.stochastic.statistics.StatisticInfoBag;
import org.sfc.meta.BoundedIntProperty;
import org.sfc.meta.MetaInformation;
import org.sfc.meta.Property;
import org.sfc.utils.Typesafe;

/**
 * This class represents an extension to all search states that use the
 * searches p2p node.
 *
 * @author Thomas Weise
 */

public class P2PState extends P2PData
  {
/**
 * The serial version uid.
 */

  private static final long serialVersionUID = 1;
  
/**
 * The p2p state meta-information.
 */

  public  static  final MetaInformation P2P_STATE_METAINFO  ;
  
  
/**
 * The property for emigrant count. 
 */

  public  static  final BoundedIntProperty  EMIGRANT_COUNT ;
/**
 * The property for immigrant count. 
 */

  public  static  final BoundedIntProperty  IMMIGRANT_COUNT;  
/**
 * The property for total emigrant count. 
 */

  public  static  final BoundedIntProperty  TOTAL_EMIGRANT_COUNT ;
/**
 * The property for total immigrant count. 
 */

  public  static  final BoundedIntProperty  TOTAL_IMMIGRANT_COUNT;
/**
 * The property for rejected immigrant count. 
 */

  public  static  final BoundedIntProperty  REJECTED_IMMIGRANT_COUNT;
/**
 * The property for total rejected immigrant count. 
 */

  public  static  final BoundedIntProperty  TOTAL_REJECTED_IMMIGRANT_COUNT;  
/**
 * The property for killed immigrant count. 
 */

  public  static  final BoundedIntProperty  KILLED_IMMIGRANT_COUNT;
/**
 * The property for total killed immigrant count. 
 */

  public  static  final BoundedIntProperty  TOTAL_KILLED_IMMIGRANT_COUNT;
/**
 * The property for the immigration fitness statistics.
 */

  public  static  final Property<StatisticInfo> IMMIGRATION_STAT;
  
  static
    {
    EMIGRANT_COUNT = new BoundedIntProperty("emigrant_count",
                             P2PSearchUtils.DISTRIBUTION_STATE_PROPERTIES,
                             0, Integer.MAX_VALUE);
    EMIGRANT_COUNT.add_port(P2PState.class"get_emigrants", null, null);
  
    IMMIGRANT_COUNT = new BoundedIntProperty("immigrant_count",
                             P2PSearchUtils.DISTRIBUTION_STATE_PROPERTIES,
                             0, Integer.MAX_VALUE);  
    IMMIGRANT_COUNT.add_port(P2PState.class"get_immigrants", null, null);

    TOTAL_EMIGRANT_COUNT = new BoundedIntProperty("total_emigrant_count",
                             P2PSearchUtils.DISTRIBUTION_STATE_PROPERTIES,
                             0, Integer.MAX_VALUE);
    TOTAL_EMIGRANT_COUNT.add_port(P2PState.class"get_total_emigrants",
                                 null, null);
  
    TOTAL_IMMIGRANT_COUNT = new BoundedIntProperty("total_immigrant_count",
                             P2PSearchUtils.DISTRIBUTION_STATE_PROPERTIES,
                             0, Integer.MAX_VALUE);
    TOTAL_IMMIGRANT_COUNT.add_port(P2PState.class"get_total_immigrants",
                                   null, null);
    
    REJECTED_IMMIGRANT_COUNT =
                new BoundedIntProperty("rejected_immigrant_count",
                             P2PSearchUtils.DISTRIBUTION_STATE_PROPERTIES,
                             0, Integer.MAX_VALUE);
    REJECTED_IMMIGRANT_COUNT.add_port(P2PState.class,
                        "get_rejected_immigrants", null, null);
    
    TOTAL_REJECTED_IMMIGRANT_COUNT =
       new BoundedIntProperty("total_rejected_immigrant_count",
                             P2PSearchUtils.DISTRIBUTION_STATE_PROPERTIES,
                             0, Integer.MAX_VALUE);
    TOTAL_REJECTED_IMMIGRANT_COUNT.add_port(P2PState.class,
                          "get_total_rejected_immigrants", null, null);
    
    KILLED_IMMIGRANT_COUNT = new BoundedIntProperty("killed_immigrant_count",
                             P2PSearchUtils.DISTRIBUTION_STATE_PROPERTIES,
                             0, Integer.MAX_VALUE);
    KILLED_IMMIGRANT_COUNT.add_port(P2PState.class"get_killed_immigrants",
                            null, null);

    TOTAL_KILLED_IMMIGRANT_COUNT =
       new BoundedIntProperty("total_killed_immigrant_count",
                             P2PSearchUtils.DISTRIBUTION_STATE_PROPERTIES,
                             0, Integer.MAX_VALUE);
    TOTAL_KILLED_IMMIGRANT_COUNT.add_port(P2PState.class,
                    "get_total_killed_immigrants", null, null);
  
    IMMIGRATION_STAT = new Property<StatisticInfo>(
                             "immigration_stat",
                             P2PSearchUtils.DISTRIBUTION_STATE_PROPERTIES,
                             StatisticInfo.class);
    IMMIGRATION_STAT.add_port(P2PState.class, true, false,
                              SearchUtils.FITNESS_FUNCTION_COUNT_FUNC);
  
    P2P_STATE_METAINFO = new MetaInformation();
    }
  
/**
 * The statistic information on the immigrants that arrived this update.
 * @see #get_immigration_stat(int)
 */

  private           StatisticInfo[]       m_immigration_stat  ;
/**
 * The total count of immigrants ever received.
 * @see #get_total_immigrants()
 */

  private           int                   m_total_immigrants  ;
/**
 * The count of immigrants rejected this update because they violated
 * fitness constraints (for example, if they were to fit for a defined
 * fitness threshold, or if they were not fit enough to compete with the
 * local peps).
 * @see #get_rejected_immigrants()
 */

  private           int                   m_rejected_immigrants ;
/**
 * The total count of immigrants ever rejected.
 * @see #get_total_rejected_immigrants()
 */

  private           int                   m_total_rejected ;
/**
 * The count of emigrants that were transmitted to another p2p-node this
 * update.
 * @see #get_emigrants()
 */

  private           int                   m_emigrants ;
/**
 * The total count of emigrants ever transmitted.
 * @see #get_total_emigrants()
 */

  private           int                   m_total_emigrants ;
/**
 * The count of immigrants killed in this update because they were not
 * able to compete with the locals. This will only happen if
 * <code>challenge_immigrants</code> is <code>true</code>.
 * @see #get_killed_immigrants()
 * @see #get_challenge_immigrants()
 */

  private           int                   m_killed_immigrants ;
 
/**
 * The count of immigrants killed in in total (all updates) because they
 * were not able to compete with the locals. This will only happen if
 * <code>challenge_immigrants</code> is <code>true</code>.
 * @see #get_total_killed_immigrants()
 * @see #get_challenge_immigrants()
 */

  private           int                   m_total_killed ;
  
/**
 * Create a new p2p state.
 * @param p_ff_count  The count of fitness functions evaluated by this
 *                    search.
 * @param p_bag       The search state bag that owns this search state
 *                    instance.
 */

  protected P2PState(      int        p_ff_count,
                     final P2PStateBag p_bag)
    {
    super(p_ff_count);
    
    StatisticInfoBag[]  l_b;
    StatisticInfo[]     l_i;

    l_b = p_bag.m_immigrant_stat;
    l_i = new StatisticInfo[p_ff_count];

    for(--p_ff_count; p_ff_count >= 0; p_ff_count--)
      {
      l_i[p_ff_count] = l_b[p_ff_count].unpack();
      }

    this.m_immigration_stat = l_i;
    }
  
/**
 * Update the count of killed immigrants.
 * @param p_int The count of immigrants killed in this update.
 */

  final void update_killed(final int p_int)
    {
    if(p_int > 0)
      {
      this.m_killed_immigrants  = p_int;
      this.m_total_killed      += p_int;
      }
    }
  
/**
 * Update the internal exchange data. Make sure you call this method
 * <strong>after</code> updating the immigration statistics.
 * @param p_rejected    The count of immigrants rejected this update.
 * @param p_emigrants   The count of emigrants that emigrated this
 *                      update.
 */

  final void  update_exchange  (final int p_rejected,
                                final int p_emigrants)
    {
    this.m_total_immigrants += this.m_immigration_stat[0].get_count();

    if(p_rejected > 0)
      {
      this.m_rejected_immigrants  = p_rejected;
      this.m_total_rejected      += p_rejected;
      }
    else this.m_rejected_immigrants = 0;

    if(p_emigrants > 0)
      {
      this.m_emigrants        = p_emigrants;
      this.m_total_emigrants += p_emigrants;
      }
    else this.m_emigrants = 0;
    }


/**
 * Obtain the count of immigrants that entered the population this update.
 * @return The count of immigrants that entered the population this update.
 */

  public  final int get_immigrants()
    {
    return this.m_immigration_stat[0].get_count();
    }

/**
 * Obtain the total count of immigrants ever received.
 * @return The total count of immigrants ever received.
 */

  public final int get_total_immigrants()
    {
    return this.m_total_immigrants;
    }

/**
 * Obtain the count of immigrants rejected this update because they
 * violated fitness constraints (for example, if they were to fit for a
 * defined fitness threshold, or if they were not fit enough to compete
 * with the local peps).
 * @return The count of immigrants rejected this update because they
 *         violated fitness constraints.
 */

  public  final int get_rejected_immigrants()
    {
    return this.m_rejected_immigrants;
    }

/**
 * Obtain the total count of immigrants ever rejected.
 * @return The total count of immigrants ever rejected.
 */

  public  final int get_total_rejected_immigrants()
    {
    return this.m_total_rejected;
    }
  

/**
 * Get the count of immigrants killed in this update because they were not
 * able to compete with the locals. This will only happen if
 * <code>challenge_immigrants</code> is <code>true</code>.
 * @return The count of immigrants killed in this update because they were
 *         not able to compete with the locals. This will only happen if
 *         <code>challenge_immigrants</code> is <code>true</code>.
 */

  public  final int get_killed_immigrants()
    {
    return this.m_killed_immigrants;
    }
 
/**
 * Get the total count of immigrants killed during all updates because they
 * were not able to compete with the locals. This will only happen if
 * <code>challenge_immigrants</code> is <code>true</code>.
 * @return The total count of immigrants killed in during all updates
 *         because they were not able to compete with the locals. This will
 *         only happen if <code>challenge_immigrants</code> is
 *         <code>true</code>.
 */

  public  final int get_total_killed_immigrants()
    {
    return this.m_total_killed;
    }
  
/**
 * Obtain the count of emigrants that were transmitted to another p2p-node
 * this update.
 * @return The count of emigrants that were transmitted to another p2p-node
 *         this update.
 */

  public  final int get_emigrants()
    {
    return this.m_emigrants;
    }

/**
 * Obtain the total count of emigrants ever transmitted.
 * @return The total count of emigrants ever transmitted.
 */

  public  final int get_total_emigrants()
    {
    return this.m_total_emigrants;
    }

/**
 * Obtain the statistics for the specified fitness function for the
 * individuals that immigrated this update.
 * For each fitness function, one statistical record is available.
 * @param p_ff_index  The index of the fitness function to obtain the
 *                    statistics of.
 * @return  The statistics record for the new individuals and the specified
 *          fitness function.
 */

  public  final StatisticInfo get_immigration_stat (final int p_ff_index)
    {
    return this.m_immigration_stat[p_ff_index];
    }

  
/**
 * Creates and returns a copy of this object.  The precise meaning 
 * of "copy" may depend on the class of the object. 
 *
 * @return     A clone of this instance.
 * 
 * @see java.lang.Cloneable
 */

  @Override
  public  Object  clone ()
    {
    final P2PState        l_ss;
    final StatisticInfo[] l_m;
          int             l_i;
    
    try
      {
      l_ss = Typesafe.cast(super.clone());      
      l_ss.m_immigration_stat = l_m = l_ss.m_immigration_stat.clone();
      
      for(l_i = (l_m.length-1); l_i >= 0; l_i--)
        {
        l_m[l_i] = ((StatisticInfo)(l_m[l_i].clone()));
        }
      
      return l_ss;
      }
    catch(Throwable l_t)
      {
      return this;
      }
    }
  }

File Information:

file name:P2PState.java
package:org.dgpf.search.api.p2p
qualified name:org.dgpf.search.api.p2p.P2PState.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/search/api/p2p/P2PState.java
size:13.570 KB (13896 B)
uploaded: 2015-07-22 04:11:00 GMT+0000
last update: 2006-07-21 12:31:14 GMT+0000
last access: 2017-11-17 21:17:13 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-17 21:17:13 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo