sdLoadScenario: Loads a Scenario Object from External Files

Description Usage Arguments Details Value EXCEL Format Examples

Description

A factory function that creates a sdScenarioClass object from XML or EXCEL files. Uses the file extension to determine it's format.

Usage

1
2
3
4
5
6
sdLoadScenario(file, timeSeriesDirectory = "", stateSheet = "state",
  constantSheet = "constant", inputSheet = "input",
  parameterSheet = "parameter", switchSheet = "switch",
  simulationSheet = "simulation", variableCol = "Variable",
  valueCol = "Value", unitCol = "Unit", descriptionCol = "Description",
  interpolationCol = "Interpolation")

Arguments

file

A scenario file name in '.xlsx', '.xls' or '.xml' containing the format extension.

timeSeriesDirectory

The directory where time series inputs are stored (when passing the time series inputs via external files).

stateSheet

A character string with the name of the EXCEL sheet that contains the state variables. Default is 'state'. (Only used if the file is a '.xlsx' or '.xls').

constantSheet

A character string with the name of the EXCEL sheet that contains the constant variables. Default is 'constant'. (Only used if the file is a '.xlsx' or '.xls').

inputSheet

A character string with the name of the EXCEL sheet that contains the input variables. Default is 'input'. (Only used if the file is a '.xlsx' or '.xls').

parameterSheet

A character string with the name of the EXCEL sheet that contains the parameter variables. Default is 'parameter'. (Only used if the file is a '.xlsx' or '.xls').

switchSheet

A character string with the name of the EXCEL sheet that contains the switch variables. Default is 'switch'.(Only used if the file is a '.xlsx' or '.xls').

simulationSheet

A character string containing the name of the EXCEL sheet that contains the simulation configuration variables. Default is 'simulation'. (Only used if the file is a '.xlsx' or '.xls').

variableCol

A character string with the name of the column containing the variables names.

valueCol

A character string with the name of the column containing the variables values.

unitCol

A character string with the name of the column containing the variables units.

descriptionCol

A character string with the name of the column containing the variables descriptions.

interpolationCol

A character string with the name of the column containing the input time series variables interpolation method.

Details

Use the sdExcelTemplate function to create an empty template for a sdsim scenario EXCEL file.

Value

A sdScenarioClass object.

EXCEL Format

The EXCEL file representing a sdScenarioClass object must have one sheet per type of variable and a sheet for the simulation configurations, e.g. the stateSheet, constantSheet, inputSheet, parameterSheet, switchSheet and the simulationSheet. A sheet can be missing if the scenario do not have the corresponding type of variable.

Each sheet must follow this guidelines:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## Let's load a model from the repository, save it's default scenario in a 
# EXECEL file, change it and then reload it to use it in a different 
# simulation

## Load the Bouncing Ball Model from the sdsim repository
bb <- sdLoadModel(file = "BouncingBall", repository = TRUE)

# save the bouncing ball default scenario to an EXCEL file
bb$defaultScenario$saveToXlsx(file = "bb.xlsx")

## Let's edit the the EXCEL file to define a new scenario where we are 
# throwing a tennis ball  from our hand to the ground
# To represent this scenario we need to edit the following 4 sheets:
# In the 'state' sheet:
#  - change the value of the variable 'height' to 1.5
#  - change the value of the variable 'speed' to -10 (negative indicating the 
# ball direction, to the ground)
# In the 'input' sheet:
#  - change the value of the variable 'k' to 0.75 (the tennis ball 
# coefficient of restitution when kicking in a tennis field)
# In the 'simulation' sheet: 
#  - change the value of the variable 'to' to 8 (it will stop faster)
#  - change the value of the variable 'by' to 0.001 (more precision)
#  - change the value of the variable 'scenarioId' to 'TennisBallKicking'
# Remove the 'constant' sheet (we will use the default value)

## Save the modified EXCEL file and reload it
tennisBallScen <- sdLoadScenario(file = "bb.xlsx")

# Simulate the Bouncing Ball model with the new scenario and plot the result
outbbTennis <- sdSimulate(model = bb, scenario = tennisBallScen)
outbbTennis$plot()

EmbrapaInformaticaAgropecuaria/sdsim documentation built on May 10, 2019, 9:58 a.m.