
clc;  clear;  close
load ("data/Parameters.mat",'m');

%% The equilibrium
% Case 1: competition + prohibit
m.DataPolicy = 'prohibit';  % prohibit free
m.MarketStruct = 'competition';  % competition oligopoly monopoly 
m.Privacy = 'nonePrivacy';  % nonePrivacy privacyExternality

tic
[wel1,Case1] = func_eqm_iter(m);
toc

% Case 2: competition + free
m.DataPolicy = 'free';  % prohibit free
m.MarketStruct = 'competition';  % competition oligopoly monopoly 
m.Privacy = 'nonePrivacy';  % nonePrivacy privacyExternality

tic
[wel2,Case2] = func_eqm_iter(m);
toc

% Case 3: monopoly + prohibit
m.DataPolicy = 'prohibit';  % prohibit free
m.MarketStruct = 'monopoly';  % competition oligopoly monopoly 
m.Privacy = 'nonePrivacy';  % nonePrivacy privacyExternality

tic
[wel3,Case3] = func_eqm_iter(m);
toc

% Case 4: monopoly + free
m.DataPolicy = 'free';  % prohibit free
m.MarketStruct = 'monopoly';  % competition oligopoly monopoly 
m.Privacy = 'nonePrivacy';  % nonePrivacy privacyExternality

tic
[wel4,Case4] = func_eqm_iter(m);
toc

%% Table 1
wel = [Case1.wel_c; Case1.wel_u; ...
       Case2.wel_c; Case2.wel_u; ...
       Case3.wel_c; Case3.wel_u; ...
       Case4.wel_c; Case4.wel_u];
Pi = [Case1.Pi_c; Case1.Pi_u; ...
      Case2.Pi_c; Case2.Pi_u; ...
      Case3.Pi_c; Case3.Pi_u; ...
      Case4.Pi_c; Case4.Pi_u];
M = [Case1.M_c; Case1.M_u; ...
     Case2.M_c; Case2.M_u; ...
     Case3.M_c; Case3.M_u; ...
     Case4.M_c; Case4.M_u];
w = [Case1.w_c; Case1.w_u; ...
     Case2.w_c; Case2.w_u; ...
     Case3.w_c; Case3.w_u; ...
     Case4.w_c; Case4.w_u];
P = [Case1.P_c; Case1.P_u; ...
     Case2.P_c; Case2.P_u; ...
     Case3.P_c; Case3.P_u; ...
     Case4.P_c; Case4.P_u];

result = reshape([round(wel,2),round(Pi,2),round(M,2),round(w,2),round(P,2)],[8,5]);
Table1 = array2table(result, 'VariableNames', {'福利', '商品利润', '数据利润', '工资', '价格指数'});
writetable(Table1, 'result/表V1.xlsx', 'WriteVariableNames', true);

fprintf('\n=================================================================\n');
fprintf('         表V1 不同数据中间商市场结构以及不同数据政策下的福利\n');
fprintf('=================================================================\n\n');
disp(Table1);

























