Skip to content

Commit 81fa01c

Browse files
committed
take into account if air conditioner cont is the input
1 parent 0f86f3e commit 81fa01c

6 files changed

Lines changed: 290 additions & 42 deletions

File tree

algorithms/partitioner/build_sb_graph.cpp

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,4 +912,158 @@ SBG::LIB::WeightedSBGraph create_air_conditioners_graph()
912912
return graph;
913913
}
914914

915+
916+
WeightedSBGraph create_air_conditioners_with_controller_graph(int size)
917+
{
918+
int quarter = size / 4;
919+
int start_q = (2 * size) + 13;
920+
int q = size / 4;
921+
922+
Set nodes = SET_FACT.createSet();
923+
924+
// th [label="N1=th {0:999}"]
925+
auto th = Interval(0, 1, size - 1);
926+
nodes.emplaceBack(th);
927+
// ierr [label="N2=ierr{1000:1000}"]
928+
auto ierr = Interval(size, 1, size);
929+
nodes.emplaceBack(ierr);
930+
// ptotal [label="N3=ptotal {1001:1001}"]
931+
auto ptotal = Interval(size + 1, 1, size + 1);
932+
nodes.emplaceBack(ptotal);
933+
// ev_1 [label="N4=ev_1 {1002:1005}"
934+
auto ev_1 = Interval(size + 2, 1, size + 5);
935+
nodes.emplaceBack(ev_1);
936+
// ev_2 [label="N5=ev_2 {1006:1009}"]
937+
auto ev_2 = Interval(size + 6, 1, size + 9);
938+
nodes.emplaceBack(ev_2);
939+
// ev_3 [label="N6=ev_3 {1010:1010}"]
940+
auto ev_3 = Interval(size + 10, 1, size + 10);
941+
nodes.emplaceBack(ev_3);
942+
// ev_4 [label="N7=ev_4 {1011:1011}"]
943+
auto ev_4 = Interval(size + 11, 1, size + 11);
944+
nodes.emplaceBack(ev_4);
945+
// ev_5 [label="N8=ev_5 {1012:1012}"]
946+
auto ev_5 = Interval(size + 12, 1, size + 12);
947+
nodes.emplaceBack(ev_5);
948+
// ev_6 [label="N9=ev_6 {1013:2012}"]
949+
auto ev_6 = Interval(size + 13, 1, (2 * size) + 12);
950+
nodes.emplaceBack(ev_6);
951+
// ev_7 [label="N10=ev_7 {2013:2262}"]
952+
auto ev_7 = Interval(start_q, 1, start_q + quarter - 1);
953+
nodes.emplaceBack(ev_7);
954+
// ev_8 [label="N11=ev_8 {2263:2512}"]
955+
auto ev_8 = Interval(start_q + quarter, 1, start_q + (2 * quarter) - 1);
956+
nodes.emplaceBack(ev_8);
957+
// ev_9 [label="N12=ev_9 {2513:2762}"]
958+
auto ev_9 = Interval(start_q + (2 * quarter), 1, start_q + (3 * quarter) - 1);
959+
nodes.emplaceBack(ev_9);
960+
// ev_10 [label="N13=ev_10 {2763:3012}"]
961+
auto ev_10 = Interval(start_q + (3 * quarter), 1, start_q + (4 * quarter) - 1);
962+
nodes.emplaceBack(ev_10);
963+
964+
// maps
965+
PWMap rhs_maps = PW_FACT.createPWMap();
966+
PWMap lhs_maps = PW_FACT.createPWMap();
967+
968+
// th -> ev_6 [label="<- {3013:4012} -> ", arrowhead="none"]
969+
rhs_maps.emplaceBack(Map(Interval(3 * size + 13, 1, 4 * size + 12), Exp(LExp(1, RATIONAL(-(3 * size + 13), 1)))));
970+
lhs_maps.emplaceBack(Map(Interval(3 * size + 13, 1, 4 * size + 12), Exp(LExp(1, RATIONAL(-(2 * size), 1)))));
971+
972+
// th -> ev_7 [label="<- {4013:4262} -> ", arrowhead="none"]
973+
rhs_maps.emplaceBack(Map(Interval(4 * size + 13, 1, 4 * size + 12 + q), Exp(LExp(1, RATIONAL(-(4 * size + 13), 1)))));
974+
lhs_maps.emplaceBack(Map(Interval(4 * size + 13, 1, 4 * size + 12 + q), Exp(LExp(1, RATIONAL(-(2 * size), 1)))));
975+
976+
// th -> ev_8 [label="<- {4263:4512} -> ", arrowhead="none"]
977+
rhs_maps.emplaceBack(Map(Interval(4 * size + 13 + q, 1, 4 * size + 12 + 2 * q), Exp(LExp(1, RATIONAL(-(4 * size + 13), 1)))));
978+
lhs_maps.emplaceBack(Map(Interval(4 * size + 13 + q, 1, 4 * size + 12 + 2 * q), Exp(LExp(1, RATIONAL(-(2 * size), 1)))));
979+
980+
// th -> ev_9 [label="<- {4513:4762} -> ", arrowhead="none"]
981+
rhs_maps.emplaceBack(Map(Interval(4 * size + 13 + 2 * q, 1, 4 * size + 12 + 3 * q), Exp(LExp(1, RATIONAL(-(4 * size + 13), 1)))));
982+
lhs_maps.emplaceBack(Map(Interval(4 * size + 13 + 2 * q, 1, 4 * size + 12 + 3 * q), Exp(LExp(1, RATIONAL(-(2 * size), 1)))));
983+
984+
// th -> ev_10 [label="<- {4763:5012} -> ", arrowhead="none"]
985+
rhs_maps.emplaceBack(Map(Interval(4 * size + 13 + 3 * q, 1, 5 * size + 12), Exp(LExp(1, RATIONAL(-(4 * size + 13), 1)))));
986+
lhs_maps.emplaceBack(Map(Interval(4 * size + 13 + 3 * q, 1, 5 * size + 12), Exp(LExp(1, RATIONAL(-(2 * size), 1)))));
987+
988+
// ierr -> ev_3 [label="<- {5013:5013} -> ", arrowhead="none"]
989+
rhs_maps.emplaceBack(Map(Interval(5 * size + 13, 1, 5 * size + 13), Exp(LExp(0, size))));
990+
lhs_maps.emplaceBack(Map(Interval(5 * size + 13, 1, 5 * size + 13), Exp(LExp(0, size + 10))));
991+
992+
// ierr -> ev_4 [label="<- {5014:5014} -> ", arrowhead="none"]
993+
rhs_maps.emplaceBack(Map(Interval(5 * size + 14, 1, 5 * size + 14), Exp(LExp(0, size))));
994+
lhs_maps.emplaceBack(Map(Interval(5 * size + 14, 1, 5 * size + 14), Exp(LExp(0, size + 11))));
995+
996+
// ierr -> ev_5 [label="<- {5015:5015} -> ", arrowhead="none"]
997+
rhs_maps.emplaceBack(Map(Interval(5 * size + 15, 1, 5 * size + 15), Exp(LExp(0, size))));
998+
lhs_maps.emplaceBack(Map(Interval(5 * size + 15, 1, 5 * size + 15), Exp(LExp(0, size + 12))));
999+
1000+
// ptotal -> ev_1 [label="1001 <- {5016:5019} -> ", arrowhead="none"]
1001+
rhs_maps.emplaceBack(Map(Interval(5 * size + 16, 1, 5 * size + 19), Exp(LExp(0, size + 1))));
1002+
lhs_maps.emplaceBack(Map(Interval(5 * size + 16, 1, 5 * size + 19), Exp(LExp(1, RATIONAL(-(4 * size + 14), 1)))));
1003+
1004+
// ptotal -> ev_2 [label="1001 <- {5020:5023} -> ", arrowhead="none"]
1005+
rhs_maps.emplaceBack(Map(Interval(5 * size + 20, 1, 5 * size + 23), Exp(LExp(0, size + 1))));
1006+
lhs_maps.emplaceBack(Map(Interval(5 * size + 20, 1, 5 * size + 23), Exp(LExp(1, RATIONAL(-(4 * size + 14), 1)))));
1007+
1008+
// ptotal -> ev_5 [label="1001 <- {5024:5024} -> 1012", arrowhead="none"]
1009+
rhs_maps.emplaceBack(Map(Interval(5 * size + 24, 1, 5 * size + 24), Exp(LExp(0, size + 1))));
1010+
lhs_maps.emplaceBack(Map(Interval(5 * size + 24, 1, 5 * size + 24), Exp(LExp(1, RATIONAL(-(4 * size + 12), 1)))));
1011+
1012+
// ev_1 -> ev_2 [label=" <- {5025:5028} -> ", arrowhead="none"]
1013+
rhs_maps.emplaceBack(Map(Interval(5 * size + 25, 1, 5 * size + 28), Exp(LExp(1, RATIONAL(-(4 * size + 23), 1)))));
1014+
lhs_maps.emplaceBack(Map(Interval(5 * size + 25, 1, 5 * size + 28), Exp(LExp(1, RATIONAL(-(4 * size + 19), 1)))));
1015+
1016+
// ev_1 -> ev_7 [label="1002 <- {5029:5278} -> ", arrowhead="none"]
1017+
rhs_maps.emplaceBack(Map(Interval(5 * size + 29, 1, 5 * size + 28 + q), Exp(LExp(0, size + 2))));
1018+
lhs_maps.emplaceBack(Map(Interval(5 * size + 29, 1, 5 * size + 28 + q), Exp(LExp(1, RATIONAL(-(3 * size + 16), 1)))));
1019+
1020+
// ev_1 -> ev_8 [label="1003 <- {5279:5528} -> ", arrowhead="none"]
1021+
rhs_maps.emplaceBack(Map(Interval(5 * size + 29 + q, 1, 5 * size + 28 + 2 * q), Exp(LExp(0, size + 3))));
1022+
lhs_maps.emplaceBack(Map(Interval(5 * size + 29 + q, 1, 5 * size + 28 + 2 * q), Exp(LExp(1, RATIONAL(-(3 * size + 16), 1)))));
1023+
1024+
// ev_1 -> ev_9 [label="1004 <- {5529:5778} -> ", arrowhead="none"]
1025+
rhs_maps.emplaceBack(Map(Interval(5 * size + 29 + 2 * q, 1, 5 * size + 28 + 3 * q), Exp(LExp(0, size + 4))));
1026+
lhs_maps.emplaceBack(Map(Interval(5 * size + 29 + 2 * q, 1, 5 * size + 28 + 3 * q), Exp(LExp(1, RATIONAL(-(3 * size + 16), 1)))));
1027+
1028+
// ev_1 -> ev_10 [label="1005 <- {5779:6028} -> ", arrowhead="none"]
1029+
rhs_maps.emplaceBack(Map(Interval(5 * size + 29 + 3 * q, 1, 6 * size + 28), Exp(LExp(0, size + 5))));
1030+
lhs_maps.emplaceBack(Map(Interval(5 * size + 29 + 3 * q, 1, 6 * size + 28), Exp(LExp(1, RATIONAL(-(3 * size + 16), 1)))));
1031+
1032+
// ev_3 -> ev_5 [label="1010 <- {6029:6029} -> 1012", arrowhead="none"]
1033+
rhs_maps.emplaceBack(Map(Interval(6 * size + 29, 1, 6 * size + 29), Exp(LExp(0, size + 10))));
1034+
lhs_maps.emplaceBack(Map(Interval(6 * size + 29, 1, 6 * size + 29), Exp(LExp(0, size + 12))));
1035+
1036+
// ev_4 -> ev_5 [label="1011 <- {6030:6030} -> 1012", arrowhead="none"]
1037+
rhs_maps.emplaceBack(Map(Interval(6 * size + 30, 1, 6 * size + 30), Exp(LExp(0, size + 11))));
1038+
lhs_maps.emplaceBack(Map(Interval(6 * size + 30, 1, 6 * size + 30), Exp(LExp(0, size + 12))));
1039+
1040+
// ev_5 -> ev_7 [label="1012 <- {6031:6280} -> ", arrowhead="none"]
1041+
rhs_maps.emplaceBack(Map(Interval(6 * size + 31, 1, 6 * size + 30 + q), Exp(LExp(0, size + 12))));
1042+
lhs_maps.emplaceBack(Map(Interval(6 * size + 31, 1, 6 * size + 30 + q), Exp(LExp(1, RATIONAL(-(4 * size + 18), 1)))));
1043+
1044+
// ev_5 -> ev_8 [label="1012 <- {6281:6530} -> ", arrowhead="none"]
1045+
rhs_maps.emplaceBack(Map(Interval(6 * size + 31 + q, 1, 6 * size + 30 + 2 * q), Exp(LExp(0, size + 12))));
1046+
lhs_maps.emplaceBack(Map(Interval(6 * size + 31 + q, 1, 6 * size + 30 + 2 * q), Exp(LExp(1, RATIONAL(-(4 * size + 18), 1)))));
1047+
1048+
// ev_5 -> ev_9 [label="1012 <- {6531:6780} -> ", arrowhead="none"]
1049+
rhs_maps.emplaceBack(Map(Interval(6 * size + 31 + 2 * q, 1, 6 * size + 30 + 3 * q), Exp(LExp(0, size + 12))));
1050+
lhs_maps.emplaceBack(Map(Interval(6 * size + 31 + 2 * q, 1, 6 * size + 30 + 3 * q), Exp(LExp(1, RATIONAL(-(4 * size + 18), 1)))));
1051+
1052+
// ev_5 -> ev_10 [label="1012 <- {6781:7030} -> ", arrowhead="none"]
1053+
rhs_maps.emplaceBack(Map(Interval(6 * size + 31 + 3 * q, 1, 7 * size + 30), Exp(LExp(0, size + 12))));
1054+
lhs_maps.emplaceBack(Map(Interval(6 * size + 31 + 3 * q, 1, 7 * size + 30), Exp(LExp(1, RATIONAL(-(4 * size + 18), 1)))));
1055+
1056+
auto vmap = PW_FACT.createPWMap();
1057+
auto vsap = PW_FACT.createPWMap();
1058+
auto emap = PW_FACT.createPWMap();
1059+
1060+
// Now, let's build a graph!
1061+
SBG::LIB::WeightedSBGraph graph(nodes, vmap, lhs_maps, rhs_maps, emap, vsap); // This will be our graph
1062+
1063+
cout << graph << endl;
1064+
1065+
return graph;
1066+
1067+
}
1068+
9151069
} // namespace sbg_partitioner

algorithms/partitioner/build_sb_graph.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ void flatten_set(SBG::LIB::Set &set, const SBG::LIB::WeightedSBGraph& graph);
8585
SBG::LIB::WeightedSBGraph create_air_conditioners_graph();
8686

8787

88+
SBG::LIB::WeightedSBGraph create_air_conditioners_with_controller_graph(int size);
89+
90+
8891
/// It returns the edge cost or node weight of the input set. It looks for a key in cost that intersects
8992
/// the input set, and returns its value. If no key intersects the input set, it will return 1.
9093
/// @param set input set we want to know the cost or weight/

algorithms/partitioner/main.cpp

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -187,32 +187,58 @@ void read_directory(const std::string& name, std::vector<std::string>& v)
187187
std::transform(start, end, std::back_inserter(v), path_leaf_string);
188188
}
189189

190+
int get_air_conditioners_controller_size(const string& name)
191+
{
192+
size_t last_underscore = name.find_last_of('_');
193+
size_t last_dot = name.find_last_of('.');
194+
195+
if (last_underscore != std::string::npos && last_dot != std::string::npos) {
196+
// Extract the string between '_' and '.'
197+
std::string size_str = name.substr(last_underscore + 1, last_dot - last_underscore - 1);
198+
int size = std::stoi(size_str);
199+
return size;
200+
}
201+
202+
cerr << "the file does not have the expected format" << std::endl;
203+
throw 1;
204+
}
205+
190206
tuple<unique_ptr<SBG::LIB::WeightedSBGraph>, PartitionMap, double, double> partitionate_traditional(const PartitionerParams& params)
191207
{
192208
auto start_build_graph = chrono::high_resolution_clock::now();
193-
auto sb_graph = build_sb_graph(params.filename->c_str());
194-
auto end_build_graph = chrono::high_resolution_clock::now();
195-
auto time_to_build_graph = chrono::duration<double, std::milli>(end_build_graph - start_build_graph).count();
209+
unique_ptr<SBG::LIB::WeightedSBGraph> sb_graph_ptr;
210+
auto filename = *params.filename;
211+
double time_to_build_graph = 0.;
212+
if (filename.find("air_conditioners_cont") != std::string::npos) {
213+
auto size = get_air_conditioners_controller_size(filename);
214+
auto sb_graph = create_air_conditioners_with_controller_graph(size);
215+
auto end_build_graph = chrono::high_resolution_clock::now();
216+
auto time_to_build_graph = chrono::duration<double, std::milli>(end_build_graph - start_build_graph).count();
217+
sb_graph_ptr = make_unique<SBG::LIB::WeightedSBGraph>(move(sb_graph));
218+
} else {
219+
auto sb_graph = build_sb_graph(filename, false);
220+
sb_graph_ptr = make_unique<SBG::LIB::WeightedSBGraph>(move(sb_graph));
221+
}
196222

197-
cout << "sb_graph: " << sb_graph << endl;
223+
cout << "sb_graph: " << *sb_graph_ptr << endl;
198224
cout << "connections:\n";
199-
for (auto it1 = sb_graph.map1().begin(), it2 = sb_graph.map2().begin(); it1 != sb_graph.map1().end() and it2 != sb_graph.map2().end(); ++it1, ++it2) {
225+
for (auto it1 = sb_graph_ptr->map1().begin(), it2 = sb_graph_ptr->map2().begin(); it1 != sb_graph_ptr->map1().end() and it2 != sb_graph_ptr->map2().end(); ++it1, ++it2) {
200226
auto n1 = (*it1).image();
201227
auto n2 = (*it2).image();
202228
cout << n1 << ", " << n2 << "\n";
203229
}
204230
cout << endl;
205231

206232
auto start_partitionate = chrono::high_resolution_clock::now();
207-
auto partitions = PartitionMap();
208-
// best_initial_partition(sb_graph, *params.number_of_partitions, params.initial_partition_strategy, params.enable_multithreading);
209-
// cout << "chosen partition " << partitions << endl;
233+
auto partitions =
234+
best_initial_partition(*sb_graph_ptr, *params.number_of_partitions, params.initial_partition_strategy, params.enable_multithreading);
235+
cout << "chosen partition " << partitions << endl;
210236

211-
// kl_sbg_imbalance_partitioner(sb_graph, partitions, params.epsilon, params.enable_multithreading);
237+
kl_sbg_imbalance_partitioner(*sb_graph_ptr, partitions, params.epsilon, params.enable_multithreading);
212238
auto end_partitionate = chrono::high_resolution_clock::now();
213239
auto time_to_partitionate = chrono::duration<double, std::milli>(end_partitionate - start_partitionate).count();
214240

215-
return {make_unique<SBG::LIB::WeightedSBGraph>(move(sb_graph)), partitions, time_to_build_graph, time_to_partitionate};
241+
return {move(sb_graph_ptr), partitions, time_to_build_graph, time_to_partitionate};
216242
}
217243

218244
tuple<unique_ptr<SBG::LIB::WeightedSBGraph>, PartitionMap, double, double> partitionate_using_adjacency_matrix(
@@ -329,7 +355,7 @@ int main(int argc, char** argv)
329355
optind = 0;
330356
while (true) {
331357
int option_index = 0;
332-
opt = getopt_long(argc, argv, "c:f:p:e:o:g:d:i:tmvh:", long_options, &option_index);
358+
opt = getopt_long(argc, argv, "c:f:p:e:o:g:d:i:ktmvh:", long_options, &option_index);
333359
if (opt == EOF) break;
334360

335361
switch (opt) {
@@ -443,14 +469,14 @@ int main(int argc, char** argv)
443469
if (params.compute_metrics) {
444470
map<string, metrics::communication_metrics> metrics;
445471

446-
// int edge_cut = metrics::edge_cut(partitions, *sb_graph);
472+
int edge_cut = metrics::edge_cut(partitions, *sb_graph);
447473

448-
// auto [comm_volume, max_comm_volume] = metrics::communication_volume(partitions, *sb_graph);
474+
auto [comm_volume, max_comm_volume] = metrics::communication_volume(partitions, *sb_graph);
449475

450-
// auto max_imb = metrics::maximum_imbalance(partitions, *sb_graph);
476+
auto max_imb = metrics::maximum_imbalance(partitions, *sb_graph);
451477

452-
// metrics::communication_metrics comm_metrics = metrics::communication_metrics{edge_cut, comm_volume, max_comm_volume, max_imb};
453-
// metrics["sbg-partitioner"] = comm_metrics;
478+
metrics::communication_metrics comm_metrics = metrics::communication_metrics{edge_cut, comm_volume, max_comm_volume, max_imb};
479+
metrics["sbg-partitioner"] = comm_metrics;
454480

455481
if (params.compute_metrics and params.directory) {
456482
std::vector<std::string> dir_files;
@@ -467,17 +493,19 @@ int main(int argc, char** argv)
467493

468494
int edge_cut = metrics::edge_cut(partition_from_file, *sb_graph);
469495

470-
// auto [comm_volume, max_comm_volume] = metrics::communication_volume(partition_from_file, *sb_graph);
496+
auto [comm_volume, max_comm_volume] = metrics::communication_volume(partition_from_file, *sb_graph);
471497

472-
// auto max_imb = metrics::maximum_imbalance(partition_from_file, *sb_graph);
498+
auto max_imb = metrics::maximum_imbalance(partition_from_file, *sb_graph);
473499

474-
metrics::communication_metrics comm_metrics = metrics::communication_metrics{edge_cut, 0, 0, 0};
500+
metrics::communication_metrics comm_metrics = metrics::communication_metrics{edge_cut, comm_volume, max_comm_volume, };
475501
metrics[std::filesystem::path(f).filename().string()] = comm_metrics;
476502
}
477503
}
478504

505+
ofstream metrics_file(*params.directory + "/metrics.csv");
479506
for (const auto& [f, m] : metrics) {
480507
cout << f << ": " << m << endl;
508+
metrics_file << f << ", " << m << endl;
481509
}
482510
}
483511

0 commit comments

Comments
 (0)