Skip to content

Commit

Permalink
Update .clang-format and apply to ConstLoadEstimator
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-watkins committed Apr 19, 2018
1 parent d486186 commit ad1af08
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ IndentWidth: 4
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: DontAlign
AlignOperands: true
Expand Down
83 changes: 43 additions & 40 deletions support/src/ConstLoadEstimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@

#include <random>

#include "ThreadSafeLog.h"
#include "ConstLoadEstimator.h"
#include "ThreadSafeLog.h"

namespace PCOE {
const std::string ConstLoadEstimator::LOADING_KEY = "LoadEstimator.loading";
const std::string ConstLoadEstimator::STDDEV_KEY = "LoadEstimator.noise_sigma";

const std::string DEBUG_TAG = "Const Load Estimator";
static Log & log = Log::Instance();

static Log& log = Log::Instance();

LoadEstimate generateNoise(LoadEstimate noiseStddev) {
static std::random_device rDevice;
static std::mt19937 generator(rDevice());
Expand All @@ -44,37 +44,41 @@ namespace PCOE {
}
return estimate;
}
ConstLoadEstimator::ConstLoadEstimator(GSAPConfigMap & configMap) {

ConstLoadEstimator::ConstLoadEstimator(GSAPConfigMap& configMap) {
log.WriteLine(LOG_INFO, DEBUG_TAG, "Configuring");
configMap.checkRequiredParams({LOADING_KEY});
std::vector<std::string> & profileStrs = configMap[LOADING_KEY];
for (auto && profileStr : profileStrs) {
std::vector<std::string>& profileStrs = configMap[LOADING_KEY];
for (auto&& profileStr : profileStrs) {
double profileItem = std::stod(profileStr);
raw_profile.push_back(profileItem);
}

if (configMap.includes(STDDEV_KEY)) {
log.WriteLine(LOG_INFO, DEBUG_TAG, "Inferred uncertainty type: gaussian");
std::vector<std::string> & stdStrs = configMap[STDDEV_KEY];
for (auto && stdStr : stdStrs) {
std::vector<std::string>& stdStrs = configMap[STDDEV_KEY];
for (auto&& stdStr : stdStrs) {
stddev.push_back(std::stod(stdStr));
}

if (stddev.size() != raw_profile.size()) {
log.FormatLine(LOG_ERROR, DEBUG_TAG, "Loading (%s) must be same size as stddev (%s), ignoring stddev and treating as constant load");
} else {
log.FormatLine(LOG_ERROR,
DEBUG_TAG,
"Loading (%s) must be same size as stddev (%s), ignoring stddev and "
"treating as constant load");
}
else {
uncertaintyMode = GAUSSIAN;
}
}

log.WriteLine(LOG_TRACE, DEBUG_TAG, "Completed configuration");
}

void ConstLoadEstimator::setNSamples(const unsigned int nSamples) {
if (GAUSSIAN == uncertaintyMode) {
profiles.resize(nSamples);
for (auto && profileSample : profiles) {
for (auto&& profileSample : profiles) {
auto noiseSample = generateNoise(stddev);
profileSample.resize(noiseSample.size());
for (size_t i = 0; i < noiseSample.size(); i++) {
Expand All @@ -83,38 +87,37 @@ namespace PCOE {
}
}
}

ConstLoadEstimator::UType ConstLoadEstimator::getUncertaintyMode() {
return uncertaintyMode;
}

LoadEstimate ConstLoadEstimator::estimateLoad(const double, const unsigned int sample) {
log.WriteLine(LOG_TRACE, DEBUG_TAG, "Sampling...");
LoadEstimate profileEstimate = raw_profile;

switch (uncertaintyMode) {
case NONE:
break;
case GAUSSIAN:
log.WriteLine(LOG_TRACE, DEBUG_TAG, "Adding Noise");
if (sample >= profiles.size()) {
auto counter = profiles.size();
profiles.resize(sample+1);
for (; counter < profiles.size(); counter++) {
auto noiseSample = generateNoise(stddev);
profiles[counter].resize(noiseSample.size());
for (size_t i = 0; i < noiseSample.size(); i++) {
profiles[counter][i] = profileEstimate[i] + noiseSample[i];
}
case NONE:
break;
case GAUSSIAN:
log.WriteLine(LOG_TRACE, DEBUG_TAG, "Adding Noise");
if (sample >= profiles.size()) {
auto counter = profiles.size();
profiles.resize(sample + 1);
for (; counter < profiles.size(); counter++) {
auto noiseSample = generateNoise(stddev);
profiles[counter].resize(noiseSample.size());
for (size_t i = 0; i < noiseSample.size(); i++) {
profiles[counter][i] = profileEstimate[i] + noiseSample[i];
}
}
profileEstimate = profiles[sample];
break;
default:
break;
}
profileEstimate = profiles[sample];
break;
default:
break;
}

return profileEstimate;
}
}

0 comments on commit ad1af08

Please sign in to comment.