@@ -42,12 +42,14 @@ namespace CXXGRAPH
4242 private:
4343 std::map<int , std::shared_ptr<CoordinatedRecord<T>>> record_map;
4444 std::vector<int > machines_load_edges;
45+ std::vector<double > machines_weight_edges;
4546 std::vector<int > machines_load_vertices;
4647 PartitionMap<T> partition_map;
4748 Globals GLOBALS;
4849 int MAX_LOAD;
4950 std::shared_ptr<std::mutex> machines_load_edges_mutex = nullptr ;
5051 std::shared_ptr<std::mutex> machines_load_vertices_mutex = nullptr ;
52+ std::shared_ptr<std::mutex> machines_weight_edges_mutex = nullptr ;
5153 std::shared_ptr<std::mutex> record_map_mutex = nullptr ;
5254 // DatWriter out; //to print the final partition of each edge
5355 public:
@@ -56,10 +58,14 @@ namespace CXXGRAPH
5658
5759 std::shared_ptr<Record<T>> getRecord (int x);
5860 int getMachineLoad (int m);
61+ int getMachineWeight (int m);
5962 int getMachineLoadVertices (int m);
6063 void incrementMachineLoad (int m, const Edge<T> *e);
64+ void incrementMachineWeight (int m, const Edge<T> *e);
6165 int getMinLoad ();
6266 int getMaxLoad ();
67+ int getMachineWithMinWeight ();
68+ int getMachineWithMinWeight (const std::set<int > &partitions);
6369 std::vector<int > getMachines_load ();
6470 int getTotalReplicas ();
6571 int getNumVertices ();
@@ -70,12 +76,22 @@ namespace CXXGRAPH
7076 const PartitionMap<T> &getPartitionMap ();
7177 };
7278 template <typename T>
73- CoordinatedPartitionState<T>::CoordinatedPartitionState(Globals &G) : record_map(), GLOBALS(G), machines_load_edges_mutex(std::make_shared<std::mutex>()), machines_load_vertices_mutex(std::make_shared<std::mutex>()), record_map_mutex(std::make_shared<std::mutex>())
79+ CoordinatedPartitionState<T>::CoordinatedPartitionState(Globals &G)
80+ : record_map(),
81+ GLOBALS (G),
82+ machines_load_edges_mutex(std::make_shared<std::mutex>()),
83+ machines_load_vertices_mutex(std::make_shared<std::mutex>()),
84+ machines_weight_edges_mutex(std::make_shared<std::mutex>()),
85+ record_map_mutex(std::make_shared<std::mutex>())
7486 {
87+ machines_load_edges.reserve (GLOBALS.numberOfPartition );
88+ machines_load_vertices.reserve (GLOBALS.numberOfPartition );
89+ machines_weight_edges.reserve (GLOBALS.numberOfPartition );
7590 for (int i = 0 ; i < GLOBALS.numberOfPartition ; ++i)
7691 {
7792 machines_load_edges.push_back (0 );
7893 machines_load_vertices.push_back (0 );
94+ machines_weight_edges.push_back (0 );
7995 partition_map[i] = std::make_shared<PARTITIONING::Partition<T>>(i);
8096 }
8197 MAX_LOAD = 0 ;
@@ -102,6 +118,13 @@ namespace CXXGRAPH
102118 return machines_load_edges.at (m);
103119 }
104120
121+ template <typename T>
122+ int CoordinatedPartitionState<T>::getMachineWeight(int m)
123+ {
124+ std::lock_guard<std::mutex> lock (*machines_weight_edges_mutex);
125+ return machines_weight_edges.at (m);
126+ }
127+
105128 template <typename T>
106129 int CoordinatedPartitionState<T>::getMachineLoadVertices(int m)
107130 {
@@ -121,6 +144,23 @@ namespace CXXGRAPH
121144 partition_map[m]->addEdge (e);
122145 }
123146 template <typename T>
147+ void CoordinatedPartitionState<T>::incrementMachineWeight(int m, const Edge<T> *e)
148+ {
149+ std::lock_guard<std::mutex> lock (*machines_weight_edges_mutex);
150+ double edge_weight = CXXGRAPH::NEGLIGIBLE_WEIGHT;
151+ if (e->isWeighted ().has_value () && e->isWeighted ().value ())
152+ {
153+ edge_weight = (dynamic_cast <const Weighted *>(e))->getWeight ();
154+ }
155+ machines_weight_edges[m] = machines_weight_edges[m] + edge_weight;
156+ // double new_value = machines_weight_edges[m];
157+ // if (new_value > MAX_LOAD)
158+ // {
159+ // MAX_LOAD = new_value;
160+ // }
161+ partition_map[m]->addEdge (e);
162+ }
163+ template <typename T>
124164 int CoordinatedPartitionState<T>::getMinLoad()
125165 {
126166 std::lock_guard<std::mutex> lock (*machines_load_edges_mutex);
@@ -141,6 +181,44 @@ namespace CXXGRAPH
141181 return MAX_LOAD;
142182 }
143183 template <typename T>
184+ int CoordinatedPartitionState<T>::getMachineWithMinWeight()
185+ {
186+ std::lock_guard<std::mutex> lock (*machines_weight_edges_mutex);
187+
188+ double MIN_LOAD = std::numeric_limits<double >::max ();
189+ int machine_id = 0 ;
190+ for (int i = 0 ; i < machines_weight_edges.size (); ++i)
191+ {
192+ double loadi = machines_weight_edges[i];
193+ if (loadi < MIN_LOAD)
194+ {
195+ MIN_LOAD = loadi;
196+ machine_id = i;
197+ }
198+ }
199+
200+ return machine_id;
201+ }
202+ template <typename T>
203+ int CoordinatedPartitionState<T>::getMachineWithMinWeight(const std::set<int > &partitions)
204+ {
205+ std::lock_guard<std::mutex> lock (*machines_weight_edges_mutex);
206+
207+ double MIN_LOAD = std::numeric_limits<double >::max ();
208+ int machine_id = 0 ;
209+ for (const auto &partition_id : partitions)
210+ {
211+ double loadi = machines_weight_edges.at (partition_id);
212+ if (loadi < MIN_LOAD)
213+ {
214+ MIN_LOAD = loadi;
215+ machine_id = partition_id;
216+ }
217+ }
218+
219+ return machine_id;
220+ }
221+ template <typename T>
144222 std::vector<int > CoordinatedPartitionState<T>::getMachines_load()
145223 {
146224 std::lock_guard<std::mutex> lock (*machines_load_edges_mutex);
0 commit comments