class pro{
public static void main(String args[]){
int s1,s2,n1,n2,n3;
double tk,tl,tr,ww,maxw,tks,tls,trs;
double th1[]=new double[11];
double th2[]=new double[11];
double c[][]=new double[11][11];
double y1[][]=new double[11][11];
double y2[][]=new double[11][11];
double u[][][][][]=new double[11][11][3][3][3];
double h,cp,yp1,yp2;
for (s1=1;s1<11;s1++){
th1[s1]=0.2*s1;
}
for (s2=1;s2<11;s2++){
th2[s2]=0.1*s2;
}
maxw=-999;
tks=0;
tls=0;
trs=0;
for (n1=5;n1<40;n1++){
for (n2=5;n2<40;n2++){
tk=0.01*n1;
tl=0.01*n2;
tr=trs(tk,tl,th1,th2);
ww=wel(tk,tl,tr,th1,th2);
if (ww>maxw)tks=tk;
if (ww>maxw)tls=tl;
if (ww>maxw)trs=tr;
if (ww>maxw)maxw=ww;
}
}
System.out.println(tks);
System.out.println(tls);
for (s1=1;s1<11;s1++){
for (s2=1;s2<11;s2++){
y1[s1][s2]=th1[s1]*mlx(s1,s2,tks,tls,trs,th1,th2);
y2[s1][s2]=th2[s2]*flx(s1,s2,tks,tls,trs,th1,th2);
c[s1][s2]=(1-tks)*y1[s1][s2]+(1-tls)*y2[s1][s2]+trs;
}
}
h=0.001;
for (s1=1;s1<11;s1++){
for (s2=1;s2<11;s2++){
for (n1=-1;n1<2;n1++){
for (n2=-1;n2<2;n2++){
for (n3=-1;n3<2;n3++){
cp=c[s1][s2]+n3*h;
yp1=y1[s1][s2]+n1*h;
yp2=y2[s1][s2]+n2*h;
u[s1][s2][n1+1][n2+1][n3+1]=ux(cp,1-yp1/th1[s1],1-yp2/th2[s2]);
}
}
}
}
}
}
static double ux(double c1,double x1,double x2){
double c2,x3,x4,u1;
int px;
c2=c1;
x3=x1;
x4=x2;
px=0;
if (c2<0)px=100;
if (c2==0)px=100;
if (x3<0)px=100;
if (x3==0)px=100;
if (x3>1)px=100;
if (x4<0)px=100;
if (x4==0)px=100;
if (x4>1)px=100;
if (px>50)c2=0.5;
if (px>50)x3=0.5;
if (px>50)x4=0.5;
u1=Math.log(c2)+Math.log(x3)+Math.log(x4);
if (px>50)u1=-999;
return u1;
}
static double trs(double tk,double tl,double[] th1,double[] th2){
double tr1,tr2,tr3,b1,b2;
int t1;
tr1=0.01;
tr2=0.4;
tr3=0;
b1=bud(tk,tl,tr1,th1,th2);
t1=0;
while(t1<100){
b2=bud(tk,tl,tr2,th1,th2);
tr3=tr2-b2*(tr2-tr1)/(b2-b1);
b1=b2;
tr1=tr2;
tr2=tr3;
b1=b2;
if (b2*b2<0.001)t1=1000;
t1=t1+1;
}
return tr3;
}
static double wel(double tk,double tl,double tr,double[] th1,double[] th2){
int s1,s2;
double ww,w1,w2,l1,l2,c1;
ww=0;
for (s1=1;s1<11;s1++){
for (s2=1;s2<11;s2++){
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
l1=mlx(s1,s2,tk,tl,tr,th1,th2);
l2=flx(s1,s2,tk,tl,tr,th1,th2);
c1=w1*l1+w2*l2+tr;
ww=ww+Math.log(c1)+Math.log(1-l1)+Math.log(1-l2);
}
}
return ww;
}
static double bud(double tk,double tl,double tr,double[] th1,double[] th2){
int s1,s2;
double b1,w1,w2,l1,l2,c1;
b1=0;
for (s1=1;s1<11;s1++){
for (s2=1;s2<11;s2++){
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
l1=mlx(s1,s2,tk,tl,tr,th1,th2);
l2=flx(s1,s2,tk,tl,tr,th1,th2);
c1=w1*l1+w2*l2+tr;
b1=b1+th1[s1]*l1+th2[s2]*l2-c1;
}
}
return b1;
}
static double mlx(int s1,int s2,double tk,double tl,double tr,double[] th1,double[] th2){
double w1,w2,c1,l1,l2;
int px;
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
c1=(w1+w2+tr)/3;
l1=1-c1/w1;
l2=1-c1/w2;
px=0;
if (l1<0)px=px+1;
if (l1==0)px=px+1;
if (l2>0)px=px+1;
if (px==2)l1=0;
if (px==2)l2=(w2-tr)/2;
px=0;
if (l2<0)px=px+1;
if (l2==0)px=px+1;
if (l1>0)px=px+1;
if (px==2)l2=0;
if (px==2)l1=(w1-tr)/2;
return l1;
}
static double flx(int s1,int s2,double tk,double tl,double tr,double[] th1,double[] th2){
double w1,w2,c1,l1,l2;
int px;
w1=(1-tk)*th1[s1];
w2=(1-tl)*th2[s2];
c1=(w1+w2+tr)/3;
l1=1-c1/w1;
l2=1-c1/w2;
px=0;
if (l1<0)px=px+1;
if (l1==0)px=px+1;
if (l2>0)px=px+1;
if (px==2)l1=0;
if (px==2)l2=(w2-tr)/2;
px=0;
if (l2<0)px=px+1;
if (l2==0)px=px+1;
if (l1>0)px=px+1;
if (px==2)l2=0;
if (px==2)l1=(w1-tr)/2;
return l2;
}
}
最終更新:2010年07月03日 22:39