Commit 432d0fbc authored by fmg005's avatar fmg005

Implemented algorithm for controller 1

parent 03a04232
project(CMD_SIM)
cmake_minimum_required(VERSION 3.9.4)
project(cmd)
find_path(CONFIG++_INCLUDE_DIR libconfig.h++ /usr/include /usr/local/include)
find_library(CONFIG++_LIBRARY NAMES config++ PATH /usr/lib /usr/local/lib)
# header files
include_directories(include)
# source files directory -> handle multiple controllers
......@@ -19,51 +23,25 @@ set(MY_SOURCE_FILES
)
source_group("" FILES ${MY_SOURCE_FILES})
set(SOURCE ${MY_SOURCE_FILES})
add_executable(HowToDriver EXCLUDE_FROM_ALL ${SOURCE})
# Preprocessor Definitions and Include Paths
set(FLAGS)
target_include_directories(HowToDriver PRIVATE ${CMAKE_INSTALL_PREFIX}/include)
target_include_directories(HowToDriver PRIVATE ${CMAKE_INSTALL_PREFIX}/include/cdm)
target_include_directories(HowToDriver PRIVATE ${CMAKE_INSTALL_PREFIX}/include/bind)
set_target_properties(HowToDriver PROPERTIES COMPILE_FLAGS "${FLAGS}" PREFIX "")
# Dependent Libraries
if(WIN32)
set(lib_ext "lib")
set(log4cpp_prefix "")
else()
set(lib_ext "a")
set(log4cpp_prefix "lib")
endif()
set(D_LIB_FILES
${CMAKE_INSTALL_PREFIX}/lib/debug${EX_CONFIG}/PulseEngine.${lib_ext}
${CMAKE_INSTALL_PREFIX}/lib/debug${EX_CONFIG}/CommonDataModel.${lib_ext}
${CMAKE_INSTALL_PREFIX}/lib/debug${EX_CONFIG}/DataModelBindings.${lib_ext}
${CMAKE_INSTALL_PREFIX}/lib/debug${EX_CONFIG}/${log4cpp_prefix}log4cpp.${lib_ext}
${CMAKE_INSTALL_PREFIX}/lib/debug${EX_CONFIG}/libprotobufd.${lib_ext}
)
set(O_LIB_FILES
${CMAKE_INSTALL_PREFIX}/lib/release${EX_CONFIG}/PulseEngine.${lib_ext}
${CMAKE_INSTALL_PREFIX}/lib/release${EX_CONFIG}/CommonDataModel.${lib_ext}
${CMAKE_INSTALL_PREFIX}/lib/release${EX_CONFIG}/DataModelBindings.${lib_ext}
${CMAKE_INSTALL_PREFIX}/lib/release${EX_CONFIG}/${log4cpp_prefix}log4cpp.${lib_ext}
${CMAKE_INSTALL_PREFIX}/lib/release${EX_CONFIG}/libprotobuf.${lib_ext}
${CMAKE_INSTALL_PREFIX}/lib/release${EX_CONFIG}/libconfig++.${lib_ext}
)
add_executable(cmd ${MY_SOURCE_FILES})
## This is how you connect that executable to Pulse
# Find the Pulse package
# Again, set Pulse_DIR to the install directory with the PulseConfig.cmake file, or make the developer set this when building the code
find_package(Pulse REQUIRED NO_MODULE) # If you don't, CMake will halt here
# You will now have access to all the variables set in the PulseConfig.cmake in the Pulse install directory
# Go open it and look through to see what you have
target_include_directories(cmd PRIVATE ${Pulse_INCLUDE_DIRS})
target_include_directories(cmd PRIVATE ${CONFIG++_INCLUDE_DIR})
# Some debug libraries have different names than the release libs
target_link_libraries(cmd debug "${Pulse_DEBUG_LIBS}")
target_link_libraries(cmd optimized "${Pulse_LIBS}")
target_link_libraries(cmd optimized "${CONFIG++_LIBRARY}")
foreach(file ${D_LIB_FILES})
target_link_libraries(HowToDriver debug ${file})
endforeach()
foreach(file ${O_LIB_FILES})
target_link_libraries(HowToDriver optimized ${file})
endforeach()
add_custom_command(TARGET HowToDriver POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${INSTALL_BIN}/${CONFIGURATION}${EX_CONFIG}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:HowToDriver> ${INSTALL_BIN}/${CONFIGURATION}${EX_CONFIG})
# That is it, your program is now linked to Pulse
install(TARGETS cmd RUNTIME DESTINATION ${Pulse_INSTALL}/bin)
......@@ -49,6 +49,45 @@ class Controller {
PhysiologyData* m_data;
std::map<string, Pump*> m_pumps;
double WAIT_10;
double WAIT_5;
unsigned long initialize_time_index;
unsigned long checkmap_time_index;
unsigned long ensure_map_time_index;
unsigned long maintain_map_time_index;
unsigned long else_maintain_map_time_index;
bool set_initialize_time_index;
bool set_checkmap_timeindex;
bool set_ensure_map_time_index;
bool set_maintain_map_time_index;
bool set_else_maintain_map_time_index;
bool INITIALIZED;
bool checkmap_initialized;
bool ensure_map_initialized;
bool maintain_map_initialized;
bool else_maintain_map_initialized;
bool DEACTIVATE_INIT;
bool WAIT_FOR_MAP_INCREASE;
bool ENSURE_MAP_DECREASE;
bool MAINTAIN_MAP_RANGE;
bool STAY_IN_2;
bool STAY_IN_3;
bool STAY_IN_4;
bool ELSE_STAY_IN_4;
double currentNorepiRate;
double SalineInfusionRate;
double maxNorepinephrineInfusionRate;
double percentOfRate;
double targetMAPRangeMax;
double targetMAPRangeMin;
double MAPIncreaseThreshold;
double MAP;
//function variable for functions to set pump rates
//void pumpSetRate; // assuming dictionary
......
......@@ -13,8 +13,11 @@
#include "PhysiologyData.h"
#include "patient/actions/SESubstanceCompoundInfusion.h"
#include "patient/actions/SESubstanceInfusion.h"
#include "substance/SESubstanceManager.h"
#include "substance/SESubstanceCompound.h"
#include "properties/SEScalarMassPerVolume.h"
#include "substance/SESubstance.h"
#include "properties/SEScalarVolume.h"
#include "properties/SEScalarVolumePerTime.h"
......@@ -42,13 +45,14 @@ class Pump : public MedicalDevice {
// rate, time_index
vector< pair<int, unsigned long> > pump_data;
vector< pair<double, unsigned long> > pump_data;
CMD::Environment* m_env;
PhysiologyData* m_data;
string m_substance;
SESubstanceCompoundInfusion* m_infusion;
SESubstanceInfusion* bpdrug_infusion;
public:
......@@ -60,7 +64,7 @@ class Pump : public MedicalDevice {
//Overload Constructor
Pump(CMD::Environment*, PhysiologyData*, string);
void ChangePumpRate(int, unsigned long);
void ChangePumpRate(double, unsigned long);
// Device logic will go in here
// This function uses the engine object to query required info
......@@ -69,10 +73,12 @@ class Pump : public MedicalDevice {
// Load all pump configurations
virtual void LoadConfig(std::unique_ptr<PhysiologyEngine>&, const char*);
void SetInfusionRate(std::unique_ptr<PhysiologyEngine>&, int);
void SetInfusionRate(std::unique_ptr<PhysiologyEngine>&, double);
void Stop();
void Clear();
// Destructor
~Pump();
};
......
This diff is collapsed.
......@@ -108,36 +108,56 @@ void Pump::LoadConfig(std::unique_ptr<PhysiologyEngine>& engine, const char* fil
}
// instatiate infusion compound
SESubstanceCompound* saline = engine->GetSubstanceManager().GetCompound(m_substance);
m_infusion = new SESubstanceCompoundInfusion(*saline);
//the total volume in the bag of Saline
m_infusion->GetBagVolume().SetValue(500,VolumeUnit::mL);
// Set up substance infusion
if(m_substance == "Saline") {
// instatiate infusion compound
SESubstanceCompound* saline = engine->GetSubstanceManager().GetCompound(m_substance);
m_infusion = new SESubstanceCompoundInfusion(*saline);
//the total volume in the bag of Saline
m_infusion->GetBagVolume().SetValue(500,VolumeUnit::mL);
}
if(m_substance == "Norepinephrine") {
SESubstance* bpdrug = engine->GetSubstanceManager().GetSubstance(m_substance);
bpdrug_infusion = new SESubstanceInfusion(*bpdrug);
bpdrug_infusion->GetConcentration().SetValue(16, MassPerVolumeUnit::ug_Per_mL);
}
}
void Pump::SetInfusionRate(std::unique_ptr<PhysiologyEngine>& eng, int infusion_rate) {
void Pump::SetInfusionRate(std::unique_ptr<PhysiologyEngine>& eng, double infusion_rate) {
pump_rate = infusion_rate;
//The rate to admnister the compound in the bag in this case saline
m_infusion->GetRate().SetValue(pump_rate, VolumePerTimeUnit::mL_Per_hr);
eng->ProcessAction(*m_infusion);
// Can't get curent BAG volume : returns the inital set volume ie 500
//cout << "CURRENT BAG Volume" << m_infusion->GetBagVolume().GetValue(VolumeUnit::mL)<< endl;
if(m_substance == "Saline") {
//The rate to admnister the compound in the bag in this case saline
m_infusion->GetRate().SetValue(pump_rate, VolumePerTimeUnit::mL_Per_hr);
eng->ProcessAction(*m_infusion);
cout<< m_substance+"_Pump rate changed to: " << pump_rate <<endl;
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
}
cout<< m_substance+"_Pump rate changed to: " << pump_rate <<endl;
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
if(m_substance == "Norepinephrine") {
bpdrug_infusion->GetRate().SetValue(pump_rate, VolumePerTimeUnit::mL_Per_hr);
eng->ProcessAction(*bpdrug_infusion);
cout<< m_substance+"_Pump rate changed to: " << pump_rate <<endl;
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
}
}
void Pump::ChangePumpRate(int new_rate, unsigned long new_time_index){
void Pump::ChangePumpRate(double new_rate, unsigned long new_time_index){
pump_data.push_back(make_pair(new_rate, new_time_index));
//SetInfusionRate(new_rate, new_time_index);
......@@ -156,11 +176,25 @@ void Pump::Stop() {
//Nolonger static variable
//vector< pair<int, unsigned long> > Pump::pump_data;
void Pump::Clear() {
m_infusion = nullptr;
bpdrug_infusion = nullptr;
// clear data accumulated in te containr after simulation
pump_data.clear();
}
// Destructor
Pump::~Pump() {
// clear data accumulated in te containr after simulation
pump_data.clear();
delete m_infusion;
};
Pump::Clear();
if (m_infusion == nullptr){
delete m_infusion;
}
if (bpdrug_infusion == nullptr) {
delete bpdrug_infusion;
}
}
......@@ -16,6 +16,7 @@
// Include the various types you will be using in your code
#include "scenario/SEDataRequestManager.h"
#include "patient/actions/SEHemorrhage.h"
#include "patient/actions/SESubstanceCompoundInfusion.h"
#include "system/physiology/SEBloodChemistrySystem.h"
......@@ -59,8 +60,8 @@ int main(){
patients_list = get_global_patients("./config/simulation_scenario.cfg", cf);
/*
/*
for(auto patient: patients_list) {
// start timer
t1 = clock();
......@@ -79,7 +80,8 @@ int main(){
cout << " took "<< sim_time_secs <<" seconds ";
cout <<"or " << sim_time_mins <<" minutes"<<endl;
}
*/
*/
t1 = clock();
......@@ -98,8 +100,6 @@ int main(){
}
......@@ -151,11 +151,11 @@ void Simulation(const string patient_name)
Pump pump_saline(&sim_env, &data, "Saline");
pump_saline.LoadConfig(pe, fname);
//Pump pump_bpdrug(&sim_env, &data, "Saline");
//pump_bpdrug.LoadConfig(pe, fname);
Pump pump_bpdrug(&sim_env, &data, "Norepinephrine");
pump_bpdrug.LoadConfig(pe, fname);
pumps.insert(make_pair("saline", &pump_saline));
//pumps.insert(make_pair("bpdrug", &pump_bpdrug));
pumps.insert(make_pair("bpdrug", &pump_bpdrug));
//Initialize Controller
Controller controller(&sim_env, &data, pumps);
......@@ -187,7 +187,7 @@ void Simulation(const string patient_name)
//the location of the hemorrhage
hemorrhageLeg.SetCompartment(pulse::VascularCompartment::RightLeg);
//the rate of hemorrhage
hemorrhageLeg.GetRate().SetValue(100,VolumePerTimeUnit::mL_Per_min);
hemorrhageLeg.GetRate().SetValue(150,VolumePerTimeUnit::mL_Per_min);
pe->ProcessAction(hemorrhageLeg);
STOP = true;
......@@ -218,7 +218,7 @@ void Simulation(const string patient_name)
monitor.update(pe);
controller.update(pe);
pumps["saline"]->update(pe);
//pumps["bpdrug"]->update(pe);
pumps["bpdrug"]->update(pe);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment