Advertisement
Guest User

Untitled

a guest
May 29th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. public Individual getFittest() {
  2.         //Individual fittest = individuals[0];
  3.         // Loop through individuals to find fittest
  4.         /*for (int i = 0; i < size(); i++) {
  5.             if (fittest.getFitness() <= getIndividual(i).getFitness()) {
  6.                 fittest = getIndividual(i);
  7.             }
  8.         }*/
  9.         ExecutorService es = Executors.newCachedThreadPool();
  10.         for(int i=0;i<5;i++)
  11.             es.execute(new Runnable() {
  12.                 /*  your task */
  13.                 Individual fittest = individuals[0];
  14.                 @Override
  15.                 public void run() {
  16.                     // A TUKAJ CEL FOR KLICEM NORMALNO?
  17.                     for (int i = 0; i < size(); i++) {
  18.                         if (fittest.getFitness() <= getIndividual(i).getFitness()) {
  19.                             fittest = getIndividual(i);
  20.                         }
  21.                     }
  22.                 }
  23.             });
  24.         es.shutdown();
  25.         try {
  26.             boolean finshed = es.awaitTermination(3000, TimeUnit.MILLISECONDS);
  27.             // all tasks have finished or the time has been reached.
  28.         } catch (InterruptedException e){
  29.             System.out.println("Thread interrupted!");
  30.         }
  31.  
  32.         // KAKO VRNEM OD ABSTRACT CLASSA
  33.         return ???;
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement