cleaned up obstacle generation

This commit is contained in:
2025-11-16 10:21:58 -08:00
parent c9ac9d7725
commit 12dbde7a02
6 changed files with 51 additions and 78 deletions

View File

@@ -1,15 +1,17 @@
function obj = initialize(obj, objectiveFunction, domain, discretizationStep) function obj = initialize(obj, objectiveFunction, domain, discretizationStep, protectedRange)
arguments (Input) arguments (Input)
obj (1,1) {mustBeA(obj, 'sensingObjective')}; obj (1,1) {mustBeA(obj, 'sensingObjective')};
objectiveFunction (1, 1) {mustBeA(objectiveFunction, 'function_handle')}; objectiveFunction (1, 1) {mustBeA(objectiveFunction, 'function_handle')};
domain (1, 1) {mustBeGeometry}; domain (1, 1) {mustBeGeometry};
discretizationStep (1, 1) double = 1; discretizationStep (1, 1) double = 1;
protectedRange (1, 1) double = 1;
end end
arguments (Output) arguments (Output)
obj (1,1) {mustBeA(obj, 'sensingObjective')}; obj (1,1) {mustBeA(obj, 'sensingObjective')};
end end
obj.groundAlt = domain.minCorner(3); obj.groundAlt = domain.minCorner(3);
obj.protectedRange = protectedRange;
% Extract footprint limits % Extract footprint limits
xMin = min(domain.footprint(:, 1)); xMin = min(domain.footprint(:, 1));
@@ -30,4 +32,6 @@ function obj = initialize(obj, objectiveFunction, domain, discretizationStep)
% store ground position % store ground position
idx = obj.values == max(obj.values, [], "all"); idx = obj.values == max(obj.values, [], "all");
obj.groundPos = [obj.X(idx), obj.Y(idx)]; obj.groundPos = [obj.X(idx), obj.Y(idx)];
assert(domain.distance([obj.groundPos, domain.center(3)]) > protectedRange, "Domain is crowding the sensing objective")
end end

View File

@@ -1,9 +1,9 @@
function obj = initializeRandomMvnpdf(obj, domain, protectedRange, discretizationStep) function obj = initializeRandomMvnpdf(obj, domain, discretizationStep, protectedRange)
arguments (Input) arguments (Input)
obj (1, 1) {mustBeA(obj, 'sensingObjective')}; obj (1, 1) {mustBeA(obj, 'sensingObjective')};
domain (1, 1) {mustBeGeometry}; domain (1, 1) {mustBeGeometry};
protectedRange (1, 1) double = 1;
discretizationStep (1, 1) double = 1; discretizationStep (1, 1) double = 1;
protectedRange (1, 1) double = 1;
end end
arguments (Output) arguments (Output)
obj (1, 1) {mustBeA(obj, 'sensingObjective')}; obj (1, 1) {mustBeA(obj, 'sensingObjective')};
@@ -23,5 +23,5 @@ function obj = initializeRandomMvnpdf(obj, domain, protectedRange, discretizatio
objectiveFunction = @(x, y) mvnpdf([x(:), y(:)], mu, sig); objectiveFunction = @(x, y) mvnpdf([x(:), y(:)], mu, sig);
% Regular initialization % Regular initialization
obj = obj.initialize(objectiveFunction, domain, discretizationStep); obj = obj.initialize(objectiveFunction, domain, discretizationStep, protectedRange);
end end

View File

@@ -9,11 +9,12 @@ classdef sensingObjective
X = []; X = [];
Y = []; Y = [];
values = []; values = [];
protectedRange = 1; % keep obstacles from crowding objective
end end
methods (Access = public) methods (Access = public)
[obj] = initialize(obj, objectiveFunction, domain, discretizationStep); [obj] = initialize(obj, objectiveFunction, domain, discretizationStep, protectedRange);
[obj] = initializeRandomMvnpdf(obj, domain, protectedRange, discretizationStep); [obj] = initializeRandomMvnpdf(obj, domain, protectedRange, discretizationStep, protectedRange);
[f ] = plot(obj, ind, f); [f ] = plot(obj, ind, f);
end end
end end

View File

@@ -1,17 +1,43 @@
function [obj] = initializeRandom(obj, minDimension, tag, label) function [obj] = initializeRandom(obj, tag, label, minDimension, maxDimension, domain)
arguments (Input) arguments (Input)
obj (1, 1) {mustBeA(obj, 'rectangularPrism')}; obj (1, 1) {mustBeA(obj, 'rectangularPrism')};
minDimension (1, 1) double = 10;
tag (1, 1) REGION_TYPE = REGION_TYPE.INVALID; tag (1, 1) REGION_TYPE = REGION_TYPE.INVALID;
label (1, 1) string = ""; label (1, 1) string = "";
minDimension (1, 1) double = 10;
maxDimension (1, 1) double= 20;
domain (1, 1) {mustBeGeometry} = rectangularPrism;
end end
arguments (Output) arguments (Output)
obj (1, 1) {mustBeA(obj, 'rectangularPrism')}; obj (1, 1) {mustBeA(obj, 'rectangularPrism')};
end end
% Produce random bounds % Produce random bounds based on region type
L = ceil(minDimension + rand * minDimension); if tag == REGION_TYPE.DOMAIN
bounds = [zeros(1, 3); L * ones(1, 3)]; % Domain
L = ceil(minDimension + rand * (maxDimension - minDimension));
bounds = [zeros(1, 3); L * ones(1, 3)];
else
% Obstacle
% Produce a corners that are contained in the domain
ii = 0;
candidateMaxCorner = domain.maxCorner + ones(1, 3);
candidateMinCorner = domain.minCorner - ones(1, 3);
% Continue until the domain contains the obstacle without crowding the objective
while ~domain.contains(candidateMaxCorner) || all(domain.objective.groundPos + domain.objective.protectedRange >= candidateMinCorner(1:2), 2) && all(domain.objective.groundPos - domain.objective.protectedRange <= candidateMaxCorner(1:2), 2)
if ii == 0 || ii > 10
candidateMinCorner = domain.random();
candidateMinCorner(3) = 0; % bind to floor
ii = 1;
end
candidateMaxCorner = candidateMinCorner + minDimension + rand(1, 3) * (maxDimension - minDimension);
ii = ii + 1;
end
bounds = [candidateMinCorner; candidateMaxCorner;];
end
% Regular initialization % Regular initialization
obj = obj.initialize(bounds, tag, label); obj = obj.initialize(bounds, tag, label);

View File

@@ -28,7 +28,7 @@ classdef rectangularPrism
methods (Access = public) methods (Access = public)
[obj ] = initialize(obj, bounds, tag, label, objectiveFunction, discretizationStep); [obj ] = initialize(obj, bounds, tag, label, objectiveFunction, discretizationStep);
[obj ] = initializeRandom(obj, tag, label); [obj ] = initializeRandom(obj, tag, label, minDimension, maxDimension, domain);
[r ] = random(obj); [r ] = random(obj);
[c ] = contains(obj, pos); [c ] = contains(obj, pos);
[d ] = distance(obj, pos); [d ] = distance(obj, pos);

View File

@@ -43,15 +43,13 @@ classdef test_miSim < matlab.unittest.TestCase
% Generate a random domain % Generate a random domain
function tc = setDomain(tc) function tc = setDomain(tc)
% random integer-dimensioned cubic domain % random integer-dimensioned cubic domain
tc.domain = tc.domain.initializeRandom(tc.minDimension, REGION_TYPE.DOMAIN, "Domain"); tc.domain = tc.domain.initializeRandom(REGION_TYPE.DOMAIN, "Domain", tc.minDimension);
% Random bivariate normal PDF objective % Random bivariate normal PDF objective
tc.domain.objective = tc.domain.objective.initializeRandomMvnpdf(tc.domain, tc.protectedRange, tc.discretizationStep); tc.domain.objective = tc.domain.objective.initializeRandomMvnpdf(tc.domain, tc.discretizationStep, tc.protectedRange);
end end
% Instantiate agents % Instantiate agents
function tc = setAgents(tc) function tc = setAgents(tc)
% Agents will be initialized under different parameters in % Agents will be initialized under different parameters in individual test cases
% individual test cases
% Instantiate a random number of agents according to parameters % Instantiate a random number of agents according to parameters
for ii = 1:randi([tc.minAgents, tc.maxAgents]) for ii = 1:randi([tc.minAgents, tc.maxAgents])
tc.agents{ii, 1} = agent; tc.agents{ii, 1} = agent;
@@ -73,19 +71,9 @@ classdef test_miSim < matlab.unittest.TestCase
for ii = 1:size(tc.obstacles, 1) for ii = 1:size(tc.obstacles, 1)
badCandidate = true; badCandidate = true;
while badCandidate while badCandidate
% Instantiate a rectangular prism obstacle % Instantiate a rectangular prism obstacle inside the domain
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);
% Randomly generate min corner for the obstacle
candidateMinCorner = tc.domain.random();
candidateMinCorner = [candidateMinCorner(1:2), 0]; % bind obstacles to floor of domain
% Randomly select a corresponding maximum corner that
% satisfies min/max obstacle size specifications
candidateMaxCorner = candidateMinCorner + tc.minObstacleSize + rand(1, 3) * (tc.maxObstacleSize - tc.minObstacleSize);
% Initialize obstacle
tc.obstacles{ii} = tc.obstacles{ii}.initialize([candidateMinCorner; candidateMaxCorner], REGION_TYPE.OBSTACLE, sprintf("Column obstacle %d", ii));
% Check if the obstacle intersects with any existing % Check if the obstacle intersects with any existing
% obstacles % obstacles
@@ -100,24 +88,6 @@ classdef test_miSim < matlab.unittest.TestCase
continue; continue;
end end
% Make sure that the obstacles are fully contained by
% the domain
if ~domainContainsObstacle(tc.domain, tc.obstacles{ii})
continue;
end
% Make sure that the obstacles don't cover the sensing
% objective
if obstacleCoversObjective(tc.domain.objective, tc.obstacles{ii})
continue;
end
% Make sure that the obstacles aren't too close to the
% sensing objective
if obstacleCrowdsObjective(tc.domain.objective, tc.obstacles{ii}, tc.protectedRange)
continue;
end
badCandidate = false; badCandidate = false;
end end
end end
@@ -241,19 +211,9 @@ classdef test_miSim < matlab.unittest.TestCase
for ii = 1:size(tc.obstacles, 1) for ii = 1:size(tc.obstacles, 1)
badCandidate = true; badCandidate = true;
while badCandidate while badCandidate
% Instantiate a rectangular prism obstacle % Instantiate a rectangular prism obstacle inside the domain
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);
% Randomly generate min corner for the obstacle
candidateMinCorner = tc.domain.random();
candidateMinCorner = [candidateMinCorner(1:2), 0]; % bind obstacles to floor of domain
% Randomly select a corresponding maximum corner that
% satisfies min/max obstacle size specifications
candidateMaxCorner = candidateMinCorner + tc.minObstacleSize + rand(1, 3) * (tc.maxObstacleSize - tc.minObstacleSize);
% Initialize obstacle
tc.obstacles{ii} = tc.obstacles{ii}.initialize([candidateMinCorner; candidateMaxCorner], REGION_TYPE.OBSTACLE, sprintf("Column obstacle %d", ii));
% Check if the obstacle intersects with any existing % Check if the obstacle intersects with any existing
% obstacles % obstacles
@@ -268,24 +228,6 @@ classdef test_miSim < matlab.unittest.TestCase
continue; continue;
end end
% Make sure that the obstacles are fully contained by
% the domain
if ~domainContainsObstacle(tc.domain, tc.obstacles{ii})
continue;
end
% Make sure that the obstacles don't cover the sensing
% objective
if obstacleCoversObjective(tc.domain.objective, tc.obstacles{ii})
continue;
end
% Make sure that the obstacles aren't too close to the
% sensing objective
if obstacleCrowdsObjective(tc.domain.objective, tc.obstacles{ii}, tc.protectedRange)
continue;
end
badCandidate = false; badCandidate = false;
end end
end end
@@ -411,7 +353,7 @@ classdef test_miSim < matlab.unittest.TestCase
tc.domain = tc.domain.initialize([zeros(1, 3); 10 * ones(1, 3)], REGION_TYPE.DOMAIN, "Domain"); tc.domain = tc.domain.initialize([zeros(1, 3); 10 * ones(1, 3)], REGION_TYPE.DOMAIN, "Domain");
% make basic sensing objective % make basic sensing objective
tc.domain.objective = tc.domain.objective.initialize(@(x, y) mvnpdf([x(:), y(:)], tc.domain.center(1:2)), tc.domain, tc.discretizationStep); tc.domain.objective = tc.domain.objective.initialize(@(x, y) mvnpdf([x(:), y(:)], tc.domain.center(1:2)), tc.domain, tc.discretizationStep, tc.protectedRange);
% Initialize agent collision geometry % Initialize agent collision geometry
geometry1 = rectangularPrism; geometry1 = rectangularPrism;