diff --git a/@agent/run.m b/@agent/run.m index ade4055..3fc1a24 100644 --- a/@agent/run.m +++ b/@agent/run.m @@ -25,8 +25,8 @@ function obj = run(obj, domain, partitioning, t) S(partitionMask) = sensorValues; % Find agent's performance - C = S.* F; % try gradient on this directly - obj.performance = [obj.performance sum(C(~isnan(C)))]; + C = S.* F; + obj.performance = [obj.performance, sum(C(~isnan(C)))]; % Compute gradient on agent's performance [gradSensorPerformanceX, gradSensorPerformanceY] = gradient(S, domain.objective.discretizationStep); % grad S_n diff --git a/@miSim/miSim.m b/@miSim/miSim.m index 0724041..c69bac1 100644 --- a/@miSim/miSim.m +++ b/@miSim/miSim.m @@ -13,7 +13,7 @@ classdef miSim adjacency = NaN; % Adjacency matrix representing communications network graph 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 + performance = 0; % cumulative sensor performance fPerf; % performance plot figure end diff --git a/@miSim/partition.m b/@miSim/partition.m index d9e9115..c292264 100644 --- a/@miSim/partition.m +++ b/@miSim/partition.m @@ -24,18 +24,4 @@ function obj = partition(obj) [m, n, ~] = size(agentInds); [jj, kk] = ndgrid(1:m, 1:n); obj.partitioning = agentInds(sub2ind(size(agentInds), jj, kk, idx)); - - % Get individual agent sensor performance - nowIdx = [0; obj.partitioningTimes] == obj.t; - if isnan(obj.t) - nowIdx = 1; - end - for ii = 1:size(obj.agents, 1) - idx = obj.partitioning == ii; - agentPerformance = squeeze(agentPerformances(:, :, ii)); - obj.perf(ii, nowIdx) = sum(agentPerformance(idx) .* obj.objective.values(idx)); - end - - % Current total performance - obj.perf(end, nowIdx) = sum(obj.perf(1:(end - 1), nowIdx)); end \ No newline at end of file diff --git a/@miSim/plotPerformance.m b/@miSim/plotPerformance.m index 5a9c635..5dff115 100644 --- a/@miSim/plotPerformance.m +++ b/@miSim/plotPerformance.m @@ -15,12 +15,14 @@ function obj = plotPerformance(obj) % Plot current cumulative performance hold(obj.fPerf.Children(1), 'on'); o = plot(obj.fPerf.Children(1), obj.perf(end, :)); + o.XData = NaN(size(o.XData)); % correct time will be set at runtime hold(obj.fPerf.Children(1), 'off'); % Plot current agent performance for ii = 1:(size(obj.perf, 1) - 1) hold(obj.fPerf.Children(1), 'on'); o = [o; plot(obj.fPerf.Children(1), obj.perf(ii, :))]; + o(end).XData = NaN(size(o(end).XData)); % correct time will be set at runtime hold(obj.fPerf.Children(1), 'off'); end diff --git a/@miSim/run.m b/@miSim/run.m index 2d49312..2474b36 100644 --- a/@miSim/run.m +++ b/@miSim/run.m @@ -28,6 +28,9 @@ function [obj] = run(obj) obj.agents{jj} = obj.agents{jj}.run(obj.domain, obj.partitioning, obj.t); end + % Update total performance + obj.performance = [obj.performance, sum(cellfun(@(x) x.performance(end), obj.agents))]; + % Update adjacency matrix obj = obj.updateAdjacency(); diff --git a/@miSim/updatePlots.m b/@miSim/updatePlots.m index 0c64610..5c07f32 100644 --- a/@miSim/updatePlots.m +++ b/@miSim/updatePlots.m @@ -39,16 +39,12 @@ function [obj] = updatePlots(obj, updatePartitions) drawnow; % Update performance plot - if updatePartitions - % find index corresponding to the current time - nowIdx = [0; obj.partitioningTimes] == obj.t; - nowIdx = find(nowIdx); - - % Re-normalize performance plot - normalizingFactor = 1/max(obj.perf(end, 1:nowIdx)); - obj.performancePlot(1).YData(1:nowIdx) = obj.perf(end, 1:nowIdx) * normalizingFactor; - for ii = 2:size(obj.performancePlot, 1) - obj.performancePlot(ii).YData(1:nowIdx) = obj.perf(ii - 1, 1:nowIdx) * normalizingFactor; - end + % Re-normalize performance plot + normalizingFactor = 1/max(obj.performance(end)); + obj.performancePlot(1).YData(1:length(obj.performance)) = obj.performance * normalizingFactor; + obj.performancePlot(1).XData(find(isnan(obj.performancePlot(1).XData), 1, 'first')) = obj.t; + for ii = 2:(size(obj.agents, 1) + 1) + obj.performancePlot(ii).YData(1:length(obj.performance)) = obj.agents{ii - 1}.performance * normalizingFactor; + obj.performancePlot(ii).XData(find(isnan(obj.performancePlot(ii).XData), 1, 'first')) = obj.t; end end \ No newline at end of file