Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gp.automaton.base.Automaton.java

Here you can find all the information about the file org.dgpf.gp.automaton.base.Automaton.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2005 Thomas Weise
 *
 * E-Mail           : tweise@gmx.de
 * Creation Date    : 2005-12-28 09:37:10
 * Original Filename: org.dgpf.automaton.base.Automaton.java
 * Version          : 2.2.2
 * 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.gp.automaton.base;



/**
 * The automaton where the programs run inside. The automaton defines the
 * virtual hardware executing the genetically evolved programs.
 *
 * @author Thomas Weise
 * @see Program
 */

public class Automaton  extends Program
  {
/**
 * The serial version uid.
 */

  private static  final long              serialVersionUID  = 1;
/**
 * The maximum amount of clock tick an automaton can be in "sleep-state".
 */

  public  static  final int   MAX_SLEEP_TIME  = 100000;

  
/**
 * The internal memory.
 */

  private               int[]             m_memory  ;
/**
 * The count of ticks already elapsed.
 */

  private               int               m_ticks   ;
/**
 * The instruction pointer.
 */

  private               int               m_ip    ;
/**
 * The ticks currently required.
 */

  private               int               m_required_ticks  ;
/**
 * This is set if the method <code>block()</code> was called.
 * @see #block()
 */

  private               boolean           m_blocked ;

  
/**
 * Create a new Automaton.
 * @param p_code  The compiled code to be run on this org.dgpf.automaton.
 */

  public  Automaton  (final Program  p_code)
    {
    super(p_code.m_code,
          p_code.m_complexity,
          p_code.m_memory_size);

    this.m_memory     = new int[this.m_memory_size];
    }


/**
 * This method is called when an instruction or an expression blocks.
 */

  public  final void  block ()
    {
    this.m_blocked = true;
    }

/**
 * Read a value from one memory cell.
 * @param p_address The memory cell's address.
 * @return  The value read from this memory cell.
 */

  public  final int read  (int p_address)
    {
    return this.m_memory[p_address];
    }

/**
 * Store a value into one memory cell.
 * @param p_address The address of the memory cell to write to.
 * @param p_value   The value to store in that memory cell.
 */

  public  final void  write (       int p_address,
                             final  int p_value)
    {
    this.m_memory[p_address] = p_value;
    }


/**
 * Read a value from one memory cell adressed relative by another memory
 * cell.
 * @param p_address The memory cell's address.
 * @return  The value read from this memory cell adressed relative by
 *          another memory cell.
 */

  public  final int read_rel  (int p_address)
    {
    int[] l_m;
    int   l_s;

    l_m = this.m_memory;
    l_s = l_m.length;

    p_address = (l_m[p_address] % l_s);
    if(p_address < 0) p_address += l_s;

    return this.m_memory[p_address];
    }

/**
 * Store a value into one memory cell adressed relative by another memory
 * cell.
 * @param p_address The address of the memory cell to write to.
 * @param p_value   The value to store in that memory cell adressed relative
 *                  by another memory cell.
 */

  public  final void  write_rel (       int p_address,
                                 final  int p_value)
    {
    int[] l_m;
    int   l_s;

    l_m = this.m_memory;
    l_s = l_m.length;

    p_address = (l_m[p_address] % l_s);
    if(p_address < 0) p_address += l_s;

    this.m_memory[p_address] = p_value;
    }



/**
 * Obtain the count of processor ticks ellapsed.
 * @return The count of processor ticks ellapsed.
 */

  public  final int get_ticks ()
    {
    return this.m_ticks;
    }

/**
 * Perform one processor tick.
 */

  public  void  tick  ()
    {
    int           l_ip, l_ncs;
    Instruction[] l_code;
    Instruction   l_instr;

    this.m_ticks++;

    l_ip = this.m_required_ticks;
    if(l_ip > 0)
      {
      this.m_required_ticks = (l_ip-1);
      }
    else
      {
      l_ip                  = this.m_ip;
      l_code                = this.m_code;
      l_instr               = l_code[l_ip];

      this.m_required_ticks = (l_instr.m_ticks-1);
      l_ncs                 = l_instr.execute(this);

      if(this.m_blocked)
        {
        this.m_blocked        = false;
        this.m_required_ticks = 0;
        return;
        }

      if(l_ncs >= 0)
        {
        this.m_ip = l_ncs;
        }
      else
        {
        if( (++l_ip) >= l_code.length ) this.m_ip = 0;
        else                            this.m_ip = l_ip;
        }
      }
    }
  }

File Information:

file name:Automaton.java
package:org.dgpf.gp.automaton.base
qualified name:org.dgpf.gp.automaton.base.Automaton.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gp/automaton/base/Automaton.java
size:5.383 KB (5513 B)
uploaded: 2015-07-22 04:10:55 GMT+0000
last update: 2006-05-28 13:46:36 GMT+0000
last access: 2017-11-18 22:58:41 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-19 04:58:22 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo