📄 matrix_games.m
字号:
% Section 5.2.5: Mixed strategies for matrix games% Boyd & Vandenberghe "Convex Optimization"% Jo雔le Skaf - 08/24/05%% Player 1 wishes to choose u to minimize his expected payoff u'Pv, while% player 2 wishes to choose v to maximize u'Pv, where P is the payoff% matrix, u and v are the probability distributions of the choices of each% player (i.e. u>=0, v>=0, sum(u_i)=1, sum(v_i)=1)% Input datarandn('state',0);n = 10;m = 10;P = randn(n,m);% Optimal strategy for Player 1fprintf(1,'Computing the optimal strategy for player 1 ... ');cvx_begin variable u(n) minimize ( max ( P'*u) ) u >= 0; ones(1,n)*u == 1;cvx_endfprintf(1,'Done! \n');obj1 = cvx_optval;% Optimal strategy for Player 2fprintf(1,'Computing the optimal strategy for player 2 ... ');cvx_begin variable v(m) maximize ( min (P*v) ) v >= 0; ones(1,m)*v == 1;cvx_endfprintf(1,'Done! \n');obj2 = cvx_optval;% Displaying resultsdisp('------------------------------------------------------------------------');disp('The optimal strategies for players 1 and 2 are respectively: ');disp([u v]);disp('The expected payoffs for player 1 and player 2 respectively are: ');[obj1 obj2]disp('They are equal as expected!');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -