From b3f83717d67ddc6e425eeab80f3239756764d3d0 Mon Sep 17 00:00:00 2001 From: quemy Date: Sat, 24 Nov 2012 15:26:11 +0100 Subject: [PATCH] Add topology to IslandModel, sending messages mecanism, rewrite Bimap container --- smp/src/abstractIsland.h | 11 ++++- smp/src/bimap.h | 44 +++++++++-------- smp/src/island.cpp | 35 +++++++++---- smp/src/island.h | 16 +++--- smp/src/islandModel.cpp | 76 +++++++++++++++++++++++------ smp/src/islandModel.h | 17 ++++++- smp/src/smp.h | 6 +++ smp/src/topology/abstractTopology.h | 4 +- smp/src/topology/topology.h | 5 ++ smp/test/t-smpIsland.cpp | 11 +++-- 10 files changed, 162 insertions(+), 63 deletions(-) diff --git a/smp/src/abstractIsland.h b/smp/src/abstractIsland.h index cab0c85c7..5ffb7927b 100644 --- a/smp/src/abstractIsland.h +++ b/smp/src/abstractIsland.h @@ -79,12 +79,19 @@ public: */ virtual void check(void) = 0; + /** + * Update the island by adding population to send in the imigrants list. + */ + virtual void update(eoPop _data) = 0; + /** * Check if the algorithm is stopped. * @return true if stopped */ - virtual bool isStopped(void) = 0; - + virtual bool isStopped(void) const = 0; + +protected: + std::mutex m; }; } diff --git a/smp/src/bimap.h b/smp/src/bimap.h index 3ab21ec37..4b1adfed6 100644 --- a/smp/src/bimap.h +++ b/smp/src/bimap.h @@ -40,7 +40,7 @@ namespace smp /** Bimap Bidirectional map in order to create a bijection between islands and vertices. -A and B objects are stocked in two std::set, then if you would avoid instances duplications, +A and B objects are stocked in two std::map, then if you would like to avoid instances duplications, template A and B with pointers. **/ @@ -50,43 +50,45 @@ class Bimap public: /** * Add a relation - * @param workersNb the number of workers - * @param args... list of parameters according to the constructor of your algorithm + * @param A right key + * @param B left key */ - void add(A a, B b) + void add(A& a, B& b) { - ASet.insert(a); - BSet.insert(b); - rightAssociation[&a] = &b; - leftAssociation[&b] = &a; + rightAssociation[a] = b; + leftAssociation[b] = a; + + std::cout << "DUMP" << std::endl; + for(auto i : rightAssociation) + std::cout << i.first << "------" << i.second << std::endl; + for(auto i : leftAssociation) + std::cout << i.first << "------" << i.second << std::endl; + std::cout << "END DUMP" << std::endl; } - - B& getRight(A const a) + std::map getRight() const { - return *rightAssociation[&a]; + return rightAssociation; } - A& getLeft(B const b) + std::map getLeft() const { - return *leftAssociation[&b]; + return leftAssociation; } - unsigned size() + unsigned size() const { - return ASet.size(); + return leftAssociation.size(); } - bool empty() + bool empty() const { - return ASet.empty(); + return leftAssociation.empty(); } protected: - std::set ASet; - std::set BSet; - std::map rightAssociation; - std::map leftAssociation; + std::map rightAssociation; + std::map leftAssociation; }; } diff --git a/smp/src/island.cpp b/smp/src/island.cpp index 14b154e74..52b9b74af 100644 --- a/smp/src/island.cpp +++ b/smp/src/island.cpp @@ -66,12 +66,6 @@ void paradiseo::smp::Island::setModel(IslandModel* _model) model = _model; } -template