N = 40;
K = 4;

p = 0.5;

g = strogatz(p,N,K);
g = g|g';
g = tril(g);

bg1 = biograph(g);
allid=get(bg1.nodes,'id');

bg = biograph(g,allid,'LayoutType','equilibrium','EdgeType','straight');
bg = view(bg);

set(bg.nodes, 'Color', [1 1 1] );
set(bg.nodes, 'UserData', 0 );

probabilitySick = 0.1;
indexes = find(rand(N,1)<probabilitySick);

set(bg.nodes(indexes), 'Color', [1 0 0] );
set(bg.nodes(indexes), 'UserData', 1 );

pHeal = 0.25;
pInfect = 0.3;

for i=1:100
   sickNodeIDs = find(cell2mat(get(bg.nodes, 'UserData')));
   if (~isempty(sickNodeIDs))
       relatives = getrelatives(bg.nodes(sickNodeIDs));
       infectedIDs = find(rand(1,length(relatives))<pInfect);
       set(relatives(infectedIDs), 'Color', [1 0 0] );
       set(relatives(infectedIDs), 'UserData', 1 );
        
       healedNodeIDs = find(rand(1,length(sickNodeIDs))<pHeal);
       set(bg.nodes(healedNodeIDs), 'Color', [1 1 1] );
       set(bg.nodes(healedNodeIDs), 'UserData', 0 );
   else
       break;
   end
   pause(0.5);
end