adding custom topologies, src and test
This commit is contained in:
parent
b30e0a9695
commit
ff5df75297
11 changed files with 547 additions and 0 deletions
|
|
@ -28,6 +28,8 @@ set (SMP_FILE
|
||||||
topology/ring.cpp
|
topology/ring.cpp
|
||||||
topology/hypercubic.cpp
|
topology/hypercubic.cpp
|
||||||
topology/mesh.cpp
|
topology/mesh.cpp
|
||||||
|
topology/customBooleanTopology.cpp
|
||||||
|
topology/customStochasticTopology.cpp
|
||||||
notifier.cpp
|
notifier.cpp
|
||||||
islandModelWrapper.h
|
islandModelWrapper.h
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -49,5 +49,8 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <topology/star.h>
|
#include <topology/star.h>
|
||||||
#include <topology/hypercubic.h>
|
#include <topology/hypercubic.h>
|
||||||
#include <topology/mesh.cpp>
|
#include <topology/mesh.cpp>
|
||||||
|
#include <topology/customBooleanTopology.h>
|
||||||
|
#include <topology/customBooleanTopology.h>
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
119
smp/src/topology/customBooleanTopology.cpp
Normal file
119
smp/src/topology/customBooleanTopology.cpp
Normal file
|
|
@ -0,0 +1,119 @@
|
||||||
|
/*
|
||||||
|
<customBooleanTopology.cpp>
|
||||||
|
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
|
||||||
|
|
||||||
|
Alexandre Quemy, Thibault Lasnier - INSA Rouen
|
||||||
|
|
||||||
|
This software is governed by the CeCILL license under French law and
|
||||||
|
abiding by the rules of distribution of free software. You can ue,
|
||||||
|
modify and/ or redistribute the software under the terms of the CeCILL
|
||||||
|
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||||
|
"http://www.cecill.info".
|
||||||
|
|
||||||
|
In this respect, the user's attention is drawn to the risks associated
|
||||||
|
with loading, using, modifying and/or developing or reproducing the
|
||||||
|
software by the user in light of its specific status of free software,
|
||||||
|
that may mean that it is complicated to manipulate, and that also
|
||||||
|
therefore means that it is reserved for developers and experienced
|
||||||
|
professionals having in-depth computer knowledge. Users are therefore
|
||||||
|
encouraged to load and test the software's suitability as regards their
|
||||||
|
requirements in conditions enabling the security of their systems and/or
|
||||||
|
data to be ensured and, more generally, to use and operate it in the
|
||||||
|
same conditions as regards security.
|
||||||
|
The fact that you are presently reading this means that you have had
|
||||||
|
knowledge of the CeCILL license and that you accept its terms.
|
||||||
|
|
||||||
|
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <topology/customBooleanTopology.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
paradiseo::smp::CustomBooleanTopology::CustomBooleanTopology(std::string filename)
|
||||||
|
{
|
||||||
|
std :: ifstream f(filename);
|
||||||
|
if (f)
|
||||||
|
{
|
||||||
|
int temp;
|
||||||
|
unsigned size;
|
||||||
|
bool isNeighbor, isFirst = true;
|
||||||
|
std::string line;
|
||||||
|
std::vector<bool> lineVector;
|
||||||
|
|
||||||
|
while(getline(f, line))
|
||||||
|
{
|
||||||
|
lineVector.clear();
|
||||||
|
|
||||||
|
//line contains a line of text from the file
|
||||||
|
std::istringstream tokenizer(line);
|
||||||
|
std::string token;
|
||||||
|
|
||||||
|
while(tokenizer>> temp >> std::skipws)
|
||||||
|
{
|
||||||
|
//white spaces are skipped, and the integer is converted to boolean, to be stored
|
||||||
|
isNeighbor = (bool) temp;
|
||||||
|
lineVector.push_back(isNeighbor);
|
||||||
|
}
|
||||||
|
|
||||||
|
//if this is the first line, we must initiate the variable size
|
||||||
|
if(isFirst)
|
||||||
|
{
|
||||||
|
size = lineVector.size();
|
||||||
|
isFirst=false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//for each vector non empty, if the size is not equal to the others, error
|
||||||
|
if(lineVector.size() != size && !lineVector.empty())
|
||||||
|
throw std::runtime_error("Mistake in the topology, line "+ std::to_string(_matrix.size()+1) );
|
||||||
|
|
||||||
|
if(!lineVector.empty())
|
||||||
|
_matrix.push_back(lineVector);
|
||||||
|
}
|
||||||
|
|
||||||
|
//for each vector, verify if the size is equal to the size of the final matrix
|
||||||
|
for(auto& line : _matrix)
|
||||||
|
if(line.size() != _matrix.size())
|
||||||
|
throw std::runtime_error("Mistake in the topology, matrix is not square" );
|
||||||
|
|
||||||
|
f.close () ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Error occured while reading the topology file " + filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<unsigned> paradiseo::smp::CustomBooleanTopology::getIdNeighbors(unsigned idNode) const
|
||||||
|
{
|
||||||
|
std::vector<unsigned> neighbors;
|
||||||
|
for(unsigned j=0; j<_matrix.size();j++)
|
||||||
|
if(_matrix[idNode][j])
|
||||||
|
neighbors.push_back(j);
|
||||||
|
|
||||||
|
return neighbors;
|
||||||
|
}
|
||||||
|
|
||||||
|
void paradiseo::smp::CustomBooleanTopology::construct(unsigned nbNode)
|
||||||
|
{
|
||||||
|
assert(nbNode==_matrix.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void paradiseo::smp::CustomBooleanTopology::isolateNode(unsigned idNode)
|
||||||
|
{
|
||||||
|
for(int i=0;i<_matrix.size();i++)
|
||||||
|
{
|
||||||
|
//Line of idNode to false : no connection FROM this node
|
||||||
|
_matrix[idNode][i]=false;
|
||||||
|
|
||||||
|
//Column of idNode to false : no connection TO this node
|
||||||
|
_matrix[i][idNode]=false;
|
||||||
|
}
|
||||||
|
}
|
||||||
77
smp/src/topology/customBooleanTopology.h
Normal file
77
smp/src/topology/customBooleanTopology.h
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
<customBooleanTopology.h>
|
||||||
|
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
|
||||||
|
|
||||||
|
Alexandre Quemy, Thibault Lasnier - INSA Rouen
|
||||||
|
|
||||||
|
This software is governed by the CeCILL license under French law and
|
||||||
|
abiding by the rules of distribution of free software. You can ue,
|
||||||
|
modify and/ or redistribute the software under the terms of the CeCILL
|
||||||
|
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||||
|
"http://www.cecill.info".
|
||||||
|
|
||||||
|
In this respect, the user's attention is drawn to the risks associated
|
||||||
|
with loading, using, modifying and/or developing or reproducing the
|
||||||
|
software by the user in light of its specific status of free software,
|
||||||
|
that may mean that it is complicated to manipulate, and that also
|
||||||
|
therefore means that it is reserved for developers and experienced
|
||||||
|
professionals having in-depth computer knowledge. Users are therefore
|
||||||
|
encouraged to load and test the software's suitability as regards their
|
||||||
|
requirements in conditions enabling the security of their systems and/or
|
||||||
|
data to be ensured and, more generally, to use and operate it in the
|
||||||
|
same conditions as regards security.
|
||||||
|
The fact that you are presently reading this means that you have had
|
||||||
|
knowledge of the CeCILL license and that you accept its terms.
|
||||||
|
|
||||||
|
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CUST_BOOL_TOPO_H_
|
||||||
|
#define CUST_BOOL_TOPO_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <topology/abstractTopology.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace paradiseo
|
||||||
|
{
|
||||||
|
namespace smp
|
||||||
|
{
|
||||||
|
|
||||||
|
class CustomBooleanTopology : public AbstractTopology
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
/**
|
||||||
|
*Constructor for a custom topology from a file
|
||||||
|
*@param filename Name of the file, must be in the same directory as the executable
|
||||||
|
*/
|
||||||
|
CustomBooleanTopology(std::string filename);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inherited from AbstractTopology
|
||||||
|
* @see smp::topology::AbstractTopology::getIdNeighbors
|
||||||
|
*/
|
||||||
|
std::vector<unsigned> getIdNeighbors(unsigned idNode) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inherited from AbstractTopology : a custom topology cannot be reconstructed in a different way, so the method throws an error if nbNode doesn't match with the actual number of nodes.
|
||||||
|
* @param nbNode number of nodes for the topology
|
||||||
|
*/
|
||||||
|
void construct(unsigned nbNode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Inherited from AbstractTopology : changes the topology : removes any connection from/to the given node.
|
||||||
|
*@param idNode index of the node to be isolated
|
||||||
|
*/
|
||||||
|
void isolateNode(unsigned idNode);
|
||||||
|
|
||||||
|
private :
|
||||||
|
std::vector<std::vector<bool>> _matrix;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
129
smp/src/topology/customStochasticTopology.cpp
Normal file
129
smp/src/topology/customStochasticTopology.cpp
Normal file
|
|
@ -0,0 +1,129 @@
|
||||||
|
/*
|
||||||
|
<customStochasticTopology.cpp>
|
||||||
|
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
|
||||||
|
|
||||||
|
Alexandre Quemy, Thibault Lasnier - INSA Rouen
|
||||||
|
|
||||||
|
This software is governed by the CeCILL license under French law and
|
||||||
|
abiding by the rules of distribution of free software. You can ue,
|
||||||
|
modify and/ or redistribute the software under the terms of the CeCILL
|
||||||
|
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||||
|
"http://www.cecill.info".
|
||||||
|
|
||||||
|
In this respect, the user's attention is drawn to the risks associated
|
||||||
|
with loading, using, modifying and/or developing or reproducing the
|
||||||
|
software by the user in light of its specific status of free software,
|
||||||
|
that may mean that it is complicated to manipulate, and that also
|
||||||
|
therefore means that it is reserved for developers and experienced
|
||||||
|
professionals having in-depth computer knowledge. Users are therefore
|
||||||
|
encouraged to load and test the software's suitability as regards their
|
||||||
|
requirements in conditions enabling the security of their systems and/or
|
||||||
|
data to be ensured and, more generally, to use and operate it in the
|
||||||
|
same conditions as regards security.
|
||||||
|
The fact that you are presently reading this means that you have had
|
||||||
|
knowledge of the CeCILL license and that you accept its terms.
|
||||||
|
|
||||||
|
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <topology/customStochasticTopology.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string>
|
||||||
|
#include <random>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
paradiseo::smp::CustomStochasticTopology::CustomStochasticTopology(std::string filename)
|
||||||
|
{
|
||||||
|
std :: ifstream f(filename);
|
||||||
|
if (f)
|
||||||
|
{
|
||||||
|
double temp;
|
||||||
|
unsigned size;
|
||||||
|
double isNeighbor, isFirst = true;
|
||||||
|
std::string line;
|
||||||
|
std::vector<double> lineVector;
|
||||||
|
|
||||||
|
while(getline(f, line))
|
||||||
|
{
|
||||||
|
lineVector.clear();
|
||||||
|
|
||||||
|
//line contains a line of text from the file
|
||||||
|
std::istringstream tokenizer(line);
|
||||||
|
std::string token;
|
||||||
|
|
||||||
|
while(tokenizer>> temp >> std::skipws)
|
||||||
|
{
|
||||||
|
//white spaces are skipped, and the integer is converted to boolean, to be stored
|
||||||
|
|
||||||
|
if(temp<0)
|
||||||
|
isNeighbor = 0;
|
||||||
|
else if(temp>1)
|
||||||
|
isNeighbor = 1;
|
||||||
|
else
|
||||||
|
isNeighbor = (double) temp;
|
||||||
|
lineVector.push_back(isNeighbor);
|
||||||
|
}
|
||||||
|
|
||||||
|
//if this is the first line, we must initiate the variable size
|
||||||
|
if(isFirst)
|
||||||
|
{
|
||||||
|
size = lineVector.size();
|
||||||
|
isFirst=false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//for each vector non empty, if the size is not equal to the others, error
|
||||||
|
if(lineVector.size() != size && !lineVector.empty())
|
||||||
|
throw std::runtime_error("Mistake in the topology, line "+ std::to_string(_matrix.size()+1) );
|
||||||
|
|
||||||
|
if(!lineVector.empty())
|
||||||
|
_matrix.push_back(lineVector);
|
||||||
|
}
|
||||||
|
|
||||||
|
//for each vector, verify if the size is equal to the size of the final matrix
|
||||||
|
for(auto& line : _matrix)
|
||||||
|
if(line.size() != _matrix.size())
|
||||||
|
throw std::runtime_error("Mistake in the topology, matrix is not square" );
|
||||||
|
|
||||||
|
f.close () ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Error occured while reading the topology file " + filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<unsigned> paradiseo::smp::CustomStochasticTopology::getIdNeighbors(unsigned idNode) const
|
||||||
|
{
|
||||||
|
std::random_device rd;
|
||||||
|
std::mt19937 gen(rd());
|
||||||
|
std::uniform_real_distribution<> dis(0,1);
|
||||||
|
|
||||||
|
std::vector<unsigned> neighbors;
|
||||||
|
for(unsigned j=0; j<_matrix.size();j++)
|
||||||
|
if(_matrix[idNode][j] > dis(gen))
|
||||||
|
neighbors.push_back(j);
|
||||||
|
return neighbors;
|
||||||
|
}
|
||||||
|
|
||||||
|
void paradiseo::smp::CustomStochasticTopology::construct(unsigned nbNode)
|
||||||
|
{
|
||||||
|
assert(nbNode==_matrix.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void paradiseo::smp::CustomStochasticTopology::isolateNode(unsigned idNode)
|
||||||
|
{
|
||||||
|
for(int i=0;i<_matrix.size();i++)
|
||||||
|
{
|
||||||
|
//Line of idNode to false : no connection FROM this node
|
||||||
|
_matrix[idNode][i]=0;
|
||||||
|
|
||||||
|
//Column of idNode to false : no connection TO this node
|
||||||
|
_matrix[i][idNode]=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
78
smp/src/topology/customStochasticTopology.h
Normal file
78
smp/src/topology/customStochasticTopology.h
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
/*
|
||||||
|
<customStochasticTopology.h>
|
||||||
|
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
|
||||||
|
|
||||||
|
Alexandre Quemy, Thibault Lasnier - INSA Rouen
|
||||||
|
|
||||||
|
This software is governed by the CeCILL license under French law and
|
||||||
|
abiding by the rules of distribution of free software. You can ue,
|
||||||
|
modify and/ or redistribute the software under the terms of the CeCILL
|
||||||
|
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||||
|
"http://www.cecill.info".
|
||||||
|
|
||||||
|
In this respect, the user's attention is drawn to the risks associated
|
||||||
|
with loading, using, modifying and/or developing or reproducing the
|
||||||
|
software by the user in light of its specific status of free software,
|
||||||
|
that may mean that it is complicated to manipulate, and that also
|
||||||
|
therefore means that it is reserved for developers and experienced
|
||||||
|
professionals having in-depth computer knowledge. Users are therefore
|
||||||
|
encouraged to load and test the software's suitability as regards their
|
||||||
|
requirements in conditions enabling the security of their systems and/or
|
||||||
|
data to be ensured and, more generally, to use and operate it in the
|
||||||
|
same conditions as regards security.
|
||||||
|
The fact that you are presently reading this means that you have had
|
||||||
|
knowledge of the CeCILL license and that you accept its terms.
|
||||||
|
|
||||||
|
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CUST_STOCH_TOPO_H_
|
||||||
|
#define CUST_STOCH_TOPO_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <topology/abstractTopology.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace paradiseo
|
||||||
|
{
|
||||||
|
namespace smp
|
||||||
|
{
|
||||||
|
|
||||||
|
class CustomStochasticTopology : public AbstractTopology
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Constructor for a custom topology from a file
|
||||||
|
*@param filename Name of the file, must be in the same directory as the executable
|
||||||
|
*/
|
||||||
|
CustomStochasticTopology(std::string filename);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inherited from AbstractTopology
|
||||||
|
* @see smp::topology::AbstractTopology::getIdNeighbors
|
||||||
|
*/
|
||||||
|
std::vector<unsigned> getIdNeighbors(unsigned idNode) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inherited from AbstractTopology : a custom topology cannot be reconstructed in a different way, so the method throws an error if nbNode doesn't match with the actual number of nodes.
|
||||||
|
* @param nbNode number of nodes for the topology
|
||||||
|
*/
|
||||||
|
void construct(unsigned nbNode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Inherited from AbstractTopology : changes the topology : removes any connection from/to the given node.
|
||||||
|
*@param idNode index of the node to be isolated
|
||||||
|
*/
|
||||||
|
void isolateNode(unsigned idNode);
|
||||||
|
|
||||||
|
private :
|
||||||
|
std::vector<std::vector<double>> _matrix;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -20,6 +20,7 @@ set (TEST_LIST
|
||||||
t-smpMI_Homogeneous
|
t-smpMI_Homogeneous
|
||||||
t-smpMI_Heterogeneous
|
t-smpMI_Heterogeneous
|
||||||
t-smpMI_Wrapper
|
t-smpMI_Wrapper
|
||||||
|
t-smpCustomTopo
|
||||||
)
|
)
|
||||||
|
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
@ -39,3 +40,15 @@ execute_process(
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/t-data.dat
|
${CMAKE_CURRENT_SOURCE_DIR}/t-data.dat
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/t-data.dat)
|
${CMAKE_CURRENT_BINARY_DIR}/t-data.dat)
|
||||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/t-data.dat DESTINATION share${INSTALL_SUB_DIR}/smp/test COMPONENT tests)
|
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/t-data.dat DESTINATION share${INSTALL_SUB_DIR}/smp/test COMPONENT tests)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/data-topo-bool
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/data-topo-bool)
|
||||||
|
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data-topo-bool DESTINATION share${INSTALL_SUB_DIR}/smp/test COMPONENT tests)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/data-topo-stoch
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/data-topo-stoch)
|
||||||
|
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data-topo-stoch DESTINATION share${INSTALL_SUB_DIR}/smp/test COMPONENT tests)
|
||||||
|
|
|
||||||
4
smp/test/data-topo-bool
Normal file
4
smp/test/data-topo-bool
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
0 1 0 0
|
||||||
|
1 0 1 1
|
||||||
|
0 1 0 1
|
||||||
|
1 0 1 0
|
||||||
3
smp/test/data-topo-stoch
Normal file
3
smp/test/data-topo-stoch
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
.25 .5 .75
|
||||||
|
.2 .1 .05
|
||||||
|
.9 .2 .03
|
||||||
118
smp/test/t-smpCustomTopo.cpp
Normal file
118
smp/test/t-smpCustomTopo.cpp
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
#include <topology/customBooleanTopology.h>
|
||||||
|
#include <topology/customStochasticTopology.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
using namespace paradiseo::smp;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
|
||||||
|
std::vector<unsigned> value;
|
||||||
|
|
||||||
|
//TEST OF CUSTOM BOOLEAN TOPOLOGY
|
||||||
|
CustomBooleanTopology topo_bool("data-topo-bool");
|
||||||
|
std::vector<unsigned> neighbors = topo_bool.getIdNeighbors(0);
|
||||||
|
|
||||||
|
value.clear();
|
||||||
|
value.push_back(1);
|
||||||
|
assert(neighbors == value);
|
||||||
|
///////////////////////////////////////////////////////
|
||||||
|
neighbors = topo_bool.getIdNeighbors(1);
|
||||||
|
|
||||||
|
value.clear();
|
||||||
|
value.push_back(0);
|
||||||
|
value.push_back(2);
|
||||||
|
value.push_back(3);
|
||||||
|
assert(neighbors == value);
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
neighbors = topo_bool.getIdNeighbors(2);
|
||||||
|
|
||||||
|
value.clear();
|
||||||
|
value.push_back(1);
|
||||||
|
value.push_back(3);
|
||||||
|
assert(neighbors == value);
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
neighbors = topo_bool.getIdNeighbors(3);
|
||||||
|
|
||||||
|
value.clear();
|
||||||
|
value.push_back(0);
|
||||||
|
value.push_back(2);
|
||||||
|
assert(neighbors == value);
|
||||||
|
|
||||||
|
|
||||||
|
//TEST OF CUSTOM STOCHASTIC TOPOLOGY
|
||||||
|
CustomStochasticTopology topo_stoch("data-topo-stoch");
|
||||||
|
std::vector<std::vector<double>> matrix;
|
||||||
|
matrix.resize(3);
|
||||||
|
for(auto& line : matrix)
|
||||||
|
line.resize(3);
|
||||||
|
|
||||||
|
//Computation of the mean probability
|
||||||
|
int it_nb = 1000;
|
||||||
|
for(int i = 0 ; i < it_nb ; i++)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
|
neighbors = topo_stoch.getIdNeighbors(j);
|
||||||
|
for(auto& node : neighbors)
|
||||||
|
{
|
||||||
|
matrix[j][node]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto& line : matrix)
|
||||||
|
{
|
||||||
|
for(auto& edge : line)
|
||||||
|
edge = edge/it_nb;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Reading the actual matrix
|
||||||
|
std :: ifstream f("data-topo-stoch");
|
||||||
|
std::vector<std::vector<double>> _matrix;
|
||||||
|
if (f)
|
||||||
|
{
|
||||||
|
double temp;
|
||||||
|
unsigned size;
|
||||||
|
double isNeighbor, isFirst = true;
|
||||||
|
std::string line;
|
||||||
|
std::vector<double> lineVector;
|
||||||
|
|
||||||
|
while(getline(f, line))
|
||||||
|
{
|
||||||
|
lineVector.clear();
|
||||||
|
|
||||||
|
//line contains a line of text from the file
|
||||||
|
std::istringstream tokenizer(line);
|
||||||
|
std::string token;
|
||||||
|
|
||||||
|
while(tokenizer>> temp >> std::skipws)
|
||||||
|
{
|
||||||
|
//white spaces are skipped, and the integer is converted to boolean, to be stored
|
||||||
|
|
||||||
|
if(temp<0)
|
||||||
|
isNeighbor = 0;
|
||||||
|
else if(temp>1)
|
||||||
|
isNeighbor = 1;
|
||||||
|
else
|
||||||
|
isNeighbor = (double) temp;
|
||||||
|
lineVector.push_back(isNeighbor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!lineVector.empty())
|
||||||
|
_matrix.push_back(lineVector);
|
||||||
|
}
|
||||||
|
|
||||||
|
f.close () ;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Comparison to the actual matrix : _matrix
|
||||||
|
for(int i = 0; i < matrix.size(); i++)
|
||||||
|
for(int j = 0; j < matrix.size(); j++)
|
||||||
|
assert(std::abs(_matrix[i][j] - matrix[i][j]) < .05);
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include <smp>
|
#include <smp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
using namespace paradiseo::smp;
|
using namespace paradiseo::smp;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue