当前位置:网站首页>Game theory matlab
Game theory matlab
2022-07-06 02:50:00 【Foreign rookie】
Catalog
1. Initialization of each parameter
2. Calculated expectation and actual expectation
1. brief introduction
Game theory It's also called game theory (Game Theory) both Modern mathematics A new branch of , It's also Operations research An important subject of .
Game theory mainly studies the interaction between formulated incentive structures . It is to study phenomena with the nature of struggle or competition Mathematical theory And methods . Game theory considers the prediction behavior and actual behavior of individuals in the game , And study their optimization strategies . Biologists use game theory to understand and predict some results of evolution .
Game theory has become economics One of the standard analysis tools . In Biology 、 economics 、 international relation 、 Computer science 、 political science 、 Military strategy and many other disciplines are widely used .
The basic concept includes players 、 action 、 Information 、 Strategy 、 earnings 、 Equilibrium and results . among People in the game 、 Strategy and revenue are the most basic elements . People in the game 、 Actions and results are collectively referred to as The rules of the game .
Game theory is simply ,A Take measures to affect B act ,B Behavior influence A The decision , The two play back and forth , Finally, a dynamic balance is achieved . Strictly speaking, game theory is just a way to solve problems .
2. Algorithm principle
Take electric taxis and power stations for example , Suppose that the electric taxi and the power station belong to the same company , The company wants to control the number of taxis in the target area to achieve the expected distribution through the price pricing measures of power station replacement .
For drivers , There are two costs , One is distance cost d, One is to pay the cost p, The payment cost is the electricity price paid for replacing the battery , We can set up weighting factors a Combine the two to build a utility function , The driver will choose the smallest replacement station of this function to replace the battery , After replacing the battery, the driver usually starts to receive orders around
For the company , The objective function is the actual distribution of taxis in different regions e And expectation distribution E The sum of absolute differences of , The company influences the driver's choice by adjusting the price , So as to adjust the distribution of drivers in different areas
Model analysis of two-tier game theory
① The first stage , After the charging station calculates the power change request of each electric taxi , According to the optimization objective , Formulate price strategy
② The second stage , The electric taxi selects the target replacement station from all the replacement stations according to its own utility function to replace the battery
③ The first stage and the second stage are carried out alternately , Until equilibrium is reached
Algorithm design steps
3. The example analysis
1. Initialization of each parameter
n=900;% Power exchange demand
min_price=170;% The price range of electricity exchange
max_price=230;
A=normrnd(36,5,1,25);% Initial expectations , The average value is 36, The variance of 5 Gaussian distribution of
E=fix(A); % the 0 Round the direction , Such as ,4.1,4.5,4.8 Round it all 4
% The following is the adjustment according to the demand E Size
a=sum(E)-n;
A=A-a/25;
E=fix(A);
b=sum(E)-n;
A=A-b/25;
E=fix(A);
a1=0.05;a2=0.95;% Distance cost and change point price weight
x=rand(n,1).*20000;% Initialize the required vehicle location
y=rand(n,1).*20000;
H=[2,2;2,6;2,10;2,14;2,18% Initialize the power station location
6,2;6,6;6,10;6,14;6,18
10,2;10,6;10,10;10,14;10,18
14,2;14,6;14,10;14,14;14,18
18,2;18,6;18,10;18,14;18,18].*1000;
% Draw the location map of the initialized driver and the power station
figure
plot(x,y,'r*')
hold on
plot(H(:,1),H(:,2),'bo')
legend(' The driver ',' Change station ')
title(' Initial location map ')
return :
2. Calculated expectation and actual expectation
%% Calculated expectation and actual expectation
D=[];% The proportion of demand vehicles to each replacement station
price=200.*ones(1,25);
for i=1:length(H)
for j=1:length(x)
D(i,j)=a1*sqrt((H(i,1)-x(j))^2+(H(i,2)-y(j))^2)+a2*price(i);% The total cost
end
end
[d1,d2]=min(D);% Select the nearest replacement station
C=tabulate(d2(:));% Count the number of power station replacement
e=C(:,2);
err=sum(abs(E-e')) % Sum of expectation differences , That is, the game object
return : Because of the random , All of them may be different every time
3. The game process
%% game
J=[]; % The difference between price changes
ER(1)=err;
for k=2:100
j=0;
for i=1:25
if e(i)<E(i) && price(i)>=min_price
price(i)=price(i)-1;
j=j+1;
end
if e(i)>E(i) && price(i)<=max_price
price(i)=price(i)+1;
j=j+1;
end
end
J=[J,j];
DD=[];
for i=1:length(H)
for j=1:length(x)
DD(i,j)=a1*sqrt((H(i,1)-x(j))^2+(H(i,2)-y(j))^2)+a2*price(i);
end
end
[dd1,dd2]=min(DD);
CC=tabulate(dd2(:));
e=CC(:,2);
err=sum(abs(E-e'));
ER=[ER,err];
end
4. mapping
% mapping
figure
plot(ER,'-o')
title('E-e The difference of ')
set(gcf,'unit','normalized','position',[0.2,0.2,0.64,0.32])
legend('E-e')
figure
plot(J,'r-o')
title(' The difference in price changes ')
xlabel('Iterations(t)')
set(gcf,'unit','normalized','position',[0.2,0.2,0.64,0.32])
legend('sum of Price(t)-Price(t-1)')
figure
bar(price,0.5)
hold on
plot([0,26],[min_price,min_price],'g--')
plot([0,26],[max_price,max_price],'r--')
title(' The replacement price of the power station ')
ylabel('Price(¥)')
axis([0,26,0,300])
set(gcf,'unit','normalized','position',[0.2,0.2,0.64,0.32]);
figure
h=bar([e,E'],'gr');
set(h(1),'FaceColor','g'); set(h(2),'FaceColor','r');
axis([0,26,0,50])
title(' Expected and actual number of taxis ')
ylabel('E and e')
set(gcf,'unit','normalized','position',[0.2,0.2,0.64,0.32]);
xlabel(' Change station ')
legend('e','E')
return :
Complete code
clear;clc;
setenv('BLAS_VERSION','') % Make error correction
n=900;% Power exchange demand
min_price=170;% The price range of electricity exchange
max_price=230;
A=normrnd(36,5,1,25);% Initial expectations , The average value is 36, The variance of 5 Gaussian distribution of
E=fix(A); % the 0 Round the direction , Such as ,4.1,4.5,4.8 Round it all 4
% The following is the adjustment according to the demand E Size
a=sum(E)-n;
A=A-a/25;
E=fix(A);
b=sum(E)-n;
A=A-b/25;
E=fix(A);
a1=0.05;a2=0.95;% Distance cost and change point price weight
x=rand(n,1).*20000;% Initialize the required vehicle location
y=rand(n,1).*20000;
H=[2,2;2,6;2,10;2,14;2,18% Initialize the power station location
6,2;6,6;6,10;6,14;6,18
10,2;10,6;10,10;10,14;10,18
14,2;14,6;14,10;14,14;14,18
18,2;18,6;18,10;18,14;18,18].*1000;
% Draw the location map of the initialized driver and the power station
figure
plot(x,y,'r*')
hold on
plot(H(:,1),H(:,2),'bo')
legend(' The driver ',' Change station ')
title(' Initial location map ')
%% Calculated expectation and actual expectation
D=[];% The proportion of demand vehicles to each replacement station
price=200.*ones(1,25);
for i=1:length(H)
for j=1:length(x)
D(i,j)=a1*sqrt((H(i,1)-x(j))^2+(H(i,2)-y(j))^2)+a2*price(i);% The total cost
end
end
[d1,d2]=min(D);% Select the nearest replacement station
C=tabulate(d2(:));% Count the number of power station replacement
e=C(:,2);
err=sum(abs(E-e')); % Sum of expectation differences , That is, the game object
% ER(1)=err
%% game
J=[]; % The difference between price changes
ER(1)=err;
for k=2:100
j=0;
for i=1:25
if e(i)<E(i) && price(i)>=min_price
price(i)=price(i)-1;
j=j+1;
end
if e(i)>E(i) && price(i)<=max_price
price(i)=price(i)+1;
j=j+1;
end
end
J=[J,j];
DD=[];
for i=1:length(H)
for j=1:length(x)
DD(i,j)=a1*sqrt((H(i,1)-x(j))^2+(H(i,2)-y(j))^2)+a2*price(i);
end
end
[dd1,dd2]=min(DD);
CC=tabulate(dd2(:));
e=CC(:,2);
err=sum(abs(E-e'));
ER=[ER,err];
end
% mapping
figure
plot(ER,'-o')
title('E-e The difference of ')
set(gcf,'unit','normalized','position',[0.2,0.2,0.64,0.32])
legend('E-e')
figure
plot(J,'r-o')
title(' The difference in price changes ')
xlabel('Iterations(t)')
set(gcf,'unit','normalized','position',[0.2,0.2,0.64,0.32])
legend('sum of Price(t)-Price(t-1)')
figure
bar(price,0.5)
hold on
plot([0,26],[min_price,min_price],'g--')
plot([0,26],[max_price,max_price],'r--')
title(' The replacement price of the power station ')
ylabel('Price(¥)')
axis([0,26,0,300])
set(gcf,'unit','normalized','position',[0.2,0.2,0.64,0.32]);
figure
h=bar([e,E'],'gr');
set(h(1),'FaceColor','g'); set(h(2),'FaceColor','r');
axis([0,26,0,50])
title(' Expected and actual number of taxis ')
ylabel('E and e')
set(gcf,'unit','normalized','position',[0.2,0.2,0.64,0.32]);
xlabel(' Change station ')
legend('e','E')
边栏推荐
- Spherical lens and cylindrical lens
- 2345 file shredding, powerful file deletion tool, unbound pure extract version
- Taobao focus map layout practice
- Introduction to robotframework (III) Baidu search of webui automation
- Software design principles
- [Yu Yue education] basic reference materials of digital electronic technology of Xi'an University of Technology
- #PAT#day10
- Installation and use tutorial of cobaltstrike-4.4-k8 modified version
- CobaltStrike-4.4-K8修改版安装使用教程
- Microsoft speech synthesis assistant v1.3 text to speech tool, real speech AI generator
猜你喜欢
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
CobaltStrike-4.4-K8修改版安装使用教程
A doctor's 22 years in Huawei
Introduction to robotframework (II) app startup of appui automation
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 6
RobotFramework入门(二)appUI自动化之app启动
Which ecology is better, such as Mi family, graffiti, hilink, zhiting, etc? Analysis of five mainstream smart brands
深度解析链动2+1模式,颠覆传统卖货思维?
Referenceerror: primordials is not defined error resolution
Is there a completely independent localization database technology
随机推荐
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15
Maturity of master data management (MDM)
MySQL winter vacation self-study 2022 11 (5)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
【Kubernetes 系列】一文学会Kubernetes Service安全的暴露应用
QT release exe software and modify exe application icon
Dachang image library
Thinking on Architecture Design (under continuous updating)
Fault analysis | analysis of an example of MySQL running out of host memory
GifCam v7.0 极简GIF动画录制工具中文单文件版
Detailed use of dbutils # yyds dry goods inventory #
Summary of Bible story reading
My C language learning records (blue bridge) -- files and file input and output
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 12
Shell script updates stored procedure to database
Apt installation ZABBIX
Six stone management: why should leaders ignore product quality
What is the investment value of iFLYTEK, which does not make money?
Large scale DDoS attacks take Myanmar offline
Follow the mouse's angle and keyboard events