I want to program a function for a two-player game. Basically it's like this: . Each player has an array of options, and the result of the game is based on both players choices. So heres my most promising approach (i've also played around with LinearProgramming
, which also works up to a point). c
is like Length[x]
. p[i,j]
is a reference to my database, and gives a value between 0 and 1. It describes the probability of a win for player x
if he chooses strategy i
and player y
chooses strategy j
.
p := {{0.5, 0.7, 0.3}, {0.3, 0.5, 0.6}, {0.7, 0.4, 0.5}}
stratmin[c_, x__] :=
NMinimize[{Sum[x[[i]]*y[j]*p[i, j], {i, c}, {j, c}],
Table[y[j] >= 0, {j, c}], Sum[y[j], {j, c}] == 1},
Table[y[j], {j, c}]]
strat[c_] :=
NMaximize[{stratmin[c, Table[x[i], {i, c}]],
Table[x[i] >= 0, {i, c}], Sum[x[i], {i, c}] == 1},
Table[x[i], {i, c}]]
strat[3]
But it doesn't work! As you could have guessed, as I am asking a question here. NMinimize
doesn't seem to use the x[i]
as a parameter that NMaximize
uses. If I program this with LinearProgramming
, since I've got to "nest" variables in the same way, I've got the same problem. The solution btw. should look smth. like strat=0.5
; x[1] ca. 0.5, x[2] ca. 0.4, x[3] ca. 0.6.
EDIT:
I looked into your program, and tried to understand and research all parts; had to read through this and this to understand all of the notation; but still dont really get how exactly the solution worked. I've reduced the problem to:
testmin[x_] := First[NMinimize[{-x^2 + y, y >= 0}, y]]
testmax := NMaximize[{testmin[x]}, x]
testmax
I don't know whether that is too much too ask, but would you do the minimal necessary correction for that example, too, please? Hopefully that helps me understand the necessary step. Also, if you know of any other good resources or tutorials, I would be thankful.
x[[i]]
(double bracket, that is,Part
) in one and x[i]` in the other. $\endgroup$testmin
is a "balck-box" behavior wherein it is only defined for explicitly numeric input. To rectify, firstClear[testmin]
to discard the existing definition, then replace withtestmin[x_?NumberQ] := First[NMinimize[{-x^2 + y, y >= 0}, y]]
. This is the point of my.../; VectorQ[xl, Element[#, Reals] &]
restrictions. $\endgroup$