From 5ef817b73252c9a9ab10da51940f1308b8e5070a Mon Sep 17 00:00:00 2001 From: alikateic Date: Mon, 28 Aug 2023 17:00:33 +0200 Subject: [PATCH 01/12] Troubleshooting in MQD and MSD --- src/Flase.jl | 5 +- src/measures/MeanQuadraticDistance.jl | 6 ++- src/measures/MeanSquaredDisplacement.jl | 4 +- src/simulations/ClusterTimeSimulation.jl | 62 ++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 src/simulations/ClusterTimeSimulation.jl diff --git a/src/Flase.jl b/src/Flase.jl index cbef485..ea38e5a 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 @@ -30,6 +30,7 @@ include("plotter/VoidPlotter.jl") include("plotter/UnicodePlotter.jl") include("simulations/Simulation.jl") +include("simulations/ClusterTimeSimulation.jl") include("simulations/InfiniteSimulation.jl") include("simulations/FiniteSimulation.jl") diff --git a/src/measures/MeanQuadraticDistance.jl b/src/measures/MeanQuadraticDistance.jl index dbbd49b..592d0f3 100644 --- a/src/measures/MeanQuadraticDistance.jl +++ b/src/measures/MeanQuadraticDistance.jl @@ -2,7 +2,9 @@ #first we need a new structure -struct MQD end +struct MQD + mqd::AbstractFloat +end #then compute the function that takes imput from object sheep::Sheeps function sqr_dist(sheep, sheep1, gridsizestorage) @@ -39,7 +41,7 @@ function measure(::MQD, sheeps::Sheeps) - mean += sheep[1] * sheep1[1] * SqrDist(sheep, sheep1, gridsizestorage) + mean += sheep[1] * sheep1[1] * sqr_dist(sheep, sheep1, gridsizestorage) counter += sheep[1] * sheep1[1] end diff --git a/src/measures/MeanSquaredDisplacement.jl b/src/measures/MeanSquaredDisplacement.jl index fc6b0ae..8b691e1 100644 --- a/src/measures/MeanSquaredDisplacement.jl +++ b/src/measures/MeanSquaredDisplacement.jl @@ -1,5 +1,7 @@ "Type for calculating the mean squared displacement." -struct MSD end +struct MSD + msd::AbstractFloat +end function measure(::MSD, sheeps::Sheeps) # get center of mass diff --git a/src/simulations/ClusterTimeSimulation.jl b/src/simulations/ClusterTimeSimulation.jl new file mode 100644 index 0000000..26abad5 --- /dev/null +++ b/src/simulations/ClusterTimeSimulation.jl @@ -0,0 +1,62 @@ +using Distributions + +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.mqd > sim.mqdThreshold + + Flase.measure( mq ,sim.world.sheeps) + iterate!( sim ) + plot!( io, p, sim.plotter, sim.world, sim.time[] ) + println(mq.mqd) + end +elseif sim.condition == 1 + while ms.msd > 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.msd < sim.msdThreshold && mq.mqd > 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 From 1df4c7576ee99903df953d134d3ad25e7e825ca5 Mon Sep 17 00:00:00 2001 From: alikateic Date: Thu, 31 Aug 2023 06:57:38 +0200 Subject: [PATCH 02/12] MQD functions --- src/Flase.jl | 4 +-- src/measures/MeanQuadraticDistance.jl | 16 ++++----- src/measures/MeanSquaredDisplacement.jl | 9 +++-- src/plotter/UnicodePlotter.jl | 2 +- src/simulations/ClusterTimeSimulation.jl | 45 +++++++++++++----------- test/test_Simulation.jl | 13 +++++++ 6 files changed, 55 insertions(+), 34 deletions(-) diff --git a/src/Flase.jl b/src/Flase.jl index ea38e5a..6cd5a0a 100644 --- a/src/Flase.jl +++ b/src/Flase.jl @@ -17,12 +17,12 @@ include("items/BaseSheeps.jl") include("items/DenseSheeps.jl") include("items/SparseSheeps.jl") +include("World.jl") + include("measures/Measure.jl") include("measures/MeanSquaredDisplacement.jl") include("measures/MeanQuadraticDistance.jl") -include("World.jl") - include("item-collector-interactions.jl") include("plotter/Plotter.jl") diff --git a/src/measures/MeanQuadraticDistance.jl b/src/measures/MeanQuadraticDistance.jl index 592d0f3..c5d4c94 100644 --- a/src/measures/MeanQuadraticDistance.jl +++ b/src/measures/MeanQuadraticDistance.jl @@ -3,7 +3,6 @@ #first we need a new structure struct MQD - mqd::AbstractFloat end #then compute the function that takes imput from object sheep::Sheeps @@ -22,12 +21,10 @@ function sqr_dist(sheep, sheep1, gridsizestorage) end - function measure(::MQD, sheeps::Sheeps) #set a 3x3 Matrix for Test purpose. Result should be 3/4 #setvariables counter(=unsigned Integer), mean(=Float64) to 0 - gridsizestorage = size(sheeps.grid)[1] counter = 0 @@ -38,17 +35,20 @@ function measure(::MQD, sheeps::Sheeps) for sheep1 in sheeps - - - mean += sheep[1] * sheep1[1] * sqr_dist(sheep, sheep1, gridsizestorage) counter += sheep[1] * sheep1[1] end end - + println(mean) + println(counter) return mean / counter - end + + +function getMQD(mqd::MQD, sheeps::Sheeps, mqdNorm::Float64) + mqd_value = measure(mqd, sheeps)/mqdNorm + return mqd_value +end \ No newline at end of file diff --git a/src/measures/MeanSquaredDisplacement.jl b/src/measures/MeanSquaredDisplacement.jl index 8b691e1..2509337 100644 --- a/src/measures/MeanSquaredDisplacement.jl +++ b/src/measures/MeanSquaredDisplacement.jl @@ -1,14 +1,17 @@ "Type for calculating the mean squared displacement." struct MSD - msd::AbstractFloat end -function measure(::MSD, sheeps::Sheeps) +function measure(::MSD, sheeps::Sheeps, world::World) # get center of mass - cmx, cmy = center_of_mass(sheeps) + cmx, cmy = center_of_mass(sheeps, world) sum = 0 for sheep in sheeps sum += real# sqr distance in real space end return sum / length(sheeps) end + +function getMSD(msd::MSD, sheeps::Sheeps, word::World, msdNorm::Float64) + return msd_value +end \ No newline at end of file diff --git a/src/plotter/UnicodePlotter.jl b/src/plotter/UnicodePlotter.jl index 448b827..b0da6e0 100644 --- a/src/plotter/UnicodePlotter.jl +++ b/src/plotter/UnicodePlotter.jl @@ -44,7 +44,7 @@ end # function function plot!(io, p, plotter::UnicodePlotter, world::World, time) if plotter.counter[] % plotter.skip == zero(CountType) - for _ = 1:(UnicodePlots.nrows(p.graphics)+p.margin) + for _ = 1:(UnicodePlots.nrows(p.graphics)+p.margin.x) print(io, "\e[2K\e[1F") end # for p = plot(plotter, world, time) diff --git a/src/simulations/ClusterTimeSimulation.jl b/src/simulations/ClusterTimeSimulation.jl index 26abad5..91a54dd 100644 --- a/src/simulations/ClusterTimeSimulation.jl +++ b/src/simulations/ClusterTimeSimulation.jl @@ -22,41 +22,46 @@ ClusterTimeSimulation(; 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) + plotter::P = UnicodePlotter() +) 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() +mqd = MQD() +msd = MSD() +mqdNorm = measure(mqd, sim.world.sheeps) +p = plot(sim.plotter, sim.world, sim.time[]) +io = IOBuffer() if sim.condition == 0 - while mq.mqd > sim.mqdThreshold + while msd < msdThreshold + + measure(msd, sim.world.sheeps) + iterate!(sim) + plot!(io, p, sim.plotter, sim.world, sim.time[]) - Flase.measure( mq ,sim.world.sheeps) - iterate!( sim ) - plot!( io, p, sim.plotter, sim.world, sim.time[] ) - println(mq.mqd) end elseif sim.condition == 1 - while ms.msd > sim.msdThreshold + while getMQD(mqd, sim.world.sheeps, mqdNorm) > sim.mqdThreshold - Flase.measure( mq ,sim.world.sheeps) - iterate!( sim ) - plot!( io, p, sim.plotter, sim.world, sim.time[] ) + measure(mqd, sim.world.sheeps) + iterate!(sim) + plot!(io, p, sim.plotter, sim.world, sim.time[]) end elseif sim.condition == 2 - while ms.msd < sim.msdThreshold && mq.mqd > sim.mqdThreshold + while ms.msd < sim.msdThreshold && getMQD(mqd, sim.world.sheeps, mqdNorm) > sim.mqdThreshold - Flase.measure( mq ,sim.world.sheeps) - iterate!( sim ) - plot!( io, p, sim.plotter, sim.world, sim.time[] ) + measure(mqd, sim.world.sheeps) + iterate!(sim) + plot!(io, p, sim.plotter, sim.world, sim.time[]) end else sim.condition == 3 -println("this is condition 3") +error("Check breaking condition! It is $condition right now.") + end + return sim.time[] + end diff --git a/test/test_Simulation.jl b/test/test_Simulation.jl index f6677e4..7cc9e8c 100644 --- a/test/test_Simulation.jl +++ b/test/test_Simulation.jl @@ -7,6 +7,7 @@ world = World( motion = BrownianMotion(noise = 0.5, friction = 1.0), sheeps = DenseSheeps(10, n_sheeps = 10), ) + simulation = FiniteSimulation(; dt = 0.2, end_time = 100.0, @@ -28,3 +29,15 @@ end # testset pos = simulation.world.dogs.member[3].position @test all(pos .< Flase.getSheepCoords(simulation.world, pos)) end + + +simulation2 = Flase.ClusterTimeSimulation(; + condition = 0, + dt = 0.2, + world = world, + plotter = Flase.VoidPlotter() +) + +@testset "ClusterTimeSimulation" begin + @show runsim(simulation2) + end \ No newline at end of file From 8898fb712c38406a3211a514a168e55bcee340da Mon Sep 17 00:00:00 2001 From: alikateic Date: Fri, 1 Sep 2023 10:01:15 +0200 Subject: [PATCH 03/12] Everything implemented but not working yet --- src/measures/MeanQuadraticDistance.jl | 10 ++++++++-- src/measures/MeanSquaredDisplacement.jl | 14 ++++++++++++-- src/simulations/ClusterTimeSimulation.jl | 4 ++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/measures/MeanQuadraticDistance.jl b/src/measures/MeanQuadraticDistance.jl index c5d4c94..7989761 100644 --- a/src/measures/MeanQuadraticDistance.jl +++ b/src/measures/MeanQuadraticDistance.jl @@ -20,6 +20,13 @@ function sqr_dist(sheep, sheep1, gridsizestorage) return d1 * d1 + d2 * d2 end +function realSpace_sqr_dist(sheep, gridsizestorage, x::Real, y::Real, world::World) + ri = sheep[2][1] / gridsizestorage * world.boxsize[] + rj = sheep[2][2] / gridsizestorage * world.boxsize[] + d1 = min(abs(ri - x), world.boxsize[] - abs(ri - x)) + d2 = min(abs(rj - y), world.boxsize[] - abs(rj - y)) + return d1 * d1 + d2 * d2 +end function measure(::MQD, sheeps::Sheeps) #set a 3x3 Matrix for Test purpose. Result should be 3/4 @@ -41,8 +48,7 @@ function measure(::MQD, sheeps::Sheeps) end end - println(mean) - println(counter) + return mean / counter end diff --git a/src/measures/MeanSquaredDisplacement.jl b/src/measures/MeanSquaredDisplacement.jl index 2509337..04d368b 100644 --- a/src/measures/MeanSquaredDisplacement.jl +++ b/src/measures/MeanSquaredDisplacement.jl @@ -4,14 +4,24 @@ end function measure(::MSD, sheeps::Sheeps, world::World) # get center of mass + gridsizestorage = size(sheeps.grid)[1] cmx, cmy = center_of_mass(sheeps, world) sum = 0 for sheep in sheeps - sum += real# sqr distance in real space + sum += realSpace_sqr_dist(sheep, gridsizestorage, cmx, cmy, world) # sqr distance in real space end return sum / length(sheeps) end -function getMSD(msd::MSD, sheeps::Sheeps, word::World, msdNorm::Float64) +function getClusterRadius(sheeps::Sheeps, world::World) + clusterRadius = sqrt(sheeps.current_sheep[] / sheeps.capacity / π) * (world.boxsize[] / size(sheeps.grid)[1]) + return clusterRadius +end + +function getMSD(msd::MSD, sheeps::Sheeps, world::World) + R_cl = getClusterRadius(sheeps, world) + R_item = size(sheeps.grid)[1] / 2 + msdNorm = R_cl * R_cl / 2 + R_cl * R_item + msd_value = msdNorm / measure(msd, sheeps, world) return msd_value end \ No newline at end of file diff --git a/src/simulations/ClusterTimeSimulation.jl b/src/simulations/ClusterTimeSimulation.jl index 91a54dd..572f5ec 100644 --- a/src/simulations/ClusterTimeSimulation.jl +++ b/src/simulations/ClusterTimeSimulation.jl @@ -34,7 +34,7 @@ mqdNorm = measure(mqd, sim.world.sheeps) p = plot(sim.plotter, sim.world, sim.time[]) io = IOBuffer() if sim.condition == 0 - while msd < msdThreshold + while getMSD(msd, sim.world.sheeps, sim.world) < sim.msdThreshold measure(msd, sim.world.sheeps) iterate!(sim) @@ -50,7 +50,7 @@ elseif sim.condition == 1 end elseif sim.condition == 2 - while ms.msd < sim.msdThreshold && getMQD(mqd, sim.world.sheeps, mqdNorm) > sim.mqdThreshold + while getMSD(msd, sim.world.sheeps, sim.world) < sim.msdThreshold && getMQD(mqd, sim.world.sheeps, mqdNorm) > sim.mqdThreshold measure(mqd, sim.world.sheeps) iterate!(sim) From 036685b4a1bc9fe2d86ad8fb226b0321f26b769b Mon Sep 17 00:00:00 2001 From: alikateic Date: Fri, 1 Sep 2023 13:27:36 +0200 Subject: [PATCH 04/12] Added initial msd_value and mqd_value --- src/measures/MeanSquaredDisplacement.jl | 5 +++-- src/simulations/ClusterTimeSimulation.jl | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/measures/MeanSquaredDisplacement.jl b/src/measures/MeanSquaredDisplacement.jl index 04d368b..30ed58c 100644 --- a/src/measures/MeanSquaredDisplacement.jl +++ b/src/measures/MeanSquaredDisplacement.jl @@ -14,14 +14,15 @@ function measure(::MSD, sheeps::Sheeps, world::World) end function getClusterRadius(sheeps::Sheeps, world::World) - clusterRadius = sqrt(sheeps.current_sheep[] / sheeps.capacity / π) * (world.boxsize[] / size(sheeps.grid)[1]) + clusterRadius = sqrt(sheeps.current_sheep[] / sheeps.capacity / π) * world.boxsize[] / size(sheeps.grid)[1] return clusterRadius end function getMSD(msd::MSD, sheeps::Sheeps, world::World) R_cl = getClusterRadius(sheeps, world) R_item = size(sheeps.grid)[1] / 2 - msdNorm = R_cl * R_cl / 2 + R_cl * R_item + msdNorm = (R_cl * R_cl) / 2 + R_cl * R_item msd_value = msdNorm / measure(msd, sheeps, world) + println(msdNorm) return msd_value end \ No newline at end of file diff --git a/src/simulations/ClusterTimeSimulation.jl b/src/simulations/ClusterTimeSimulation.jl index 572f5ec..4aa89bb 100644 --- a/src/simulations/ClusterTimeSimulation.jl +++ b/src/simulations/ClusterTimeSimulation.jl @@ -31,30 +31,40 @@ function runsim(sim::ClusterTimeSimulation) mqd = MQD() msd = MSD() mqdNorm = measure(mqd, sim.world.sheeps) +mqd_value = getMQD(mqd, sim.world.sheeps, mqdNorm) +msd_value = getMSD(msd, sim.world.sheeps, sim.world) + p = plot(sim.plotter, sim.world, sim.time[]) io = IOBuffer() if sim.condition == 0 - while getMSD(msd, sim.world.sheeps, sim.world) < sim.msdThreshold + while msd_value < sim.msdThreshold + println("I'm in 1") measure(msd, sim.world.sheeps) iterate!(sim) plot!(io, p, sim.plotter, sim.world, sim.time[]) + msd_value = getMSD(msd, sim.world.sheeps, sim.world) end elseif sim.condition == 1 - while getMQD(mqd, sim.world.sheeps, mqdNorm) > sim.mqdThreshold + while mqd_value > sim.mqdThreshold + println("I'm in 2") measure(mqd, sim.world.sheeps) iterate!(sim) plot!(io, p, sim.plotter, sim.world, sim.time[]) + mqd_value = getMQD(mqd, sim.world.sheeps, mqdNorm) end elseif sim.condition == 2 - while getMSD(msd, sim.world.sheeps, sim.world) < sim.msdThreshold && getMQD(mqd, sim.world.sheeps, mqdNorm) > sim.mqdThreshold + while msd_value < sim.msdThreshold && mqd_value > sim.mqdThreshold + println("I'm in 3") measure(mqd, sim.world.sheeps) iterate!(sim) plot!(io, p, sim.plotter, sim.world, sim.time[]) + mqd_value = getMQD(mqd, sim.world.sheeps, mqdNorm) + msd_value = getMSD(msd, sim.world.sheeps, sim.world) end else sim.condition == 3 From 1780400ce7aaec0865c533d0329abfe6c5f195bd Mon Sep 17 00:00:00 2001 From: alikateic Date: Mon, 4 Sep 2023 13:49:56 +0200 Subject: [PATCH 05/12] Test for MSD and MQD initial value --- src/measures/MeanSquaredDisplacement.jl | 1 - src/simulations/ClusterTimeSimulation.jl | 8 ++++---- test/test_Simulation.jl | 2 ++ 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/measures/MeanSquaredDisplacement.jl b/src/measures/MeanSquaredDisplacement.jl index 30ed58c..f501308 100644 --- a/src/measures/MeanSquaredDisplacement.jl +++ b/src/measures/MeanSquaredDisplacement.jl @@ -23,6 +23,5 @@ function getMSD(msd::MSD, sheeps::Sheeps, world::World) R_item = size(sheeps.grid)[1] / 2 msdNorm = (R_cl * R_cl) / 2 + R_cl * R_item msd_value = msdNorm / measure(msd, sheeps, world) - println(msdNorm) return msd_value end \ No newline at end of file diff --git a/src/simulations/ClusterTimeSimulation.jl b/src/simulations/ClusterTimeSimulation.jl index 4aa89bb..93d60b6 100644 --- a/src/simulations/ClusterTimeSimulation.jl +++ b/src/simulations/ClusterTimeSimulation.jl @@ -39,8 +39,8 @@ io = IOBuffer() if sim.condition == 0 while msd_value < sim.msdThreshold - println("I'm in 1") - measure(msd, sim.world.sheeps) + println("I'm in 0") + measure(msd, sim.world.sheeps, sim.world) iterate!(sim) plot!(io, p, sim.plotter, sim.world, sim.time[]) msd_value = getMSD(msd, sim.world.sheeps, sim.world) @@ -49,7 +49,7 @@ if sim.condition == 0 elseif sim.condition == 1 while mqd_value > sim.mqdThreshold - println("I'm in 2") + println("I'm in 1") measure(mqd, sim.world.sheeps) iterate!(sim) plot!(io, p, sim.plotter, sim.world, sim.time[]) @@ -59,7 +59,7 @@ elseif sim.condition == 1 elseif sim.condition == 2 while msd_value < sim.msdThreshold && mqd_value > sim.mqdThreshold - println("I'm in 3") + println("I'm in 2") measure(mqd, sim.world.sheeps) iterate!(sim) plot!(io, p, sim.plotter, sim.world, sim.time[]) diff --git a/test/test_Simulation.jl b/test/test_Simulation.jl index 7cc9e8c..9996187 100644 --- a/test/test_Simulation.jl +++ b/test/test_Simulation.jl @@ -40,4 +40,6 @@ simulation2 = Flase.ClusterTimeSimulation(; @testset "ClusterTimeSimulation" begin @show runsim(simulation2) + @test getMSD(msd, sim.world.sheeps, sim.world) < 0.7 + @test getMQD(mqd, sim.world.sheeps, mqdNorm) > 0.1 end \ No newline at end of file From 1726a19ccbe8b7a40ccd1a8e589c3462e1e5ff34 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Mon, 4 Sep 2023 14:10:03 +0200 Subject: [PATCH 06/12] add automatic testing --- .github/workflows/tests.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..650dee1 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,32 @@ +name: Run tests + +on: + push: + branches: + - master + - main + pull_request: + workflow_dispatch: + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + julia-version: ['1'] + julia-arch: [x64, x86] + os: [ubuntu-latest, windows-latest, macOS-latest] + exclude: + - os: macOS-latest + julia-arch: x86 + + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: ${{ matrix.julia-version }} + arch: ${{ matrix.julia-arch }} + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-runtest@v1 + # with: + # annotate: true From a4c62f1b370c46083a687c092a20fd0aefdb5f2b Mon Sep 17 00:00:00 2001 From: alikateic Date: Tue, 5 Sep 2023 13:48:09 +0200 Subject: [PATCH 07/12] mqdNorm field in MQD and revised tests --- Project.toml | 2 + scripts/bench_init.jl | 41 ++++----- scripts/bench_runsim.jl | 45 +++++----- scripts/movingDogs.jl | 17 ++-- scripts/movingDogs_staticSheeps.jl | 45 +++++----- src/measures/MeanQuadraticDistance.jl | 14 ++- src/measures/MeanSquaredDisplacement.jl | 9 +- src/simulations/ClusterTimeSimulation.jl | 110 ++++++++++++----------- test/test_Simulation.jl | 37 ++++---- 9 files changed, 164 insertions(+), 156 deletions(-) diff --git a/Project.toml b/Project.toml index 43bb30f..d7695d5 100644 --- a/Project.toml +++ b/Project.toml @@ -5,7 +5,9 @@ version = "0.1.0" [deps] Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" +DocumentFormat = "ffa9a821-9c82-50df-894e-fbcef3ed31cd" GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb" +JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" diff --git a/scripts/bench_init.jl b/scripts/bench_init.jl index 4b67f5d..16c5055 100644 --- a/scripts/bench_init.jl +++ b/scripts/bench_init.jl @@ -5,32 +5,29 @@ using Flase using BenchmarkTools println("gridsize, fraction, time, bytes") -for gridsize in (10, 20, 100, 200, 400, 800, #=1600, 2000=#) +for gridsize in (10, 20, 100, 200, 400, 800) #=1600, 2000=# for sheep_ration in (0.1, 0.5, 0.9) t = @timed begin - v0 = 5.0 - Dϕ = 4.0 - world = World( - v0 = 1., - n_dogs = 9, - boxsize = float(gridsize), - freedom_rate = 10.0, - business_rate = 10.0, - meanSleepyness = 10.0, - motion = BrownianMotion( - noise = v0^4 / Dϕ, - friction = Dϕ / v0^2 + v0 = 5.0 + Dϕ = 4.0 + world = World( + v0 = 1.0, + n_dogs = 9, + boxsize = float(gridsize), + freedom_rate = 10.0, + business_rate = 10.0, + meanSleepyness = 10.0, + motion = BrownianMotion(noise = v0^4 / Dϕ, friction = Dϕ / v0^2), + sheeps = Flase.SparseSheeps( + gridsize, # gridsize + n_sheeps = sheep_ration * gridsize^2, ), - sheeps = Flase.SparseSheeps( - gridsize, # gridsize - n_sheeps = sheep_ration * gridsize^2, - ) ) - simulation = FiniteSimulation(; - dt = 0.1, - end_time = 100.0, - world = world, - plotter = Flase.VoidPlotter() + simulation = FiniteSimulation(; + dt = 0.1, + end_time = 100.0, + world = world, + plotter = Flase.VoidPlotter(), ) end println("$gridsize, $sheep_ration, $(t.time), $(t.bytes)") diff --git a/scripts/bench_runsim.jl b/scripts/bench_runsim.jl index 96ba455..c49a149 100644 --- a/scripts/bench_runsim.jl +++ b/scripts/bench_runsim.jl @@ -5,34 +5,31 @@ using Flase using BenchmarkTools @time begin -v0 = 5.0 -Dϕ = 4.0 -gridsize = 200 -frac = 0.9 -world = World( - v0 = 1., - n_dogs = 9, - boxsize = float(gridsize), - freedom_rate = 10.0, - business_rate = 10.0, - meanSleepyness = 10.0, - motion = BrownianMotion( - noise = v0^4 / Dϕ, - friction = Dϕ / v0^2 + v0 = 5.0 + Dϕ = 4.0 + gridsize = 200 + frac = 0.9 + world = World( + v0 = 1.0, + n_dogs = 9, + boxsize = float(gridsize), + freedom_rate = 10.0, + business_rate = 10.0, + meanSleepyness = 10.0, + motion = BrownianMotion(noise = v0^4 / Dϕ, friction = Dϕ / v0^2), + sheeps = Flase.BaseSheeps( + gridsize, # gridsize + n_sheeps = frac * gridsize^2, ), - sheeps = Flase.BaseSheeps( - gridsize, # gridsize - n_sheeps = frac * gridsize^2, - ) ) -simulation = FiniteSimulation(; - dt = 0.1, - end_time = 100.0, - world = world, - plotter = Flase.VoidPlotter() + simulation = FiniteSimulation(; + dt = 0.1, + end_time = 100.0, + world = world, + plotter = Flase.VoidPlotter(), ) end t = @benchmark begin - Flase.runsim( simulation ) + Flase.runsim(simulation) end display(t) diff --git a/scripts/movingDogs.jl b/scripts/movingDogs.jl index 510d137..0c7b22a 100644 --- a/scripts/movingDogs.jl +++ b/scripts/movingDogs.jl @@ -1,17 +1,10 @@ using Flase world = World( - v0 = 1., + v0 = 1.0, n_dogs = 120, boxsize = 10.0, - motion = BrownianMotion( - noise = 0.5, - friction = 1.0 - ) - ) -simulation = InfiniteSimulation(; - dt = 0.05, - world = world, - plotter = UnicodePlotter() - ) -Flase.runsim( simulation ) + motion = BrownianMotion(noise = 0.5, friction = 1.0), +) +simulation = InfiniteSimulation(; dt = 0.05, world = world, plotter = UnicodePlotter()) +Flase.runsim(simulation) diff --git a/scripts/movingDogs_staticSheeps.jl b/scripts/movingDogs_staticSheeps.jl index 871bc2b..dc72543 100644 --- a/scripts/movingDogs_staticSheeps.jl +++ b/scripts/movingDogs_staticSheeps.jl @@ -5,33 +5,30 @@ using Flase using BenchmarkTools @time begin -v0 = 5.0 -Dϕ = 4.0 -gridsize = 10 -frac = 0.1 -world = World( - v0 = 1., - n_dogs = 9, - boxsize = float(gridsize), - freedom_rate = 10.0, - business_rate = 10.0, - meanSleepyness = 10.0, - motion = BrownianMotion( - noise = v0^4 / Dϕ, - friction = Dϕ / v0^2 + v0 = 5.0 + Dϕ = 4.0 + gridsize = 10 + frac = 0.1 + world = World( + v0 = 1.0, + n_dogs = 9, + boxsize = float(gridsize), + freedom_rate = 10.0, + business_rate = 10.0, + meanSleepyness = 10.0, + motion = BrownianMotion(noise = v0^4 / Dϕ, friction = Dϕ / v0^2), + sheeps = DenseSheeps( + gridsize, # gridsize + n_sheeps = frac * gridsize^2, ), - sheeps = DenseSheeps( - gridsize, # gridsize - n_sheeps = frac * gridsize^2, - ) ) -simulation = FiniteSimulation(; - dt = 0.1, - end_time = 100.0, - world = world, - plotter = Flase.VoidPlotter() + simulation = FiniteSimulation(; + dt = 0.1, + end_time = 100.0, + world = world, + plotter = Flase.VoidPlotter(), ) end @benchmark begin - Flase.runsim( simulation ) + Flase.runsim(simulation) end samples = 1 evals = 1 gcsample = true diff --git a/src/measures/MeanQuadraticDistance.jl b/src/measures/MeanQuadraticDistance.jl index 7989761..d4b4a16 100644 --- a/src/measures/MeanQuadraticDistance.jl +++ b/src/measures/MeanQuadraticDistance.jl @@ -2,7 +2,15 @@ #first we need a new structure -struct MQD +Base.@kwdef struct MQD + mqdNorm::Float64 +end + +MQD() = MQD(0) + +function MQD(sheeps::Sheeps) + mqdNorm = measure(MQD(), sheeps) + return mqdNorm end #then compute the function that takes imput from object sheep::Sheeps @@ -55,6 +63,6 @@ end function getMQD(mqd::MQD, sheeps::Sheeps, mqdNorm::Float64) - mqd_value = measure(mqd, sheeps)/mqdNorm + mqd_value = measure(mqd, sheeps) / mqdNorm return mqd_value -end \ No newline at end of file +end diff --git a/src/measures/MeanSquaredDisplacement.jl b/src/measures/MeanSquaredDisplacement.jl index f501308..82271e6 100644 --- a/src/measures/MeanSquaredDisplacement.jl +++ b/src/measures/MeanSquaredDisplacement.jl @@ -1,6 +1,5 @@ "Type for calculating the mean squared displacement." -struct MSD -end +struct MSD end function measure(::MSD, sheeps::Sheeps, world::World) # get center of mass @@ -14,7 +13,9 @@ function measure(::MSD, sheeps::Sheeps, world::World) end function getClusterRadius(sheeps::Sheeps, world::World) - clusterRadius = sqrt(sheeps.current_sheep[] / sheeps.capacity / π) * world.boxsize[] / size(sheeps.grid)[1] + clusterRadius = + sqrt(sheeps.current_sheep[] / sheeps.capacity / π) * world.boxsize[] / + size(sheeps.grid)[1] return clusterRadius end @@ -24,4 +25,4 @@ function getMSD(msd::MSD, sheeps::Sheeps, world::World) msdNorm = (R_cl * R_cl) / 2 + R_cl * R_item msd_value = msdNorm / measure(msd, sheeps, world) return msd_value -end \ No newline at end of file +end diff --git a/src/simulations/ClusterTimeSimulation.jl b/src/simulations/ClusterTimeSimulation.jl index 93d60b6..2d00190 100644 --- a/src/simulations/ClusterTimeSimulation.jl +++ b/src/simulations/ClusterTimeSimulation.jl @@ -1,6 +1,6 @@ using Distributions -struct ClusterTimeSimulation{P<:Plotter, F<:Number, W<:World } <: Simulation +struct ClusterTimeSimulation{P<:Plotter,F<:Number,W<:World} <: Simulation time::Base.RefValue{F} t_sheep_boredom::Base.RefValue{F} @@ -11,67 +11,77 @@ struct ClusterTimeSimulation{P<:Plotter, F<:Number, W<:World } <: Simulation world::W plotter::P -end +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 = UnicodePlotter() -) where {F<:Number, W<:World,P<:Plotter} = - ClusterTimeSimulation{P,F,W}(Ref(time), Ref(t_sheep_boredom), condition, msdThreshold, mqdThreshold, dt, world, plotter) + time::F = convert(typeof(dt), 0), + t_sheep_boredom = rand( + Exponential(world.meanSheepDiffusionTime / world.sheeps.current_sheep[]), + ), + plotter::P = UnicodePlotter(), +) 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) -mqd = MQD() -msd = MSD() -mqdNorm = measure(mqd, sim.world.sheeps) -mqd_value = getMQD(mqd, sim.world.sheeps, mqdNorm) -msd_value = getMSD(msd, sim.world.sheeps, sim.world) - -p = plot(sim.plotter, sim.world, sim.time[]) -io = IOBuffer() -if sim.condition == 0 - while msd_value < sim.msdThreshold - - println("I'm in 0") - measure(msd, sim.world.sheeps, sim.world) - iterate!(sim) - plot!(io, p, sim.plotter, sim.world, sim.time[]) - msd_value = getMSD(msd, sim.world.sheeps, sim.world) - - end -elseif sim.condition == 1 - while mqd_value > sim.mqdThreshold - - println("I'm in 1") - measure(mqd, sim.world.sheeps) - iterate!(sim) - plot!(io, p, sim.plotter, sim.world, sim.time[]) - mqd_value = getMQD(mqd, sim.world.sheeps, mqdNorm) + mqd = MQD() + msd = MSD() + mqdNorm = MQD(sim.world.sheeps) + mqd_value = getMQD(mqd, sim.world.sheeps, mqdNorm) + msd_value = getMSD(msd, sim.world.sheeps, sim.world) + + p = plot(sim.plotter, sim.world, sim.time[]) + io = IOBuffer() + if sim.condition == 0 + while msd_value < sim.msdThreshold + + println("I'm in 0") + measure(msd, sim.world.sheeps, sim.world) + iterate!(sim) + plot!(io, p, sim.plotter, sim.world, sim.time[]) + msd_value = getMSD(msd, sim.world.sheeps, sim.world) + + end + elseif sim.condition == 1 + while mqd_value > sim.mqdThreshold + + println("I'm in 1") + measure(mqd, sim.world.sheeps) + iterate!(sim) + plot!(io, p, sim.plotter, sim.world, sim.time[]) + mqd_value = getMQD(mqd, sim.world.sheeps, mqdNorm) + + end + elseif sim.condition == 2 + while msd_value < sim.msdThreshold && mqd_value > sim.mqdThreshold + + println("I'm in 2") + measure(mqd, sim.world.sheeps) + iterate!(sim) + plot!(io, p, sim.plotter, sim.world, sim.time[]) + mqd_value = getMQD(mqd, sim.world.sheeps, mqdNorm) + msd_value = getMSD(msd, sim.world.sheeps, sim.world) + + end + else + sim.condition == 3 + error("Check breaking condition! It is $condition right now.") end -elseif sim.condition == 2 - while msd_value < sim.msdThreshold && mqd_value > sim.mqdThreshold - - println("I'm in 2") - measure(mqd, sim.world.sheeps) - iterate!(sim) - plot!(io, p, sim.plotter, sim.world, sim.time[]) - mqd_value = getMQD(mqd, sim.world.sheeps, mqdNorm) - msd_value = getMSD(msd, sim.world.sheeps, sim.world) - - end -else sim.condition == 3 -error("Check breaking condition! It is $condition right now.") - -end -return sim.time[] + return sim.time[] end diff --git a/test/test_Simulation.jl b/test/test_Simulation.jl index 9996187..805364e 100644 --- a/test/test_Simulation.jl +++ b/test/test_Simulation.jl @@ -1,18 +1,18 @@ using Flase, Test world = World( - v0 = 1.0, - n_dogs = 120, - boxsize = 10.0, - motion = BrownianMotion(noise = 0.5, friction = 1.0), - sheeps = DenseSheeps(10, n_sheeps = 10), + v0=1.0, + n_dogs=120, + boxsize=10.0, + motion=BrownianMotion(noise=0.5, friction=1.0), + sheeps=DenseSheeps(10, n_sheeps=10), ) simulation = FiniteSimulation(; - dt = 0.2, - end_time = 100.0, - world = world, - plotter = UnicodePlotter(), + dt=0.2, + end_time=100.0, + world=world, + plotter=UnicodePlotter() ) @testset "Move items" begin @@ -32,14 +32,17 @@ end simulation2 = Flase.ClusterTimeSimulation(; - condition = 0, - dt = 0.2, - world = world, - plotter = Flase.VoidPlotter() + condition=0, + dt=0.2, + world=world, + plotter=Flase.VoidPlotter() ) @testset "ClusterTimeSimulation" begin - @show runsim(simulation2) - @test getMSD(msd, sim.world.sheeps, sim.world) < 0.7 - @test getMQD(mqd, sim.world.sheeps, mqdNorm) > 0.1 - end \ No newline at end of file + mqd = Flase.MQD() + msd = Flase.MSD() + mqdNorm = Flase.measure(mqd, simulation2.world.sheeps) + @show Flase.runsim(simulation2) + @test Flase.getMSD(msd, simulation2.world.sheeps, simulation2.world) < 0.7 + @test Flase.getMQD(mqd, simulation2.world.sheeps, mqdNorm) > 0.1 +end From 2ee9560bf53183fbdcced049388c5d5612451251 Mon Sep 17 00:00:00 2001 From: alikateic Date: Tue, 5 Sep 2023 16:28:17 +0200 Subject: [PATCH 08/12] Made suggested changes --- Project.toml | 1 - src/measures/MeanQuadraticDistance.jl | 8 ++++---- src/simulations/ClusterTimeSimulation.jl | 9 ++++----- test/test_Simulation.jl | 5 ++--- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Project.toml b/Project.toml index d7695d5..9d5b56d 100644 --- a/Project.toml +++ b/Project.toml @@ -7,7 +7,6 @@ version = "0.1.0" Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" DocumentFormat = "ffa9a821-9c82-50df-894e-fbcef3ed31cd" GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb" -JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" diff --git a/src/measures/MeanQuadraticDistance.jl b/src/measures/MeanQuadraticDistance.jl index d4b4a16..3d5d131 100644 --- a/src/measures/MeanQuadraticDistance.jl +++ b/src/measures/MeanQuadraticDistance.jl @@ -6,11 +6,11 @@ Base.@kwdef struct MQD mqdNorm::Float64 end -MQD() = MQD(0) +MQD() = MQD(1) function MQD(sheeps::Sheeps) mqdNorm = measure(MQD(), sheeps) - return mqdNorm + return MQD(mqdNorm) end #then compute the function that takes imput from object sheep::Sheeps @@ -62,7 +62,7 @@ function measure(::MQD, sheeps::Sheeps) end -function getMQD(mqd::MQD, sheeps::Sheeps, mqdNorm::Float64) - mqd_value = measure(mqd, sheeps) / mqdNorm +function getMQD(mqd::MQD, sheeps::Sheeps) + mqd_value = measure(mqd, sheeps) / mqd.mqdNorm return mqd_value end diff --git a/src/simulations/ClusterTimeSimulation.jl b/src/simulations/ClusterTimeSimulation.jl index 2d00190..39df26a 100644 --- a/src/simulations/ClusterTimeSimulation.jl +++ b/src/simulations/ClusterTimeSimulation.jl @@ -37,10 +37,9 @@ ClusterTimeSimulation(; function runsim(sim::ClusterTimeSimulation) - mqd = MQD() msd = MSD() - mqdNorm = MQD(sim.world.sheeps) - mqd_value = getMQD(mqd, sim.world.sheeps, mqdNorm) + mqd = MQD(sim.world.sheeps) + mqd_value = getMQD(mqd, sim.world.sheeps) msd_value = getMSD(msd, sim.world.sheeps, sim.world) p = plot(sim.plotter, sim.world, sim.time[]) @@ -62,7 +61,7 @@ function runsim(sim::ClusterTimeSimulation) measure(mqd, sim.world.sheeps) iterate!(sim) plot!(io, p, sim.plotter, sim.world, sim.time[]) - mqd_value = getMQD(mqd, sim.world.sheeps, mqdNorm) + mqd_value = getMQD(mqd, sim.world.sheeps) end elseif sim.condition == 2 @@ -72,7 +71,7 @@ function runsim(sim::ClusterTimeSimulation) measure(mqd, sim.world.sheeps) iterate!(sim) plot!(io, p, sim.plotter, sim.world, sim.time[]) - mqd_value = getMQD(mqd, sim.world.sheeps, mqdNorm) + mqd_value = getMQD(mqd, sim.world.sheeps) msd_value = getMSD(msd, sim.world.sheeps, sim.world) end diff --git a/test/test_Simulation.jl b/test/test_Simulation.jl index 805364e..5cfd746 100644 --- a/test/test_Simulation.jl +++ b/test/test_Simulation.jl @@ -39,10 +39,9 @@ simulation2 = Flase.ClusterTimeSimulation(; ) @testset "ClusterTimeSimulation" begin - mqd = Flase.MQD() + mqd = Flase.MQD(simulation2.world.sheeps) msd = Flase.MSD() - mqdNorm = Flase.measure(mqd, simulation2.world.sheeps) @show Flase.runsim(simulation2) @test Flase.getMSD(msd, simulation2.world.sheeps, simulation2.world) < 0.7 - @test Flase.getMQD(mqd, simulation2.world.sheeps, mqdNorm) > 0.1 + @test Flase.getMQD(mqd, simulation2.world.sheeps) > 0.1 end From 67b3ad3e6367c22dfe763ad3f8968ecab5661fec Mon Sep 17 00:00:00 2001 From: alikateic Date: Thu, 7 Sep 2023 12:56:08 +0200 Subject: [PATCH 09/12] Found parameters for working MSD --- src/simulations/ClusterTimeSimulation.jl | 3 --- test/test_Simulation.jl | 12 ++++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/simulations/ClusterTimeSimulation.jl b/src/simulations/ClusterTimeSimulation.jl index 39df26a..8423c07 100644 --- a/src/simulations/ClusterTimeSimulation.jl +++ b/src/simulations/ClusterTimeSimulation.jl @@ -47,7 +47,6 @@ function runsim(sim::ClusterTimeSimulation) if sim.condition == 0 while msd_value < sim.msdThreshold - println("I'm in 0") measure(msd, sim.world.sheeps, sim.world) iterate!(sim) plot!(io, p, sim.plotter, sim.world, sim.time[]) @@ -57,7 +56,6 @@ function runsim(sim::ClusterTimeSimulation) elseif sim.condition == 1 while mqd_value > sim.mqdThreshold - println("I'm in 1") measure(mqd, sim.world.sheeps) iterate!(sim) plot!(io, p, sim.plotter, sim.world, sim.time[]) @@ -67,7 +65,6 @@ function runsim(sim::ClusterTimeSimulation) elseif sim.condition == 2 while msd_value < sim.msdThreshold && mqd_value > sim.mqdThreshold - println("I'm in 2") measure(mqd, sim.world.sheeps) iterate!(sim) plot!(io, p, sim.plotter, sim.world, sim.time[]) diff --git a/test/test_Simulation.jl b/test/test_Simulation.jl index 5cfd746..ea4630b 100644 --- a/test/test_Simulation.jl +++ b/test/test_Simulation.jl @@ -31,17 +31,25 @@ end # testset end +world2 = World( + v0=1.0, + n_dogs=100, + boxsize=50.0, + motion=BrownianMotion(noise=0.5, friction=1.0), + sheeps=DenseSheeps(20, n_sheeps=20), +) + simulation2 = Flase.ClusterTimeSimulation(; condition=0, dt=0.2, - world=world, + world=world2, plotter=Flase.VoidPlotter() ) @testset "ClusterTimeSimulation" begin mqd = Flase.MQD(simulation2.world.sheeps) msd = Flase.MSD() - @show Flase.runsim(simulation2) @test Flase.getMSD(msd, simulation2.world.sheeps, simulation2.world) < 0.7 @test Flase.getMQD(mqd, simulation2.world.sheeps) > 0.1 + @show Flase.runsim(simulation2) end From 4cd9e676ab7e39230eae5dbd7e5e6be922b55530 Mon Sep 17 00:00:00 2001 From: alikateic Date: Fri, 8 Sep 2023 10:24:05 +0200 Subject: [PATCH 10/12] Added changes to test_Simulation --- Project.toml | 1 + test/test_Simulation.jl | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index 9d5b56d..ac8f6a3 100644 --- a/Project.toml +++ b/Project.toml @@ -8,6 +8,7 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" DocumentFormat = "ffa9a821-9c82-50df-894e-fbcef3ed31cd" GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228" diff --git a/test/test_Simulation.jl b/test/test_Simulation.jl index ea4630b..77dd315 100644 --- a/test/test_Simulation.jl +++ b/test/test_Simulation.jl @@ -33,23 +33,23 @@ end world2 = World( v0=1.0, - n_dogs=100, - boxsize=50.0, + n_dogs=10, + boxsize=25.0, motion=BrownianMotion(noise=0.5, friction=1.0), - sheeps=DenseSheeps(20, n_sheeps=20), + sheeps=DenseSheeps(30, n_sheeps=30), ) simulation2 = Flase.ClusterTimeSimulation(; condition=0, dt=0.2, world=world2, - plotter=Flase.VoidPlotter() + plotter=Flase.UnicodePlotter() ) @testset "ClusterTimeSimulation" begin mqd = Flase.MQD(simulation2.world.sheeps) msd = Flase.MSD() - @test Flase.getMSD(msd, simulation2.world.sheeps, simulation2.world) < 0.7 - @test Flase.getMQD(mqd, simulation2.world.sheeps) > 0.1 @show Flase.runsim(simulation2) + @test Flase.getMSD(msd, simulation2.world.sheeps, simulation2.world) >= 0.7 + @test Flase.getMQD(mqd, simulation2.world.sheeps) <= 0.1 end From 9904d358e4748b03c843ae54c1a317eaa8d16c3b Mon Sep 17 00:00:00 2001 From: alikateic Date: Fri, 8 Sep 2023 10:25:25 +0200 Subject: [PATCH 11/12] Forgot to change back to VoidPlotter --- test/test_Simulation.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_Simulation.jl b/test/test_Simulation.jl index 77dd315..8bf93bf 100644 --- a/test/test_Simulation.jl +++ b/test/test_Simulation.jl @@ -43,7 +43,7 @@ simulation2 = Flase.ClusterTimeSimulation(; condition=0, dt=0.2, world=world2, - plotter=Flase.UnicodePlotter() + plotter=Flase.VoidPlotter() ) @testset "ClusterTimeSimulation" begin From 42687073fdfc76cca6ffb50ab1b21c552d20e0d9 Mon Sep 17 00:00:00 2001 From: alikateic Date: Mon, 11 Sep 2023 13:02:56 +0200 Subject: [PATCH 12/12] Extra szenario for MQD test --- test/test_Simulation.jl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/test_Simulation.jl b/test/test_Simulation.jl index 8bf93bf..aa68596 100644 --- a/test/test_Simulation.jl +++ b/test/test_Simulation.jl @@ -46,10 +46,18 @@ simulation2 = Flase.ClusterTimeSimulation(; plotter=Flase.VoidPlotter() ) +simulation3 = Flase.ClusterTimeSimulation(; + condition=1, + dt=0.2, + world=world, + plotter=Flase.VoidPlotter() +) + @testset "ClusterTimeSimulation" begin mqd = Flase.MQD(simulation2.world.sheeps) msd = Flase.MSD() @show Flase.runsim(simulation2) + @show Flase.runsim(simulation3) @test Flase.getMSD(msd, simulation2.world.sheeps, simulation2.world) >= 0.7 - @test Flase.getMQD(mqd, simulation2.world.sheeps) <= 0.1 + @test Flase.getMQD(mqd, simulation3.world.sheeps) <= 0.1 end