Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fmg005
clasim
Commits
b71d6106
Commit
b71d6106
authored
Mar 14, 2018
by
pkda001
Browse files
removing hardcoded configuration paths
parent
1d240ae4
Changes
3
Hide whitespace changes
Inline
Side-by-side
simsrc/mcps2018/algo1/SimEngine.cpp
View file @
b71d6106
...
@@ -53,8 +53,8 @@ using namespace libconfig;
...
@@ -53,8 +53,8 @@ using namespace libconfig;
int
main
(
int
argc
,
const
char
*
argv
[]){
int
main
(
int
argc
,
const
char
*
argv
[]){
if
(
argc
<
2
)
if
(
argc
<
2
)
{
{
cout
<<
"Error: must provide a configuration file"
;
cout
<<
"Error: must provide a configuration file
\n
"
;
cout
<<
"Usage: ./clasim configfile"
;
cout
<<
"Usage: ./clasim configfile
\n
"
;
}
}
else
else
{
{
...
@@ -63,14 +63,30 @@ int main(int argc, const char * argv[]){
...
@@ -63,14 +63,30 @@ int main(int argc, const char * argv[]){
auto
cf
=
std
::
make_shared
<
Config
>
();
auto
cf
=
std
::
make_shared
<
Config
>
();
float
sim_time_secs
,
sim_time_mins
;
float
sim_time_secs
,
sim_time_mins
;
patients_list
=
get_global_patients
(
argv
[
1
],
cf
);
try
{
cf
->
readFile
(
argv
[
1
]);
}
catch
(
const
FileIOException
&
fioex
)
{
std
::
cerr
<<
"I/O error while reading file: "
<<
filepath
<<
std
::
endl
;
//return(EXIT_FAILURE);
}
catch
(
const
ParseException
&
pex
)
{
std
::
cerr
<<
"Parse error at "
<<
pex
.
getFile
()
<<
":"
<<
pex
.
getLine
()
<<
" - "
<<
pex
.
getError
()
<<
std
::
endl
;
//return(EXIT_FAILURE);
}
patients_list
=
get_global_patients
(
cf
);
for
(
auto
patient
:
patients_list
)
{
for
(
auto
patient
:
patients_list
)
{
// start timer
// start timer
t1
=
clock
();
t1
=
clock
();
//Simulation input : Name of patient
//Simulation input : Name of patient
Simulation
(
patient
);
Simulation
(
patient
,
cf
);
//stop timer
//stop timer
t2
=
clock
();
t2
=
clock
();
...
@@ -86,7 +102,7 @@ int main(int argc, const char * argv[]){
...
@@ -86,7 +102,7 @@ int main(int argc, const char * argv[]){
}
}
}
}
void
Simulation
(
const
string
patient_name
)
void
Simulation
(
const
string
patient_name
,
const
std
::
shared_ptr
<
Config
>&
cf
)
{
{
// Create the engine and load the patient
// Create the engine and load the patient
...
@@ -113,19 +129,12 @@ void Simulation(const string patient_name)
...
@@ -113,19 +129,12 @@ void Simulation(const string patient_name)
const
double
initialMAP
=
70.0
;
const
double
initialMAP
=
70.0
;
double
currentMAP
;
double
currentMAP
;
// Configuration file path
// Note: Path is relative to the bin folder not src folder
const
char
*
fname
=
"./config/simulation_scenario.cfg"
;
// Configuration object
auto
cfg
=
std
::
make_shared
<
Config
>
();
//instatiate enviroment object
//instatiate enviroment object
CMD
::
Environment
sim_env
;
CMD
::
Environment
sim_env
;
PhysiologyData
data
;
PhysiologyData
data
;
// load simulation environment
// load simulation environment
Global_LoadConfig
(
pe
,
cf
g
,
fname
,
&
sim_env
);
Global_LoadConfig
(
pe
,
cf
,
&
sim_env
);
// List of pumps
// List of pumps
map
<
string
,
Pump
*>
pumps
;
map
<
string
,
Pump
*>
pumps
;
...
@@ -232,15 +241,15 @@ void Simulation(const string patient_name)
...
@@ -232,15 +241,15 @@ void Simulation(const string patient_name)
}
// End Simulation function
}
// End Simulation function
void
Global_LoadConfig
(
std
::
unique_ptr
<
PhysiologyEngine
>&
engine
,
const
std
::
shared_ptr
<
Config
>&
cf
,
const
char
*
file_path
,
CMD
::
Environment
*
env
)
{
void
Global_LoadConfig
(
std
::
unique_ptr
<
PhysiologyEngine
>&
engine
,
const
std
::
shared_ptr
<
Config
>&
cf
,
CMD
::
Environment
*
env
)
{
/* read the configuration file */
try
try
{
{
cf
->
readFile
(
file_path
);
// Read configration file
cf
->
readFile
(
file_path
);
// Read configration file
}
}
catch
(
const
FileIOException
&
fioex
)
catch
(
const
FileIOException
&
fioex
)
{
{
std
::
cerr
<<
"I/O error while reading file."
<<
std
::
endl
;
std
::
cerr
<<
"I/O error while reading file."
<<
file_path
<<
std
::
endl
;
}
}
catch
(
const
ParseException
&
pex
)
catch
(
const
ParseException
&
pex
)
{
{
...
@@ -248,9 +257,32 @@ void Global_LoadConfig(std::unique_ptr<PhysiologyEngine>& engine, const std::sha
...
@@ -248,9 +257,32 @@ void Global_LoadConfig(std::unique_ptr<PhysiologyEngine>& engine, const std::sha
<<
" - "
<<
pex
.
getError
()
<<
std
::
endl
;
<<
" - "
<<
pex
.
getError
()
<<
std
::
endl
;
}
}
/* get the simulation run time */
try
{
env
->
simulation_time
=
cf
->
lookup
(
"simulation.time.run"
);
env
->
simulation_time
=
cf
->
lookup
(
"simulation.time.run"
);
env
->
simulation_injury_start
=
cf
->
lookup
(
"simulation.time.injury_start"
);
}
env
->
simulation_injury_stop
=
cf
->
lookup
(
"simulation.time.injury_stop"
);
catch
(
const
SettingNotFoundException
)
{
cout
<<
"Setting Not Found: simulation.time.run"
<<
endl
;
}
/* get the injury start time */
try
{
env
->
simulation_injury_start
=
cf
->
lookup
(
"simulation.time.injury_start"
);
}
catch
(
const
SettingNotFoundException
)
{
cout
<<
"Setting Not Found: simulation.time.injury_start"
<<
endl
;
}
/* get the injury stop time */
try
{
env
->
simulation_injury_stop
=
cf
->
lookup
(
"simulation.time.injury_stop"
);
}
catch
(
const
SettingNotFoundException
)
{
cout
<<
"Setting Not Found: simulation.time.injury_stop"
<<
endl
;
}
env
->
time_index
=
0
;
// initialize the time index
env
->
time_index
=
0
;
// initialize the time index
env
->
engine_timestep
=
engine
->
GetTimeStep
(
TimeUnit
::
s
);
env
->
engine_timestep
=
engine
->
GetTimeStep
(
TimeUnit
::
s
);
...
@@ -265,26 +297,10 @@ void Global_LoadConfig(std::unique_ptr<PhysiologyEngine>& engine, const std::sha
...
@@ -265,26 +297,10 @@ void Global_LoadConfig(std::unique_ptr<PhysiologyEngine>& engine, const std::sha
}
// End Global_LoadConfig
}
// End Global_LoadConfig
vector
<
string
>
get_global_patients
(
const
char
*
filepath
,
const
std
::
shared_ptr
<
Config
>&
cf
){
vector
<
string
>
get_global_patients
(
const
std
::
shared_ptr
<
Config
>&
cf
){
vector
<
string
>
patients
;
vector
<
string
>
patients
;
try
{
cf
->
readFile
(
filepath
);
}
catch
(
const
FileIOException
&
fioex
)
{
std
::
cerr
<<
"I/O error while reading file."
<<
std
::
endl
;
//return(EXIT_FAILURE);
}
catch
(
const
ParseException
&
pex
)
{
std
::
cerr
<<
"Parse error at "
<<
pex
.
getFile
()
<<
":"
<<
pex
.
getLine
()
<<
" - "
<<
pex
.
getError
()
<<
std
::
endl
;
//return(EXIT_FAILURE);
}
try
{
try
{
Setting
&
names
=
cf
->
lookup
(
"simulation.patients.names"
);
Setting
&
names
=
cf
->
lookup
(
"simulation.patients.names"
);
...
@@ -301,7 +317,7 @@ vector<string> get_global_patients(const char* filepath,const std::shared_ptr<Co
...
@@ -301,7 +317,7 @@ vector<string> get_global_patients(const char* filepath,const std::shared_ptr<Co
}
}
catch
(
const
SettingNotFoundException
)
{
catch
(
const
SettingNotFoundException
)
{
cout
<<
"Setting Not Found"
<<
endl
;
cout
<<
"Setting Not Found
: simulation.patients.names
"
<<
endl
;
}
}
return
patients
;
return
patients
;
...
...
simsrc/mcps2018/algo2/SimEngine.cpp
View file @
b71d6106
...
@@ -53,8 +53,8 @@ using namespace libconfig;
...
@@ -53,8 +53,8 @@ using namespace libconfig;
int
main
(
int
argc
,
const
char
*
argv
[]){
int
main
(
int
argc
,
const
char
*
argv
[]){
if
(
argc
<
2
)
if
(
argc
<
2
)
{
{
cout
<<
"Error: must provide a configuration file"
;
cout
<<
"Error: must provide a configuration file
\n
"
;
cout
<<
"Usage: ./clasim configfile"
;
cout
<<
"Usage: ./clasim configfile
\n
"
;
}
}
else
else
{
{
...
...
simsrc/mcps2018/scenario.cfg
View file @
b71d6106
...
@@ -4,15 +4,13 @@
...
@@ -4,15 +4,13 @@
## rate : Number of samples per second ## MAX: 50.0 Hz ## Type: double
## rate : Number of samples per second ## MAX: 50.0 Hz ## Type: double
monitor = {
monitor = {
input_rate = 0.02; ## MUST be multiple of 50.0
input_rate = 0.02; ## MUST be multiple of 50.0
output_rate = 0.01; ## Must be less than monitor.rate and also multiple of 50.0
output_rate = 0.01; ## Must be less than monitor.rate and also multiple of 50.0
};
};
controller = {
controller = {
rate = 0.01;
rate = 0.01;
patientData = {
patientData = {
enabled = ["HeartRate", "BloodPressure", "BloodVolume"];
enabled = ["HeartRate", "BloodPressure", "BloodVolume"];
}
}
...
@@ -24,22 +22,19 @@ controller = {
...
@@ -24,22 +22,19 @@ controller = {
pump = {
pump = {
rate = 1.0; # Intercommand delay -> to be used later
rate = 1.0; # Intercommand delay -> to be used later
delay = 15.0;
delay = 15.0;
};
};
simulation = {
simulation = {
patients = {
patients = {
names = ["
Soldier", "Jeff", "Gus
"];
names = ["
Hassan", "Gus", "ExtremeFemale
"];
}
}
time = {
time = {
run = 3600.0; # Time -> Seconds # How long should simulation run
run = 3600.0; # Time -> Seconds # How long should simulation run
injury_start = 50.0; # When should injury be introduced to patient
injury_start = 50.0; # When should injury be introduced to patient
injury_stop = 700.0; # When should injury be stopped
injury_stop = 700.0; # When should injury be stopped
}
}
path = "results"; # folder to store out sim output files -> to be used later
path = "results"; # folder to store out sim output files -> to be used later
};
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment