Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gp.netvm.base.NetVMDefinition.java

Here you can find all the information about the file org.dgpf.gp.netvm.base.NetVMDefinition.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-06 13:48:00
 * Original Filename: org.dgpf.gp.netvm.NetVMDefinition.java
 * Version          : 1.0.0
 * Last modification: 2006-07-06
 *                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.base;

import org.dgpf.gp.netvm.instructions.SendHandler;
import org.dgpf.gp.netvm.netimpl.FullyConnectedNetworkImpl;
import org.dgpf.gp.vm.base.InstructionSet;
import org.dgpf.gp.vm.base.Program;
import org.dgpf.gp.vm.base.VMDefinition;
import org.dgpf.search.api.FitnessFunction;

/**
 * A definition for a network of virtual machines.
 *
 * @author Thomas Weise
 */

public class NetVMDefinition  extends VMDefinition
  {
/**
 * The serial version uid.
 */

  private static  final long  serialVersionUID        = 1;  

/**
 * The count of virtual machines to be simulated.
 * @see #get_vm_count()
 */

  private int                 m_vm_count  ;
/**
 * The maximum count of messages a virtual machine may send.
 * @see #get_max_message_count() 
 */

  private int                 m_max_msgs   ;
/**
 * The network implemenation factory to be used.
 * @see #get_network_impl_factory()
 */

  private INetworkImplFactory m_net_factory;
  
/**
 * Create a new virtual network definition.
 * @param p_definition  The search definition to use as blueprint for the
 *                      internally stored data.
 */

  public  NetVMDefinition(final NetVMDefinition p_definition)
    {
    super(p_definition);  
    }
 
/**
 * Create a new search definition.
 * @param p_functions   The fitness functions to be applied in this
 *                      evolution.
 */

  public NetVMDefinition(final FitnessFunction<Program,?>[]  p_functions)
    {
    super(p_functions);
    this.m_vm_count = NetVMUtils.DEFAULT_VM_COUNT;
    this.m_max_msgs = NetVMUtils.DEFAULT_MAX_MSGS;
    
    if(this.get_min_proc_count() < 2)
      {
      super.set_min_proc_count(2);
      }
    
    if(!(this.get_instruction_set().contains(SendHandler.INSTANCE)))
      {
      super.set_instruction_set(NetVMUtils.DEFAULT_INSTRUCTION_SET);
      }
    
    this.m_net_factory = FullyConnectedNetworkImpl.FACTORY;
    }
  
/**
 * Set the instruction set to be used form virtual machines.
 * @param p_set The instruction set to be used form virtual machines.
 */

  @Override
  public  void  set_instruction_set (final InstructionSet p_set)
    {
    if((p_set != null) && (p_set.contains(SendHandler.INSTANCE)))
      {
      super.set_instruction_set(p_set);
      }
    }
  
/**
 * The minimum count of procedures. You may set this count to some value
 * greater than one if needing asynchronous io.
 * @param p_min_proc_count  The new minimum procedure count. You may set
 *                          this count to some value greater than one if
 *                          needing asynchronous io.
 */

  @Override
  public  void  set_min_proc_count  (final int p_min_proc_count)
    {
    if(p_min_proc_count > NetVMUtils.RECEIVE_INTERRUPT)
      {
      super.set_min_proc_count(p_min_proc_count);
      }
    }

/**
 * Obtain the count of virtual machines to be simulated.
 * @return The count of virtual machines to be simulated.
 */

  public  final int get_vm_count()
    {
    return this.m_vm_count;
    }
  
  
/**
 * Set the count of virtual machines to be simulated.
 * @param p_vm_count  The new count of virtual machines to be simulated.
 */

  public  final void set_vm_count(final int p_vm_count)
    {
    if(p_vm_count > 0) this.m_vm_count = p_vm_count;
    }
  
/**
 * Obtain the maximum count of messages a virtual machine may send.
 * @return  The maximum count of messages a virtual machine may send.
 */

  public  final int get_max_message_count ()
    {
    return this.m_max_msgs;
    }
  

/**
 * Set the maximum count of messages a virtual machine may send.
 * @param p_max_msgs  The next maximum count of messages a virtual machine
 *                    may send.
 */

  public  final void set_max_message_count (final int p_max_msgs)
    {
    if(p_max_msgs > 0) this.m_max_msgs = p_max_msgs;
    }
  
/**
 * Obtain the network implementation factory.
 * @return The network implementation factory used to power up the network
 *         simulation.
 */

  public  final INetworkImplFactory get_network_impl_factory  ()
    {
    return this.m_net_factory;
    }
  
/**
 * Set the network implementation factory to be used by contexts derived
 * from this definition.
 * @param p_factory   The network implementation factory to be used by
 *                    contexts derived from this definition.
 */

  public  final void  set_network_impl_factory(
                          final INetworkImplFactory p_factory)
    {
    if(p_factory != null)
      {
      this.m_net_factory = p_factory;
      }
    }
  
/**
 * Assign this virtual machine context to the specified object.
 * @param p_data  The object to assign to.
 */

  @Override
  public  void  assign  (final Object p_data)
    {
    NetVMDefinition l_def;
    NetVMContext    l_ctx;
    
    super.assign(p_data);
    
    if(p_data instanceof NetVMDefinition)
      {
      l_def = ((NetVMDefinition)p_data);
      this.set_network_impl_factory(l_def.get_network_impl_factory());
      this.set_vm_count(l_def.get_vm_count());
      this.set_max_message_count(l_def.get_max_message_count());
      }
    else if(p_data instanceof NetVMContext)
      {
      l_ctx = ((NetVMContext)p_data);
      
      this.set_network_impl_factory(l_ctx.get_network_impl_factory());
      this.set_vm_count(l_ctx.get_vm_count());
      this.set_max_message_count(l_ctx.get_max_message_count());
      }    
    }
  }

File Information:

file name:NetVMDefinition.java
package:org.dgpf.gp.netvm.base
qualified name:org.dgpf.gp.netvm.base.NetVMDefinition.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gp/netvm/base/NetVMDefinition.java
size:6.537 KB (6694 B)
uploaded: 2015-07-22 04:10:56 GMT+0000
last update: 2006-07-19 12:31:48 GMT+0000
last access: 2017-11-18 06:31:53 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-18 06:31:53 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo