Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gp.regression.optimizer.O2.java

Here you can find all the information about the file org.dgpf.gp.regression.optimizer.O2.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-08-17 08:46:13
 * Original Filename: org.dgpf.gp.regression.optimizer.O1.java
 * Version          : 1.0.0
 * Last modification: 2006-08-17
 *                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.regression.optimizer;

import org.dgpf.gp.regression.base.Calculation;
import org.dgpf.gp.regression.base.CalculationAccessor;
import org.dgpf.gp.regression.base.Formula;
import org.sfc.utils.Typesafe;

/**
 * This internal optimizer removes unused variables.
 *
 * @author Thomas Weise
 */

final class O2  extends CalculationAccessor
  {
/**
 * Nah, no creating of instances around here.
 */

  private O2()
    {
    Typesafe.do_not_call();
    }
  
  
/**
 * Optimize a calculation.
 * @param p_source    The source calculation.
 * @return  The optimized calculation.
 */

  private static final Calculation internal_optimize(
                                          final Calculation p_source)
    {
    byte[]    l_v1;
    Formula[] l_f1, l_f2;
    double[]  l_d1;
    int       l_i, l_j, l_k, l_m;
    boolean   l_b;
    
    l_v1 = get_variable_types(p_source);
    l_f1 = get_formulas(p_source);
    l_d1 = get_start_values(p_source);
    l_b  = false;
    
//kill all useless formulas
main:
    for(l_i = (l_f1.length-1); l_i >= 0; l_i--)
      {
      l_j = l_f1[l_i].get_variable();
      if( (l_v1[l_j] & (Calculation.OUTPUT_VARIABLE |
                        Calculation.TARGET_VARIABLE)) == 0)
        {
        if((l_v1[l_j] & Calculation.INPUT_VARIABLE) != 0) l_m = 0;
        else                                              l_m = l_i;
                
//        for(l_k = (l_f1.length-1); l_k > l_m; l_k--)
//          {
//          if( (l_f1[l_k].get_variable_usage(l_j) & 1) != 0)
//            {
//            continue main;
//            }
//          }
        for(l_k = ((l_i+1)%l_f1.length); l_k != l_m;
            l_k = ((l_k+1)%l_f1.length))
          {
          if( (l_f1[l_k].get_variable_usage(l_j) & 1) != 0)
            {
            continue main;
            }
          }
        
        l_f2 = new Formula[l_f1.length-1];
        System.arraycopy(l_f1, 0, l_f2, 0, l_i);
        System.arraycopy(l_f1, l_i+1, l_f2, l_i, l_f2.length-l_i);
        l_f1 = l_f2;
        l_b = true;
        }      
      }
    
    return (l_b ? ((l_f1.length > 0) ? new Calculation(l_f1, l_v1, l_d1)
                : null) : p_source);
    }
  
/**
 * Optimize a calculation.
 * @param p_source    The source calculation.
 * @return  The optimized calculation.
 */

  static  final Calculation optimize(final Calculation p_source)
    {
    Calculation l_c1, l_c2;
    
    l_c1 = p_source;
    do
      {
      l_c2 = l_c1;
      l_c1 = internal_optimize(l_c1);
      } while( (l_c1 != l_c2) && (l_c1 != null) );
      
    return l_c1;
    }
  }

File Information:

file name:O2.java
package:org.dgpf.gp.regression.optimizer
qualified name:org.dgpf.gp.regression.optimizer.O2.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gp/regression/optimizer/O2.java
size:3.719 KB (3809 B)
uploaded: 2015-07-22 04:10:56 GMT+0000
last update: 2006-08-17 11:08:49 GMT+0000
last access: 2017-11-21 15:22:32 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-21 15:22:32 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo