Skip to content

Commit 1054285

Browse files
committed
Merge branch 'release_1_1_0'
2 parents c87b7ee + 1b7bd8f commit 1054285

File tree

175 files changed

+491872
-2374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+491872
-2374
lines changed

.clang-format

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
BasedOnStyle: LLVM
2+
IndentWidth: 4
3+
---
4+
Language: Cpp
5+
AccessModifierOffset: -4
6+
AlignAfterOpenBracket: Align
7+
AlignConsecutiveAssignments: true
8+
AlignConsecutiveDeclarations: false
9+
AlignEscapedNewlines: DontAlign
10+
AlignOperands: true
11+
AlignTrailingComments: false
12+
AllowAllParametersOfDeclarationOnNextLine: false
13+
AllowShortBlocksOnASingleLine: false
14+
AllowShortCaseLabelsOnASingleLine: false
15+
AllowShortFunctionsOnASingleLine: Empty
16+
AllowShortIfStatementsOnASingleLine: false
17+
AllowShortLoopsOnASingleLine: false
18+
AlwaysBreakAfterReturnType: None
19+
AlwaysBreakBeforeMultilineStrings: false
20+
AlwaysBreakTemplateDeclarations: true
21+
BinPackArguments: false
22+
BinPackParameters: false
23+
BraceWrapping:
24+
AfterClass: false
25+
AfterControlStatement: false
26+
AfterEnum: false
27+
AfterFunction: false
28+
AfterNamespace: false
29+
AfterStruct: false
30+
AfterUnion: false
31+
BeforeCatch: true
32+
BeforeElse: true
33+
IndentBraces: false
34+
SplitEmptyFunction: false
35+
SplitEmptyRecord: true
36+
SplitEmptyNamespace: true
37+
BreakBeforeBinaryOperators: None
38+
BreakBeforeBraces: Custom
39+
BreakBeforeInheritanceComma: false
40+
BreakBeforeTernaryOperators: true
41+
BreakConstructorInitializers: BeforeColon
42+
ColumnLimit: 100
43+
CompactNamespaces: false
44+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
45+
ConstructorInitializerIndentWidth: 4
46+
ContinuationIndentWidth: 4
47+
Cpp11BracedListStyle: true
48+
FixNamespaceComments: false
49+
IndentCaseLabels: false
50+
KeepEmptyLinesAtTheStartOfBlocks: false
51+
NamespaceIndentation: All
52+
PenaltyBreakBeforeFirstCallParameter: 160
53+
PenaltyReturnTypeOnItsOwnLine: 80
54+
PointerAlignment: Left
55+
ReflowComments: true
56+
SortIncludes: true
57+
SortUsingDeclarations: true
58+
TabWidth: 4
59+
UseTab: Never
60+
...

CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
1313
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
1414
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
1515

16+
# Build option for enabling compiler and linker flags for gathering coverage data
17+
# In command line, set option this way:
18+
# cmake -DCoverage=ON <build folder>
19+
option(Coverage "Coverage" OFF)
20+
1621
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
1722
# -g: Produce debugging information
1823
# -O3: Optimize as much as possible while remaning standards compliant
@@ -63,6 +68,13 @@ elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
6368
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wcast-qual -Wextra -Wfloat-equal")
6469
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat -Wold-style-cast -Wpedantic -Wshadow")
6570
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-conversion -Wswitch-default -Wno-unknown-pragmas")
71+
72+
if(Coverage)
73+
# If coverage option enabled, set compiler and linker flags to gather coverage data
74+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
75+
set(CMAKE_EXE_LINKER_FLAGS "-lgcov")
76+
endif()
77+
6678
set(CMAKE_CXX_FLAGS_DEBUG "-g -Og -Winline")
6779
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Werror")
6880
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")

Test/BenchmarkPrognoser/BenchmarkPrognoser.cpp

+16-143
Original file line numberDiff line numberDiff line change
@@ -6,165 +6,38 @@
66
* BenchmarkPrognoser class.
77
*
88
* @author Micah Ricks
9-
* @version 0.1.0
9+
* @version 1.1.0
1010
*
1111
*
12-
* Contact: Micah Ricks (mricks1@bulldogs.aamu.edu)
12+
* Contact: Christopher Teubert (christopher.a.teubert@nasa.gov)
1313
* Created: January 31, 2017
1414
*
15-
* @copyright Copyright (c) 2017 United States Government as represented by
15+
* @copyright Copyright (c) 2018 United States Government as represented by
1616
* the Administrator of the National Aeronautics and Space Administration.
1717
* All Rights Reserved.
1818
*/
1919

20-
#include <stdio.h>
21-
#include <stdlib.h>
22-
#include <cstddef>
20+
#include <stdio.h>
2321

24-
#include <memory>
25-
#include <vector>
26-
27-
#include "Benchmark.h"
28-
#include "SharedLib.h"
29-
#include "BenchmarkPrognoser.h"
30-
#include "ObserverFactory.h"
31-
#include "PredictorFactory.h"
32-
#include "PrognosticsModelFactory.h"
33-
#include "UData.h"
34-
#include "CommManager.h"
35-
#include "GSAPConfigMap.h"
22+
#include "BenchmarkTimer.h"
23+
#include "BenchmarkPrognoser.h"
24+
#include "GSAPConfigMap.h"
3625

3726
namespace PCOE {
3827
// Configuration Keys
39-
const std::string MODEL_KEY = "model";
40-
const std::string OBSERVER_KEY = "observer";
41-
const std::string PREDICTOR_KEY = "predictor";
42-
const std::string EVENT_KEY = "Model.event";
43-
const std::string NUMSAMPLES_KEY = "Predictor.numSamples";
44-
const std::string HORIZON_KEY = "Predictor.horizon";
45-
const std::string PREDICTEDOUTPUTS_KEY = "Model.predictedOutputs";
46-
const std::string INPUTS_KEY = "inputs";
47-
const std::string OUTPUTS_KEY = "outputs";
48-
Benchmark benchmark1,benchmark2;
49-
unsigned long long const INIT_TIME=0;
50-
51-
BenchmarkPrognoser::BenchmarkPrognoser(GSAPConfigMap & configMap) : CommonPrognoser(configMap), initialized(false) {
52-
// Check for required config parameters
53-
configMap.checkRequiredParams({ MODEL_KEY,OBSERVER_KEY,PREDICTOR_KEY,EVENT_KEY,NUMSAMPLES_KEY,HORIZON_KEY,PREDICTEDOUTPUTS_KEY,INPUTS_KEY,OUTPUTS_KEY });
54-
/// TODO(CT): Move Model, Predictor subkeys into Model/Predictor constructor
55-
56-
// Create Model
57-
log.WriteLine(LOG_DEBUG, moduleName, "Creating Model");
58-
PrognosticsModelFactory & pProgModelFactory = PrognosticsModelFactory::instance();
59-
model = std::unique_ptr<PrognosticsModel>(pProgModelFactory.Create(configMap[MODEL_KEY][0], configMap));
60-
61-
// Create Observer
62-
log.WriteLine(LOG_DEBUG, moduleName, "Creating Observer");
63-
ObserverFactory & pObserverFactory = ObserverFactory::instance();
64-
observer = std::unique_ptr<Observer>(pObserverFactory.Create(configMap[OBSERVER_KEY][0], configMap));
65-
66-
// Create Predictor
67-
log.WriteLine(LOG_DEBUG, moduleName, "Creating Predictor");
68-
PredictorFactory & pPredictorFactory = PredictorFactory::instance();
69-
predictor = std::unique_ptr<Predictor>(pPredictorFactory.Create(configMap[PREDICTOR_KEY][0], configMap));
7028

71-
// Set model for observer and predictor
72-
observer->setModel(model.get());
73-
predictor->setModel(model.get());
29+
BenchmarkPrognoser::BenchmarkPrognoser(GSAPConfigMap & configMap) : ModelBasedPrognoser(configMap) {
7430

75-
// Set configuration parameters
76-
unsigned int numSamples = static_cast<unsigned int>(std::stoul(configMap[NUMSAMPLES_KEY][0]));
77-
unsigned int horizon = static_cast<unsigned int>(std::stoul(configMap[HORIZON_KEY][0]));
78-
std::string event = configMap[EVENT_KEY][0];
79-
std::vector<std::string> predictedOutputs = configMap[PREDICTEDOUTPUTS_KEY];
80-
81-
// Set inputs and outputs
82-
inputs = configMap[INPUTS_KEY];
83-
outputs = configMap[OUTPUTS_KEY];
84-
85-
// Create progdata
86-
results.setUncertainty(UType::Samples); // @todo(MD): do not force samples representation
87-
results.addEvent(event); // @todo(MD): do not assume only a single event
88-
results.addSystemTrajectories(predictedOutputs); // predicted outputs
89-
results.setPredictions(1, horizon); // interval, number of predictions
90-
results.setupOccurrence(numSamples);
91-
results.events[event].timeOfEvent.npoints(numSamples);
92-
results.sysTrajectories.setNSamples(numSamples);
9331
}
9432

9533
void BenchmarkPrognoser::step() {
96-
97-
//init time in nanoseconds
98-
if(benchmark2.begin != INIT_TIME)
99-
{
100-
benchmark2.nanosecondsEnd();
101-
benchmark2.findElapsedTime();
102-
103-
}
104-
benchmark1.nanosecondsBegin();
105-
106-
static double initialTime = comm.getValue(outputs[0]).getTime() / 1.0e3;
107-
108-
// Get new relative time (convert to seconds)
109-
// @todo(MD): Add config for time units so conversion is not hard-coded
110-
double newT = comm.getValue(outputs[0]).getTime() / 1.0e3 - initialTime;
111-
112-
// Fill in input and output data
113-
log.WriteLine(LOG_DEBUG, moduleName, "Getting data in step");
114-
std::vector<double> u(model->getNumInputs());
115-
std::vector<double> z(model->getNumOutputs());
116-
for (unsigned int i = 0; i < model->getNumInputs(); i++) {
117-
u[i] = comm.getValue(inputs[i]);
118-
}
119-
for (unsigned int i = 0; i < model->getNumOutputs(); i++) {
120-
z[i] = comm.getValue(outputs[i]);
121-
}
122-
123-
// If this is the first step, will want to initialize the observer and the predictor
124-
if (!initialized) {
125-
log.WriteLine(LOG_DEBUG, moduleName, "Initializing BenchmarkPrognoser");
126-
std::vector<double> x(model->getNumStates());
127-
model->initialize(x, u, z);
128-
observer->initialize(newT, x, u);
129-
initialized = true;
130-
lastTime = newT;
131-
} else {
132-
// If time has not advanced, skip this step
133-
if (newT <= lastTime) {
134-
log.WriteLine(LOG_TRACE, moduleName, "Skipping step because time did not advance.");
135-
136-
benchmark1.nanosecondsEnd();
137-
benchmark1.findElapsedTime();
138-
benchmark2.nanosecondsBegin();
139-
return;
140-
}
141-
142-
// Run observer
143-
log.WriteLine(LOG_DEBUG, moduleName, "Running Observer Step");
144-
observer->step(newT, u, z);
145-
log.WriteLine(LOG_DEBUG, moduleName, "Done Running Observer Step");
146-
147-
// Run predictor
148-
log.WriteLine(LOG_DEBUG, moduleName, "Running Prediction Step");
149-
// Set up state
150-
std::vector<UData> stateEst = observer->getStateEstimate();
151-
predictor->predict(newT, stateEst, results);
152-
log.WriteLine(LOG_DEBUG, moduleName, "Done Running Prediction Step");
153-
154-
// Set lastTime
155-
lastTime = newT;
156-
157-
}
34+
benchmark1.start();
35+
ModelBasedPrognoser::step();
36+
benchmark1.stop();
15837
}
15938

160-
//destructor
161-
BenchmarkPrognoser::~BenchmarkPrognoser() {
162-
benchmark1.clearFile();
163-
benchmark1.printTemp();
164-
benchmark1.printScreen();
165-
benchmark2.printScreen();
166-
benchmark1.writeFile();
167-
benchmark2.writeFile();
168-
}
169-
170-
}
39+
// destructor
40+
BenchmarkPrognoser::~BenchmarkPrognoser() {
41+
printf("Runtime: [%lld, %lld, %lld] ns\n", benchmark1.getMinStepTime()/nanoseconds(1), benchmark1.getAveStepTime()/nanoseconds(1), benchmark1.getMaxStepTime()/nanoseconds(1));
42+
}
43+
} // namespace PCOE
+27-38
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,43 @@
11
/** Benchmark Prognoser - Header
2-
* @class BenchmarkPrognoser BenchmarkPrognoser.h
3-
*
4-
* @brief Benchmark Prognoser Class
5-
*
6-
* BenchmarkPrognoser class.
7-
*
8-
* @author Micah Ricks
9-
* @version 0.1.0
10-
*
11-
*
12-
* Contact: Micah Ricks (mricks1@bulldogs.aamu.edu)
13-
* Created: March 16, 2016
14-
*
15-
* @copyright Copyright (c) 2017 United States Government as represented by
16-
* the Administrator of the National Aeronautics and Space Administration.
17-
* All Rights Reserved.
18-
*/
19-
2+
* @class BenchmarkPrognoser BenchmarkPrognoser.h
3+
*
4+
* @brief Benchmark Prognoser Class
5+
*
6+
* BenchmarkPrognoser class.
7+
*
8+
* @author Micah Ricks
9+
* @version 1.1.0
10+
*
11+
*
12+
* Contact: Christopher Teubert (christopher.a.teubert@nasa.gov)
13+
* Created: March 16, 2016
14+
*
15+
* @copyright Copyright (c) 2018 United States Government as represented by
16+
* the Administrator of the National Aeronautics and Space Administration.
17+
* All Rights Reserved.
18+
*/
2019
#ifndef PCOE_BENCHMARKPROGNOSER_H
2120
#define PCOE_BENCHMARKPROGNOSER_H
2221

23-
24-
#include "CommonPrognoser.h"
25-
#include "PrognosticsModel.h"
22+
#include "BenchmarkTimer.h"
23+
#include "ModelBasedPrognoser.h"
2624
#include "Observer.h"
2725
#include "Predictor.h"
26+
#include "PrognosticsModel.h"
2827

2928
namespace PCOE {
30-
class BenchmarkPrognoser : public CommonPrognoser
31-
{
29+
class BenchmarkPrognoser : public ModelBasedPrognoser {
3230
private:
33-
std::unique_ptr<PrognosticsModel> model;
34-
std::unique_ptr<Observer> observer;
35-
std::unique_ptr<Predictor> predictor;
36-
std::vector<std::string> inputs;
37-
std::vector<std::string> outputs;
38-
bool initialized;
39-
double firstTime;
40-
double lastTime;
31+
BenchmarkTimer benchmark1;
4132

4233
public:
43-
/** @brief Benchmark Prognoser Constructor
44-
* @param config Map of config parameters from the prognoser config file
34+
/**
35+
* @brief Benchmark Prognoser Constructor
36+
* @param config Map of config parameters from the prognoser config file
4537
*/
46-
BenchmarkPrognoser(GSAPConfigMap & config);
47-
~BenchmarkPrognoser(); //destructor
38+
BenchmarkPrognoser(GSAPConfigMap& config);
39+
~BenchmarkPrognoser(); // destructor
4840
void step();
4941
};
50-
51-
extern bool regModelProg;
5242
}
53-
5443
#endif // PCOE_BENCHMARKPROGNOSER_H

Test/BenchmarkPrognoser/main.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Example
44
//
55
// Created by Teubert, Christopher (ARC-TI)[SGT, INC] on 5/4/16.
6-
// Copyright © 2016 United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All Rights Reserved.
6+
// Copyright © 2018 United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All Rights Reserved.
77
//
88

99
#include "ProgManager.h"
@@ -31,12 +31,6 @@
3131
using namespace PCOE;
3232

3333
int main() {
34-
// Specify configuration file directories
35-
// std::ofstream file;
36-
//file.open("test.txt");
37-
//file<<"test \n";
38-
//file.close();
39-
4034
ConfigMap::addSearchPath("../example/cfg/");
4135

4236
// Specify Prognosers
@@ -63,6 +57,13 @@ int main() {
6357
pPredictorFactory.Register("MC", PredictorFactory::Create<MonteCarloPredictor>);
6458

6559
ProgManager PM = ProgManager("bench.cfg");
66-
PM.run();
60+
61+
printf("Benchmarking\n");
62+
PM.enable();
63+
std::this_thread::sleep_for(std::chrono::seconds(3));
64+
PM.start();
65+
std::this_thread::sleep_for(std::chrono::minutes(1));
66+
PM.stop();
67+
6768
return 0;
6869
}

0 commit comments

Comments
 (0)