cleaned up randomly generated obstacle collision code

This commit is contained in:
2025-11-16 10:49:13 -08:00
parent 12dbde7a02
commit 9dbd29849f

View File

@@ -25,7 +25,7 @@ classdef test_miSim < matlab.unittest.TestCase
% Agents % Agents
minAgents = 3; % Minimum number of agents to be randomly generated minAgents = 3; % Minimum number of agents to be randomly generated
maxAgents = 9; % Maximum number of agents to be randomly generated maxAgents = 6; % Maximum number of agents to be randomly generated
sensingLength = 0.05; % length parameter used by sensing function sensingLength = 0.05; % length parameter used by sensing function
agents = cell(0, 1); agents = cell(0, 1);
@@ -75,22 +75,12 @@ classdef test_miSim < matlab.unittest.TestCase
tc.obstacles{ii} = rectangularPrism; tc.obstacles{ii} = rectangularPrism;
tc.obstacles{ii} = tc.obstacles{ii}.initializeRandom(REGION_TYPE.OBSTACLE, sprintf("Obstacle %d", ii), tc.minObstacleSize, tc.maxObstacleSize, tc.domain); tc.obstacles{ii} = tc.obstacles{ii}.initializeRandom(REGION_TYPE.OBSTACLE, sprintf("Obstacle %d", ii), tc.minObstacleSize, tc.maxObstacleSize, tc.domain);
% Check if the obstacle intersects with any existing % Check if the obstacle collides with an existing obstacle
% obstacles if ~tc.obstacleCollisionCheck(tc.obstacles(1:(ii - 1)), tc.obstacles{ii})
violation = false;
for kk = 1:(ii - 1)
if geometryIntersects(tc.obstacles{kk}, tc.obstacles{ii})
violation = true;
break;
end
end
if violation
continue;
end
badCandidate = false; badCandidate = false;
end end
end end
end
% Add agents individually, ensuring that each addition does not % Add agents individually, ensuring that each addition does not
% invalidate the initialization setup % invalidate the initialization setup
@@ -215,22 +205,12 @@ classdef test_miSim < matlab.unittest.TestCase
tc.obstacles{ii} = rectangularPrism; tc.obstacles{ii} = rectangularPrism;
tc.obstacles{ii} = tc.obstacles{ii}.initializeRandom(REGION_TYPE.OBSTACLE, sprintf("Obstacle %d", ii), tc.minObstacleSize, tc.maxObstacleSize, tc.domain); tc.obstacles{ii} = tc.obstacles{ii}.initializeRandom(REGION_TYPE.OBSTACLE, sprintf("Obstacle %d", ii), tc.minObstacleSize, tc.maxObstacleSize, tc.domain);
% Check if the obstacle intersects with any existing % Check if the obstacle collides with an existing obstacle
% obstacles if ~tc.obstacleCollisionCheck(tc.obstacles(1:(ii - 1)), tc.obstacles{ii})
violation = false;
for kk = 1:(ii - 1)
if geometryIntersects(tc.obstacles{kk}, tc.obstacles{ii})
violation = true;
break;
end
end
if violation
continue;
end
badCandidate = false; badCandidate = false;
end end
end end
end
% Add agents individually, ensuring that each addition does not % Add agents individually, ensuring that each addition does not
% invalidate the initialization setup % invalidate the initialization setup
@@ -380,4 +360,16 @@ classdef test_miSim < matlab.unittest.TestCase
[tc.testClass, f] = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.timestep, tc.partitoningFreq, tc.maxIter); [tc.testClass, f] = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.timestep, tc.partitoningFreq, tc.maxIter);
end end
end end
methods
function c = obstacleCollisionCheck(~, obstacles, obstacle)
% Check if the obstacle intersects with any other obstacles
c = false;
for ii = 1:size(obstacles, 1)
if geometryIntersects(obstacles{ii}, obstacle)
c = true;
end
end
end
end
end end