MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Trouble Implementing Schelling's Segregation Model

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91676] Re: Trouble Implementing Schelling's Segregation Model
  • From: Steve_Kinsella <stephen.kinsella at gmail.com>
  • Date: Thu, 4 Sep 2008 06:39:00 -0400 (EDT)
  • References: <g7uo2p$5un$1@smc.vnet.net>

Anybody?

Steve_Kinsella wrote:
> Hi All,
>
> I'm trying to write a demonstration for a class on Schelling's 1978
> segregation model. An implementation exists from Gaylord and D'Andria,
> 1998, but it's not playing ball with Mathematica 6.0. If anyone wants
> to take a pop at the code below, I'd appreciate it. Thanks, Steve
>
> (*Schelling Model (1978, 147 - 153) Demonstration
>
> Model uses a square n*n lattice with wraparound boundary conditions \
> with a population density p of individuals occupying lattice sites \
> and the rest empty. System evolves over t time steps. *)
>
> neighborhood[n_, p_, v_, w_, t_] :=
>  Module[{walk, movestay, society, RND, Moore, GN} ,
>   RND := RandomInteger[ {1, 4}]
>     society :=
>      Table[Floor[p + RandomInteger[]], {n}, {n}] /.
>
>       1 :> {RND, Table[Integer, {1, w}], {v}};
>   movestay[0, __] := 0;
>   movestay[{a_, b_},
>     res__] := {a*
>      Round[1 -
>        Count[Map[
>           Count[b - #[[2]], 0] &, {res}/.0 -> {0,
>             0}], _?{# >= v/2 &}]/8.] , b };
>   (*Walk Rules*)
>
>   Moore[func_, lat_] :=
>    MapThread[func,
>     Map[RotateRight[lat, #] &, {{0, 0}, {1, 0}, {0, -1}, {-1, 0}, {0,
>        1}, {1, -1}, {-1, -1}, {-1, 1}, {1, 1}} , 2];
>     GN[func_, lat_] :=
>      MapThread[func,
>       Map[RotateRight[lat, #] &, {{0, 0}, {1, 0},  {0, -1}, {-1,
>          0}, {0, 1}, {1, -1}, {-1, -1}, {-1, 1}, {1, 1}, {2,
>          0}, {0, -2}, {-2, 0}, {0, 2}}], 2];
>     NestList[GN[walk, Moore[movestay, #]] &, society, t]]]
>
> SeedRandom[9]
> results = neighborhood[20, 0.6, 1, 2, 500]
>
> Show[GraphicsArray[
>   Map[Show[Graphics[
>       Raster[# /. {0 -> RGBColor[0.7, 0.7, 0.7], {_, {1}} ->
>           RGBColor[0, 1, 0], {_, {2}} -> RGBColor[0, 0, 1]}]],
>      AspectRatio -> Automatic, DisplayFunction -> Identity] &, {First[
>      results], Last[results]}]]]


  • Prev by Date: Re: Thinking Mathematica: Any suggestions?
  • Next by Date: ListDensityPlot in 6.0 creates large eps
  • Previous by thread: Evaluating a notebook with a talk presentation from another notebook
  • Next by thread: Re: Trouble Implementing Schelling's Segregation Model