added early exit from main loop for semistable final states

This commit is contained in:
2025-11-24 23:34:43 -08:00
parent a8380985e1
commit 59805dff72
4 changed files with 30 additions and 7 deletions

View File

@@ -14,6 +14,9 @@ classdef miSim
sensorPerformanceMinimum = 1e-6; % minimum sensor performance to allow assignment of a point in the domain to a partition
partitioning = NaN;
performance = NaN; % current cumulative sensor performance
oldMeanTotalPerf = 0;
fPerf; % performance plot figure
end
properties (Access = private)
@@ -29,7 +32,6 @@ classdef miSim
graphPlot; % objects for abstract network graph plot
partitionPlot; % objects for partition plot
fPerf; % performance plot figure
performancePlot; % objects for sensor performance plot
% Indicies for various plot types in the main tiled layout figure

View File

@@ -10,6 +10,7 @@ function [obj] = run(obj)
v = obj.setupVideoWriter();
v.open();
steady = 0;
for ii = 1:size(obj.times, 1)
% Display current sim time
obj.t = obj.times(ii);
@@ -18,6 +19,19 @@ function [obj] = run(obj)
% Check if it's time for new partitions
updatePartitions = false;
if ismember(obj.t, obj.partitioningTimes)
% Check if it's time to end the sim (performance has settled)
if obj.t >= obj.partitioningTimes(5)
idx = find(obj.t == obj.partitioningTimes);
newMeanTotalPerf = mean(obj.perf(end, ((idx - 5 + 1):idx)));
if (obj.oldMeanTotalPerf * 0.95 <= newMeanTotalPerf) && (newMeanTotalPerf <= max(1e-6, obj.oldMeanTotalPerf * 1.05))
steady = steady + 1;
if steady >= 3
fprintf("Performance is stable, terminating early at %4.2f (%d/%d)\n", obj.t, ii, obj.maxIter + 1);
break; % performance is not improving further, exit main sim loop
end
end
obj.oldMeanTotalPerf = newMeanTotalPerf;
end
updatePartitions = true;
obj = obj.partition();
end