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
Show whitespace changes
Inline
Side-by-side
simsrc/mcps2018/algo1/SimEngine.cpp
View file @
b71d6106
...
...
@@ -53,8 +53,8 @@ using namespace libconfig;
int
main
(
int
argc
,
const
char
*
argv
[]){
if
(
argc
<
2
)
{
cout
<<
"Error: must provide a configuration file"
;
cout
<<
"Usage: ./clasim configfile"
;
cout
<<
"Error: must provide a configuration file
\n
"
;
cout
<<
"Usage: ./clasim configfile
\n
"
;
}
else
{
...
...
@@ -63,14 +63,30 @@ int main(int argc, const char * argv[]){
auto
cf
=
std
::
make_shared
<
Config
>
();
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
)
{
// start timer
t1
=
clock
();
//Simulation input : Name of patient
Simulation
(
patient
);
Simulation
(
patient
,
cf
);
//stop timer
t2
=
clock
();
...
...
@@ -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
...
...
@@ -113,19 +129,12 @@ void Simulation(const string patient_name)
const
double
initialMAP
=
70.0
;
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
CMD
::
Environment
sim_env
;
PhysiologyData
data
;
// load simulation environment
Global_LoadConfig
(
pe
,
cf
g
,
fname
,
&
sim_env
);
Global_LoadConfig
(
pe
,
cf
,
&
sim_env
);
// List of pumps
map
<
string
,
Pump
*>
pumps
;
...
...
@@ -232,15 +241,15 @@ void Simulation(const string patient_name)
}
// 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
{
cf
->
readFile
(
file_path
);
// Read configration file
}
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
)
{
...
...
@@ -248,9 +257,32 @@ void Global_LoadConfig(std::unique_ptr<PhysiologyEngine>& engine, const std::sha
<<
" - "
<<
pex
.
getError
()
<<
std
::
endl
;
}
/* get the simulation run time */
try
{
env
->
simulation_time
=
cf
->
lookup
(
"simulation.time.run"
);
}
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
->
engine_timestep
=
engine
->
GetTimeStep
(
TimeUnit
::
s
);
...
...
@@ -265,26 +297,10 @@ void Global_LoadConfig(std::unique_ptr<PhysiologyEngine>& engine, const std::sha
}
// 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
;
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
{
Setting
&
names
=
cf
->
lookup
(
"simulation.patients.names"
);
...
...
@@ -301,7 +317,7 @@ vector<string> get_global_patients(const char* filepath,const std::shared_ptr<Co
}
catch
(
const
SettingNotFoundException
)
{
cout
<<
"Setting Not Found"
<<
endl
;
cout
<<
"Setting Not Found
: simulation.patients.names
"
<<
endl
;
}
return
patients
;
...
...
simsrc/mcps2018/algo2/SimEngine.cpp
View file @
b71d6106
...
...
@@ -53,8 +53,8 @@ using namespace libconfig;
int
main
(
int
argc
,
const
char
*
argv
[]){
if
(
argc
<
2
)
{
cout
<<
"Error: must provide a configuration file"
;
cout
<<
"Usage: ./clasim configfile"
;
cout
<<
"Error: must provide a configuration file
\n
"
;
cout
<<
"Usage: ./clasim configfile
\n
"
;
}
else
{
...
...
simsrc/mcps2018/scenario.cfg
View file @
b71d6106
...
...
@@ -4,14 +4,12 @@
## rate : Number of samples per second ## MAX: 50.0 Hz ## Type: double
monitor = {
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
};
controller = {
rate = 0.01;
patientData = {
enabled = ["HeartRate", "BloodPressure", "BloodVolume"];
...
...
@@ -24,16 +22,14 @@ controller = {
pump = {
rate = 1.0; # Intercommand delay -> to be used later
delay = 15.0;
};
simulation = {
patients = {
names = ["
Soldier", "Jeff", "Gus
"];
names = ["
Hassan", "Gus", "ExtremeFemale
"];
}
time = {
run = 3600.0; # Time -> Seconds # How long should simulation run
...
...
@@ -41,5 +37,4 @@ simulation = {
injury_stop = 700.0; # When should injury be stopped
}
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