Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. /**************************************************************************
  2. * *
  3. * Copyright: (c) 2016, Florin Leon *
  4. * E-mail: florin.leon@tuiasi.ro *
  5. * Website: http://florinleon.byethost24.com/lab_ia.htm *
  6. * Description: Evolutionary Algorithms *
  7. * (Artificial Intelligence lab 9) *
  8. * *
  9. * This code and information is provided "as is" without warranty of *
  10. * any kind, either expressed or implied, including but not limited *
  11. * to the implied warranties of merchantability or fitness for a *
  12. * particular purpose. You are free to use this source code in your *
  13. * applications as long as the original copyright notice is included. *
  14. * *
  15. **************************************************************************/
  16.  
  17. using System;
  18.  
  19. namespace EvolutionaryAlgorithm
  20. {
  21. /// <summary>
  22. /// Clasa care reprezinta problema din prima aplicatie: rezolvarea ecuatiei
  23. /// </summary>
  24. public class Equation : IOptimizationProblem
  25. {
  26. public Chromosome MakeChromosome()
  27. {
  28. // un cromozom are o gena (x) care poate lua valori in intervalul (-5, 5)
  29. return new Chromosome(1, new double[] { -5 }, new double[] { 5 });
  30. }
  31.  
  32. public void ComputeFitness(Chromosome c)
  33. {
  34. throw new Exception("Aceasta metoda trebuie completata");
  35.  
  36. c.Genes[0] = -1.680494;
  37. double x = c.Genes[0];
  38. // c.Fitness = functia care va fi maximizata
  39.  
  40. double s1 = Math.Pow(x, 5);
  41. double s2 = x * 5;
  42. double s3 = 5;
  43.  
  44. double f = s1 + s2 + s3;
  45.  
  46. // Need positive value to evaluate proximity
  47. // 0 is the best value
  48. c.Fitness = -Math.Abs(f);
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement