Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gp.netvm.netimpl.FullyConnectedNetworkImpl.java

Here you can find all the information about the file org.dgpf.gp.netvm.netimpl.FullyConnectedNetworkImpl.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-07-19 14:13:43
 * Original Filename: org.dgpf.gp.netvm.netimpl.FullyConnectedNetworkImpl.java
 * Version          : 1.0.0
 * Last modification: 2006-07-19
 *                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.gp.netvm.netimpl;

import org.dgpf.gp.netvm.base.INetworkImplFactory;
import org.dgpf.gp.netvm.base.NetVM;
import org.dgpf.gp.netvm.base.NetVMContext;
import org.dgpf.gp.netvm.base.NetworkImpl;
import org.dgpf.gp.vm.base.VMMemory;
import org.sfc.math.stochastic.Randomizer;

/**
 * This class modells a fully conntected network where each host is in
 * one-hop reach.
 *
 * @author Thomas Weise
 */

public final  class FullyConnectedNetworkImpl  extends NetworkImpl
  {
/**
 * The factory class for this network implementation.
 */

  public  static  final INetworkImplFactory FACTORY =
    new INetworkImplFactory()
    {
    private static  final long  serialVersionUID = 1;
    
    public  final NetworkImpl create  (final NetVMContext p_context)
      {
      return new FullyConnectedNetworkImpl(p_context);
      }
    
    private final Object writeReplace()
      {
      return FACTORY;
      }
    
    private final Object readResolve()
      {
      return FACTORY;
      }
    };
  
/**
 * The networked virtual machines.
 */

  private           NetVM[]             m_vms  ;
/**
 * The count of vms.
 */

  private           int                 m_count ;
  
/**
 * Create a new fully connected network implementation.
 * @param p_nvc The network vm context to be used.
 */

  public  FullyConnectedNetworkImpl (final NetVMContext p_nvc)
    {
    super(p_nvc);                  
    }
/**
 * Deliver a message from a source to the destinations in reach.
 * @param p_source  The source node.
 * @param p_data    The message data.
 * @return  <code>true</code> if and only if the message was delivered to
 *          at least one node. 
 */

  @Override
  protected final boolean deliver (final NetVM         p_source,
                                         VMMemory      p_data)
    {
    int           l_i;
    NetVM         l_t;
    NetVM[]       l_g;
    Randomizer    l_r;
    
    l_r = this.get_context().get_randomizer();    
    l_g = this.m_vms;
    for(l_i = (this.m_count-1); l_i >= 0; l_i--)
      {
      l_t = l_g[l_i];
      if(l_t != p_source)
        {
        if(l_t.receive(p_data, 1+l_r.nextInt(20)))
          {
          p_data = this.copy_mem(p_data);   
          } 
        }           
      }
        
    this.dispose_mem(p_data);
    return true;
    }
  
/**
 * Set the count of virtual machines to be simulated.
 * @param p_vm_count  The new count of virtual machines to be simulated.
 */

  @Override
  protected final void set_vm_count(final int p_vm_count)
    {        
    if((this.m_vms == null) || (p_vm_count > this.m_vms.length))
      {
      this.m_vms = new NetVM[p_vm_count << 1];
      this.m_count = p_vm_count;
      this.reset_caches();
      }
    }
  
/**
 * Reset the internal caches used.
 */

  @Override
  protected final void  reset_caches()
    {
    NetVM[]             l_c;
    NetVMContext        l_cc;
    int                 l_i;
    
    l_cc  = this.get_context();
    l_c   = this.m_vms;
    
    for(l_i = (this.m_count-1); l_i >= 0; l_i--)
      {
      l_c[l_i] = l_cc.get_vm(l_i);
      }
    }
  
  
/**
 * This method is called right before a simulation starts to initialize the
 * virtual network.
 * The simulation-setup of the fitness functions will also be invoked here.
 * @param p_index   The index number of the current simulation. The first
 *                  simulation will have index 0, the second will have
 *                  index 1 and so on.
 */

  @Override
  protected void init_network (final int p_index)
    {
    //
    }
  
/**
 * This method is called right when a simulation has finished and cleans
 * up the network.
 * @param p_index   The index number of the current simulation. The first
 *                  simulation will have index 0, the second will have
 *                  index 1 and so on.
 */

  @Override
  protected void    end_network    (final int p_index)
    {
//
    }
  
  }

File Information:

file name:FullyConnectedNetworkImpl.java
package:org.dgpf.gp.netvm.netimpl
qualified name:org.dgpf.gp.netvm.netimpl.FullyConnectedNetworkImpl.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gp/netvm/netimpl/FullyConnectedNetworkImpl.java
size:5.084 KB (5207 B)
uploaded: 2015-07-22 04:10:56 GMT+0000
last update: 2006-08-04 12:44:16 GMT+0000
last access: 2017-11-21 15:42:10 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-21 15:42:10 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo