Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding ClusterTimeSimulation #18

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Flase.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Flase

export InfiniteSimulation, FiniteSimulation, runsim
export InfiniteSimulation, FiniteSimulation, runsim, ClusterTimeSimulation
export BrownianMotion, ConstVelocity
export UnicodePlotter
export UnicodePlotter, VoidPlotter
export World
export DenseSheeps

Expand Down Expand Up @@ -32,6 +32,7 @@ include("plotter/UnicodePlotter.jl")
include("simulations/Simulation.jl")
include("simulations/InfiniteSimulation.jl")
include("simulations/FiniteSimulation.jl")
include("simulations/ClusterTimeSimulation.jl")

include("interactions.jl")

Expand Down
13 changes: 9 additions & 4 deletions src/measures/MeanQuadraticDistance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#first we need a new structur

struct MQD end
mutable struct MQD
vmqd::Float64
end

#then compute the function that takes imput from object sheep::Sheeps
function SqrDist(sheep, sheep1, gridsizestorage)
Expand All @@ -15,7 +17,7 @@ end



function measure(::MQD, sheeps::Sheeps)
function measure(vmqd::MQD, sheeps::Sheeps)
#set a 3x3 Matrix for Test purpose. Result should be 3/4
#setvariables counter(=unsigned Integer), mean(=Float64) to 0

Expand All @@ -24,7 +26,7 @@ gridsizestorage = size(sheeps.grid)[1]

counter = 0
mean::Float64 = 0

mq = MQD(1)

for sheep in sheeps

Expand All @@ -40,7 +42,10 @@ for sheep in sheeps

end

return mean/counter
mq.vmqd = mean/counter
return mq.vmqd


end


9 changes: 6 additions & 3 deletions src/measures/MeanSquaredDisplacement.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"Type for calculating the mean squared displacement."
struct MSD end
mutable struct MSD
vmsd::Int64
end

function measure(::MSD, sheeps::Sheeps)
function measure(vmqd::MSD, sheeps::Sheeps)
# get center of mass
cmx, cmy = center_of_mass(sheeps)
sum = 0
for sheep in sheeps
sum += real# sqr distance in real space
end
return sum / length(sheeps)
msd.vmsd = sum / length(sheeps)
return msd.vmsd
end
88 changes: 88 additions & 0 deletions src/simulations/ClusterTimeSimulation.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#This is for clustering time

using Distributions #weil wird bei Finite auch gemacht

#define the ClusterTime Datastructure




struct ClusterTimeSimulation{P<:Plotter, F<:Number, W<:World } <: Simulation

time::Base.RefValue{F}
t_sheep_boredom::Base.RefValue{F}
condition::Int64
msdThreshold::Float64
mqdThreshold::Float64
dt::F
world::W
plotter::P

end




ClusterTimeSimulation(;

msdThreshold::Float64 = 0.7,
mqdThreshold::Float64 = 0.1,
dt::F,
world::W,
condition::Int64,
time::F = convert(typeof(dt), 0) ,
t_sheep_boredom = rand(Exponential(world.meanSheepDiffusionTime / world.sheeps.current_sheep[])),
plotter::P = VoidPlotter()
) where {F<:Number, W<:World,P<:Plotter} = ClusterTimeSimulation{P,F,W}(Ref(time), Ref(t_sheep_boredom), condition, msdThreshold, mqdThreshold, dt, world, plotter)

function runsim(sim::ClusterTimeSimulation)


mq = MQD(1)
ms = MSD(1)



p = plot( sim.plotter, sim.world, sim.time[] )
io = IOBuffer()

if sim.condition == 0


while mq.vmqd > sim.mqdThreshold

Flase.measure( mq ,sim.world.sheeps)
iterate!( sim )
plot!( io, p, sim.plotter, sim.world, sim.time[] )
println(mq.vmqd)
end

elseif sim.condition == 1

while ms.vmsd > sim.msdThreshold

Flase.measure( mq ,sim.world.sheeps)
iterate!( sim )
plot!( io, p, sim.plotter, sim.world, sim.time[] )

end


elseif sim.condition == 2

while ms.vmsd < sim.msdThreshold && mq.vmqd > sim.mqdThreshold

Flase.measure( mq ,sim.world.sheeps)
iterate!( sim )
plot!( io, p, sim.plotter, sim.world, sim.time[] )

end
else sim.condition == 3

println("this is condition 3")

end

return sim.time[]

end
2 changes: 1 addition & 1 deletion src/simulations/Simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ function move_sheep!( sim::Simulation )

kickSheep!( sim.world.sheeps )
return true
end # if
end # if
return false
end # function
23 changes: 21 additions & 2 deletions test/test_Simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ using Flase, Test

world = World(
v0 = 1.,
n_dogs = 120,
n_dogs = 25,
boxsize = 10.0,
motion = BrownianMotion(
noise = 0.5,
friction = 1.0
),
sheeps = DenseSheeps(
10,
n_sheeps = 10,
n_sheeps = 50,
)
)
simulation = FiniteSimulation(;
Expand All @@ -20,6 +20,24 @@ simulation = FiniteSimulation(;
plotter = UnicodePlotter()
)


simulation2 = Flase.ClusterTimeSimulation(;
condition = 0,
dt = 0.2,
world = world,
plotter = VoidPlotter()
)

@testset "ClusterTimeSimulation" begin


@show runsim(simulation2)


end



@testset "Move items" begin
old_grid = copy(simulation.world.sheeps.grid)
@test simulation.time[] < simulation.t_sheep_boredom[]
Expand All @@ -34,3 +52,4 @@ end # testset
pos = simulation.world.dogs.member[3].position
@test all(pos .< Flase.getSheepCoords(simulation.world, pos))
end