csv parse update
This commit is contained in:
12
@miSim/initializeFromCsv.m
Normal file
12
@miSim/initializeFromCsv.m
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
function obj = initializeFromCsv(obj, csvPath)
|
||||||
|
arguments (Input)
|
||||||
|
obj (1, 1) {mustBeA(obj, 'miSim')};
|
||||||
|
csvPath (1, 1) string;
|
||||||
|
end
|
||||||
|
arguments (Output)
|
||||||
|
obj (1, 1) {mustBeA(obj, 'miSim')};
|
||||||
|
end
|
||||||
|
|
||||||
|
params = obj.readScenarioCsv(tc.csvPath);
|
||||||
|
|
||||||
|
end
|
||||||
@@ -64,6 +64,7 @@ classdef miSim
|
|||||||
obj.agents = {agent};
|
obj.agents = {agent};
|
||||||
end
|
end
|
||||||
[obj] = initialize(obj, domain, agents, barrierGain, barrierExponent, minAlt, timestep, maxIter, obstacles, makePlots, makeVideo);
|
[obj] = initialize(obj, domain, agents, barrierGain, barrierExponent, minAlt, timestep, maxIter, obstacles, makePlots, makeVideo);
|
||||||
|
[obj] = initializeFromCsv(obj, csvPath);
|
||||||
[obj] = run(obj);
|
[obj] = run(obj);
|
||||||
[obj] = lesserNeighbor(obj);
|
[obj] = lesserNeighbor(obj);
|
||||||
[obj] = constrainMotion(obj);
|
[obj] = constrainMotion(obj);
|
||||||
@@ -77,6 +78,7 @@ classdef miSim
|
|||||||
[obj] = plotH(obj);
|
[obj] = plotH(obj);
|
||||||
[obj] = updatePlots(obj);
|
[obj] = updatePlots(obj);
|
||||||
[obj] = teardown(obj);
|
[obj] = teardown(obj);
|
||||||
|
inits = readScenarioCsv(csvPath);
|
||||||
writeInits(obj);
|
writeInits(obj);
|
||||||
validate(obj);
|
validate(obj);
|
||||||
end
|
end
|
||||||
|
|||||||
34
@miSim/readScenarioCsv.m
Normal file
34
@miSim/readScenarioCsv.m
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
function scenario = readScenarioCsv(obj, csvPath)
|
||||||
|
arguments (Input)
|
||||||
|
obj (1, 1) {mustBeA(obj, 'miSim')};
|
||||||
|
csvPath (1, 1) string;
|
||||||
|
end
|
||||||
|
arguments (Output)
|
||||||
|
scenario struct;
|
||||||
|
end
|
||||||
|
|
||||||
|
% File input validation
|
||||||
|
assert(isfile(csvPath), "%s is not a valid filepath.");
|
||||||
|
assert(endsWith(csvPath, ".csv"), "%s is not a CSV file.");
|
||||||
|
|
||||||
|
% Read file
|
||||||
|
csv = readtable(csvPath, "TextType", "String", "NumHeaderLines", 0, "VariableNamingRule", "Preserve");
|
||||||
|
csv.Properties.VariableNames = ["timestep", "maxIter", "minAlt", "discretizationStep", "protectedRange", "sensorPerformanceMinimum", "initialStepSize", "barrierGain", "barrierExponent", "numObstacles", "numAgents", "collisionRadius", "comRange", "alphaDist", "betaDist", "alphaTilt", "betaTilt"];
|
||||||
|
|
||||||
|
for ii = 1:size(csv.Properties.VariableNames, 2)
|
||||||
|
csv.(csv.Properties.VariableNames{ii}) = cell2mat(cellfun(@(x) str2num(x), csv.(csv.Properties.VariableNames{ii}), "UniformOutput", false));
|
||||||
|
end
|
||||||
|
|
||||||
|
% Put params into standard structure
|
||||||
|
scenario = struct("timestep", csv.timestep, "maxIter", csv.maxIter, "minAlt", csv.minAlt, "discretizationStep", csv.discretizationStep, ...
|
||||||
|
"protectedRange", csv.protectedRange, "sensorPerformanceMinimum", csv.sensorPerformanceMinimum, "initialStepSize", csv.initialStepSize, ...
|
||||||
|
"barrierGain", csv.barrierGain, "barrierExponent", csv.barrierExponent, "numObstacles", csv.numObstacles,...
|
||||||
|
"numAgents", csv.numAgents, "collisionRadius", csv.collisionRadius, "comRange", csv.comRange, "alphaDist", csv.alphaDist, ...
|
||||||
|
"betaDist", csv.betaDist, "alphaTilt", csv.alphaTilt, "betaTilt", csv.betaTilt);
|
||||||
|
|
||||||
|
% size check
|
||||||
|
fns = fieldnames(scenario);
|
||||||
|
for ii = 2:size(fns, 1)
|
||||||
|
assert(size(scenario.(fns{ii}), 1) == size(scenario.(fns{ii - 1}), 1), "Mismatched number of rows in scenario definition CSV");
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -83,6 +83,11 @@
|
|||||||
<Size type="coderapp.internal.codertype.Dimension"/>
|
<Size type="coderapp.internal.codertype.Dimension"/>
|
||||||
<Size type="coderapp.internal.codertype.Dimension"/>
|
<Size type="coderapp.internal.codertype.Dimension"/>
|
||||||
</Types>
|
</Types>
|
||||||
|
<Types id="17" type="coderapp.internal.codertype.PrimitiveType">
|
||||||
|
<ClassName>int32</ClassName>
|
||||||
|
<Size type="coderapp.internal.codertype.Dimension"/>
|
||||||
|
<Size type="coderapp.internal.codertype.Dimension"/>
|
||||||
|
</Types>
|
||||||
</Types>
|
</Types>
|
||||||
</coderapp.internal.interface.project.Interface>
|
</coderapp.internal.interface.project.Interface>
|
||||||
</MF0>
|
</MF0>
|
||||||
@@ -1074,7 +1079,7 @@
|
|||||||
</Artifacts>
|
</Artifacts>
|
||||||
<BuildFolder type="coderapp.internal.util.mfz.FileSpec"/>
|
<BuildFolder type="coderapp.internal.util.mfz.FileSpec"/>
|
||||||
<Success>true</Success>
|
<Success>true</Success>
|
||||||
<Timestamp>2026-02-24T18:31:43</Timestamp>
|
<Timestamp>2026-02-25T11:42:50</Timestamp>
|
||||||
</MainBuildResult>
|
</MainBuildResult>
|
||||||
</coderapp.internal.mlc.mfz.MatlabCoderProjectState>
|
</coderapp.internal.mlc.mfz.MatlabCoderProjectState>
|
||||||
</MF0>
|
</MF0>
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Info>
|
||||||
|
<Category UUID="FileClassCategory">
|
||||||
|
<Label UUID="design"/>
|
||||||
|
</Category>
|
||||||
|
</Info>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Info location="readScenarioCsv.m" type="File"/>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Info>
|
||||||
|
<Category UUID="FileClassCategory">
|
||||||
|
<Label UUID="design"/>
|
||||||
|
</Category>
|
||||||
|
</Info>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Info location="initializeFromCsv.m" type="File"/>
|
||||||
@@ -25,41 +25,11 @@ classdef parametricTestSuite < matlab.unittest.TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
methods (Static)
|
|
||||||
function params = readIterationsCsv(csvPath)
|
|
||||||
arguments (Input)
|
|
||||||
csvPath (1, 1) string;
|
|
||||||
end
|
|
||||||
arguments (Output)
|
|
||||||
params (1, 1) struct;
|
|
||||||
end
|
|
||||||
|
|
||||||
% File input validation
|
|
||||||
assert(isfile(csvPath), "%s is not a valid filepath.");
|
|
||||||
assert(endsWith(csvPath, ".csv"), "%s is not a CSV file.");
|
|
||||||
|
|
||||||
% Read file
|
|
||||||
csv = readtable(csvPath, "TextType", "String", "NumHeaderLines", 0, "VariableNamingRule", "Preserve");
|
|
||||||
csv.Properties.VariableNames = ["timestep", "maxIter", "minAlt", "discretizationStep", "protectedRange", "sensorPerformanceMinimum", "initialStepSize", "barrierGain", "barrierExponent", "numObstacles", "numAgents", "collisionRadius", "comRange", "alphaDist", "betaDist", "alphaTilt", "betaTilt"];
|
|
||||||
|
|
||||||
for ii = 1:size(csv.Properties.VariableNames, 2)
|
|
||||||
csv.(csv.Properties.VariableNames{ii}) = cell2mat(cellfun(@(x) str2num(x), csv.(csv.Properties.VariableNames{ii}), "UniformOutput", false));
|
|
||||||
end
|
|
||||||
|
|
||||||
% Put params into standard structure
|
|
||||||
params = struct("timestep", csv.timestep, "maxIter", csv.maxIter, "minAlt", csv.minAlt, "discretizationStep", csv.discretizationStep, ...
|
|
||||||
"protectedRange", csv.protectedRange, "sensorPerformanceMinimum", csv.sensorPerformanceMinimum, "initialStepSize", csv.initialStepSize, ...
|
|
||||||
"barrierGain", csv.barrierGain, "barrierExponent", csv.barrierExponent, "numObstacles", csv.numObstacles,...
|
|
||||||
"numAgents", csv.numAgents, "collisionRadius", csv.collisionRadius, "comRange", csv.comRange, "alphaDist", csv.alphaDist, ...
|
|
||||||
"betaDist", csv.betaDist, "alphaTilt", csv.alphaTilt, "betaTilt", csv.betaTilt);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
methods (Test)
|
methods (Test)
|
||||||
% Test cases
|
% Test cases
|
||||||
function csv_parametric_tests(tc)
|
function csv_parametric_tests_random_agents(tc)
|
||||||
% Read in parameters to iterate over
|
% Read in parameters to iterate over
|
||||||
params = tc.readIterationsCsv(tc.csvPath);
|
params = tc.testClass.readScenarioCsv(tc.csvPath);
|
||||||
|
|
||||||
% Test case setup
|
% Test case setup
|
||||||
l = 10; % domain size
|
l = 10; % domain size
|
||||||
|
|||||||
Reference in New Issue
Block a user