diff --git a/@miSim/initialize.m b/@miSim/initialize.m index 056136b..b6568d9 100644 --- a/@miSim/initialize.m +++ b/@miSim/initialize.m @@ -1,4 +1,4 @@ -function obj = initialize(obj, domain, objective, agents, timestep, partitoningFreq, maxIter, obstacles) +function obj = initialize(obj, domain, objective, agents, timestep, partitoningFreq, maxIter, obstacles, makeVideo) arguments (Input) obj (1, 1) {mustBeA(obj, 'miSim')}; domain (1, 1) {mustBeGeometry}; @@ -8,11 +8,15 @@ function obj = initialize(obj, domain, objective, agents, timestep, partitoningF partitoningFreq (:, 1) double = 0.25 maxIter (:, 1) double = 1000; obstacles (:, 1) cell {mustBeGeometry} = cell(0, 1); + makeVideo (1, 1) logical = true; end arguments (Output) obj (1, 1) {mustBeA(obj, 'miSim')}; end + % enable/disable video writer + obj.makeVideo = makeVideo; + % Define simulation time parameters obj.timestep = timestep; obj.maxIter = maxIter - 1; diff --git a/@miSim/miSim.m b/@miSim/miSim.m index 4742c84..2fe9a25 100644 --- a/@miSim/miSim.m +++ b/@miSim/miSim.m @@ -27,6 +27,7 @@ classdef miSim partitioningTimes; % Plot objects + makeVideo = true; % enable/disable VideoWriter (performance implications) f = firstPlotSetup(); % main plotting tiled layout figure connectionsPlot; % objects for lines connecting agents in spatial plots graphPlot; % objects for abstract network graph plot diff --git a/@miSim/run.m b/@miSim/run.m index 391057d..bf027d9 100644 --- a/@miSim/run.m +++ b/@miSim/run.m @@ -7,8 +7,10 @@ function [obj] = run(obj) end % Start video writer - v = obj.setupVideoWriter(); - v.open(); + if obj.makeVideo + v = obj.setupVideoWriter(); + v.open(); + end for ii = 1:size(obj.times, 1) % Display current sim time @@ -41,10 +43,14 @@ function [obj] = run(obj) obj = obj.updatePlots(updatePartitions); % Write frame in to video - I = getframe(obj.f); - v.writeVideo(I); + if obj.makeVideo + I = getframe(obj.f); + v.writeVideo(I); + end end - % Close video file - v.close(); + if obj.makeVideo + % Close video file + v.close(); + end end diff --git a/test/test_miSim.m b/test/test_miSim.m index 65bff46..594b383 100644 --- a/test/test_miSim.m +++ b/test/test_miSim.m @@ -3,6 +3,9 @@ classdef test_miSim < matlab.unittest.TestCase % System under test testClass = miSim; + % Debug + makeVideo = false; % disable video writing for big performance increase + % Sim maxIter = 250; timestep = 0.05 @@ -204,7 +207,7 @@ classdef test_miSim < matlab.unittest.TestCase end % Initialize the simulation - tc.testClass = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.timestep, tc.partitoningFreq, tc.maxIter, tc.obstacles); + tc.testClass = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.timestep, tc.partitoningFreq, tc.maxIter, tc.obstacles, tc.makeVideo); end function misim_run(tc) % randomly create obstacles @@ -338,7 +341,7 @@ classdef test_miSim < matlab.unittest.TestCase end % Initialize the simulation - tc.testClass = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.timestep, tc.partitoningFreq, tc.maxIter, tc.obstacles); + tc.testClass = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.timestep, tc.partitoningFreq, tc.maxIter, tc.obstacles, tc.makeVideo); % Run simulation loop tc.testClass = tc.testClass.run(); @@ -382,7 +385,7 @@ classdef test_miSim < matlab.unittest.TestCase tc.agents{3} = tc.agents{3}.initialize(tc.domain.center + dh - [0, d, 0], zeros(1, 3), 0, 0, geometry3, sensor, @gradientAscent, 3*d, 3, sprintf("Agent %d", 3)); % Initialize the simulation - tc.testClass = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.timestep, tc.partitoningFreq, tc.maxIter); + tc.testClass = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.timestep, tc.partitoningFreq, tc.maxIter, tc.makeVideo); close(tc.testClass.fPerf); end function test_single_partition(tc) @@ -412,7 +415,7 @@ classdef test_miSim < matlab.unittest.TestCase tc.agents{1} = tc.agents{1}.initialize([tc.domain.center(1:2), 3], zeros(1,3), 0, 0, geometry1, sensor, @gradientAscent, 3, 1, sprintf("Agent %d", 1)); % Initialize the simulation - tc.testClass = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.timestep, tc.partitoningFreq, tc.maxIter); + tc.testClass = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.timestep, tc.partitoningFreq, tc.maxIter, tc.makeVideo); close(tc.testClass.fPerf); end function test_single_partition_basic_GA(tc) @@ -442,7 +445,7 @@ classdef test_miSim < matlab.unittest.TestCase tc.agents{1} = tc.agents{1}.initialize([tc.domain.center(1:2)-tc.domain.dimensions(1)/3, 3], zeros(1,3), 0, 0, geometry1, sensor, @gradientAscent, 3, 1, sprintf("Agent %d", 1), true); % Initialize the simulation - tc.testClass = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.timestep, tc.partitoningFreq, tc.maxIter); + tc.testClass = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.timestep, tc.partitoningFreq, tc.maxIter, tc.makeVideo); % Run the simulation tc.testClass.run(); @@ -482,7 +485,7 @@ classdef test_miSim < matlab.unittest.TestCase tc.agents{2} = tc.agents{2}.initialize(tc.domain.center - d, zeros(1,3), 0, 0, geometry2, sensor, @gradientAscent, 3, 2, sprintf("Agent %d", 2)); % Initialize the simulation - tc.testClass = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.timestep, tc.partitoningFreq, tc.maxIter); + tc.testClass = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.timestep, tc.partitoningFreq, tc.maxIter, tc.makeVideo); % Run the simulation tc.testClass.run();