Skip to content

Commit

Permalink
update to new LightSumTypes version
Browse files Browse the repository at this point in the history
  • Loading branch information
mastrof committed Sep 24, 2024
1 parent 341c11c commit b6bc436
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Agents = "46ada45e-f475-11e8-01d0-f70cc89e6671"
Autocorrelations = "b9118d5e-f165-4cbd-b2ae-b030566b7b26"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DynamicSumTypes = "5fcdbb90-de43-509e-b9a6-c4d43f29cf26"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
LightSumTypes = "f56206fc-af4c-5561-a72a-43fe2ca5a923"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MeanSquaredDisplacement = "13c93d70-909c-440c-af92-39d48ffa2ba2"
Quaternions = "94ee1d12-ae83-5a48-8b1c-48b8ff168ae0"
Expand All @@ -22,8 +22,8 @@ Agents = "6"
Autocorrelations = "0.1"
DataFrames = "1"
Distributions = "0.25"
DynamicSumTypes = "1"
GeometryBasics = "0.4"
LightSumTypes = "4"
MeanSquaredDisplacement = "0.2"
Quaternions = "0.7"
StaticArrays = "1"
Expand Down
2 changes: 1 addition & 1 deletion src/MicrobeAgents.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export add_agent!, add_agent_own_pos!
export move_agent!, walk!, run!

using Distributions
using DynamicSumTypes
using LightSumTypes
using LinearAlgebra
using Random
using Quaternions
Expand Down
4 changes: 2 additions & 2 deletions src/microbe_step.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function microbe_step!(microbe::AbstractMicrobe, model::AgentBasedModel)
# if the new motile state is a TurnState with duration 0
# immediately turn and transition to another state
new_motilestate = motilestate(microbe)
if kindof(new_motilestate) === :TurnState && iszero(duration(new_motilestate))
if variantof(new_motilestate) === TurnState && iszero(duration(new_motilestate))
turn!(microbe, model)
update_motilestate!(microbe, model)
end
Expand Down Expand Up @@ -53,7 +53,7 @@ function microbe_pathfinder_step!(microbe::AbstractMicrobe, model::AgentBasedMod
# if the new motile state is a TurnState with duration 0
# immediately turn and transition to another state
new_motilestate = motilestate(microbe)
if kindof(new_motilestate) === :TurnState && iszero(duration(new_motilestate))
if variantof(new_motilestate) === TurnState && iszero(duration(new_motilestate))
turn!(microbe, model)
update_motilestate!(microbe, model)
end
Expand Down
37 changes: 22 additions & 15 deletions src/motility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,30 @@ export motilepattern, motilestate, state, states, transition_weights
export duration, speed, polar, azimuthal
export Arccos # from Agents

@sum_structs MotileState begin
@kwdef struct RunState
duration
speed
polar = nothing
azimuthal = nothing
end
@kwdef struct TurnState
duration
speed = [zero(duration)]
polar
azimuthal
end

struct RunState
duration
speed
polar
azimuthal
end
struct TurnState
duration
speed
polar
azimuthal
end
@sumtype MotileState(RunState, TurnState)
function RunState(; duration, speed, polar=nothing, azimuthal=nothing)
MotileState(RunState(duration, speed, polar, azimuthal))
end
function TurnState(; duration, speed=[zero(duration)], polar, azimuthal)
MotileState(TurnState(duration, speed, polar, azimuthal))
end

@pattern biased(::RunState) = true
@pattern biased(::TurnState) = false
biased(s::MotileState) = biased(variant(s))
biased(::RunState) = true
biased(::TurnState) = false

# Base motile states
Run(duration::Real, speed) = RunState(; duration, speed)
Expand Down

0 comments on commit b6bc436

Please sign in to comment.