Skip to content

Commit

Permalink
Reformat files
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonChern authored and Mstrutov committed Oct 25, 2023
1 parent 61e80af commit 3206b2a
Show file tree
Hide file tree
Showing 13 changed files with 813 additions and 731 deletions.
3 changes: 1 addition & 2 deletions src/core/algorithms/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@

/* Algebraic constraints*/
#include "algorithms/algebraic_constraints/ac_algorithm.h"

#include "algorithms/gfd/gfd_validation.h"
#include "algorithms/gfd/egfd_validation.h"
#include "algorithms/gfd/gfd_validation.h"
45 changes: 19 additions & 26 deletions src/core/algorithms/gfd/balancer.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "balancer.h"

#include <algorithm>
#include <map>
#include <numeric>
#include <algorithm>
#include <vector>

#include "balancer.h"

std::vector<std::vector<int>>
Balancer::balance(const std::vector<int>& weights, const int& processors_num) {
std::vector<std::vector<int>> Balancer::balance(const std::vector<int>& weights,
const int& processors_num) {
std::size_t m = std::min(processors_num, (int)weights.size());
std::vector<std::vector<int>> result = {};
if (weights.begin() == weights.end()) {
Expand All @@ -18,7 +18,7 @@ Balancer::balance(const std::vector<int>& weights, const int& processors_num) {
}
for (std::size_t i = 0; i < m; ++i) {
// the first value is index
std::vector<int> temp = { static_cast<int>(i) };
std::vector<int> temp = {static_cast<int>(i)};
result.push_back(temp);
}
// fill processors initially
Expand All @@ -45,8 +45,7 @@ Balancer::balance(const std::vector<int>& weights, const int& processors_num) {
if (*(it - 1) > optimal / 2) {
deleted_large.push_back(*it);
border = it;
}
else {
} else {
break;
}
}
Expand All @@ -68,10 +67,8 @@ Balancer::balance(const std::vector<int>& weights, const int& processors_num) {
}
int a = 0;
int b = 0;
float sum_small =
std::accumulate(processor.begin() + 1, last_small, 0, std::plus<int>());
float sum =
std::accumulate(processor.begin() + 1, last, 0, std::plus<int>());
float sum_small = std::accumulate(processor.begin() + 1, last_small, 0, std::plus<int>());
float sum = std::accumulate(processor.begin() + 1, last, 0, std::plus<int>());
while (sum_small > optimal / 2) {
++a;
--last_small;
Expand All @@ -93,8 +90,7 @@ Balancer::balance(const std::vector<int>& weights, const int& processors_num) {
for (const std::vector<int>& processor : result) {
if (*(--processor.end()) > optimal / 2) {
large_processors.push_back(processor);
}
else {
} else {
small_processors.push_back(processor);
}
}
Expand Down Expand Up @@ -132,24 +128,21 @@ Balancer::balance(const std::vector<int>& weights, const int& processors_num) {
for (const int& weight : deleted_large) {
if (i < m - large_processors.size()) {
(result.begin() + i)->push_back(weight);
}
else {
sort(result.begin(), result.end(),
[](std::vector<int> a, std::vector<int> b) {
return std::accumulate(a.begin(), a.end(), 0, std::plus<int>()) <
std::accumulate(b.begin(), b.end(), 0, std::plus<int>());
});
} else {
sort(result.begin(), result.end(), [](std::vector<int> a, std::vector<int> b) {
return std::accumulate(a.begin(), a.end(), 0, std::plus<int>()) <
std::accumulate(b.begin(), b.end(), 0, std::plus<int>());
});
result.begin()->push_back(weight);
}
++i;
}
// 6th step
for (const int& weight : deleted_small) {
sort(result.begin(), result.end(),
[](std::vector<int> a, std::vector<int> b) {
return std::accumulate(a.begin(), a.end(), 0, std::plus<int>()) <
std::accumulate(b.begin(), b.end(), 0, std::plus<int>());
});
sort(result.begin(), result.end(), [](std::vector<int> a, std::vector<int> b) {
return std::accumulate(a.begin(), a.end(), 0, std::plus<int>()) <
std::accumulate(b.begin(), b.end(), 0, std::plus<int>());
});
result.begin()->push_back(weight);
}
// delete indices
Expand Down
4 changes: 2 additions & 2 deletions src/core/algorithms/gfd/balancer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

class Balancer {
public:
static std::vector<std::vector<int>> balance(const std::vector<int>& weights, const int& processors_num);
static std::vector<std::vector<int>> balance(const std::vector<int>& weights,
const int& processors_num);
};

Loading

0 comments on commit 3206b2a

Please sign in to comment.