⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plotgraph2.bak

📁 Differential Evolution(JAVA)
💻 BAK
📖 第 1 页 / 共 2 页
字号:
	increment = ((double) (abs_max_y - abs_min_y) / 
		         (double) y_tics); 

	/*---Draw y-axis ticks----------------------*/
	for (i = 0;  i <= y_tics;  i++)                       
	{ 
	  int y = base_pos - (int) (i * increment);
	  g.drawLine (static1, y, static2, y);
    } 

	/*---Prepare x-tick labeling----------------*/
	g.setFont (new Font ("Helvetica", Font.PLAIN, 10));      

	static0 = absY (0) - 10;
	double x = min_x;

    increment = (double) (max_x - min_x) / (double) x_tics;

	/*---Draw x-tick labeling-------------------*/
	for (i = 0;  i <= x_tics;  i++, x += increment)
    {
      x = Math.rint(x*100.0)*0.01; //accuracy to 2 decimal places
	  Double DblObj = new Double (x);
	  g.drawString (DblObj.toString(), absX (x) - 10, static0);
	}

	Double DblObj = new Double (max_y);
	g.drawString (DblObj.toString(), absX (0), absY (max_y) - 8);
  }

 /*
    c0-----------------
					  |
    c1----------	  |
			   |	  |
    c2		   |	  |
			   |	   ---
    c3		   |		  ---
			   |
	----------------------------		   
	o0         o1     o2     o3
  */
  protected double upperTolerance (double x)
  /*******************************************************
  ** Computes the upper part of the tolerance scheme.   **
  *******************************************************/
  {
    if ((x >= o0) && (x < o2))
      return c0;

    if ((x >=o2) && (x <= o3))
      return ((c2-c3)*(x-o3)/(o2-o3)+c3);

    return 0;	 // default	 
  }


  protected double lowerTolerance (double x)
  /*******************************************************
  ** Computes the lower part of the tolerance scheme.   **
  ** Note that this scheme only holds for the T4        **
  ** problem.                                           **
  *******************************************************/
  {
    if ((x >= o0) && (x < o1))
      return c1;

	if (x >= o1) return 0;

    return 0;	 // default	 
  }


  public void plotTolerance (Graphics g)
  /*******************************************************
  ** Plot the tolerance scheme.                         **
  *******************************************************/
  {
	g.setColor (Color.red);          // Plot upper part of tolerance scheme
	int i;
    double coefficient = (max_x - min_x) / ((double) tolerance_samples);
    double d1, d2;

	d1 = min_x;
    for (i = 1;  i <= tolerance_samples;  i++)
    {
      d2 = min_x + ((double) i) * coefficient;
	  g.drawLine (absX (d1), absY (upperTolerance (d1)),
	               absX (d2), absY (upperTolerance (d2)));
	  d1 = d2;
    }

    d1 = min_x;                       // Plot lower part of tolerance scheme
    for (i = 1;  i <= tolerance_samples;  i++)
    {
      d2 = min_x + ((double) i) * coefficient;
	  g.drawLine (absX (d1), absY (lowerTolerance (d1)),
	               absX (d2), absY (lowerTolerance (d2)));
	  d1 = d2;
    } 
  }

public double amag(double p[], double x, int czero, int cpole, double a0)
/*****************************************************************
**                                                              **
**   Computes magnitude over normalized frequency x.            **
**                                                              **
**   czero:    denotes the number of conjugate complex poles,   **
**             i.e. p[1]       ... p[czero] contains the radii  **
**                  p[czero+1] ... p[2*czero] the angles.       **
**                                                              **
**   cpole:    denotes the number of conjugate complex poles,   **
**             i.e. p[2*czero+1] ... p[2*czero+cpole] -> radii  **
**                  p[2*czero+cpole+1] ... p[2*(czero+cpole)]   **
**                  -> angles.                                  **
**   a0:       amplification factor. If <= 0 a0 = p[0].         **
**                                                              **
*****************************************************************/
{
   double sum, prod, r2;
   int k, k1, k2, k3, k4, cz1, cz2, czp;
   double MINI = 1.0e-10;
   double pi   =   3.14159265358979323846;
   double pi2  =   6.28318530717958647692;

/*--------Initialization----------------------------------*/

   cz1  = czero+1;
   cz2  = 2*czero+1;
   czp  = 2*czero+cpole+1;

/*--------Calculation of amag-----------------------------*/

   r2  = pi*x;

   //sum = -0.066542*Math.cos(r2*3.5)    /* contribution from FIR-filter */
  /*	 -0.039632*Math.cos(r2*2.5)
	 +0.33973*Math.cos(r2*1.5)
	 +0.830908*Math.cos(r2*0.5);     */

   //sum = sum*sum;
   sum = 1.;

   if (a0 > 0)  /* a0 in reasonable range ? */
   {
     p[0]= a0;
   }            /* else amplification is variable */

   prod = p[0]*p[0];/* amplification */
   for (k=0; k < czero; k++)
   {
      k1    = k+1;       /* counter for zero radii  */
      k2    = k+cz1; /* counter for zero angles */

      r2    = p[k1]*p[k1];
      prod *= (1. - 2.*p[k+1]*Math.cos(pi2*(x-p[k2])) + r2)*
	      (1. - 2.*p[k+1]*Math.cos(pi2*(x+p[k2])) + r2);
   }
   sum = sum*prod;

   prod = 1;

   if (cpole > 0)
   {
      for (k=0; k < cpole; k++)
      {
	 k3    = k+cz2; /* counter for pole radii */
	 k4    = k+czp;
	 r2    = p[k3]*p[k3];
	 prod *= (1. - 2.*p[k3]*Math.cos(pi2*(x-p[k4])) + r2)*
		 (1. - 2.*p[k3]*Math.cos(pi2*(x+p[k4])) + r2);
      }

      if (prod < MINI) prod = MINI;
   }
   sum = Math.sqrt(sum/prod);
   return(sum);
}



  public void plot (Graphics g)
  /*******************************************************
  ** Plots the current polynomial.                      **
  *******************************************************/
  {
	g.setColor (Color.blue);
	best = deScreen.getBest();
	dim  = deScreen.getDimension();
    double coefficient = (max_x - min_x) / ((double) plotting_samples);
    double x1 = min_x;
	double x2;
	int    i;
	inti    czero = 8;
	int    cpole = 0;
	double a0    = 0.005;

    for (i = 1;  i <= plotting_samples;  i++)
    {
      x2 = min_x + ((double)i) * coefficient;
	  g.drawLine (absX (x1), absY(amag(best,x1,czero,cpole,a0)),
	               absX (x2), absY(amag(best,x2,czero,cpole,a0)));
	  x1 = x2;
    } 
  }


  public void paint (Graphics g)
  /*******************************************************
  ** Actually draws on the canvas.                      **
  *******************************************************/
  {
	init();	// initializing with every paint() call 
	        // allows for resizing of the plot screen
	g.drawImage (offscreenImage, 0, 0, null);
  }

  public void refreshImage()
  /***********************************************************
  ** Update function which recomputes the variable screen   **
  ** image.                                                 **
  ***********************************************************/
  {
	if (offscreenGraphics == null)
	{
		init();
	}

    offscreenGraphics.drawImage (staticImage, 0, 0, null); 
	plot (offscreenGraphics);
	repaint();	  
  }

  public void update(Graphics g)
  /*******************************************************
  ** Overriding update() reduces flicker. The normal    **
  ** update() method clears the screen before it        **
  ** repaints and hence causes flicker. We dont like	**
  ** this and leave out the screen clearing.			**
  *******************************************************/
  {
	g.drawImage (offscreenImage, 0, 0, null);
  }


}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -