diff --git a/src/Flase.jl b/src/Flase.jl index cbef485..8e243c2 100644 --- a/src/Flase.jl +++ b/src/Flase.jl @@ -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 @@ -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") diff --git a/src/measures/MeanQuadraticDistance.jl b/src/measures/MeanQuadraticDistance.jl index 9c3c655..23d7e68 100644 --- a/src/measures/MeanQuadraticDistance.jl +++ b/src/measures/MeanQuadraticDistance.jl @@ -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) @@ -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 @@ -24,7 +26,7 @@ gridsizestorage = size(sheeps.grid)[1] counter = 0 mean::Float64 = 0 - +mq = MQD(1) for sheep in sheeps @@ -40,7 +42,10 @@ for sheep in sheeps end -return mean/counter +mq.vmqd = mean/counter +return mq.vmqd end + + diff --git a/src/measures/MeanSquaredDisplacement.jl b/src/measures/MeanSquaredDisplacement.jl index fc6b0ae..8dd36b4 100644 --- a/src/measures/MeanSquaredDisplacement.jl +++ b/src/measures/MeanSquaredDisplacement.jl @@ -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 diff --git a/src/simulations/ClusterTimeSimulation.jl b/src/simulations/ClusterTimeSimulation.jl new file mode 100644 index 0000000..e98b742 --- /dev/null +++ b/src/simulations/ClusterTimeSimulation.jl @@ -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 \ No newline at end of file diff --git a/src/simulations/Simulation.jl b/src/simulations/Simulation.jl index 86b065f..3f5c296 100644 --- a/src/simulations/Simulation.jl +++ b/src/simulations/Simulation.jl @@ -21,6 +21,6 @@ function move_sheep!( sim::Simulation ) kickSheep!( sim.world.sheeps ) return true - end # if + end # if return false end # function diff --git a/test/test_Simulation.jl b/test/test_Simulation.jl index 9cfe9d3..a263802 100644 --- a/test/test_Simulation.jl +++ b/test/test_Simulation.jl @@ -2,7 +2,7 @@ using Flase, Test world = World( v0 = 1., - n_dogs = 120, + n_dogs = 25, boxsize = 10.0, motion = BrownianMotion( noise = 0.5, @@ -10,7 +10,7 @@ world = World( ), sheeps = DenseSheeps( 10, - n_sheeps = 10, + n_sheeps = 50, ) ) simulation = FiniteSimulation(; @@ -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[] @@ -34,3 +52,4 @@ end # testset pos = simulation.world.dogs.member[3].position @test all(pos .< Flase.getSheepCoords(simulation.world, pos)) end +