Agent Based Model :Simple segregation model

조회 수: 6 (최근 30일)
Tsang Chak Ng
Tsang Chak Ng 2018년 3월 30일
댓글: Alice Pearce 2019년 12월 9일
Hello guys, Can I just ask u how to modify my original Model in the following way? 1.Specify that the there are initially more psychologists than economists. 2.Only allow adjacent neighbours to switch
Below is the coding for my original Coding %Orignal Model %Schelling-style model clear all
%first we set up a world with randomly scattered economists and psychologists
nside=50; %the number of agents on each side of the matrix randworld=rand(nside,nside); %Or could use round(rand(nside,nside)) world=randworld>.5; %say psychologist=0; economist=1;
colormap([0 1 0; 1 0 0]);% sets psychs as green , econs as red
numsadecons=100; numsadpsychs=100; %give these temp high values just to satisfy the while condition
while (numsadecons>50) && (numsadpsychs>50)
%first calcuate number of econs surrounding each agent
A=circshift(world,1); B=circshift(world,-1);
C=circshift(world',1)'; D=circshift(world',-1)';
necon=A+B+C+D; %now necon has numbers of econ neighbours for each person in world
%Now determine the unhappy econs
sadecons=world.*((world.*necon)<3); %an econ wants to be around at least 3 econs
%Now determine the unhappy psychs
sadpsychs=abs(world-1).*((abs(world-1).*necon)>1); %a psych is unhappy around > 1 econ
numsadecons=sum(sum(sadecons)); numsadpsychs=sum(sum(sadpsychs));
%now choose a random sad econ and change to be a psych:
[r,c]=find(sadecons); %get the row and col indices of all sad econs
index=ceil(rand*numsadecons); %choose a random sad econ
world(r(index),c(index))=0; %change the econ to a psych
%now choose a random sad psych and change to be an econ:
[r,c]=find(sadpsychs); %get the row and col indices of all sad psychs
index=ceil(rand*numsadpsychs); %choose a random sad psych
world(r(index),c(index))=1; %change the psych to an econ
imagesc(world) %draw a colourmap
pause(0.01) %pause for 0.01 second
end
  댓글 수: 2
yawen deng
yawen deng 2018년 12월 5일
Have you solved this problem?Seems I have the same problem and don't know how to solve it.
Alice Pearce
Alice Pearce 2019년 12월 9일
Hi, did you ever figure out how to get adjacent neighbours to switch?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Eigenvalue Problems에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by