/* * * Copyright (c) 2000 JAVIR, Ltd. All Rights Reserved. * * * JAVIR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. JAVIR SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. * */ import com.javir.Optimizer.*; public class MyFunctionViewer extends FunctionViewer { public MyFunctionViewer(){ } //------------------------------------------- public String getFunctionName(int i){ String Names[]={ "Function1: hills+banana", "Function2: random hils", "Function3: circles" }; if (i>=Names.length) return null; return Names[i]; } //------------------------------------------- public String getFunctionText(int i){ switch (getCurrentFunction()){ case 0: return "0.6*(x*x+y*y)\n"+ "+k1/[k2*((x-k3)^2+(y-k4)^2)+1]\n"+ "+k5/[k6*((x-k7)^2+(y-k8)^2)+1]\n"+ "+k9/[k10*((x-k11)^2+(y-k12)^2)+1]\n"; case 1: return "Y=0.6*(x*x+y*y)\n"+ "for(int i=0;i<20;i++)// kn are random\n"+ " Y+=k1/[k2*((x-k3)^2+(y-k4)^2)+1]\n"; case 2: return "see source for details"; default: return "";} } //------------------------------------------- public double getValue(double xx[]){ switch (getCurrentFunction()){ case 0: return hills_and_banana(xx); case 1: return hills(xx); case 2: return circles(xx);} return 0;} //------------------------------------------- public double hills_and_banana(double xx[]){ double x= xx[0]; double y= xx[1]; double Y=0; Y+=0.6*(x*x+y*y); int r=11; // hills for(int i=0;i<3;i++){ x= xx[0]+Rnd[r++]*0.8; y= xx[1]+Rnd[r++]*0.8; Y+=(2+Rnd[r++])/(5*(x*x+y*y)+1); } //banana x= xx[0]+Rnd[r++]*0.8; y= xx[1]+Rnd[r++]*0.8; Y+=-1/(100*Math.pow(y-x*x,2)+Math.pow(1-x,2)+1); return Y; }; //------------------------------------------- public double hills(double xx[]){ double x= xx[0]; double y= xx[1]; double Y=0; Y+=0.6*(x*x+y*y); int r=0; // hills for(int i=0;i<20;i++){ x= xx[0]+Rnd[r++]*2; y= xx[1]+Rnd[r++]*2; Y+=(2+Rnd[r++])/(10*(x*x+y*y)+1); } return Y; } //------------------------------------------- public double circles(double xx[]){ double Y=0; double x= xx[0]; double y= xx[1]; Y+=0.06*(x*x+y*y); double PI= Math.PI; double r = Optimizer.getRho(x,y); double a = Optimizer.getTheta(x,y); double sina = Math.sin(a); sina *= sina; double R=0.5*(1+Math.abs(sina));; Y=1-0.01/(Math.pow(R*R-r,2)+0.01); sina = Math.sin(a+PI/4); sina *= sina; R=0.35*(2+Math.abs(sina));; Y*=1-0.01/(Math.pow(R*R-r,2)+0.01); Y+=0.4*(y+x); return Y; } //final public double pow(double x){ return Math.pow(x);} }
Make your own free website on Tripod.com