Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.search.algorithms.sa.p2p.adaption.DefaultP2PSAAdapter.java

Here you can find all the information about the file org.dgpf.search.algorithms.sa.p2p.adaption.DefaultP2PSAAdapter.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-06-05 13:27:42
 * Created by       : Stefan Niemczyk, Marc Kirchhoff
 * Original Filename: org.dgpf.search.algorithms.sa.p2p.adaption.DefaultP2PSAAdationStrategy.java
 * Version          : 1.0.1
 * Last modification: 2006-06-22
 *                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.search.algorithms.sa.p2p.adaption;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import org.dgpf.search.algorithms.sa.adaptation.DefaultSAAdapter;
import org.dgpf.search.algorithms.sa.p2p.P2PSAParameters;
import org.dgpf.search.algorithms.sa.p2p.P2PSAState;
import org.dgpf.search.api.AdaptationStrategy;
import org.dgpf.search.api.SearchState;
import org.dgpf.search.api.p2p.P2PAdaptationStrategy;
import org.dgpf.search.api.p2p.P2PParameters;
import org.dgpf.search.api.p2p.adaptation.DefaultP2PAdapter;
import org.sfc.utils.Typesafe;

/**
 * The default adapter for peer-to-peer extended simulated annealing
 * searches.
 *
 * @author Stefan Niemczyk, Marc Kirchhoff
 */

public class DefaultP2PSAAdapter extends DefaultSAAdapter
{
/**
 * The serial version uid.
 */

  private static final long serialVersionUID            = 1;

  
/**
 * The peer-to-peer adaptation strategy.
 */

  private transient P2PAdaptationStrategy m_p2p_adapt ;

/**
 * Create a new stateful adaptation strategy.
 * @param p_parameters  The search parameter set to be adapted.
 */

  public DefaultP2PSAAdapter(final P2PSAParameters<?> p_parameters)
    {
    super(p_parameters);
    this.m_p2p_adapt = this.create_p2p_adapter(
                              p_parameters.get_p2p_parameters());
    }

/**
 * Create a new stateful adaptation strategy by using another search
 * adaptation strategy as blueprint.
 * @param p_parameters  The search parameter set to be adapted.
 * @param p_strategy    The blueprint to copy the internal data from.
 */

  public  DefaultP2PSAAdapter(final P2PSAParameters<?> p_parameters,
                                   final AdaptationStrategy      p_strategy)
    {
    super(p_parameters, p_strategy);
    this.m_p2p_adapt = this.create_p2p_adapter(
                              p_parameters.get_p2p_parameters());
    }
  
/**
 * The internal routine used to create the adaptation strategy for the
 * peer-to-peer-nodes.
 * @param p_parameters  The parameter set to adapt.
 * @return  The new p2p-adaptation strategy.
 */

  protected P2PAdaptationStrategy create_p2p_adapter(
                              final P2PParameters p_parameters)
    {
    return new DefaultP2PAdapter(p_parameters);
    }

/**
 * Obtain the peer-to-peer adaptation strategy.
 * @return The peer-to-peer adaptation strategy.
 */

  public  final P2PAdaptationStrategy get_p2p_adaptation_strategy ()
    {
    return this.m_p2p_adapt;
    }

/**
 * Set the peer-to-peer adaptation strategy.
 * @param p_strategy The peer-to-peer adaptation strategy to be used.
 */

  public  final void  set_p2p_adaptation_strategy
                        (final P2PAdaptationStrategy p_strategy)
    {
    P2PSAParameters<?> l_g;

    if(p_strategy != null)
      {
      l_g = Typesafe.cast(this.get_parameters());
      l_g.get_p2p_parameters().notify_strategy(p_strategy);
      this.m_p2p_adapt = p_strategy;
      }
    }

/**
 * This method will be called by the search engine whenever it feels like
 * it is time to adapt the current search parameters to the current search
 * state. If you override this method, you must also declare your class
 * as instance of <code>ICloneable</code>.
 * @param p_state The current state of the search.
 * @return  <code>true</code> if and only if the update level should be
 *          resetted, <code>false</code> if everything should continue
 *          normal.
 * @see SearchState#get_update_level()
 */

  @Override
  protected boolean  adapt (final SearchState<?> p_state)
    {
    P2PSAState<?> l_p;

    if(super.adapt(p_state)) return true;

    l_p = Typesafe.cast(p_state);
    return this.m_p2p_adapt.adapt(p_state, l_p.get_p2p_state());
    }

/**
 * This method will be called whenever the search parameters perform a
 * reset, meaning that the search level is set back to 0.
 */

 @Override
  public void  reset ()
    {
    super.reset();
    this.m_p2p_adapt.reset();
    }



/**
 * Stores the <code>SfcEvent</code> into the stream.
 * @param p_s The output stream.
 * @throws  IOException If something io-like went wrong.
 */

  private final void writeObject(final ObjectOutputStream p_s)
        throws IOException
    {
    p_s.defaultWriteObject();
    p_s.writeUnshared(this.m_p2p_adapt);
    }



/**
 * Reconstitute the <code>SfcEvent</code> instance from a stream (that is,
 * deserialize it).
 * @param p_s The input stream.
 * @throws  IOException If something io-like went wrong.
 * @throws  ClassNotFoundException  If a needed class could not be found.
 */

  private final void readObject(final ObjectInputStream p_s)
        throws IOException, ClassNotFoundException
    {
    P2PAdaptationStrategy   l_c;
    P2PSAParameters<?> l_p;

    p_s.defaultReadObject();
    l_c = ((P2PAdaptationStrategy)(p_s.readUnshared()));
    l_p = Typesafe.cast(this.get_parameters());
    l_p.get_p2p_parameters().notify_strategy(l_c);
    this.m_p2p_adapt = l_c;
    }
}

File Information:

file name:DefaultP2PSAAdapter.java
package:org.dgpf.search.algorithms.sa.p2p.adaption
qualified name:org.dgpf.search.algorithms.sa.p2p.adaption.DefaultP2PSAAdapter.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/search/algorithms/sa/p2p/adaption/DefaultP2PSAAdapter.java
size:6.204 KB (6353 B)
uploaded: 2015-07-22 04:10:59 GMT+0000
last update: 2006-06-22 13:16:37 GMT+0000
last access: 2017-11-23 07:15:36 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 07:15:36 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo