Advertisement
Guest User

distribIA

a guest
Oct 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. va en Tablerojuego.java
  2. static int getPeticion(int i) {
  3. return gasolineras.get(i/3).getPeticiones().get(i%3);
  4. }
  5.  
  6. va en Camion.java
  7.  
  8. public Viaje getViaje(int i) {
  9. return viajes.get(i);
  10. }
  11.  
  12. va en Heuristica.java
  13.  
  14. import aima.search.framework.HeuristicFunction;
  15.  
  16. import static java.lang.Math.pow;
  17.  
  18. public class Heuristica implements HeuristicFunction{
  19. @Override
  20. public double getHeuristicValue(Estado e) {
  21. double beneficios=0;
  22. double beneficios_totales=0;
  23. double distancia_recorrida=0;
  24. Viaje aux;
  25. for (int i=0; i<e.camiones.length; ++i) {
  26. for (int j=0 ; j<e.camiones[i].getNumViajes() ; ++j) {
  27. aux = e.camiones[i].getViaje(j);
  28. if (aux.getParadas()==1) {
  29. distancia_recorrida = TableroJuego.calcularDistanciaCDG(i,aux.getPeticion1()/3);
  30. int porcentaje = 102;
  31. if (aux.getPeticion1()!=0) {
  32. porcentaje = (100 - (int)Math.pow(2,aux.getPeticion1()));
  33. }
  34. beneficios += 1000*(porcentaje/100);
  35. }
  36. else {
  37. distancia_recorrida = TableroJuego.calcularDistanciaCDGG(i,aux.getPeticion1()/3,
  38. aux.getPeticion2()/3);
  39. int porcentaje = 102;
  40. if (aux.getPeticion1()!=0) {
  41. porcentaje = (100 - (int)Math.pow(2,aux.getPeticion1()));
  42. }
  43. beneficios += 1000*(porcentaje/100);
  44. porcentaje = 102;
  45. if (aux.getPeticion2()!=0) {
  46. porcentaje = (100 - (int)Math.pow(2,aux.getPeticion2()));
  47. }
  48. beneficios += 1000*(porcentaje/100);
  49. }
  50. }
  51. }
  52. beneficios -= distancia_recorrida*2;
  53. beneficios_totales = beneficios;
  54. for (int i=e.getSiguientePedido(0) ; i>=0 ; i=e.getSiguientePedido(i+1)) {
  55. int peticion = TableroJuego.getPeticion(i);
  56. int porcentaje = 4;
  57. if (peticion!=0) {
  58. porcentaje = ((int) Math.pow(2, peticion + 1) - (int) Math.pow(2, peticion));
  59. }
  60.  
  61. beneficios -= 1000*(porcentaje/100);
  62. }
  63.  
  64. return beneficios;
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement