class pro{
public static void main(String args[]){
double c1,l1,trs,b1,w1,w2,maxw,tk,h;
int s,n,time,p;
double th[]=new double[101];
double tl[]=new double[11];
double tr[]=new double[11];
double tls[]=new double[11];
for (s=1;s<101;s++){
th[s]=0.02*s;
}
for (n=0;n<11;n++){
tls[n]=0.5;
}
for (n=0;n<11;n++){
tl[n]=tls[n];
}
trs=seektrs(th,tl);
maxw=wel(th,tl,trs);
System.out.println(maxw);
h=0.02;
for (p=1;p<10;p++){
h=h/2;
for (n=0;n<11;n++){
time=0;
while(time<50){
tk=tls[n];
tl[n]=tls[n]+h;
trs=seektrs(th,tl);
w1=wel(th,tl,trs);
if (w1>maxw)tls[n]=tl[n];
if (w1>maxw)maxw=w1;
tl[n]=tls[n]-h;
trs=seektrs(th,tl);
w2=wel(th,tl,trs);
if (w2>maxw)tls[n]=tl[n];
if (w2>maxw)maxw=w2;
if (tk==tls[n])time=1000;
time=time+1;
}
System.out.println(maxw);
}
}
for (n=0;n<11;n++){
System.out.println(tls[n]);
}
}
public static double wel(double[] th,double[] tl,double trs){
double c1,y1,w1;
double tr[]=new double[11];
int s,n;
tr[0]=trs;
for(n=1;n<11;n++){
tr[n]=(1-tl[n-1])*0.1*n+tr[n-1]-(1-tl[n])*0.1*n;
}
w1=0;
for (s=1;s<101;s++){
c1=con(th[s],tl,tr);
y1=th[s]*lab(th[s],tl,tr);
w1=w1+u(c1,1-y1/th[s]);;
}
return w1;
}
public static double seektrs(double[] th,double[] tl){
double tr1,tr2,tr3,b1,b2;
double tr[]=new double[11];
int t1,n;
tr1=0.1;
tr2=0.2;
tr[0]=tr1;
for(n=1;n<11;n++){
tr[n]=(1-tl[n-1])*0.1*n+tr[n-1]-(1-tl[n])*0.1*n;
}
b1=bud(th,tl,tr);
t1=0;
while(t1<100){
tr[0]=tr2;
for(n=1;n<11;n++){
tr[n]=(1-tl[n-1])*0.1*n+tr[n-1]-(1-tl[n])*0.1*n;
}
b2=bud(th,tl,tr);
tr3=tr2-b2*(tr2-tr1)/(b2-b1);
b1=b2;
tr1=tr2;
tr2=tr3;
t1=t1+1;
if (b2*b2<0.001)t1=1000;
}
return tr2;
}
public static double con(double th1,double[] tl,double[] tr){
double l1,y1,c1,u1,maxu,maxc;
int n;
maxu=-999;
maxc=0;
for (n=0;n<10;n++){
l1=lx(th1,tl[n],tr[n]);
y1=th1*l1;
if(y1<0.1*n)y1=0.1*n;
if(y1>0.1*(n+1))y1=0.1*(n+1);
c1=(1-tl[n])*y1+tr[n];
u1=u(c1,1-y1/th1);
if (u1>maxu)maxc=c1;
if (u1>maxu)maxu=u1;
}
l1=lx(th1,tl[10],tr[10]);
y1=th1*l1;
if(y1<1)y1=1;
c1=(1-tl[10])*y1+tr[10];
u1=u(c1,1-y1/th1);
if (u1>maxu)maxc=c1;
return maxc;
}
public static double bud(double[] th,double[] tl,double[] tr){
double c1,y1,b1;
int s;
b1=0;
for (s=1;s<101;s++){
c1=con(th[s],tl,tr);
y1=th[s]*lab(th[s],tl,tr);
b1=b1+y1-c1;
}
return b1;
}
public static double lab(double th1,double[] tl,double[] tr){
double l1,y1,c1,u1,maxu,maxl;
int n;
maxu=-999;
maxl=0;
for (n=0;n<10;n++){
l1=lx(th1,tl[n],tr[n]);
y1=th1*l1;
if(y1<0.1*n)y1=0.1*n;
if(y1>0.1*(n+1))y1=0.1*(n+1);
c1=(1-tl[n])*y1+tr[n];
u1=u(c1,1-y1/th1);
if (u1>maxu)maxl=y1/th1;
if (u1>maxu)maxu=u1;
}
l1=lx(th1,tl[10],tr[10]);
y1=th1*l1;
if(y1<1)y1=1;
c1=(1-tl[10])*y1+tr[10];
u1=u(c1,1-y1/th1);
if (u1>maxu)maxl=y1/th1;
return maxl;
}
public static double lx(double th1,double tlp,double trp){
double w1,l1;
w1=(1-tlp)*th1;
l1=(w1-trp)/(2*w1);
if (l1<0)l1=0;
return l1;
}
public static double u(double c1,double x1){
double c2,x2,z2,u2;
c2=c1;
x2=x1;
z2=0;
if (c2<0)z2=100;
if (c2==0)z2=100;
if (x2>1)z2=100;
if (x2<0)z2=100;
if (x2==0)z2=100;
if (z2>50)c2=0.01;
if (z2>50)x2=0.5;
u2=Math.log(c2)+Math.log(x2);
if (z2>50)u2=-999;
return u2;
}
}
最終更新:2010年04月16日 07:30