Skip to content

Instantly share code, notes, and snippets.

@pjpetersik
Last active April 6, 2022 10:02
Show Gist options
  • Save pjpetersik/a620f3ec0b26a015986d77971bac2359 to your computer and use it in GitHub Desktop.
Save pjpetersik/a620f3ec0b26a015986d77971bac2359 to your computer and use it in GitHub Desktop.
mutable struct Agent
position::Vector{Real}
cohere_factor::Real
repel_factor::Real
energy::Real
desired_rank::Real
end
struct Model
peloton::Vector{Agent}
road_center::Real
end
# Constructors
function Agent()
position = 0.1 * rand(2) .+ [0.4; 0.4]
energy = 0.5 + 0.5 * rand()
desired_rank = rand()
cohere_factor = 0.005 + 0.01 * rand()
repel_factor = 0.005 + 0.01 * rand()
Agent(position, cohere_factor, repel_factor, energy, desired_rank)
end
function Model(n_agents::Integer)
peloton = [ Agent() for i ∈ 1:n_agents ]
Model(peloton, 0.5)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment