-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnashdemo.c
67 lines (51 loc) · 1.67 KB
/
nashdemo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*********************************************************/
/* nashdemo is a simple template for lrsnashlib.c */
/* */
/* It builds two 3x4 matrices A B and computes */
/* their equilibria */
/*********************************************************/
/*
Compile:
gcc -O3 -o nashdemo nashdemo.c lrsnashlib.c lrslib.c lrsgmp.c -lgmp -DGMP
Usage:
nashdemo
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "lrslib.h"
#include "lrsnashlib.h"
int main()
{
long s,t;
game Game; // Storage for one game
game *g = &Game;
gInfo GI= {.name="Game"}; // Input file name could go here if there is one
g->aux = &GI;
if ( !lrs_init ("\n*nashdemo:")) // Done once but essential for lrslib usage !
return 1;
g->nstrats[ROW]=3; // row player
g->nstrats[COL]=4; // col player
setFwidth(g,4); // field length for printing games
for(s=0;s<3;s++) // Game 1: load payoff matrices with some integers
for(t=0;t<4;t++)
{
g->payoff[s][t][ROW].num=s+t;
g->payoff[s][t][COL].num=s*t;
g->payoff[s][t][ROW].den=1;
g->payoff[s][t][COL].den=1;
}
printGame(g);
lrs_solve_nash(g);
for(s=0;s<3;s++) // Game 2: load payoff matrices with some rationals
for(t=0;t<4;t++)
{
g->payoff[s][t][ROW].num=s+t;
g->payoff[s][t][COL].num=1;
g->payoff[s][t][ROW].den=2;
g->payoff[s][t][COL].den=3;
}
printGame(g);
lrs_solve_nash(g);
return 0;
}