アットウィキロゴ

JAVA RAX 412

public class tax41{
public static void main(String[] args) {
int s1,s2,n1,n2,m1,m2;
double tk,tl,tr;
double b1,w1,maxw,maxtk,maxtl;
double[] th1=new double[11];
double[] th2=new double[11];
double[] y1=new double[11];
double[] y2=new double[5];
double[][] c=new double[11][5];

for (s1=1;s1<11;s1++){
th1[s1]=0.2*s1;
}

for (s2=1;s2<11;s2++){
th2[s2]=0.1*s2;
}

for (n1=0;n1<11;n1++){
y1[n1]=0.1*n1;
}

for (n2=0;n2<5;n2++){
y2[n2]=0.1*n2;
}

maxw=-999;
maxtk=0;
maxtl=0;
for (m1=10;m1<41;m1++){
for (m2=10;m2<41;m2++){
tk=0.01*m1;
tl=0.01*m2;
tr=trs(tk,tl,y1,y2,th1,th2);
w1=wel(tk,tl,tr,y1,y2,th1,th2);
if (w1>maxw)maxtk=tk;
if (w1>maxw)maxtl=tl;
if (w1>maxw)maxw=w1;
}
}
System.out.println(maxtk);
System.out.println(maxtl);
System.out.println(maxw);

}
public static double u(double c1,double x1,double x2){
double u1,c2,l1,l2;
int h;
c2=c1;
l1=1-x1;
l2=1-x2;
h=0;
if (c2<0)h=100;
if (c2==0)h=100;
if (l1<0)h=100;
if (l1==1)h=100;
if (l1>1)h=100;
if (l2<0)h=100;
if (l2==1)h=100;
if (l2>1)h=100;
if (h>50)c2=0.5;
if (h>50)l1=0.5;
if (h>50)l2=0.5;
u1=Math.log(c2)+Math.log(1-l1)+Math.log(1-l2);
if (h>50)u1=-999;
return u1;
}

public static double trs(double tk,double tl,double[] y1,double[] y2,double[] th1,double[] th2 ){
double b1,b2,tr1,tr2,tr3;
int t;
tr1=0.1;
tr2=0.2;
t=0;
b1=bud(tk,tl,tr1,y1,y2,th1,th2);
while(t<100){
b2=bud(tk,tl,tr2,y1,y2,th1,th2);
tr3=tr2-b2*(tr2-tr1)/(b2-b1);
b1=b2;
tr1=tr2;
tr2=tr3;
t=t+1;
if (b2*b2<0.0001)t=1000;
}
return tr2;
}

public static double wel(double tk,double tl,double tr,double[] y1,double[] y2,double[] th1,double[] th2 ){
int s1,s2,n1,n2;
double w1;
double[][] c=new double[11][5];
for (n1=0;n1<11;n1++){
for (n2=0;n2<5;n2++){
c[n1][n2]=(1-tk)*y1[n1]+(1-tl)*y2[n2]+tr;
}
}
w1=0;
for (s1=1;s1<11;s1++){
for (s2=1;s2<11;s2++){
n1=mprefer(s1,s2,c,y1,y2,th1,th2);
n2=fprefer(s1,s2,c,y1,y2,th1,th2);
w1=w1+u(c[n1][n2],1-y1[n1]/th1[s1],1-y2[n2]/th2[s2]);
}
}
return w1;
}


public static double bud(double tk,double tl,double tr,double[] y1,double[] y2,double[] th1,double[] th2){
int s1,s2,n1,n2;
double b1;
double[][] c=new double[11][5];
for (n1=0;n1<11;n1++){
for (n2=0;n2<5;n2++){
c[n1][n2]=(1-tk)*y1[n1]+(1-tl)*y2[n2]+tr;
}
}
b1=0;
for (s1=1;s1<11;s1++){
for (s2=1;s2<11;s2++){
n1=mprefer(s1,s2,c,y1,y2,th1,th2);
n2=fprefer(s1,s2,c,y1,y2,th1,th2);
b1=b1+y1[n1]+y2[n2]-c[n1][n2];
}
}
return b1;
}



public static int mprefer(int s1,int s2,double[][] c,double[] y1,double[] y2,double[] th1,double[] th2){
double c1,x1,x2,maxu,u1;
int n1,n2,nx;
maxu=-999;
nx=0;
for (n1=0;n1<11;n1++){
for (n2=0;n2<5;n2++){
c1=c[n1][n2];
x1=1-y1[n1]/th1[s1];
x2=1-y2[n2]/th2[s2];
u1=u(c1,x1,x2);
if (u1>maxu)nx=n1;
if (u1>maxu)maxu=u1;
}
}
return nx;
}

public static int fprefer(int s1,int s2,double[][] c,double[] y1,double[] y2,double[] th1,double[] th2 ){
double c1,x1,x2,maxu,u1;
int n1,n2,nx;
maxu=-999;
nx=0;
for (n1=0;n1<11;n1++){
for (n2=0;n2<5;n2++){
c1=c[n1][n2];
x1=1-y1[n1]/th1[s1];
x2=1-y2[n2]/th2[s2];
u1=u(c1,x1,x2);
if (u1>maxu)nx=n2;
if (u1>maxu)maxu=u1;
}
}
return nx;
}


}
最終更新:2010年05月17日 19:26