implemented basic gradient ascent

This commit is contained in:
2025-10-27 21:29:54 -07:00
parent 8955d4d29b
commit faa8bad596
6 changed files with 91 additions and 14 deletions

25
agent.m
View File

@@ -6,6 +6,7 @@ classdef agent
% Sensor
sensingFunction = @(r) 0.5; % probability of detection as a function of range
sensingLength = 0.05; % length parameter used by sensing function
% State
pos = NaN(1, 3);
@@ -20,14 +21,15 @@ classdef agent
end
methods (Access = public)
function obj = initialize(obj, pos, vel, cBfromC, collisionGeometry, sensingFunction, comRange, index, label)
function obj = initialize(obj, pos, vel, cBfromC, collisionGeometry, sensingFunction, sensingLength, comRange, index, label)
arguments (Input)
obj (1, 1) {mustBeA(obj, 'agent')};
pos (1, 3) double;
vel (1, 3) double;
cBfromC (3, 3) double {mustBeDcm};
collisionGeometry (1, 1) {mustBeGeometry};
sensingFunction (1, 1) {mustBeA(sensingFunction, 'function_handle')}
sensingFunction (1, 1) {mustBeA(sensingFunction, 'function_handle')} = @(r) 0.5;
sensingLength (1, 1) double = NaN;
comRange (1, 1) double = NaN;
index (1, 1) double = NaN;
label (1, 1) string = "";
@@ -40,10 +42,29 @@ classdef agent
obj.vel = vel;
obj.cBfromC = cBfromC;
obj.collisionGeometry = collisionGeometry;
obj.sensingFunction = sensingFunction;
obj.sensingLength = sensingLength;
obj.comRange = comRange;
obj.index = index;
obj.label = label;
end
function obj = run(obj, objectiveFunction)
arguments (Input)
obj (1, 1) {mustBeA(obj, 'agent')};
objectiveFunction (1, 1) {mustBeA(objectiveFunction, 'function_handle')};
end
arguments (Output)
obj (1, 1) {mustBeA(obj, 'agent')};
end
% Do sensing to determine target position
nextPos = obj.sensingFunction(objectiveFunction, obj.pos, obj.sensingLength);
% Move to next position
% (dynamics not modeled at this time)
obj.pos = nextPos;
end
function f = plot(obj, f)
arguments (Input)
obj (1, 1) {mustBeA(obj, 'agent')};