adding custom topologies, src and test
This commit is contained in:
parent
b30e0a9695
commit
ff5df75297
11 changed files with 547 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ set (TEST_LIST
|
|||
t-smpMI_Homogeneous
|
||||
t-smpMI_Heterogeneous
|
||||
t-smpMI_Wrapper
|
||||
t-smpCustomTopo
|
||||
)
|
||||
|
||||
######################################################################################
|
||||
|
|
@ -39,3 +40,15 @@ execute_process(
|
|||
${CMAKE_CURRENT_SOURCE_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)
|
||||
|
||||
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 <iostream>
|
||||
#include <vector>
|
||||
#include <assert.h>
|
||||
|
||||
using namespace paradiseo::smp;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue