Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- va en Tablerojuego.java
- static int getPeticion(int i) {
- return gasolineras.get(i/3).getPeticiones().get(i%3);
- }
- va en Camion.java
- public Viaje getViaje(int i) {
- return viajes.get(i);
- }
- va en Heuristica.java
- import aima.search.framework.HeuristicFunction;
- import static java.lang.Math.pow;
- public class Heuristica implements HeuristicFunction{
- @Override
- public double getHeuristicValue(Estado e) {
- double beneficios=0;
- double beneficios_totales=0;
- double distancia_recorrida=0;
- Viaje aux;
- for (int i=0; i<e.camiones.length; ++i) {
- for (int j=0 ; j<e.camiones[i].getNumViajes() ; ++j) {
- aux = e.camiones[i].getViaje(j);
- if (aux.getParadas()==1) {
- distancia_recorrida = TableroJuego.calcularDistanciaCDG(i,aux.getPeticion1()/3);
- int porcentaje = 102;
- if (aux.getPeticion1()!=0) {
- porcentaje = (100 - (int)Math.pow(2,aux.getPeticion1()));
- }
- beneficios += 1000*(porcentaje/100);
- }
- else {
- distancia_recorrida = TableroJuego.calcularDistanciaCDGG(i,aux.getPeticion1()/3,
- aux.getPeticion2()/3);
- int porcentaje = 102;
- if (aux.getPeticion1()!=0) {
- porcentaje = (100 - (int)Math.pow(2,aux.getPeticion1()));
- }
- beneficios += 1000*(porcentaje/100);
- porcentaje = 102;
- if (aux.getPeticion2()!=0) {
- porcentaje = (100 - (int)Math.pow(2,aux.getPeticion2()));
- }
- beneficios += 1000*(porcentaje/100);
- }
- }
- }
- beneficios -= distancia_recorrida*2;
- beneficios_totales = beneficios;
- for (int i=e.getSiguientePedido(0) ; i>=0 ; i=e.getSiguientePedido(i+1)) {
- int peticion = TableroJuego.getPeticion(i);
- int porcentaje = 4;
- if (peticion!=0) {
- porcentaje = ((int) Math.pow(2, peticion + 1) - (int) Math.pow(2, peticion));
- }
- beneficios -= 1000*(porcentaje/100);
- }
- return beneficios;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement