Iterated games

In this post, we will explore the concept of graph coloring and how payoffs can be calculated based on different vertex colors. We will use a graph with 30 vertices as an example.

Setting up the Parameters

To start, we need to set the number of vertices in the graph to 30:

n = 30;

Next, we will define two parameters, beta and psi, which will be used in the payoff calculation. Beta represents one parameter in the payoff calculation, while psi represents another parameter:

\[Beta] = 15;
\[Psi] = 1;

Initializing the Graph

We will generate a random adjacency matrix for the graph, with each entry being either 0 or 1. This will define the connections between the vertices:

G = Table[RandomInteger[{0, 1}], {k, 1, n}, {j, 1, n}];

Graph Coloring

We will assign a random color, either Red or Blue, to each vertex in the graph. We can do this by creating a list of colors for each vertex and randomly choosing between Red and Blue:

couleur = Table[k -> RandomChoice[{Red, Blue}], {k, 1, n}];

Payoff Calculation

Now we can calculate the payoff for each vertex based on its color and the colors of its neighbors. We will repeat this process 10 times:

Do[
    (* Initialization *)
    payoff = {};
    
    (* Calculate the payoff for each vertex *)
    Do[
        If[couleur[[j]][[2]] == RGBColor[1, 0, 0],
            payoff = Join[payoff, {Count[Table[couleur[[Flatten[Position[G[[j]], 1]][[k]]]][[2]], {k, 1, Length[Flatten[Position[G[[j]], 1]]]}], RGBColor[0, 0, 1]] * \[Beta]}],
            payoff = Join[payoff, {Count[Table[couleur[[Flatten[Position[G[[j]], 1]][[k]]]][[2]], {k, 1, Length[Flatten[Position[G[[j]], 1]]]}], RGBColor[0, 0, 1]] * (\[Beta] - \[Psi]) - Count[Table[couleur[[Flatten[Position[G[[j]], 1]][[k]]]][[2]], {k, 1, Length[Flatten[Position[G[[j]], 1]]]}], RGBColor[1, 0, 0]] * \[Psi]}]
        ],
        {j, 1, n}
    );
    
    (* Determine the vertices with maximum payoff *)
    L = Flatten[
        Table[
            Intersection[
                Flatten[Position[payoff, Max[Table[payoff[[Flatten[Position[G[[k]], 1]][[j]]]], {j, 1, Length[Flatten[Position[G[[k]], 1]]]}]]]],
                Flatten[Position[G[[k]], 1]]
            ],
            {k, 1, n}
        ]
    ];
    
    (* Update vertex colors *)
    Do[
        If[payoff[[k]] - payoff[[L[[k]]]] < 0,
            couleur[[k]][[2]] = couleur[[L[[k]]]][[2]]
        ],
        {k, 1, n}
    ];
    
    (* Plot the graph with vertex colors *)
    Print[GraphPlot[G, VertexLabels -> Automatic, VertexStyle -> couleur]];
    
    (* Repeat the process *)
    , {s, 1, 10}
];

This code will generate a graph plot with automatic vertex labeling and custom vertex colors for each iteration. The payoff calculation will be performed based on the colors of the vertices and their neighbors, and the colors of the vertices will be updated based on the payoff values.

By repeating this process 10 times, we can observe how the graph evolves as the colors of the vertices are updated according to the payoff calculation.