Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F25860309
State.hpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Size
6 KB
Referenced Files
None
Subscribers
None
State.hpp
View Options
//===-- rosa/agent/State.hpp ----------------------------*- C++ -*-===//
//
// The RoSA Framework
//
//===----------------------------------------------------------------------===//
///
/// \file rosa/agent/State.hpp
///
/// \author Maximilian Götzinger (maximilian.goetzinger@tuwien.ac.at)
///
/// \date 2019
///
/// \brief Definition of *state* *functionality*.
///
//===----------------------------------------------------------------------===//
#ifndef ROSA_AGENT_STATE_HPP
#define ROSA_AGENT_STATE_HPP
#include
"rosa/agent/FunctionAbstractions.hpp"
#include
"rosa/agent/Functionality.h"
#include
"rosa/agent/History.hpp"
namespace
rosa
{
namespace
agent
{
// QUESTION: I would like to define the variable nextID as static variable
// inside the struct or the class but it is not possible because I cannot define
// it there (initialize it with 0) because "no const variable". However, using a
// global variable is not that nice in my opinion.
unsigned
int
nextID
=
0
;
/// State conditions defining how the condition of a \c rosa::agent::State is
/// saved in \c rosa::agent::StateInformation.
enum
class
StateCondition
{
STABLE
,
///< The state is STABLE
DRIFTING
///< The state is drifting
};
template
<
typename
CONFTYPE
>
struct
StateInformation
{
// Make sure the actual type arguments are matching our expectations.
STATIC_ASSERT
((
std
::
is_arithmetic
<
CONFTYPE
>::
value
),
"confidence type is not to arithmetic"
);
/// The state ID saved as an unsigned integer number
unsigned
int
StateID
;
/// The StateConfidence shows the overall confidence value of the state.
CONFTYPE
StateConfidence
;
/// The StateCondition shows the condition of a state (stable or drifting)
StateCondition
StateCondition
;
/// The StateIsValid shows whether a state is valid or invalid. In this
/// context, valid means that enough samples which are in close proximitry
/// have been inserted into the state.
bool
StateIsValid
;
/// The StateIsValidAfterReentrance shows whether a state is valid after the
/// variable changed back to it again.
bool
StateIsValidAfterReentrance
;
};
// TODO (1/2): change name of DABSTORETYPE to something else
/// \tparam INDATATYPE type of input data, \tparam DABSTORETYPE type of data
/// in which DABs are saved,
template
<
typename
INDATATYPE
,
typename
DABSTORETYPE
>
class
State
:
public
Functionality
{
// Make sure the actual type arguments are matching our expectations.
STATIC_ASSERT
((
std
::
is_arithmetic
<
INDATATYPE
>::
value
),
"input data type not arithmetic"
);
STATIC_ASSERT
((
std
::
is_arithmetic
<
DABSTORETYPE
>::
value
),
"DAB storage type is not to arithmetic"
);
private
:
// For the convinience to write a shorter data type name
using
partFuncPointer
=
std
::
shared_ptr
<
PartialFunction
<
INDATATYPE
,
DABSTORETYPE
>>
;
// TODO (2/2): because here, DABSTORETYPE makes no sense
using
stateInfoPtr
=
std
::
shared_ptr
<
StateInformation
<
DABSTORETYPE
>>
;
stateInfoPtr
StateInfo
;
partFuncPointer
PartialFunctionSampleMatches
;
partFuncPointer
PartialFunctionSampleMismatches
;
partFuncPointer
PartialFunctionNumOfSamplesMatches
;
partFuncPointer
PartialFunctionNumOfSamplesMismatches
;
DynamicLengthHistory
<
INDATATYPE
,
HistoryPolicy
::
FIFO
>
SampleHistory
;
DynamicLengthHistory
<
INDATATYPE
,
HistoryPolicy
::
SRWF
>
DAB
;
DynamicLengthHistory
<
DABSTORETYPE
,
HistoryPolicy
::
LIFO
>
DABHistory
;
/// The StateIsValid shows whether a state is valid or invalid. In this
/// context, valid means that enough samples which are in close proximitry
/// have been inserted into the state.
bool
StateIsValid
;
/// The StateIsValidAfterReentrance shows whether a state is valid after the
/// variable changed back to it again.
bool
StateIsValidAfterReentrance
;
public
:
State
(
partFuncPointer
PartialFunctionSampleMatches
,
partFuncPointer
PartialFunctionSampleMismatches
,
partFuncPointer
PartialFunctionNumOfSamplesMatches
,
partFuncPointer
PartialFunctionNumOfSamplesMismatches
,
unsigned
int
sampleHistorySize
,
unsigned
int
DABSize
,
unsigned
int
DABHistorySize
)
noexcept
:
SampleHistory
(
sampleHistorySize
),
DAB
(
DABSize
),
DABHistory
(
DABHistorySize
),
PartialFunctionSampleMatches
(
PartialFunctionSampleMatches
),
PartialFunctionSampleMismatches
(
PartialFunctionSampleMismatches
),
PartialFunctionNumOfSamplesMatches
(
PartialFunctionNumOfSamplesMatches
),
PartialFunctionNumOfSamplesMismatches
(
PartialFunctionNumOfSamplesMismatches
)
{
/*
StateIsValid = false;
StateIsValidAfterReentrance = false;
*/
}
/// Destroys \p this object.
~
State
(
void
)
=
default
;
void
leaveState
(
void
)
{
DAB
.
clear
();
StateIsValidAfterReentrance
=
false
;
}
bool
insertSample
(
INDATATYPE
Sample
)
{
bool
workedForAll
;
// maybe ignor that //auc hnicht abchecken einfach kübeln
workedForAll
=
SampleHistory
.
addEntry
(
Sample
);
// QUESTION: is it important to have this flag (workedForAll). What should I
// do if it does not work at some point?
if
(
workedForAll
)
{
workedForAll
&=
DAB
.
addEntry
(
Sample
);
if
(
workedForAll
)
{
if
(
DAB
.
full
())
{
DABSTORETYPE
AvgOfDAB
=
DAB
.
average
<
DABSTORETYPE
>
();
workedForAll
&=
DABHistory
.
addEntry
(
AvgOfDAB
);
if
(
workedForAll
)
{
DAB
.
clear
();
}
// QUESTION: - what should be done if it has not worked?
}
if
(
workedForAll
)
{
// TODO: calculate whether state is valid
// TODO: check actual state whether it drifts
// TODO: write in StateInfo
}
}
}
return
workedForAll
;
}
DABSTORETYPE
confSampleMatchesState
(
INDATATYPE
sample
)
{}
DABSTORETYPE
confSampleMismatchesState
(
INDATATYPE
sample
)
{}
// unsigned int stateId(void) { return StateId; }
/// Gives information about the current state.
///
/// \return a struct StateInformation that contains information about the
/// current state.
stateInfoPtr
stateInformation
(
void
)
{
// TODO: check what happens when currentStateInformation(void) is called in
// the beginning when no state has recognized at all.
return
StateInfo
;
}
};
}
// End namespace agent
}
// End namespace rosa
#endif
// ROSA_AGENT_STATE_HPP
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Sat, Aug 29, 4:47 PM (19 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
369315
Default Alt Text
State.hpp (6 KB)
Attached To
Mode
R20 SoC_Rosa_repo
Attached
Detach File
Event Timeline
Log In to Comment