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/hypercubic.cpp
|
||||
topology/mesh.cpp
|
||||
topology/customBooleanTopology.cpp
|
||||
topology/customStochasticTopology.cpp
|
||||
notifier.cpp
|
||||
islandModelWrapper.h
|
||||
)
|
||||
|
|
|
|||
|
|
@ -49,5 +49,8 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
|||
#include <topology/star.h>
|
||||
#include <topology/hypercubic.h>
|
||||
#include <topology/mesh.cpp>
|
||||
#include <topology/customBooleanTopology.h>
|
||||
#include <topology/customBooleanTopology.h>
|
||||
|
||||
|
||||
#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
|
||||
Loading…
Add table
Add a link
Reference in a new issue