35 numInputs(fix==
WorkPiece::
Fix::Inputs? types.size() : -1),
36 numOutputs(fix==
WorkPiece::
Fix::Outputs? types.size() : -1),
37 inputTypes(fix==
WorkPiece::
Fix::Inputs? Types(types) : std::map<unsigned int, std::string>()),
38 outputTypes(fix==
WorkPiece::
Fix::Outputs? Types(types) : std::map<unsigned int, std::string>()),
47 inputTypes(fix==
WorkPiece::
Fix::Inputs? types : std::map<unsigned int, std::string>()),
48 outputTypes(fix==
WorkPiece::
Fix::Outputs? types : std::map<unsigned int, std::string>()),
57 inputTypes(fixTypes==
WorkPiece::
Fix::Inputs? types : std::map<unsigned int, std::string>()),
58 outputTypes(fixTypes==
WorkPiece::
Fix::Outputs? types : std::map<unsigned int, std::string>()),
65 numInputs(types.size()),
67 inputTypes(Types(types)),
75 numOutputs(types.size()),
76 outputTypes(Types(types)),
82 WorkPiece::WorkPiece(std::map<unsigned int, std::string>
const& inTypes,
int const numIns,
int const numOuts) :
91 WorkPiece::WorkPiece(
int const numIns, std::map<unsigned int, std::string>
const& outTypes,
int const numOuts) :
94 outputTypes(outTypes),
101 numInputs(inTypes.size()),
102 numOutputs(outTypes.size()),
103 inputTypes(Types(inTypes)),
104 outputTypes(Types(outTypes)),
110 WorkPiece::WorkPiece(std::map<unsigned int, std::string>
const& inTypes, std::vector<std::string>
const& outTypes) :
112 numOutputs(outTypes.size()),
114 outputTypes(Types(outTypes)),
120 WorkPiece::WorkPiece(std::map<unsigned int, std::string>
const& inTypes,
int const num, std::vector<std::string>
const& outTypes) :
122 numOutputs(outTypes.size()),
124 outputTypes(Types(outTypes)),
130 WorkPiece::WorkPiece(std::vector<std::string>
const& inTypes, std::map<unsigned int, std::string>
const& outTypes) :
131 numInputs(inTypes.size()),
133 inputTypes(Types(inTypes)),
134 outputTypes(outTypes),
140 WorkPiece::WorkPiece(std::vector<std::string>
const& inTypes, std::map<unsigned int, std::string>
const& outTypes,
int const num) :
141 numInputs(inTypes.size()),
143 inputTypes(Types(inTypes)),
144 outputTypes(outTypes),
150 WorkPiece::WorkPiece(std::map<unsigned int, std::string>
const& inTypes, std::map<unsigned int, std::string>
const& outTypes) :
154 outputTypes(outTypes),
160 WorkPiece::WorkPiece(std::map<unsigned int, std::string>
const& inTypes,
int const numIn, std::map<unsigned int, std::string>
const& outTypes) :
164 outputTypes(outTypes),
170 WorkPiece::WorkPiece(std::map<unsigned int, std::string>
const& inTypes, std::map<unsigned int, std::string>
const& outTypes,
int const numOut) :
174 outputTypes(outTypes),
180 WorkPiece::WorkPiece(std::map<unsigned int, std::string>
const& inTypes,
int const numIn, std::map<unsigned int, std::string>
const& outTypes,
int const numOut) :
184 outputTypes(outTypes),
189 std::map<unsigned int, std::string>
WorkPiece::Types(std::vector<std::string>
const& typesVec)
const {
191 std::map<unsigned int, std::string> typesMap;
194 for(
unsigned int i=0; i<typesVec.size(); ++i ) {
195 typesMap[i] = typesVec.at(i);
203 std::vector<std::string> types;
204 types.reserve(vec.size());
207 for(
auto it : vec ) {
208 types.push_back(it.type().name());
212 assert(types.size()==vec.size());
218 static unsigned int workPieceId = 0;
219 return ++workPieceId;
230 std::vector<std::reference_wrapper<const boost::any>> emptyVec;
237 for(
unsigned int i=0; i<
outputTypes.size(); ++i ) {
262 for(
unsigned int i=0; i<
outputs.size(); ++i ) {
275 for(
unsigned int i=0; i<
inputTypes.size(); ++i ) {
548 std::stringstream ss;
553 if(className.rfind(
"muq::Modeling", 0) == 0)
554 className.erase(0,15);
557 std::string simpleName =
"";
559 for(
int i=0; i<className.size(); ++i){
560 if(className[i]==
'<'){
562 }
else if(className[i]==
'>'){
564 }
else if(openCnt==0){
565 simpleName += className[i];
569 ss << simpleName <<
"_" <<
id;
582 const double toMilli = 1.0e-6;
584 if (method.compare(
"Evaluate") == 0) {
587 assert(method.compare(
"Evaluate") == 0);
600 if (method.compare(
"Evaluate") == 0) {
603 assert(method.compare(
"Evaluate") == 0);
666 refs.reserve(vec.size());
669 for(
int i=0; i<vec.size(); ++i)
670 refs.push_back(std::cref(vec.at(i)));
678 refs.reserve(anyVec.size());
681 for(
int i=0; i<anyVec.size(); ++i)
682 refs.push_back(std::cref(anyVec.at(i)));
691 const std::string outtype = obj.type().name();
693 #if MUQ_HAS_SUNDIALS==1
695 if(outtype.compare(
typeid(N_Vector).name())==0){
696 N_VDestroy(boost::any_cast<N_Vector&>(obj));
701 if( outtype.compare(
typeid(std::vector<N_Vector>).name())==0 ) {
702 std::vector<N_Vector>& vec = boost::any_cast<std::vector<N_Vector>&>(obj);
703 for(
auto it : vec ) {
711 if( outtype.compare(
typeid(DlsMat).name())==0 ) {
712 DestroyMat(boost::any_cast<DlsMat&>(obj));
717 if( outtype.compare(
typeid(std::vector<DlsMat>).name())==0 ) {
718 std::vector<DlsMat>& vec = boost::any_cast<std::vector<DlsMat>&>(obj);
719 for(
auto it : vec ) {
734 for(
unsigned int i=0; i<
outputs.size(); ++i ) {
748 if( it!=
inputTypes.end() && it->second.compare(type)!=0 ) {
749 std::cerr << std::endl <<
"ERROR: Input types do not match." << std::endl <<
"\tGiven input: " <<
boost::core::demangle(type.c_str()) <<
", expected " <<
boost::core::demangle(it->second.c_str()) << std::endl << std::endl;
761 if( it!=
outputTypes.end() && it->second.compare(type)!=0 ) {
762 std::cerr << std::endl <<
"ERROR: Output types do not match." << std::endl <<
"\tGiven output: " <<
boost::core::demangle(type.c_str()) <<
", expected " <<
boost::core::demangle(it->second.c_str()) << std::endl << std::endl;
Base class for MUQ's modelling envronment.
void Clear()
Clear muq::Modeling::WorkPiece::outputs when muq::Modeling::Evaluate is called.
std::string const & Name()
Get the (unique) name of this work piece.
std::map< unsigned int, std::string > outputTypes
The output types.
std::map< unsigned int, int > inputSizes
bool CheckOutputType(unsigned int const outputNum, std::string const &type) const
Check the output type.
std::map< unsigned int, std::string > OutputTypes() const
Get the output types.
bool CheckInputType(unsigned int const inputNum, std::string const &type) const
Check the input type.
const unsigned int id
A unique ID number assigned by the constructor.
virtual unsigned long int GetNumCalls(const std::string &method="Evaluate") const
get the number of times one of the implemented methods has been called.
std::map< unsigned int, std::string > inputTypes
The input types.
WorkPiece()
Create a muq::Modeling::WorkPiece with no fixed number of inputs and outputs and variable input/outpu...
std::string OutputType(unsigned int outputNum, bool const demangle=true) const
Get the output type (if we know it) for a specific output.
virtual double GetRunTime(const std::string &method="Evaluate") const
Get the average run time for one of the implemented methods.
virtual void EvaluateImpl(ref_vector< boost::any > const &inputs)=0
User-implemented function that determines the behavior of this muq::Modeling::WorkPiece.
unsigned long int numEvalCalls
virtual void ResetCallTime()
Resets the number of call and times.
std::map< unsigned int, std::string > InputTypes() const
Get the input types.
std::vector< std::string > Types(std::vector< boost::any > const &vec) const
Get the types from a vector of boost::any's.
static ref_vector< const boost::any > ToRefVector(std::vector< boost::any > const &anyVec)
Create vector of references from a vector of boost::any's.
void SetName(std::string const &newName)
Set the name of this work piece.
std::string InputType(unsigned int inputNum, bool const demangle=true) const
Get the input type (if we know it) for a specific input.
unsigned int ID() const
Get the unique ID number.
bool clearOutputs
Clear outputs every time Evaluate is called.
void DestroyAny(boost::any &obj) const
Destroy a boost any.
int numOutputs
The number of outputs.
void SetInputSize(unsigned int inputNum, int newSize)
Fix
Does the constructor fix the inputs or the outputs?
virtual std::string CreateName() const
virtual void DestroyAnyImpl(boost::any &obj) const
Destroy a boost any.
std::vector< boost::any > outputs
The outputs.
std::vector< boost::any > const & Evaluate()
Evaluate this muq::Modeling::WorkPiece in the case that there are no inputs.
static unsigned int CreateID()
Creates a unique ID number, must be called by the constructor.
int InputSize(unsigned int inputNum) const
Get the length of a vector valued input with fixed size.
std::string name
A unique name for this WorkPiece. Defaults to <ClassName>_<id>
int numInputs
The number of inputs.
Exception to throw when matrices, vectors, or arrays are the wrong size.
std::vector< std::reference_wrapper< const T > > ref_vector
A vector of references to something ...
std::string demangle(const char *name)
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values