比例加惯例
function mingejieguo=bilijiaguanli(renshu,minge)
renshuzonghe=sum(renshu);
bilifenpei=renshu./renshuzonghe.*minge;
bilifenpei_zhengshu=floor(bilifenpei);
bilifenpei_yushu=bilifenpei-bilifenpei_zhengshu;
shengyufenpei=minge-sum(bilifenpei_zhengshu);
[bilifenpei_yushu_paixv,idx]=sort(bilifenpei,'ascend');
for i=1:shengyufenpei
bilifenpei_zhengshu(idx(i))=bilifenpei_zhengshu(idx(i))+1;
end
mingejieguo=bilifenpei_zhengshu;
Q值法
function mingejieguo=Qzhifa(renshu,minge,q)
renshuzonghe=sum(renshu);
bilifenpei=renshu./renshuzonghe.*minge;
bilifenpei_zhengshu=floor(bilifenpei);
shengyufenpei=minge-sum(bilifenpei_zhengshu);
fenpei=bilifenpei_zhengshu;
while shengyufenpei>0
Q=(renshu.^q)./(bilifenpei_zhengshu.*(bilifenpei_zhengshu+1));
[Q_paixv,idx1]=sort(Q,'descend');
for i=1:1:1
fenpei(idx1(i))=fenpei(idx1(i))+1;
end
shengyufenpei=shengyufenpei-1;
end
mingejieguo=fenpei;
d`Hondt方法
function mingejieguo=Dhondt(renshu,minge)
zushu=size(renshu);
kongjuzhen=zeros(zushu(2),minge);
for i=1:1:zushu(2)
for j=1:1:minge
kongjuzhen(i,j)=renshu(i)./j;
end
end
zhongjianxiangliang=kongjuzhen(:);
di_minge=maxk(zhongjianxiangliang,minge);
zuixiaozhi=di_minge(minge);
shuaixuanjuzhen=kongjuzhen>zuixiaozhi;
mingejieguo=sum(shuaixuanjuzhen');
综合结果比较
renshu=[235 333 432];
minge=10;
q=2;
mingejieguo1=bilijiaguanli(renshu,minge);
mingejieguo2=Qzhifa(renshu,minge,q);
mingejieguo3=Dhondt(renshu,minge);
renshu=[235 333 432];
minge=15;
q=2;
mingejieguo4=bilijiaguanli(renshu,minge);
mingejieguo5=Qzhifa(renshu,minge,q);
mingejieguo6=Dhondt(renshu,minge);
disp(mingejieguo4);
disp(mingejieguo5);
disp(mingejieguo6);
disp(' Method 10minge 15minge')
disp('————————————————————————')
disp([' 比例加惯例 ' num2str(mingejieguo1) ' ' num2str(mingejieguo4)])
disp([' Q值法 ' num2str(mingejieguo2) ' ' num2str(mingejieguo5)])
disp([' D’Hondt ' num2str(mingejieguo3) ' ' num2str(mingejieguo6)])