You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
multipleruns.lua
--- Save the results of MultipleRuns to a CSV file.
-- Each line represents the values in a different simulation.
-- The columns are each of the parameters passed to MultipleRuns
-- and the return values of all additional functions and parameters in the output table.
-- @arg name The name of the CSV file.
-- @arg separator The chosen separator to be used in the CSV file.
-- @Usage
-- import("calibration")
-- MyModel = Model{
-- x = Choice{-100, -1, 0, 1, 2, 100},
-- finalTime = 1,
-- init = function(self)
-- self.timer = Timer{
-- Event{action = function()
-- self.value = x
-- end}
-- }
-- end
-- }
--
-- m = MultipleRuns{
-- model = MyModel,
-- parameters = {scenario = {x = 2}},
-- repetition = 3,
-- }
--
-- -- Saves MultipleRuns results:
-- m:saveCSV("myCSVFile", ";")
saveCSV = function(self, name, separator)
mandatoryArgument(2, "string", separator)
mandatoryArgument(1, "string", name)
local CSVTable = {}
forEachOrderedElement(self, function(idx, att, typ)
if typ == "table" and idx ~= "parameters" then
local counter = 0
print(idx)
print(type(att))
forEachOrderedElement(att, function(_, att2, _)
counter = counter + 1
if CSVTable[counter] == nil then
CSVTable[counter] = {}
end
CSVTable[counter][idx] = att2
end)
end
end)
print(vardump(CSVTable))
local csvFile = File(name..".csv")
csvFile:write(CSVTable, separator)
end
}
The text was updated successfully, but these errors were encountered:
useful code:
basic test
saveCSV = function(unitTest)
MyModel = Model{
x = Choice{-100, -1, 0, 1, 2, 100},
finalTime = 1,
init = function(self)
self.timer = Timer{
Event{action = function()
self.value = x
end}
}
end
}
end,
multipleruns.lua
--- Save the results of MultipleRuns to a CSV file.
-- Each line represents the values in a different simulation.
-- The columns are each of the parameters passed to MultipleRuns
-- and the return values of all additional functions and parameters in the output table.
-- @arg name The name of the CSV file.
-- @arg separator The chosen separator to be used in the CSV file.
-- @Usage
-- import("calibration")
-- MyModel = Model{
-- x = Choice{-100, -1, 0, 1, 2, 100},
-- finalTime = 1,
-- init = function(self)
-- self.timer = Timer{
-- Event{action = function()
-- self.value = x
-- end}
-- }
-- end
-- }
--
-- m = MultipleRuns{
-- model = MyModel,
-- parameters = {scenario = {x = 2}},
-- repetition = 3,
-- }
--
-- -- Saves MultipleRuns results:
-- m:saveCSV("myCSVFile", ";")
saveCSV = function(self, name, separator)
mandatoryArgument(2, "string", separator)
mandatoryArgument(1, "string", name)
local CSVTable = {}
}
The text was updated successfully, but these errors were encountered: