Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gp.automaton.instructions.IfJump.java

Here you can find all the information about the file org.dgpf.gp.automaton.instructions.IfJump.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-11-25 14:36:46
 * Original Filename: org.dgpf.automaton.instructions.IfJump.java
 * Version          : 2.2.1
 * Last modification: 2006-05-08
 *                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.instructions;

import org.dgpf.gp.automaton.base.Automaton;
import org.dgpf.gp.automaton.base.Expression;
import org.dgpf.gp.automaton.base.Instruction;
import org.dgpf.gp.automaton.expressions.Constant;
import org.dgpf.gp.automaton.search.InstructionHandler;

/**
 * The conditional jump instruction.
 *
 * @author Thomas Weise
 */

public  final class IfJump extends Instruction
  {
/**
 * The serial version uid.
 */

  private static  final long         serialVersionUID  = 1;
/**
 * The shared singleton handler instance.
 */

  public  static  final InstructionHandler<Instruction>  HANDLER
                                = IfJumpHandler.INSTANCE;

/**
 * The jump condition.
 */

  private               Expression  m_condition       ;
/**
 * The target instruction to jump to.
 */

  private         final int         m_target          ;

/**
 * Create a new absolute jump.
 * @param p_condition The jump condition.
 * @param p_target    The target instruction to jump to.
 */

  public  IfJump(final Expression p_condition,
                 final int        p_target)
    {
    super(1 + p_condition.get_complexity());
    this.m_condition = p_condition;
    this.m_target    = p_target;
    }

/**
 * Initialize an absolute jump.
 * @param p_condition The jump condition.
 */

  final void  init  (final Expression p_condition)
    {
    this.set_ticks(1 + p_condition.get_complexity());
    this.m_condition = p_condition;
    }


/**
 * Obtain the jump condition.
 * @return The jump condition.
 */

  public  final Expression  get_condition ()
    {
    return this.m_condition;
    }


/**
 * Obtain the count of memory cells this item needs.
 * @return  The count of memory cells this item needs.
 */

  @Override
  public  final int   get_memory_size ()
    {
    return this.m_condition.get_memory_size();
    }

/**
 * Obtain the jump target instruction.
 * @return  The jump target instruction.
 */

  public  final int get_target()
    {
    return this.m_target;
    }

/**
 * This method is called when the instruction is executed. It performs the
 * work of the instruction.
 * @param p_automate    The automate it is invoked on.
 * @return  This method must return always <code>-1</code>.
 */

  @Override
  protected final int   execute (final Automaton p_automate)
    {
    if(is_true(this.m_condition.execute(p_automate)))
      {
      return this.m_target;
      }
    return RETURN;
    }


/**
 * Checks wether this object is equal to another object.
 * @param p_object  The object to compare with.
 * @return  <code>true</code> if and only if the two objects are exactly
 *          equal.
 */

  @Override
  public  final boolean equals  (final Object p_object)
    {
    IfJump l_be;

    if(p_object == thisreturn true;

    if(p_object instanceof IfJump)
      {
      l_be = ((IfJump)p_object);
      if(l_be.m_condition.equals(this.m_condition))
        {
        return (this.m_target == this.m_target);
        }
      }

    return false;
    }

/**
 * Store this objects content into a string builder.
 * @param p_sb  The string builder to store stuff into.
 */

  @Override
  public final void  to_string (final StringBuilder p_sb)
    {
    Expression l_c;

    l_c = this.m_condition;

    if(!((l_c instanceof Constant) && (((Constant)l_c).get_value() != 0)))
      {
      p_sb.append("If ");
      this.m_condition.to_string(p_sb);
      p_sb.append(' ');
      }

    p_sb.append(GOTO);
    p_sb.append(this.m_target);
    }


/**
 * Returns the genetic handler of the code construct.
 * @return The genetic handler of the code construct.
 */

  @Override
  public final InstructionHandler<Instruction> get_handler ()
    {
    return HANDLER;
    }
  }

File Information:

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