clear all
close all

N = 60;
fokszam = 4;
p = fokszam/N;

%g = rand(N)<p;
g = strogatz(0.5, N, fokszam);
g = g | g';
g = (ones(N)-diag(ones(1,N))) & g;
g = tril(g);

bg1 = biograph(g);
allid=get(bg1.nodes,'id');
bg = biograph(g,allid,'LayoutType','equilibrium','EdgeType','straight');
bg = view(bg);

%make some sick
set(bg.nodes, 'UserData', 0)
set(bg.nodes, 'Color', [1 1 1])

probability = 0.1;
indexes = find(rand(1,N)<probability);
set(bg.Nodes(indexes), 'Color', [1 0.4 0.4])
set(bg.Nodes(indexes), 'UserData', 1)

pInfect = 0.4;
pHeal = 0.25;

for i = 1:100
    
    %set(bg.edges,'LineColor',[0.5 0.5 0.5])
    
    %infect others
    sicknodeIDs = find(cell2mat(get(bg.nodes, 'UserData')));
    if (~isempty(sicknodeIDs))
        relatives = getrelatives(bg.nodes(sicknodeIDs));
        infectedNodes = find(rand(1,length(relatives))<pInfect);
        set(relatives(infectedNodes), 'UserData', 1);
        set(relatives(infectedNodes), 'Color', [1 0.4 0.4])
        
        %heal
        healedNodes = find(rand(1,length(relatives))<pHeal);
        set(relatives(healedNodes), 'UserData', 0);
        set(relatives(healedNodes), 'Color', [1 1 1])
    else
        break
    end
    pause(0.5)
end

