Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@MateuszKubuszok
Created February 4, 2014 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MateuszKubuszok/8806221 to your computer and use it in GitHub Desktop.
Save MateuszKubuszok/8806221 to your computer and use it in GitHub Desktop.
MathProg: calculate mixed strategies Nash equilibrium (2 players, 0-sum game)
data;
set P1S := a b c;
set P2S := 1 2 3 4;
param Payoff
: 1 2 3 4 :=
a -5 3 1 8
b 5 5 4 6
c -4 6 0 5;
end;
set P1S;
set P2S;
param Payoff{P1S, P2S};
var y{P1S} >= 0;
minimize GameValue: sum{i in P1S} y[i];
s.t. Condition2{j in P2S}:
sum{i in P1S} Payoff[i,j] * y[i] >= 1;
solve;
printf "Value: %s\n", GameValue;
printf "Player 1 strategies:\n";
for{i in P1S}
printf "Found %s, actual %s\n", y[i], y[i]/GameValue;
end;
set P1S;
set P2S;
param Payoff{P1S, P2S};
var x{P2S} >= 0;
maximize GameValue: sum{j in P2S} x[j];
s.t. Condition1{i in P1S}:
sum{j in P2S} Payoff[i,j] * x[j] <= 1;
solve;
printf "Value: %s\n", GameValue;
printf "Player 2 strategies:\n";
for{j in P2S}
printf "Found %s, actual %s\n", x[j], x[j]/GameValue;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment