Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gp.automaton.optimizer.Optimizer.java

Here you can find all the information about the file org.dgpf.gp.automaton.optimizer.Optimizer.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-30 10:34:19
 * Original Filename: org.dgpf.automaton.optimizer.Optimizer.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.optimizer;

import org.dgpf.gp.automaton.base.Instruction;
import org.dgpf.gp.automaton.base.Program;
import org.dgpf.gp.automaton.base.ProgramAccessor;
import org.sfc.utils.MultiBuffer;
import org.sfc.utils.Typesafe;

/**
 * An optimizer for programs.
 *
 * @author Thomas Weise
 */

public  final  class Optimizer extends ProgramAccessor
  {
/**
 * The empty program.
 */

  static  final Instruction[]  EMPTY = new Instruction[0];
  
/**
 * The optimizer cannot be instantiated, its purely static.
 */

  private Optimizer ()
    {
    Typesafe.do_not_call();
    }


/**
 * This method optimizes a piece of code by removing all unnecessary
 * instructions and flattening expressions.
 * @param p_source        The source instruction melange to optimize.
 * @param p_buffer        The multi-buffer to be used.
 * @param p_min_mem_size  The minimum memory size required.
 * @return  The optimized program. If the returned value is the same as
 *          <code>p_source</code>, no optimizations could have been
 *          performed.
 */

  public static final Program optimize(final Program       p_source,
                                       final int           p_min_mem_size,
                                       final MultiBuffer   p_buffer)
    {
    Instruction[] l_ins, l_src, l_o;
    
    l_o   = get_code(p_source);
    l_src = l_o;
    L0.optimize(l_src);
    
    do
      {
      l_ins = l_src;
      l_src = L2.optimize(L1.optimize(l_src, p_buffer), p_buffer);
      } while( (l_src.length < l_ins.length) && (l_src.length > 0));
    
    if(l_src != l_o) return new Program(l_src, p_min_mem_size);
    return p_source;
    }
  }

File Information:

file name:Optimizer.java
package:org.dgpf.gp.automaton.optimizer
qualified name:org.dgpf.gp.automaton.optimizer.Optimizer.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gp/automaton/optimizer/Optimizer.java
size:2.770 KB (2837 B)
uploaded: 2015-07-22 04:10:55 GMT+0000
last update: 2006-05-08 13:38:47 GMT+0000
last access: 2017-11-23 05:24:29 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-23 05:24:29 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo