Add a builder attribute to the topology and construct method
This commit is contained in:
parent
6159309ab2
commit
631d693bef
8 changed files with 86 additions and 18 deletions
|
|
@ -38,7 +38,7 @@ namespace smp
|
||||||
class AbstractTopology
|
class AbstractTopology
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
virtual std::vector<unsigned> getIdNeighbours(unsigned idIsland) const =0;
|
virtual std::vector<unsigned> getIdNeighbors(unsigned idIsland) const =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <topology/topologyBuilder.h>
|
|
||||||
#include <topology/ring.h>
|
#include <topology/ring.h>
|
||||||
|
|
||||||
void paradiseo::smp::Ring::operator()(unsigned nbIsland, std::vector<std::vector<bool>>& matrix) const
|
void paradiseo::smp::Ring::operator()(unsigned nbIsland, std::vector<std::vector<bool>>& matrix) const
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <topology/topologyBuilder.h>
|
|
||||||
#include <topology/star.h>
|
#include <topology/star.h>
|
||||||
|
|
||||||
void paradiseo::smp::Star::operator()(unsigned nbIsland, std::vector<std::vector<bool>>& matrix) const
|
void paradiseo::smp::Star::operator()(unsigned nbIsland, std::vector<std::vector<bool>>& matrix) const
|
||||||
|
|
|
||||||
|
|
@ -31,17 +31,17 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
template <class TopologyType>
|
template <class TopologyType>
|
||||||
paradiseo::smp::Topology<TopologyType>::Topology(unsigned nbIsland)
|
std::vector<unsigned> paradiseo::smp::Topology<TopologyType>::getIdNeighbors(unsigned idIsland) const
|
||||||
{
|
{
|
||||||
TopologyType builder;
|
std::vector<unsigned> neighbors;
|
||||||
builder(nbIsland, _matrix);
|
|
||||||
}
|
|
||||||
template <class TopologyType>
|
|
||||||
std::vector<unsigned> paradiseo::smp::Topology<TopologyType>::getIdNeighbours(unsigned idIsland) const
|
|
||||||
{
|
|
||||||
std::vector<unsigned> neighbours;
|
|
||||||
for(unsigned j=0; j<_matrix.size();j++)
|
for(unsigned j=0; j<_matrix.size();j++)
|
||||||
if(_matrix[idIsland][j]) neighbours.push_back(j);
|
if(_matrix[idIsland][j]) neighbors.push_back(j);
|
||||||
|
|
||||||
return neighbours;
|
return neighbors;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class TopologyType>
|
||||||
|
void paradiseo::smp::Topology<TopologyType>::construct(unsigned nbIsland)
|
||||||
|
{
|
||||||
|
_builder(nbIsland, _matrix);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,9 @@ class Topology : public AbstractTopology
|
||||||
{
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
Topology(unsigned nbIsland);
|
Topology() = default;
|
||||||
|
std::vector<unsigned> getIdNeighbors(unsigned idIsland) const;
|
||||||
std::vector<unsigned> getIdNeighbours(unsigned idIsland) const;
|
void construct(unsigned nbIsland);
|
||||||
|
|
||||||
private :
|
private :
|
||||||
TopologyType _builder;
|
TopologyType _builder;
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ set (TEST_LIST
|
||||||
t-smpMW_eoEasyPSO
|
t-smpMW_eoEasyPSO
|
||||||
t-smpMW_eoSyncEasyPSO
|
t-smpMW_eoSyncEasyPSO
|
||||||
t-smpIsland
|
t-smpIsland
|
||||||
t-smpTopo)
|
t-smpTopo)
|
||||||
|
|
||||||
######################################################################################
|
######################################################################################
|
||||||
### 3) Create each test
|
### 3) Create each test
|
||||||
|
|
|
||||||
70
smp/test/t-smpTopo.cpp
Normal file
70
smp/test/t-smpTopo.cpp
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
#include <topology/topology.h>
|
||||||
|
#include <topology/complete.h>
|
||||||
|
#include <topology/star.h>
|
||||||
|
#include <topology/ring.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace paradiseo::smp;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
//Test of Complete Topology
|
||||||
|
Topology<Complete> topo_comp;
|
||||||
|
topo_comp.construct(5);
|
||||||
|
|
||||||
|
std::cout << std::endl << "---------------" << std::endl << "Test of Complete Topology" << std::endl;
|
||||||
|
|
||||||
|
std::vector<unsigned> neighbors=topo_comp.getIdNeighbors(1);
|
||||||
|
std::cout << "neighbors of Island 1 : "<<std::endl;
|
||||||
|
for (int i=0; i < neighbors.size(); i++)
|
||||||
|
std::cout << " " << neighbors[i];
|
||||||
|
|
||||||
|
neighbors=topo_comp.getIdNeighbors(2);
|
||||||
|
std::cout <<std::endl << "Neighbors of Island 2 : "<<std::endl;
|
||||||
|
for (int i=0; i < neighbors.size(); i++)
|
||||||
|
std::cout << " " << neighbors[i];
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
//Test of Star Topology
|
||||||
|
Topology<Star> topo_star;
|
||||||
|
topo_star.construct(4);
|
||||||
|
|
||||||
|
std::cout << std::endl << "---------------" << std::endl << "Test of Star Topology" << std::endl;
|
||||||
|
|
||||||
|
neighbors=topo_star.getIdNeighbors(0);
|
||||||
|
std::cout <<std::endl << "Neighbors of Island 0 : "<<std::endl;
|
||||||
|
for (int i=0; i < neighbors.size(); i++)
|
||||||
|
std::cout << " " << neighbors[i];
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
neighbors=topo_star.getIdNeighbors(1);
|
||||||
|
std::cout <<std::endl << "Neighbors of Island 1 : "<<std::endl;
|
||||||
|
for (int i=0; i < neighbors.size(); i++)
|
||||||
|
std::cout << " " << neighbors[i];
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
//Test of Ring Topology
|
||||||
|
Topology<Ring> topo_ring;
|
||||||
|
topo_ring.construct(8);
|
||||||
|
|
||||||
|
std::cout << std::endl << "---------------" << std::endl << "Test of Ring Topology" << std::endl;
|
||||||
|
|
||||||
|
neighbors=topo_ring.getIdNeighbors(4);
|
||||||
|
std::cout <<std::endl << "Neighbors of Island 4 : "<<std::endl;
|
||||||
|
for (int i=0; i < neighbors.size(); i++)
|
||||||
|
std::cout << " " << neighbors[i];
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
neighbors=topo_ring.getIdNeighbors(7);
|
||||||
|
std::cout <<std::endl << "Neighbors of Island 7 : "<<std::endl;
|
||||||
|
for (int i=0; i < neighbors.size(); i++)
|
||||||
|
std::cout << " " << neighbors[i];
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
neighbors=topo_ring.getIdNeighbors(0);
|
||||||
|
std::cout <<std::endl << "Neighbors of Island 0 : "<<std::endl;
|
||||||
|
for (int i=0; i < neighbors.size(); i++)
|
||||||
|
std::cout << " " << neighbors[i];
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue