20 #ifndef __CXXGRAPH_PARTITIONING_HDRF_H__
21 #define __CXXGRAPH_PARTITIONING_HDRF_H__
25 #include "Partitioning/Utility/Globals.hpp"
26 #include "Edge/Edge.hpp"
27 #include "PartitionStrategy.hpp"
32 namespace PARTITIONING
60 void HDRF<T>::performStep(
const Edge<T> &e, PartitionState<T> &state)
62 int P = GLOBALS.numberOfPartition;
63 double lambda = GLOBALS.param1;
64 double epsilon = GLOBALS.param2;
65 auto nodePair = e.getNodePair();
66 int u = nodePair.first->getId();
67 int v = nodePair.second->getId();
68 std::shared_ptr<Record<T>> u_record = state.getRecord(u);
69 std::shared_ptr<Record<T>> v_record = state.getRecord(v);
72 bool locks_taken =
false;
75 srand((
unsigned)time(NULL));
77 while (!u_record->getLock())
79 std::this_thread::sleep_for(std::chrono::microseconds(usleep_time));
80 usleep_time = (int)pow(usleep_time, 2);
85 while (!v_record->getLock())
87 std::this_thread::sleep_for(std::chrono::microseconds(usleep_time));
88 usleep_time = (int)pow(usleep_time, 2);
90 if (usleep_time > GLOBALS.SLEEP_LIMIT)
92 u_record->releaseLock();
93 performStep(e, state);
104 int MIN_LOAD = state.getMinLoad();
105 int MAX_LOAD = state.getMaxLoad();
108 std::vector<int> candidates;
109 double MAX_SCORE = 0.0;
110 for (
int m = 0; m < P; m++)
113 int degree_u = u_record->getDegree() + 1;
114 int degree_v = v_record->getDegree() + 1;
115 int SUM = degree_u + degree_v;
118 if (u_record->hasReplicaInPartition(m))
124 if (v_record->hasReplicaInPartition(m))
130 int load = state.getMachineLoad(m);
131 double bal = (MAX_LOAD - load);
132 bal /= (epsilon + MAX_LOAD - MIN_LOAD);
137 double SCORE_m = fu + fv + lambda * bal;
140 std::cout <<
"ERRORE: SCORE_m<0" << std::endl;
141 std::cout <<
"fu: " << fu << std::endl;
142 std::cout <<
"fv: " << fv << std::endl;
143 std::cout <<
"lambda: " << lambda << std::endl;
144 std::cout <<
"bal: " << bal << std::endl;
147 if (SCORE_m > MAX_SCORE)
151 candidates.push_back(m);
153 else if (SCORE_m == MAX_SCORE)
155 candidates.push_back(m);
159 if (candidates.empty())
161 std::cout <<
"ERROR: GreedyObjectiveFunction.performStep -> candidates.isEmpty()" << std::endl;
162 std::cout <<
"MAX_SCORE: " << MAX_SCORE << std::endl;
168 unsigned int seed = (
unsigned int)time(NULL);
170 int choice = rand_r(&seed) % candidates.size();
171 machine_id = candidates.at(choice);
174 CoordinatedPartitionState<T> &cord_state =
dynamic_cast<CoordinatedPartitionState<T> &
>(state);
176 if (!u_record->hasReplicaInPartition(machine_id))
178 u_record->addPartition(machine_id);
179 cord_state.incrementMachineLoadVertices(machine_id);
181 if (!v_record->hasReplicaInPartition(machine_id))
183 v_record->addPartition(machine_id);
184 cord_state.incrementMachineLoadVertices(machine_id);
187 catch (
const std::bad_cast &e)
191 if (!u_record->hasReplicaInPartition(machine_id))
193 u_record->addPartition(machine_id);
195 if (!v_record->hasReplicaInPartition(machine_id))
197 v_record->addPartition(machine_id);
202 state.incrementMachineLoad(machine_id, &e);
205 u_record->incrementDegree();
206 v_record->incrementDegree();
209 u_record->releaseLock();
210 v_record->releaseLock();
Definition: Globals.hpp:32
A Vertex Cut Partioning Algorithm ( as described by this paper https://www.fabiopetroni....
Definition: HDRF.hpp:40
Definition: PartitionState.hpp:33
Definition: PartitionStrategy.hpp:34