Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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