Logo
Distributed Genetic Programming Framework
print print

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

Here you can find all the information about the file org.dgpf.gp.automaton.base.ProgramAccessor.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 10:59:28
 * Original Filename: org.dgpf.automaton.base.ProgramAccessor.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;


/**
 * This class comes with methods that allow introspection of the code of a
 * program.
 *
 * @author Thomas Weise
 */

public abstract class ProgramAccessor extends Conventions
  {
/**
 * The protected constructor to create a program accessor.
 */

  protected ProgramAccessor()
    {
    super();
    }

/**
 * Returns the code of a program.
 * @param p_program   The program that should be inspected.
 * @return  The instruction array encapsulated by this program.
 */

  protected static final Instruction[] get_code(final Program p_program)
    {
    return p_program.m_code;
    }

/**
 * Calculate the static complexity of a set of instructions.
 * That is the count of cpu ticks that would be consumed if every single
 * sub-statement of the set was executed once.
 * @param p_code  The instruction set to calculate the complexity of.
 * @return The static complexity of this element.
 */

  protected static final int calculate_complexity(final Instruction[] p_code)
    {
    int l_c, l_j;

    l_c = 0;
    for(l_j = (p_code.length-1); l_j >= 0; l_j--)
      {
      l_c += p_code[l_j].get_complexity();
      }

    return l_c;
    }

/**
 * Calculate the memory size of some sets of instructions.
 * That is the count of memory cells needed by that code.
 * @param p_code  The instruction sets to calculate the required memory
 *                size.
 * @return The memory size required by this code.
 */

  protected static final int calculate_memory_size(
                                  final Instruction[] p_code)
    {
    int l_c, l_j;

    l_c = 0;
    for(l_j = (p_code.length-1); l_j >= 0; l_j--)
      {
      l_c = Math.max(l_c, p_code[l_j].get_memory_size());
      }

    return l_c;
    }


/**
 * Checks wether two code programs are equal.
 * @param p_code_1    The first code program.
 * @param p_code_2    The second code program.
 * @return  <code>true</code> if and only if the two code programs are
 *          exactly equivalent.
 */

  protected static  final boolean equals_code (final Instruction[] p_code_1,
                                               final Instruction[] p_code_2)
    {
    int l_i;

    l_i = p_code_1.length;
    if(l_i == p_code_2.length)
      {
      for(--l_i; l_i >= 0; l_i--)
        {
        if(!(p_code_1[l_i].equals(p_code_2[l_i]))) return false;
        }
      
      return true;
      }

    return false; 
    }
  
/**
 * Count the occurences of a specified instruction in the code.
 * @param p_class   The instruction's class.
 * @param p_prog    The program to evaluate.
 * @param <T>       The instruction's type.
 * @return  The count of the occurences of the specified instruction.
 */

  public static final <T extends Instruction> int count_occurences(
                                                    final Class<T> p_class,
                                                    final Program  p_prog)
    {
    Instruction[] l_c;
    int           l_i, l_j;
    
    l_c = p_prog.m_code;
    l_j = 0;
    for(l_i = (l_c.length-1); l_i >= 0; l_i--)
      {
      if(p_class.isAssignableFrom(l_c[l_i].getClass())) l_j++;
      }
    
    return l_j;
    }
  }

File Information:

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