Advertisement
Guest User

tema 0 genetici

a guest
Oct 7th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. package ga.t0;
  2. import java.util.Random;
  3. import static java.lang.Math.pow;
  4.  
  5.  
  6. public class GAT0 {
  7.     public double  Beale(double x1,double x2)
  8.     {
  9.        
  10.         double rez;
  11.         rez= (double) (double) ((double) pow((1.5-x1+x1*x2),2) + pow((2.25-x1+x1*x2*x2),2) + pow((2.625-x1+x1*x2*x2*x2),2));
  12.         System.out.print("Rezultatul functiei Beale este:");
  13.         System.out.println(rez);
  14.         System.out.println('\n');
  15.         return rez;
  16.     }
  17.    
  18.    
  19.     public Random random = new Random();
  20.     public double nextDouble(double min, double max)
  21.     {
  22.  
  23.        double x = min + random.nextDouble() * (max - min);
  24.        System.out.print("Numar Generat:");
  25.        System.out.println(x);
  26.        return x;
  27.        
  28.        //System.out.print(min + random.nextFloat() * (max - min));
  29.     }
  30.    
  31.    
  32.    
  33.     public static void main(String[] args)
  34.     {
  35.        
  36.          GAT0 d = new GAT0();
  37.          //d.Beale(0, 0);
  38.          double min=1000000,max=-1000000;
  39.          for(int i=1;i<=3;i++)
  40.          {
  41.              double p = d.Beale(d.nextDouble(-4.5,4.5),d.nextDouble(-4.5,4.5));
  42.              if(p>max)
  43.                  max = p;
  44.              else
  45.                  if(p<min)
  46.                      min = p;
  47.          
  48.         // d.Beale(d.nextDouble(-4.5,4.5),d.nextDouble(-4.5,4.5));
  49.          }
  50.        
  51.          System.out.print("Minimul functiei este ");
  52.          System.out.println(min);
  53.          System.out.print("Maximul functiei este ");
  54.          System.out.println(max);
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement