A lamp is an object in 2D space with a scalar brightness. A sensor is a similar object, but with scalar property illumination instead of brightness. I have an arbitrary amount of lamps and sensors in an area.
Each sensors illumination is defined as follows:
Where a_kj = distance_kj^(-2) and p_j is the brightness of that lamp.
Each sensor has a desired illumination level. I wish to minimize the maximum deviated illumination level. To do so, I can control the individual brightness level of each lamp. The brightness level must be in bounds of max/min [0, 1].
What is the optimal optimization function for this? ie: set brightness of lamps in order to minimize function calculate()
local lamps = {}
local sensors = {}
local lamp = {}
local sensor = {}
local min_lamp_brightness = 0
local max_lamp_brigtness = 1
function lamp:new(position, brightness)
local instance = {}
instance.position = position
instance.brightness = brightness
setmetatable(instance, self)
self.__index = self
return instance
end
function sensor:new(position, illumination, desired_illumination)
local instance = {}
instance.position = position
instance.illumination = illumination
instance.desired_illumination = desired_illumination
setmetatable(instance, self)
self.__index = self
return instance
end
local function calculate(lamps, sensors)
local largest_illumination_deviation = 0
for _,sensor in pairs(sensors) do
local illumination_sum = 0
for _,lamp in pairs(lamps) do
local indvidual_illumination = lamp.brightness * 1/math.pow((lamp.position - sensor.position).magnitude, 2)
illumination_sum = illumination_sum + indvidual_illumination
-- Calculate the illumination level imparted on a sensor due to the brightness of each lamp
end
sensor.illumination = illumination_sum
local illumination_deviation = math.abs(sensor.illumination - sensor.desired_illumination)
if illumination_deviation > largest_illumination_deviation then
largest_illumination_deviation = illumination_deviation
end
end
return largest_illumination_deviation
end
local function optimize(lamps, sensors)
for _,lamp in pairs(lamps) do
lamp.brightness = math.random() -- Algorithm here to optimize the lamp brightness
lamp.brightness = math.max(min_lamp_brightness, lamp.brightness) -- Must obey max/min lamp brightness
lamp.brightness = math.min(max_lamp_brigtness, lamp.brightness)
end
end
-- All lamps are set to 0.5 brightness
lamps[1] = lamp:new(Vector2.new(1, 2), 0.5)
lamps[2] = lamp:new(Vector2.new(4, 6), 0.5)
lamps[3] = lamp:new(Vector2.new(8, 9), 0.5)
lamps[4] = lamp:new(Vector2.new(4, 5), 0.5)
-- Sensors all have a distinct desired illumination level
sensors[1] = sensor:new(Vector2.new(0, 0), nil, 0.3)
sensors[2] = sensor:new(Vector2.new(4, 2), nil, 0.5)
sensors[3] = sensor:new(Vector2.new(8, 4), nil, 0.7)
print(calculate(lamps, sensors)) -- Calculate the maximum sensor deviation
optimize(lamps, sensors) -- Algorithm to control each lamp brightness in order to minimize the maximum sensor deviation
print(calculate(lamps, sensors)) -- Verify the maximum sensor deviation is minimized