Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/project-web/dgpf/htdocs/scripts/datetime.php on line 7

Warning: Cannot modify header information - headers already sent by (output started at /home/project-web/dgpf/htdocs/scripts/datetime.php:7) in /home/project-web/dgpf/htdocs/scripts/init.php on line 28

Warning: Cannot modify header information - headers already sent by (output started at /home/project-web/dgpf/htdocs/scripts/datetime.php:7) in /home/project-web/dgpf/htdocs/scripts/init.php on line 29
Distributed Genetic Programming Framework
Logo
Distributed Genetic Programming Framework
print print


Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/project-web/dgpf/htdocs/scripts/datetime.php on line 16

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/project-web/dgpf/htdocs/scripts/datetime.php on line 16

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/project-web/dgpf/htdocs/scripts/datetime.php on line 16

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/project-web/dgpf/htdocs/scripts/datetime.php on line 16

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/project-web/dgpf/htdocs/scripts/datetime.php on line 16

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/project-web/dgpf/htdocs/scripts/datetime.php on line 16

File org.dgpf.gp.regression.base.AggregationContext.java

Here you can find all the information about the file org.dgpf.gp.regression.base.AggregationContext.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-07-24 13:30:16
 * Original Filename: org.dgpf.gp.regression.RegressionContext.java
 * Version          : 1.0.0
 * Last modification: 2006-07-24
 *                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.base;

import org.dgpf.gp.regression.optimizer.Optimizer;
import org.dgpf.gp.regression.optimizer.SenseChecker;
import org.dgpf.gp.regression.search.CalculationCreator;
import org.dgpf.gp.regression.search.CalculationCrossover;
import org.dgpf.gp.regression.search.CalculationMutator;
import org.dgpf.gp.regression.search.MutationInfo;
import org.dgpf.search.api.FitnessFunction;
import org.dgpf.search.api.SearchContext;
import org.sfc.collections.Arrays;
import org.sfc.events.IEventListener;
import org.sfc.math.stochastic.Randomizer;
import org.sfc.utils.Typesafe;

/**
 * This context is able to host and execute formulas.
 *
 * @author Thomas Weise
 */

public class AggregationContext  extends SearchContext<Calculation>
  {
/**
 * The serial version uid.
 */

  private static final long serialVersionUID = 1;
/**
 * The scale modulus.
 */

  private static final int  TRUE_SCALE = 7;
    
/**
 * The simulation modulus.
 */

          static final int  MAX_SIM   = (((TRUE_SCALE*16)+8)*2);
  
  
/**
 * The count of calculators/nodes participating in this aggregation
 * function regression.
 * @see #get_node_count()
 */

  private       int                 m_node_count  ;
/**
 * The nodes (represented by calculators).
 * @see #get_node(int)
 */
 
  private       Calculator[]        m_nodes ;
/**
 * The test sets.
 */

  private       double[][]          m_test_sets;
/**
 * The current test set.
 */

                double[]            m_cur_test_set;
/**
 * The results for the test sets per fitness function.
 */

  private       double[][]          m_results ;
/**
 * The current results.
 */

                double[]            m_cur_res ;
/**
 * The maximum count of variables available.
 * @see #get_max_variables()
 */

  private       int                 m_max_variables ;
/**
 * The maximum count of formulas allowed in one calculation.
 * @see #get_max_formulas()
 */

  private       int                 m_max_formulas ;
/**
 * The set of available expressions which can be used in calculations.
 * @see #get_expression_set()
 */

  private       ExpressionSet       m_expressions ;
/**
 * The count of target variables.
 * @see #get_target_count()
 */

  private       int                 m_target_count  ;
/**
 * The internal mutation info record.
 */

  private final MutationInfo        m_info  ;
  
/**
 * The network implementation factory.
 * @see #get_network_impl_factory()
 */

  private       INetworkImplFactory m_net_factory ;
/**
 * The network implementation.
 */

  private       NetworkImpl         m_net ;
/**
 * The output variables.
 */

  private       int[]               m_out ;
/**
 * The input variables.
 */

  private       int[]               m_in  ;
/**
 * The provided variable copies.
 */

  private       int[]               m_prov  ;
/**
 * The target variables.
 */

                int[]               m_targets  ;
/**
 * The count of variables to be transfered.
 */

  private       int                 m_transfer_cnt  ;
/**
 * The count of copies of the provided variables.
 */

  private       int                 m_prov_cnt  ;
/**
 * The maximum allowed formula depth.
 */

  private       int                 m_max_depth ;
/**
 * The current step.
 */
  
  private       int                 m_cur_step;
  
/**
 * Create a new regression context.
 * @param p_definition  The regression definition to use as blueprint for
 *                      the internally stored data.
 * @param p_events      The event listener to be used to propagate
 *                      error events, if needed.
 */

  public  AggregationContext (final AggregationDefinition p_definition,
                             final IEventListener       p_events) 
    {
    super(p_definition, p_events);    
    
    int l_i, l_j;
    
    if(this.m_expressions == null)
      {
      this.m_expressions = AggregationUtils.DEFAULT_EXPRESSION_SET;
      }
    
    if(this.m_test_sets == null)
      {
      this.setup_testdata();
      }
    
    this.m_info = new MutationInfo();
    
    l_j = 0;
    for(l_i = (this.get_fitness_function_count()-1); l_i >= 0; l_i--)
      {
      if(this.get_fitness_function(l_i) instanceof AggregationFitnessFunction)
        {
        l_j++;
        }
      }
    }
  
/**
 * Set the count of simulations to be performed for every individual
 * (genotype) to determine a stable fitness value.
 * @param p_simulation_count  How many simulations will be needed
 *                            per individual.
 */

  @Override
  public synchronized void  set_simulation_count
                                (final int p_simulation_count)
    {
    int l_sc;
    
    l_sc = this.get_simulation_count();
    super.set_simulation_count(p_simulation_count);
    if(l_sc != this.get_simulation_count())
      {
      this.setup_testdata();
      }
    }
  
/**
 * Setup the internal test data.
 */

  private final void  setup_testdata()
    {
    int                             l_sc, l_nc, l_cc;
    double[][]                      l_d;
    double[][]                      l_res;
    double[]                        l_rr;
    Randomizer                      l_r;
    FitnessFunction<Calculation,?>  l_ff;
    AggregationFitnessFunction      l_af;

    l_sc = this.get_simulation_count();
    if(l_sc <= 0) return;
    l_nc = this.get_node_count();
    if(l_sc <= 0) return;
    l_r  = this.get_randomizer();
    if(l_r == null) return;
        
    l_r.set_fixed_seed();
    
    this.m_test_sets  = l_d   = new double[l_sc][l_nc];
    this.m_results    = l_res = new double[l_sc][this.m_target_count];
    
    for(--l_sc; l_sc >= 0; l_sc--)
      {
      fill(l_d[l_sc], 0, l_nc, l_r, l_sc);

      l_rr      = l_res[l_sc];
      for(l_cc = (this.get_fitness_function_count()-1); l_cc >= 0; l_cc--)
        {
        l_ff = this.get_fitness_function(l_cc);
        if(l_ff instanceof AggregationFitnessFunction)
          {
          l_af = Typesafe.cast(l_ff);
          l_rr[l_af.m_ti] = l_af.m_target.compute(l_d[l_sc], l_nc);
          }
        }
      }

    l_r.reset();
    }

/**
 * Obtain the count of calculators/nodes participating in this aggregation
 * function regression.
 * @return  The count of calculators/nodes participating in this
 *          aggregation function regression.
 */

  public  final int get_node_count()
    {
    return this.m_node_count;
    }
  
/**
 * Set the count of nodes participating in this aggregation function
 * regression.
 * @param p_count The new count of nodes participating in this aggregation
 *                function regression.
 */

  public  final void  set_node_count  (final int p_count)
    {
    Calculator[]  l_c;
    int           l_i, l_j;
    
    if((p_count > 1) && (p_count != this.m_node_count))
      {
      l_c = this.m_nodes;
      
alloc:  {
        if(l_c == null)
          {
          l_c = new Calculator[p_count];
          l_i = 0;
          }
        else if( (l_i=l_c.length) < p_count ) 
          {        
          l_c = new Calculator[p_count << 1];
          System.arraycopy(this.m_nodes, 0, l_c, 0, l_i);
          }
        else break alloc;
        
        this.setup_testdata();
        
        if(this.m_net != null)
          {
          this.m_net.set_features(p_count,
                               ((int)(this.get_steps_per_simulation())));
          }
        
        this.m_nodes = l_c;
        for(l_j = (l_c.length-1); l_j >= l_i; l_j--)
          {
          l_c[l_j] = this.create_calculator();
          }
        }
      
      this.m_node_count = p_count;
      }
    }
  
  
  
/**
 * Generate test values.
 * @param p_d The array of double to fill with values.
 * @param p_c The count of values to fill in.
 * @param p_r The randomizer to be used.
 * @param p_sim The index of the simulation.
 * @param p_start The start index to begin filling at.
 */

  private static  final void   fill  (final double[]   p_d,
                                      final int        p_start,
                                      final int        p_c,
                                      final Randomizer p_r,
                                      final int        p_sim)
    {
          int     l_idx, l_i, l_j;
    final int     l_vert, l_scale;
    final boolean l_sign;
          double  l_max, l_v;
    final double  l_shift, l_m;
    
    l_idx    = (p_sim % MAX_SIM);
    l_vert   = (l_idx & 7);
    l_idx  >>= 3;

    if(l_vert == 3)
      {
      l_i = (p_r.nextInt(p_c/3)+(p_c/3));
      do
        {
        l_j = p_r.nextInt(MAX_SIM);
        } while( (l_i<9) && (((l_j % MAX_SIM) & 3) == 3 ));

      fill(p_d, p_start, l_i, p_r, l_j);
      do
        {
        l_idx = p_r.nextInt(MAX_SIM);
        } while( (l_j == l_idx) || (((p_c-l_i)<9) && (((l_idx % MAX_SIM)&3)==3)));

      fill(p_d, p_start+l_i, p_c-l_i, p_r, l_idx);
      
      }
    else
      {
      l_sign   = ((l_idx & 1) != 0);
      l_idx  >>= 1;
      
      l_scale  = ((l_idx % ((TRUE_SCALE << 1) + 1))-TRUE_SCALE);
         
      l_max    = -1.0d;
      for(l_i = p_start, l_j = p_c; l_j > 0; l_j--, l_i++)
        {
        switch(l_vert)
          {
          case  0: { l_v = ((l_i==p_start)?1:0); break; }
          case  1: { l_v = p_r.nextGaussian();   break; }
          default: { l_v = p_r.nextDouble();     break; }
          }
        l_max = Math.max(l_max, Math.abs(l_v));
        p_d[l_i] = l_v;
        }
      
      l_max   = (Math.abs(p_r.normal(l_max, 2*l_max)) + (2*l_max));
      
      if(l_vert == 2)
        {
        if(l_sign) p_d[p_start] = -1;
        l_shift = 0;
        }
      else
        {
        l_shift = (l_sign ? (-l_max) : l_max);
        }
      l_m     = Math.exp(2.302585d*l_scale);
      
      for(l_i = p_start, l_j = p_c; l_j > 0; l_j--, l_i++)
        {
        p_d[l_i] = ((p_d[l_i] + l_shift) * l_m);
        }
      }        
    }
  
//  private static  final void   fill  (final double[]   p_d,
//                                      final int        p_c,
//                                      final Randomizer p_r,
//                                      final int        p_index)
//    {
//    double  l_shift, l_d;
//    boolean l_sign;
//    int     l_i, l_s;
//
//    l_s     = (p_index % MAX_SCALE);
//    
//    
//    l_sign  = ((l_s & 1) != 0);
//    l_s >>= 1;
//    if(l_s > 0) l_s = (((l_s & 1) == 0) ? (l_s >>> 1) : (-(l_s >>> 1)));
//
//    l_shift = (40.0d*p_r.nextDouble());
//    if(l_sign) l_shift = (-l_shift);
//    
//    for(l_i = (p_c-1); l_i >= 0; l_i--)
//      {
//      if(p_r.nextBoolean())
//        {
//        l_d = (p_r.nextDouble()+l_shift);
//        }
//      else
//        {
//        l_d = (p_r.nextGaussian()+l_shift);
//        }
//      
//      l_d      = ((l_d+l_shift) * Math.exp(p_r.normal(l_s, 1.0d)));
//      p_d[l_i] = l_d;
//      }
//    }
  
/**
 * Assign the internal data of this search data to the data of
 * another one.
 * @param p_data  The simulation data  to assign to.
 */

  @Override
  public void  assign  (final Object p_data)
    {
    AggregationContext     l_rc;
    AggregationDefinition  l_rd;
    
    super.assign(p_data);
    
    if(p_data instanceof AggregationContext)
      {
      l_rc = ((AggregationContext)p_data);
      
      this.set_node_count(l_rc.m_node_count);
      this.set_network_impl_factory(l_rc.m_net_factory);      
      
      this.set_max_formulas(l_rc.m_max_formulas);
      this.set_max_variables(l_rc.m_max_variables);
      this.set_expression_set(l_rc.m_expressions);
      this.m_target_count = l_rc.m_target_count;
      this.m_targets      = new int[l_rc.m_max_variables];//this.m_target_count];
      this.set_max_depth(l_rc.get_max_depth());
      }
    else if(p_data instanceof AggregationDefinition)
      {
      l_rd = ((AggregationDefinition)p_data);
      
      this.set_node_count(l_rd.get_node_count());
      this.set_network_impl_factory(l_rd.get_network_impl_factory());
            
      this.set_max_formulas(l_rd.get_max_formulas());
      this.set_max_variables(l_rd.get_max_variables());
      this.set_expression_set(l_rd.get_expression_set());
      this.m_target_count = l_rd.get_target_count();
      this.m_targets      = new int[l_rd.get_max_variables()];//this.m_target_count];
      this.set_max_depth(l_rd.get_max_depth());
      }    
    }
  
/**
 * Obtain the representation node at the given index.
 * @param p_index The index of the node wanted.
 * @return  The node at the specified index, represented as calculator
 *          object.
 */

  public  final Calculator  get_node  (final int p_index)
    {
    return this.m_nodes[p_index];
    }


/**
 * Obtain the maximum count of variables available.
 * @return The maximum count of variables available.
 */

  public  final int get_max_variables ()
    {
    return this.m_max_variables;
    }
  
/**
 * The maximum count of allowed variables.
 * @param p_max_variables   The new maximum count of allowed variables.
 */

  public  void  set_max_variables (final int p_max_variables)
    {
    int           l_m;
    Calculator[]  l_c;
    
    if(p_max_variables > 0)
      {
      l_m                  = this.m_max_variables;
      this.m_max_variables = p_max_variables;
              
      if(p_max_variables > l_m)
        {
        this.m_out     = new int[p_max_variables];
        this.m_in      = new int[p_max_variables];
        this.m_prov    = new int[p_max_variables];
        l_c = this.m_nodes;
        if(l_c != null)
          {
          for(l_m = (l_c.length-1); l_m >= 0; l_m--)
            {
            l_c[l_m] = this.create_calculator();
            }
          }
        }
      }
    }
  
  
/**
 * Obtain the maximum count of formulas allowed in one calculation.
 * @return  The maximum count of formulas allowed in one calculation.
 */

  public  final int get_max_formulas ()
    {
    return this.m_max_formulas;
    }
  
/**
 * Set the maximum count of formulas allowed in one calculation.
 * @param p_max_formulas  The new maximum count of formulas allowed in one
 *                        calculation.
 */

  public  final void  set_max_formulas  (final int p_max_formulas)
    {
    if(p_max_formulas > 0)
      {
      this.m_max_formulas = p_max_formulas;
      }
    }
  
  
  
  
/**
 * This method is used by <code>create()</code> to obtain new, random
 * instances of the genotype.
 * The new instance returned by this method should be created totally
 * randomly, with all its contents based on the internal random number
 * generator. No postprocessing must be done here, all will be performed
 * in the <code>create()</code>-routine. 
 * @return  The new, random instance of the genotype.
 */

  @Override
  protected Calculation do_create  ()
    {
    return CalculationCreator.create(thisthis.m_info);
    }
  
/**
 * This method is used by <code>mutate()</code> to create a new instance of
 * the genotype by mutating an existing one.
 * The new instance will be created basing on the one passed it. It will
 * not be equal to it though - small changes will randomly be performed.
 * No postprocessing must be done here, all will be performed in the
 * <code>mutate()</code>-routine.
 * 
 * @param p_parent  The parent genotype which should be mutated a bit.
 * @return  <p>
 *          The new, mutated instance of the genotype. Or <code>null</code>,
 *          if no new instance could be created successfully.</p><p>
 *          <i>Warning:</i> This method currently always returns
 *          <code>null</code>, you must override it in order to provide a
 *          proper mutation operator.</p>.
 */

  @Override
  protected Calculation do_mutate  (final Calculation p_parent)
    {
    return CalculationMutator.INSTANCE.mutate(p_parent, thisthis.m_info);
    }
  

/**
 * Create a new individual by merging two other individuals. This method
 * instanciates the genotype by emulating the biological crossover
 * operation.
 * No postprocessing must be done here, all will be performed in the
 * <code>crossover()</code>-routine.
 * 
 * @param p_parent_1    The first parent individual.
 * @param p_parent_2    The second parent individual.
 * 
 * @return  <p>The new genotype instance (individual) which is a
 *          combination of both parents, or <code>null</code>, if no new
 *          instance could be created successfully.</p><p>
 *          <i>Warning:</i> This method currently always returns
 *          <code>null</code>, you must override it in order to provide a
 *          proper crossover operator.</p>.
 */

  @Override
  protected Calculation  do_crossover (final Calculation p_parent_1,
                                       final Calculation p_parent_2)
    {
    return CalculationCrossover.INSTANCE.crossover(p_parent_1, p_parent_2,
                                                   this);
    }
  
  

/**
 * Obtain the set of available expressions which can be used in
 * calculations.
 * @return  The set of available expressions which can be used in
 *          calculations.
 */

  public  final ExpressionSet get_expression_set()
    {
    return this.m_expressions;
    }
  
/**
 * Set the set of available expressions which can be used in
 * calculations.
 * @param p_expressions The new set of available expressions.
 */

  public  final void  set_expression_set(final ExpressionSet p_expressions)
    {
    if((p_expressions != null) && (!(p_expressions.isEmpty())))
      {
      this.m_expressions = p_expressions;
      }
    }
  

/**
 * Obtain the count of target variables.
 * @return The count of target variables.
 */

  public  final int get_target_count()
    {
    return this.m_target_count;
    }
  
/**
 * Create a calculator. You may override this method when providing an
 * extended implementation of the calculators.
 * @return A brent new calculator.
 */

  protected Calculator  create_calculator()
    {
    return new Calculator(this);
    }
  
  
  
/**
 * Check if an individual is ok.
 * @param p_check The individual to be checked.
 * @return  <code>true</code> if and only if the individual is worth being
 *          simulated.
 */

  private final boolean check_individual  (final Calculation p_check)
    {
    int l_i;
    
    l_i = p_check.get_formula_count();
    
    return ( (p_check.get_variable_count() <= this.get_max_variables()) &&
             (p_check.get_depth()          <= this.m_max_depth)         &&
             (l_i                          >= this.get_target_count())  &&
             (l_i                          <= this.m_max_formulas)      &&
             (SenseChecker.makes_sense(p_check, this)));
    }

/**
 * This method is called right before a simulation starts. It allows you
 * to perform some simulation-specific initialization.
 * The simulation-setup of the fitness functions will also be invoked here.
 * @param p_index   The index number of the current simulation. The first
 *                  simulation will have index 0, the second will have
 *                  index 1 and so on.
 * @see #end_simulation(int)
 */

  @Override
  protected final void begin_simulation  (final int p_index)
    {
    Calculator[]  l_c;
    int           l_i, l_j;
    Calculation   l_cc;
    double[]      l_ts;
    int[]         l_p;
    double        l_d;
    Calculator    l_q;
    
    this.m_cur_step = 0;
    
    l_ts = this.m_cur_test_set  = this.m_test_sets[p_index];
           this.m_cur_res       = this.m_results[p_index];
    l_cc  = this.get_current();
    l_c   = this.m_nodes;    
    l_i   = this.m_node_count;
    l_p   = this.m_prov;   
    
    for(--l_i; l_i >= 0; l_i--)
      {
      l_q = l_c[l_i];
      l_q.init(l_cc);
      l_d = l_ts[l_i];
      for(l_j = (this.m_prov_cnt-1); l_j >= 0; l_j--)
        {
        l_q.set_variable(l_p[l_j], l_d);
        }
      }
        
    super.begin_simulation(p_index);
    }
  
/**
 * Perform some simulation steps. This method is used to simulate the
 * current individual.
 * @param p_steps       The count of stepps suggested to run now in a row.
 * @return  <code>true</code> if everything went ok, <code>false</code> if
 *          something failed.
 */

  @Override
  protected final boolean  simulate  (final long p_steps)
    {
    final NetworkImpl                      l_n;
          int                              l_i, l_j, l_k;
    final int                              l_tr, l_nc;
    final Calculator[]                     l_c;
    final int[]                            l_in, l_out;
    
    l_n   = this.m_net;
    l_c   = this.m_nodes;
    l_in  = this.m_in;
    l_out = this.m_out;
    l_tr  = (this.m_transfer_cnt-1);
    l_nc  = (this.m_node_count-1);
    l_j   = this.m_cur_step;
    
    for(l_k = ((int)p_steps); l_k > 0; l_k--)
      {      
      for(l_i = l_tr; l_i >= 0; l_i--)
        {
        l_n.deliver(l_out[l_i], l_in[l_i], l_j++);
        }
      
      for(l_i = l_nc; l_i >= 0; l_i--)
        {
        l_c[l_i].step();        
        }
      }
    
    this.m_cur_step = l_j;
    
    return true;
    }
  
  

/**
 * Obtain the network implementation factory.
 * @return The network implementation factory used to power up the network
 *         simulation.
 */

  public  final INetworkImplFactory get_network_impl_factory  ()
    {
    return this.m_net_factory;
    }
  
/**
 * Set the network implementation factory to be used by contexts derived
 * from this definition.
 * @param p_factory   The network implementation factory to be used by
 *                    contexts derived from this definition.
 */

  public  final void  set_network_impl_factory(
                          final INetworkImplFactory p_factory)
    {
    if(p_factory != null)
      {
      this.m_net_factory = p_factory;
      this.m_net = p_factory.create(this);
      }
    }
  
/**
 * Prepare the context for the given individual. This method is called
 * before any simulation concerning the given individual is done. It
 * provides the context the opportunity to prepare some information or
 * other data. This function also invokes the sanity checking of the
 * fitness functions.
 * @param p_individual  The individual to prepare for.
 * @return  <code>true</code> if everything is ok and we cal begin the
 *          simulations, <code>false/<code> if something is wrong and no
 *          simulations should be performed.
 * @see #get_current()
 * @see #end_individual()
 */

  @Override
  protected final boolean begin_individual(final Calculation p_individual)
    {
    byte[]                          l_b;
    int[]                           l_in, l_out, l_t, l_p;
    int                             l_i, l_j, l_k, l_tt, l_pp;
    
    this.m_transfer_cnt = 0;
    this.m_prov_cnt     = 0;
    l_out               = this.m_out;
    l_in                = this.m_in;
    l_t                 = this.m_targets;
    l_p                 = this.m_prov;
    Arrays.fill(l_out,  -1);
    Arrays.fill(l_in,   -1);
    Arrays.fill(l_t,    -1);
    Arrays.fill(l_p,    -1);
    
    if(super.begin_individual(p_individual))
      {   
      if(!(check_individual(p_individual)))
        {
        return false;
        }
      
      l_b   = p_individual.m_variable_types;
      l_j   = 0;
      l_k   = 0;
      l_tt  = 0;
      l_pp  = 0;
      
      for(l_i = 0; l_i < l_b.length; l_i++)
        {
        if( (l_b[l_i] & Calculation.OUTPUT_VARIABLE) != 0)
          {
          l_out[l_j++] = l_i;
          }
        
        if( (l_b[l_i] & Calculation.INPUT_VARIABLE) != 0)
          {
          l_in[l_k++] = l_i;
          }
        
        if( (l_b[l_i] & Calculation.TARGET_VARIABLE) != 0)
          {
          l_t[l_tt++] = l_i;
          }
        
        if( (l_b[l_i] & Calculation.PROVIDED_VARIABLE) != 0)
          {
          l_p[l_pp++] = l_i;
          }
        }
      
      this.m_transfer_cnt = ((l_k < l_j) ? l_k : l_j);      
      this.m_prov_cnt     = l_pp;
      
      if((this.m_transfer_cnt <= 0) || (this.m_prov_cnt <= 0) ||
         (l_tt < this.m_target_count)) return false;
      
      return true;
      }
    
    return false;
    }
  
  
  
/**
 * Set the count of steps to perform per simulation.
 * @param p_steps_per_simulation  How many steps will be performed
 *                                per simulation.
 */

  @Override
  public     void  set_steps_per_simulation
                                      (final long p_steps_per_simulation)
    {
    int l_s, l_j;
    
    l_s = ((int)(this.get_steps_per_simulation()));
    super.set_steps_per_simulation(Math.min(Integer.MAX_VALUE, 
                                            p_steps_per_simulation));
    
    l_j = ((int)(this.get_steps_per_simulation()));
    if(l_j != l_s)
      {
      if(this.m_net != null) this.m_net.set_features(this.m_node_count, l_j);
      }
    }
  
/**
 * Postprocess a genotype newly created. Whenever the internal creation
 * routines create or derive a new instance of the genotype, it will not
 * be returned directly. Instead, it will be postprocessed first. The post-
 * production may return <code>null</code> if the individual passed in is
 * invalid or should not be investigated any further.
 * @param p_new The newly created or derived individual which now should be
 *              postprocessed.
 * @return  A postprocessed version of <code>p_new</code>, or
 *          <code>null</code>
 */

  @Override
  protected Calculation postprocess (final Calculation p_new)
    {
    Calculation c;
    
    if( (p_new != null) && (this.check_individual(p_new)))
      {      
      c = Optimizer.optimize(p_new, this);
      if((c != null) && ((c == p_new) || this.check_individual(c)))
        {
        return c;
        }
      }
    
    return null;
    }
  

/**
 * Obtain the maximum formula depth.
 * @return The maximum formula depth.
 */

  public  int get_max_depth()
    {
    return this.m_max_depth;
    }
  
/**
 * Set the maximum formula depth.
 * @param p_max_depth The new maximum formula depth.
 */

  public  void  set_max_depth(final int p_max_depth)
    {
    this.m_max_depth = p_max_depth;
    }
  }

File Information:

file name:AggregationContext.java
package:org.dgpf.gp.regression.base
qualified name:org.dgpf.gp.regression.base.AggregationContext.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gp/regression/base/AggregationContext.java
size:27.402 KB (28060 B)
uploaded: 2018-01-07 12:03:34 GMT+0000
last update: 2006-09-11 12:15:45 GMT+0000
last access: 2018-01-07 12:03:34 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
Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/project-web/dgpf/htdocs/scripts/datetime.php on line 16

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/project-web/dgpf/htdocs/scripts/datetime.php on line 16
last modified at 2018-01-07 12:03:34 GMT+0000
Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/project-web/dgpf/htdocs/scripts/datetime.php on line 19

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/project-web/dgpf/htdocs/scripts/datetime.php on line 19
served at 2018-02-19 02:14:38 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo