/* London Blitz example in Picat. From Church https://ocw.mit.edu/courses/res-9-003-brains-minds-and-machines-summer-course-summer-2015/3a08df2946c91378cf03d672fec3e037_church_ex.rtf """ 3.5.1 London Blitz example """ Cf my Gamble model gamble_london_blitz.rkt This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import ppl_distributions, ppl_utils, ppl_common_utils. import util. % import ordset. main => go. % random draw center from 10x10 box sample_gaussian_center() = [uniform(0,10),uniform(0,10)]. number_of_gaussian() = random_integer1(10). % 2D gaussian, sample around the center twod_gaussian(Center) = [normal_dist(Center[1],1.0),normal_dist(Center[2],1.0)]. % Sample the Gaussian centers centers() = [sample_gaussian_center() : _ in 1..number_of_gaussian()]. % Random bombing uniform_bombing(NumBomb) = [[uniform(0,10),uniform(0,10)] : _ in 1..100]. % 'cluster' bombing target_bombing(NumBomb) = Points => NumberOfGaussian = 3 + random_integer(5), Centers = [sample_gaussian_center() : _ in 1..NumberOfGaussian], Points1 = [[twod_gaussian(Center) : _ in 1..floor(NumBomb / NumberOfGaussian)] : Center in Centers], Points = fold(++,[],Points1). /* uniform_bombing Scatter plot: ymax = 9.97542 | * * * * | * * | * ** * * | * ** * | * * | ** * * ** | *** * * * | * * | * * * * * * ** * * | * * ** | * * * * ** | ** * * * * * | * * | * * * * ** | * * * * |* * * * * * | * * * * ** * * ** * | * * ** | * | * * * ymin = 0.27152 x = [0.298871,9.89337] uniform_bombing Scatter plot: ymax = 9.78006 | * * * | * * * | * * * * * * * * | * * * * * * | * * ** * |* * * | * * * * * | * * * * ** * | * * * * * | * * * | * * * * * | * * * * | * * * * * * * | * * * *** | * * * * * | * * * * * * * * | * | * * * * | * * * ** * | * * * ymin = 0.0255787 x = [0.103132,9.97701] uniform_bombing Scatter plot: ymax = 9.94957 | * * * * ** | * * * * * * |* * * * * * | * ** ** * * | * | * * * | * * * * | * * * *** | * * * | * | * ** * * * | * * * * * * | * * * * ** | * * * * * * | * * * | * * * * * * * * * | * * * * * | * * * * * * | * * * | * * * ymin = 0.043926 x = [0.124256,9.9902] target_bombing Scatter plot: ymax = 11.1824 | * | | | * | ** | * | * * | | * | | | * * | * * | * * | * * | * |* | * | | * ymin = -0.385279 x = [2.22095,10.2845] */ go ?=> _ = random2(), member(T,1..4), NumBombs = 20, if flip(0.5) = true then println(uniform_bombing), Points = uniform_bombing(NumBombs) else println(target_bombing), Points = target_bombing(NumBombs) end, show_scatter_plot(Points), nl, nl, fail, nl. go => true.