From 1d11ac4e90cdd2a30d8a8b0730ec969244bdc2a1 Mon Sep 17 00:00:00 2001 From: krdee1 Date: Wed, 24 Dec 2025 16:20:57 -0800 Subject: [PATCH] made no plotting flag for better performance and unit testing --- @miSim/initialize.m | 14 +++++++++++--- @miSim/miSim.m | 3 ++- @miSim/plot.m | 5 +++++ @miSim/plotPerformance.m | 7 +++++++ @miSim/updatePlots.m | 5 +++++ test/test_miSim.m | 6 +++--- 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/@miSim/initialize.m b/@miSim/initialize.m index c4366ea..9a27236 100644 --- a/@miSim/initialize.m +++ b/@miSim/initialize.m @@ -1,4 +1,4 @@ -function obj = initialize(obj, domain, objective, agents, minAlt, timestep, partitoningFreq, maxIter, obstacles, makeVideo) +function obj = initialize(obj, domain, objective, agents, minAlt, timestep, partitoningFreq, maxIter, obstacles, makePlots, makeVideo) arguments (Input) obj (1, 1) {mustBeA(obj, 'miSim')}; domain (1, 1) {mustBeGeometry}; @@ -9,14 +9,23 @@ function obj = initialize(obj, domain, objective, agents, minAlt, timestep, part partitoningFreq (:, 1) double = 0.25 maxIter (:, 1) double = 1000; obstacles (:, 1) cell {mustBeGeometry} = cell(0, 1); + makePlots(1, 1) logical = true; makeVideo (1, 1) logical = true; end arguments (Output) obj (1, 1) {mustBeA(obj, 'miSim')}; end - % enable/disable video writer + % enable/disable plotting and video writer + obj.makePlots = makePlots; + if ~obj.makePlots + if makeVideo + warning("makeVideo set to true, but makePlots set to false. Setting makeVideo to false."); + makeVideo = false; + end + end obj.makeVideo = makeVideo; + % Define simulation time parameters obj.timestep = timestep; @@ -51,7 +60,6 @@ function obj = initialize(obj, domain, objective, agents, minAlt, timestep, part obj.partitioningTimes = obj.times(obj.partitioningFreq:obj.partitioningFreq:size(obj.times, 1)); % Prepare performance data store (at t = 0, all have 0 performance) - obj.fPerf = figure; obj.perf = [zeros(size(obj.agents, 1) + 1, 1), NaN(size(obj.agents, 1) + 1, size(obj.partitioningTimes, 1) - 1)]; % Create initial partitioning diff --git a/@miSim/miSim.m b/@miSim/miSim.m index d4bfa7d..3ebc020 100644 --- a/@miSim/miSim.m +++ b/@miSim/miSim.m @@ -28,8 +28,9 @@ classdef miSim partitioningTimes; % Plot objects + makePlots = true; % enable/disable simulation plotting (performance implications) makeVideo = true; % enable/disable VideoWriter (performance implications) - f = firstPlotSetup(); % main plotting tiled layout figure + f; % main plotting tiled layout figure connectionsPlot; % objects for lines connecting agents in spatial plots graphPlot; % objects for abstract network graph plot partitionPlot; % objects for partition plot diff --git a/@miSim/plot.m b/@miSim/plot.m index 88bebe8..1f93b16 100644 --- a/@miSim/plot.m +++ b/@miSim/plot.m @@ -5,6 +5,11 @@ function obj = plot(obj) arguments (Output) obj (1, 1) {mustBeA(obj, 'miSim')}; end + + % fast exit when plotting is disabled + if ~obj.makePlots + return; + end % Plot domain [obj.domain, obj.f] = obj.domain.plotWireframe(obj.spatialPlotIndices); diff --git a/@miSim/plotPerformance.m b/@miSim/plotPerformance.m index 27b6305..c5d77d6 100644 --- a/@miSim/plotPerformance.m +++ b/@miSim/plotPerformance.m @@ -6,6 +6,13 @@ function obj = plotPerformance(obj) obj (1, 1) {mustBeA(obj, 'miSim')}; end + % fast exit when plotting is disabled + if ~obj.makePlots + return; + end + + obj.fPerf = figure; + axes(obj.fPerf); title(obj.fPerf.Children(1), "Sensor Performance"); xlabel(obj.fPerf.Children(1), 'Time (s)'); diff --git a/@miSim/updatePlots.m b/@miSim/updatePlots.m index 5c07f32..8d25cf1 100644 --- a/@miSim/updatePlots.m +++ b/@miSim/updatePlots.m @@ -7,6 +7,11 @@ function [obj] = updatePlots(obj, updatePartitions) obj (1, 1) {mustBeA(obj, 'miSim')}; end + % Fast exit when plotting is disabled + if ~obj.makePlots + return; + end + % Update agent positions, collision geometries for ii = 1:size(obj.agents, 1) obj.agents{ii}.updatePlots(); diff --git a/test/test_miSim.m b/test/test_miSim.m index a3d3f77..77f2b0f 100644 --- a/test/test_miSim.m +++ b/test/test_miSim.m @@ -5,6 +5,7 @@ classdef test_miSim < matlab.unittest.TestCase % Debug makeVideo = true; % disable video writing for big performance increase + makePlots = true; % disable plotting for big performance increase (also disables video) % Sim maxIter = 250; @@ -528,7 +529,6 @@ classdef test_miSim < matlab.unittest.TestCase % Run the simulation tc.testClass.run(); end - function test_obstacle_blocks_comms_LOS(tc) % Fixed single obstacle % Fixed two agents initial conditions @@ -565,8 +565,8 @@ classdef test_miSim < matlab.unittest.TestCase tc.obstacles{1} = tc.obstacles{1}.initialize([tc.domain.center(1:2) - obstacleLength, 0; tc.domain.center(1:2) + obstacleLength, tc.domain.maxCorner(3)], REGION_TYPE.OBSTACLE, "Obstacle 1"); % Initialize the simulation - tc.testClass = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, 0, tc.timestep, tc.partitoningFreq, 125, tc.obstacles, tc.makeVideo); - + tc.testClass = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, 0, tc.timestep, tc.partitoningFreq, 125, tc.obstacles, false, false); + % No communications link should be established tc.assertEqual(tc.testClass.adjacency, logical(eye(2))); end