Page MenuHomePhorge

create_unit.cpp
No OneTemporary

Authored By
Unknown
Size
13 KB
Referenced Files
None
Subscribers
None

create_unit.cpp

This document is not UTF8. It was detected as JIS and converted to UTF8 for display.
#include "create_unit.h"
#include "rlutil.h"
using namespace rlutil;
//#define PRINT
/*
template<typename Unit> Unit createUnit(string name) {
Unit unit(name);
cout << " > ";
setColor(LIGHTCYAN);
cout << unit.getName() + " ";
setColor(GREY);
cout << "ID:";
setColor(TXTCOLOR_YELLOW);
cout << unit.getId();
setColor(LIGHTGREEN);
cout << " created\n";
setColor(GREY);
return unit;
}
template Agent createUnit<Agent>(string name);
template Sensor createUnit<Sensor>(string name);
*/
Agent create_agent() {
return create_agent(NO_NAME);
}
Agent create_agent(char* name) {
Agent agent(name);
#ifdef PRINT
printf(" > Agent ");
setColor(LIGHTCYAN);
printf("%s ", agent.getName().c_str());
setColor(GREY);
printf("(id: %03u) ", agent.getId());
setColor(LIGHTGREEN);
printf("created\n");
setColor(GREY);
#endif
return agent;
}
Sensor create_sensor() {
return create_sensor(NO_NAME);
}
Sensor create_sensor(char* name) {
Sensor sensor(name);
#ifdef PRINT
printf(" > Sensor ");
setColor(LIGHTCYAN);
printf("%s ", sensor.getName().c_str());
setColor(GREY);
printf("(id: %03u) ", sensor.getId());
setColor(LIGHTGREEN);
printf("created\n");
setColor(GREY);
#endif
return sensor;
}
HistoryModule create_historyModule(unsigned int history_length, int delimitation_mode) {
return create_historyModule(NO_NAME, history_length, delimitation_mode);
}
HistoryModule create_historyModule(char* name, unsigned int history_length, int delimitation_mode) {
/*
HistoryModule historyModule(name);
printf(" > History ");
setColor(LIGHTCYAN);
printf("%s ", historyModule.getName().c_str());
setColor(GREY);
printf("(id: %03u) ", historyModule.getId());
setColor(LIGHTGREEN);
printf("created\n");
setColor(GREY);
if(historyModule.set_maxHistoryLength(history_length)) {
printf(" > History length ");
setColor(LIGHTGREEN);
printf("set ");
setColor(GREY);
printf("to %u\n", history_length);
}
else {
setColor(LIGHTRED);
printf(" > historyLength could not set (out of allowed range).");
setColor(GREY);
}
if(historyModule.set_delimitationMode(delimitation_mode)) {
printf(" > Delimitation Mode ");
setColor(LIGHTGREEN);
printf("set ");
setColor(GREY);
printf("to %u\n", delimitation_mode);
}
else {
setColor(LIGHTRED);
printf(" > Delimitation Mode could not set (out of allowed range).");
setColor(GREY);
}
return historyModule;
*/
return NULL;
}
Channel create_channel(unsigned int transferRate) {
return create_channel(NO_NAME, transferRate);
}
Channel create_channel(char* name, unsigned int transferRate) {
Channel channel(name);
#ifdef PRINT
printf(" > Channel ");
setColor(LIGHTCYAN);
printf("%s ", channel.getName().c_str());
setColor(GREY);
printf("(id: %03u) ", channel.getId());
setColor(LIGHTGREEN);
printf("created\n");
setColor(GREY);
#endif
if (channel.setTransferRate(transferRate)) {
if (transferRate != 0) {
#ifdef PRINT
printf(" > transfer rate ");
setColor(LIGHTGREEN);
printf("set ");
setColor(GREY);
printf("to %i\n", transferRate);
#endif
}
else {
#ifdef PRINT
printf(" > transfer ");
setColor(LIGHTGREEN);
printf("set ");
setColor(GREY);
printf("to immediately transportation\n");
#endif
}
}
else {
#ifdef PRINT
setColor(LIGHTRED);
printf(" > Transfer Rate out of allowed bounds!\n");
setColor(GREY);
#endif
}
return channel;
}
Testbench create_testbench() {
Testbench testbench;
#ifdef PRINT
printf(" > ");
setColor(LIGHTCYAN);
printf("%s ", testbench.getName().c_str());
rlutil::setColor(GREY);
printf("(id: %03u) ", testbench.getId());
rlutil::setColor(LIGHTGREEN);
printf("created\n");
rlutil::setColor(GREY);
#endif
return testbench;
}
Testbench create_testbench(char* name) {
Testbench testbench(name);
#ifdef PRINT
printf(" > ");
rlutil::setColor(LIGHTCYAN);
printf("%s ", testbench.getName().c_str());
rlutil::setColor(GREY);
printf("(id: %03u) ", testbench.getId());
rlutil::setColor(LIGHTGREEN);
printf("created\n");
rlutil::setColor(GREY);
#endif
return testbench;
}
Lookuptable create_lookuptable() {
Lookuptable lut;
#ifdef PRINT
printf(" > ");
rlutil::setColor(LIGHTCYAN);
printf("%s ", lut.getName().c_str());
rlutil::setColor(GREY);
printf("(id: %03u) ", lut.getId());
rlutil::setColor(LIGHTGREEN);
printf("created\n");
rlutil::setColor(GREY);
#endif
return lut;
}
Lookuptable create_lookuptable(char* name) {
Lookuptable lut(name);
#ifdef PRINT
printf(" > ");
rlutil::setColor(LIGHTCYAN);
printf("%s ", lut.getName().c_str());
rlutil::setColor(GREY);
printf("(id: %03u) ", lut.getId());
rlutil::setColor(LIGHTGREEN);
printf("created\n");
rlutil::setColor(GREY);
#endif
return lut;
}
/*
void print_confidence_validator(Confidence_Validator conf_valid) {
printf(" > ");
rlutil::setColor(LIGHTCYAN);
printf("%s ", conf_valid.getName().c_str());
rlutil::setColor(GREY);
printf("(id: %03u) ", conf_valid.getId());
rlutil::setColor(LIGHTGREEN);
printf("created\n");
rlutil::setColor(GREY);
printf(" - range of validity ");
if(conf_valid.get_flag_lower_bound_exist())
printf("[ %.3f, ", conf_valid.get_lower_bound());
else
printf("] -inf, ");
if(conf_valid.get_flag_upper_bound_exist())
printf("%.3f ] ", conf_valid.get_upper_bound());
else
printf("+inf [ ");
rlutil::setColor(LIGHTGREEN);
printf("set\n");
rlutil::setColor(GREY);
if(conf_valid.get_flag_rates_of_change_exist()) {
printf(" - validity for rates of change of ");
printf("%.3f ", conf_valid.get_rates_of_change());
rlutil::setColor(LIGHTGREEN);
printf("set\n");
rlutil::setColor(GREY);
}
}
Confidence_Validator create_confidence_validator(float lower_bound, bool flag_lower_bound_exist, float upper_bound, bool flag_upper_bound_exist, float rates_of_change, bool flag_rates_of_change_exist) {
Confidence_Validator conf_valid(lower_bound, flag_lower_bound_exist, upper_bound, flag_upper_bound_exist, rates_of_change, flag_rates_of_change_exist);
print_confidence_validator(conf_valid);
return conf_valid;
}
Confidence_Validator create_confidence_validator(char* name, float lower_bound, bool flag_lower_bound_exist, float upper_bound, bool flag_upper_bound_exist, float rates_of_change, bool flag_rates_of_change_exist) {
Confidence_Validator conf_valid(name, lower_bound, flag_lower_bound_exist, upper_bound, flag_upper_bound_exist, rates_of_change, flag_rates_of_change_exist);
print_confidence_validator(conf_valid);
return conf_valid;
}
*/
void print_abstraction_module(AbstractionModule abstraction) {
#ifdef PRINT
printf(" > ");
rlutil::setColor(LIGHTCYAN);
printf("%s ", abstraction.getName().c_str());
rlutil::setColor(GREY);
printf("(id: %03u) ", abstraction.getId());
rlutil::setColor(LIGHTGREEN);
printf("created\n");
rlutil::setColor(GREY);
//TODO: abstraction method printen
printf(" - abstraction method %u ", abstraction.get_abstraction_method());
rlutil::setColor(LIGHTGREEN);
printf("set\n");
rlutil::setColor(GREY);
#endif
//TODO: auch das hier bissl sch?ner machen
if (abstraction.get_flag_lookuptable_exist(0)) {
#ifdef PRINT
printf(" - position 0 connected mit Look up Table ");
rlutil::setColor(LIGHTCYAN);
printf("%s ", abstraction.get_lookuptable(0)->getName().c_str());
rlutil::setColor(GREY);
printf("(id: %03u) ", abstraction.get_lookuptable(0)->getId());
rlutil::setColor(LIGHTGREEN);
printf("set\n");
rlutil::setColor(GREY);
#endif
}
}
AbstractionModule create_abstraction_module(Lookuptable* lut, unsigned int abstraction_method) {
AbstractionModule abstraction(lut, abstraction_method);
print_abstraction_module(abstraction);
return abstraction;
}
AbstractionModule create_abstraction_module(char* name, Lookuptable* lut, unsigned int abstraction_method) {
AbstractionModule abstraction(name, lut, abstraction_method);
print_abstraction_module(abstraction);
return abstraction;
}
/*
void print_bunch_module(Bunch_Module bunch_module) {
printf(" > ");
rlutil::setColor(LIGHTCYAN);
printf("%s ", bunch_module.getName().c_str());
rlutil::setColor(GREY);
printf("(id: %03u) ", bunch_module.getId());
rlutil::setColor(LIGHTGREEN);
printf("created\n");
rlutil::setColor(GREY);
//TODO: abstraction method printen
printf(" - abstraction method %u ", bunch_module.get_bunch_method());
rlutil::setColor(LIGHTGREEN);
printf("set\n");
rlutil::setColor(GREY);
}
Bunch_Module create_bunch_module(unsigned int bunch_method) {
Bunch_Module bunch_module(bunch_method);
print_bunch_module(bunch_module);
return bunch_module;
}
Bunch_Module create_bunch_module(char* name, unsigned int bunch_method) {
Bunch_Module bunch_module(name, bunch_method);
print_bunch_module(bunch_module);
return bunch_module;
}
*/
FILE* make_file_pointer(char* filepath, int mode) {
FILE* fpointer;
bool file_opened;
if (mode == CSV_MODE_READ) {
file_opened = fopen_s(&fpointer, filepath, "r");
}
else if (mode == CSV_MODE_WRITE) {
file_opened = fopen_s(&fpointer, filepath, "w");
}
else {
#ifdef PRINT
printf("File pointer mode for \"%s\" ", filepath);
rlutil::setColor(LIGHTRED);
printf("is not supported!\n");
rlutil::setColor(GREY);
#endif
return NULL;
}
if (file_opened == 0) {
return fpointer;
}
#ifdef PRINT
printf("File pointer \"%s\" ", filepath);
rlutil::setColor(LIGHTRED);
printf("could not created!\n");
rlutil::setColor(GREY);
#endif
return NULL;
}
void print_csv_reader(CSVreaderModule* csvReaderModule, char* filepath) {
#ifdef PRINT
printf(" > ");
rlutil::setColor(LIGHTCYAN);
printf("%s ", csvReaderModule->getName().c_str());
rlutil::setColor(GREY);
printf("(id: %03u) for \"%s\" ", csvReaderModule->getId(), filepath);
rlutil::setColor(LIGHTGREEN);
printf("created\n");
rlutil::setColor(GREY);
#endif
}
CSVreaderModule* create_CSVreaderModule(char* filepath, unsigned int column, unsigned int start_row) {
FILE* fpointer = make_file_pointer(filepath, CSV_MODE_READ);
if (fpointer) {
CSVreaderModule* csvr = new CSVreaderModule(fpointer, column, start_row);
print_csv_reader(csvr, filepath);
return csvr;
}
else {
CSVreaderModule* csvr = new CSVreaderModule();
return csvr;
}
}
CSVreaderModule* create_CSVreaderModule(char* name, char* filepath, unsigned int column, unsigned int start_row) {
FILE* fpointer = make_file_pointer(filepath, CSV_MODE_READ);
//printf("filepathCSVreader: %s\n", filepath);
if (fpointer) {
CSVreaderModule* csvr = new CSVreaderModule(name, fpointer, column, start_row);
print_csv_reader(csvr, filepath);
return csvr;
}
else {
CSVreaderModule* csvr = new CSVreaderModule();
printf("file gibts nicht\n");
getchar();
return csvr;
}
}
StateHandler create_stateHandler() {
return create_stateHandler(NO_NAME);
}
StateHandler create_stateHandler(char* name) {
StateHandler stateHandler(name);
return stateHandler;
}
StabilityModule createStabilityModule(unsigned int slidingWindowBufferSize, unsigned int minNumOfRelatedValuesToBeStable, float maxDeviationToBeStable) {
return createStabilityModule(NO_NAME, slidingWindowBufferSize, minNumOfRelatedValuesToBeStable, maxDeviationToBeStable);
}
StabilityModule createStabilityModule(char* name, unsigned int slidingWindowBufferSize, unsigned int minNumOfRelatedValuesToBeStable, float maxDeviationToBeStable) {
StabilityModule stabilityModule(name);
#ifdef PRINT
printf(" > Stability Module ");
rlutil::setColor(LIGHTCYAN);
printf("%s ", stabilityModule.getName().c_str());
rlutil::setColor(GREY);
printf("(id: %03u) ", stabilityModule.getId());
rlutil::setColor(LIGHTGREEN);
printf("created\n");
rlutil::setColor(GREY);
#endif
if (stabilityModule.setSlidingWindowBufferSize(slidingWindowBufferSize)) {
#ifdef PRINT
printf(" > Sliding Window Size ");
setColor(LIGHTGREEN);
printf("set ");
setColor(GREY);
printf("to %u\n", slidingWindowBufferSize);
#endif
}
else {
#ifdef PRINT
setColor(LIGHTRED);
printf(" > Sliding Window Size couldn't be set to %u\n", slidingWindowBufferSize);
setColor(GREY);
#endif
}
if (stabilityModule.setMinNumOfRelatedValuesToBeStable(minNumOfRelatedValuesToBeStable)) {
#ifdef PRINT
printf(" > Minimum Number of Related Values to be Stable ");
setColor(LIGHTGREEN);
printf("set ");
setColor(GREY);
printf("to %u\n", minNumOfRelatedValuesToBeStable);
#endif
}
else {
#ifdef PRINT
setColor(LIGHTRED);
printf(" > Minimum Number of Related Values to be Stable couldn't be set to %u\n", minNumOfRelatedValuesToBeStable);
setColor(GREY);
#endif
}
if (stabilityModule.setMaxDeviationToBeStable(maxDeviationToBeStable)) {
#ifdef PRINT
printf(" > Maximum Deviation to be Stable ");
setColor(LIGHTGREEN);
printf("set ");
setColor(GREY);
printf("to %f\n", maxDeviationToBeStable);
#endif
}
else {
#ifdef PRINT
setColor(LIGHTRED);
printf(" > Maximum Deviation to be Stable couldn't be set to %f\n", maxDeviationToBeStable);
setColor(GREY);
#endif
}
return stabilityModule;
}
ConfidenceModule createConfidenceModule() {
return createConfidenceModule(NO_NAME);
}
ConfidenceModule createConfidenceModule(char* name) {
ConfidenceModule confidenceModule(name);
#ifdef PRINT
printf(" > Confidence Module ");
rlutil::setColor(LIGHTCYAN);
printf("%s ", confidenceModule.getName().c_str());
rlutil::setColor(GREY);
printf("(id: %03u) ", confidenceModule.getId());
rlutil::setColor(LIGHTGREEN);
printf("created\n");
rlutil::setColor(GREY);
#endif
return confidenceModule;
}
HistoryModule createHistoryModule(unsigned int maximumHistoryLength) {
return createHistoryModule(NO_NAME, maximumHistoryLength);
}
HistoryModule createHistoryModule(char* name, unsigned int maximumHistoryLength) {
HistoryModule historyModule(name, maximumHistoryLength);
#ifdef PRINT
printf(" > History Module ");
rlutil::setColor(LIGHTCYAN);
printf("%s ", historyModule.getName().c_str());
rlutil::setColor(GREY);
printf("(id: %03u) ", historyModule.getId());
rlutil::setColor(LIGHTGREEN);
printf("created\n");
rlutil::setColor(GREY);
#endif
return historyModule;
}

File Metadata

Mime Type
text/x-c
Expires
Fri, Nov 20, 11:53 PM (5 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
422944
Default Alt Text
create_unit.cpp (13 KB)

Event Timeline