Skip to content

Instantly share code, notes, and snippets.

@pjpetersik
Last active April 6, 2022 11:14
Show Gist options
  • Save pjpetersik/cbfb9b22cf504df2a310ea2afbe895fa to your computer and use it in GitHub Desktop.
Save pjpetersik/cbfb9b22cf504df2a310ea2afbe895fa to your computer and use it in GitHub Desktop.
function energy_usage(agent::Agent, model::Model)
usage = 0.02
for other_agent in model.peloton
heading = other_agent.position - agent.position
distance = sum((heading).^2)^0.5
if agent != other_agent
if distance < 0.2 && heading[1] > 0
angle_factor = abs(acot(heading[2] / heading[1])) / π * 2
usage -= 0.1 * (0.2 - distance) * angle_factor
end
end
end
return min(max(-0.01, usage), 0.02)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment