eoVector_mesg.h

00001 /*
00002 * <eoVector_comm.h>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
00004 * (C) OPAC Team, LIFL, 2002-2008
00005 *
00006 * Sebastien Cahon, Alexandru-Adrian Tantar, Clive Canape
00007 *
00008 * This software is governed by the CeCILL license under French law and
00009 * abiding by the rules of distribution of free software.  You can  use,
00010 * modify and/ or redistribute the software under the terms of the CeCILL
00011 * license as circulated by CEA, CNRS and INRIA at the following URL
00012 * "http://www.cecill.info".
00013 *
00014 * As a counterpart to the access to the source code and  rights to copy,
00015 * modify and redistribute granted by the license, users are provided only
00016 * with a limited warranty  and the software's author,  the holder of the
00017 * economic rights,  and the successive licensors  have only  limited liability.
00018 *
00019 * In this respect, the user's attention is drawn to the risks associated
00020 * with loading,  using,  modifying and/or developing or reproducing the
00021 * software by the user in light of its specific status of free software,
00022 * that may mean  that it is complicated to manipulate,  and  that  also
00023 * therefore means  that it is reserved for developers  and  experienced
00024 * professionals having in-depth computer knowledge. Users are therefore
00025 * encouraged to load and test the software's suitability as regards their
00026 * requirements in conditions enabling the security of their systems and/or
00027 * data to be ensured and,  more generally, to use and operate it in the
00028 * same conditions as regards security.
00029 * The fact that you are presently reading this means that you have had
00030 * knowledge of the CeCILL license and that you accept its terms.
00031 *
00032 * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
00033 * Contact: paradiseo-help@lists.gforge.inria.fr
00034 *
00035 */
00036 
00037 #ifndef __eoVector_mesg_h
00038 #define __eoVector_mesg_h
00039 
00040 #include <eoVector.h>
00041 #include <core/moeoVector.h>
00042 
00043 #include "messaging.h"
00044 
00045 
00046 template <class F, class T> void pack (const eoVector <F, T> & __v)
00047 {
00048 
00049   if (__v.invalid())
00050     {
00051       pack((unsigned)0);
00052     }
00053   else
00054     {
00055       pack((unsigned)1);
00056       pack (__v.fitness ());
00057     }
00058 
00059   unsigned len = __v.size ();
00060   pack (len);
00061   for (unsigned i = 0 ; i < len; i ++)
00062     pack (__v [i]);
00063 }
00064 
00065 template <class F, class T> void unpack (eoVector <F, T> & __v)
00066 {
00067 
00068   unsigned valid;
00069   unpack(valid);
00070 
00071   if (! valid)
00072     {
00073       __v.invalidate();
00074     }
00075   else
00076     {
00077       F fit;
00078       unpack (fit);
00079       __v.fitness (fit);
00080     }
00081 
00082   unsigned len;
00083   unpack (len);
00084   __v.resize (len);
00085   for (unsigned i = 0 ; i < len; i ++)
00086     unpack (__v [i]);
00087 }
00088 
00089 template <class F, class T, class V> void pack (const eoVectorParticle <F, T, V> & __v)
00090 {
00091 
00092   if (__v.invalid())
00093     {
00094       pack((unsigned)0);
00095     }
00096   else
00097     {
00098       pack((unsigned)1);
00099       pack (__v.fitness ());
00100       pack (__v.best());
00101     }
00102 
00103   unsigned len = __v.size ();
00104   pack (len);
00105   for (unsigned i = 0 ; i < len; i ++)
00106     pack (__v [i]);
00107   for (unsigned i = 0 ; i < len; i ++)
00108     pack (__v.bestPositions[i]);
00109   for (unsigned i = 0 ; i < len; i ++)
00110     pack (__v.velocities[i]);
00111 }
00112 
00113 template <class F, class T, class V> void unpack (eoVectorParticle <F, T, V> & __v)
00114 {
00115 
00116   unsigned valid;
00117   unpack(valid);
00118 
00119   if (! valid)
00120     {
00121       __v.invalidate();
00122     }
00123   else
00124     {
00125       F fit;
00126       unpack (fit);
00127       __v.fitness (fit);
00128       unpack(fit);
00129       __v.best(fit);
00130 
00131     }
00132   unsigned len;
00133   unpack (len);
00134   __v.resize (len);
00135   for (unsigned i = 0 ; i < len; i ++)
00136     unpack (__v [i]);
00137   for (unsigned i = 0 ; i < len; i ++)
00138     unpack (__v.bestPositions[i]);
00139   for (unsigned i = 0 ; i < len; i ++)
00140     unpack (__v.velocities[i]);
00141 }
00142 
00143 template <class F, class T, class V, class W> void unpack (moeoVector <F,T,V,W> &_v)
00144 {
00145   unsigned valid;
00146   unpack(valid);
00147   if (! valid)
00148     _v.invalidate();
00149   else
00150     {
00151       T fit;
00152       unpack (fit);
00153       _v.fitness (fit);
00154     }
00155   unpack(valid);
00156   if (! valid)
00157     _v.invalidateDiversity();
00158   else
00159     {
00160       V diver;
00161       unpack(diver);
00162       _v.diversity(diver);
00163     }
00164   unsigned len;
00165   unpack (len);
00166   _v.resize (len);
00167   for (unsigned i = 0 ; i < len; i ++)
00168     unpack (_v [i]);
00169   unpack(valid);
00170   if (! valid)
00171     _v.invalidateObjectiveVector();
00172   else
00173     {
00174       F object;
00175       unpack (len);
00176       object.resize(len);
00177       for (unsigned i = 0 ; i < len; i ++)
00178         unpack (object[i]);
00179       _v.objectiveVector(object);
00180     }
00181 }
00182 
00183 
00184 template <class F, class T, class V, class W> void pack (moeoVector <F,T,V,W> &_v)
00185 {
00186   if (_v.invalid())
00187     pack((unsigned)0);
00188   else
00189     {
00190       pack((unsigned)1);
00191       pack (_v.fitness ());
00192     }
00193   if (_v.invalidDiversity())
00194     pack((unsigned)0);
00195   else
00196     {
00197       pack((unsigned)1);
00198       pack(_v.diversity());
00199     }
00200   unsigned len = _v.size ();
00201   pack (len);
00202   for (unsigned i = 0 ; i < len; i ++)
00203     pack (_v[i]);
00204   if (_v.invalidObjectiveVector())
00205     pack((unsigned)0);
00206   else
00207     {
00208       pack((unsigned)1);
00209       F object;
00210       object=_v.objectiveVector();
00211       len=object.nObjectives();
00212       pack (len);
00213       for (unsigned i = 0 ; i < len; i ++)
00214         pack (object[i]);
00215     }
00216 }
00217 
00218 #endif

Generated on Thu Mar 13 15:55:03 2008 for ParadisEO-PEO-ParallelanddistributedEvolvingObjects by  doxygen 1.4.7