diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/libraries/llibreries.xml b/.idea/libraries/llibreries.xml new file mode 100644 index 0000000..f47f9e9 --- /dev/null +++ b/.idea/libraries/llibreries.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..31e1ebc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..2fb5ee2 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/fichero_tonto.txt b/fichero_tonto.txt index a19abfe..26b670c 100644 --- a/fichero_tonto.txt +++ b/fichero_tonto.txt @@ -1 +1 @@ -Hola +Adeu \ No newline at end of file diff --git a/out/production/practicaIA1/com/lluc/practicaIA1/AzamonGoalTest.class b/out/production/practicaIA1/com/lluc/practicaIA1/AzamonGoalTest.class new file mode 100644 index 0000000..c01779d Binary files /dev/null and b/out/production/practicaIA1/com/lluc/practicaIA1/AzamonGoalTest.class differ diff --git a/out/production/practicaIA1/com/lluc/practicaIA1/AzamonHeuristicFunction1.class b/out/production/practicaIA1/com/lluc/practicaIA1/AzamonHeuristicFunction1.class new file mode 100644 index 0000000..881a01b Binary files /dev/null and b/out/production/practicaIA1/com/lluc/practicaIA1/AzamonHeuristicFunction1.class differ diff --git a/out/production/practicaIA1/com/lluc/practicaIA1/AzamonHeuristicFunction2.class b/out/production/practicaIA1/com/lluc/practicaIA1/AzamonHeuristicFunction2.class new file mode 100644 index 0000000..317f169 Binary files /dev/null and b/out/production/practicaIA1/com/lluc/practicaIA1/AzamonHeuristicFunction2.class differ diff --git a/out/production/practicaIA1/com/lluc/practicaIA1/AzamonSuccessorFunction.class b/out/production/practicaIA1/com/lluc/practicaIA1/AzamonSuccessorFunction.class new file mode 100644 index 0000000..3392fb5 Binary files /dev/null and b/out/production/practicaIA1/com/lluc/practicaIA1/AzamonSuccessorFunction.class differ diff --git a/out/production/practicaIA1/com/lluc/practicaIA1/AzamonSuccessorFunctionSA.class b/out/production/practicaIA1/com/lluc/practicaIA1/AzamonSuccessorFunctionSA.class new file mode 100644 index 0000000..8ea61da Binary files /dev/null and b/out/production/practicaIA1/com/lluc/practicaIA1/AzamonSuccessorFunctionSA.class differ diff --git a/out/production/practicaIA1/com/lluc/practicaIA1/Estado.class b/out/production/practicaIA1/com/lluc/practicaIA1/Estado.class new file mode 100644 index 0000000..6936e39 Binary files /dev/null and b/out/production/practicaIA1/com/lluc/practicaIA1/Estado.class differ diff --git a/out/production/practicaIA1/com/lluc/practicaIA1/Main$1.class b/out/production/practicaIA1/com/lluc/practicaIA1/Main$1.class new file mode 100644 index 0000000..2955186 Binary files /dev/null and b/out/production/practicaIA1/com/lluc/practicaIA1/Main$1.class differ diff --git a/out/production/practicaIA1/com/lluc/practicaIA1/Main.class b/out/production/practicaIA1/com/lluc/practicaIA1/Main.class new file mode 100644 index 0000000..3752421 Binary files /dev/null and b/out/production/practicaIA1/com/lluc/practicaIA1/Main.class differ diff --git a/practicaIA1.iml b/practicaIA1.iml index 35a07c1..3a747d0 100644 --- a/practicaIA1.iml +++ b/practicaIA1.iml @@ -7,7 +7,6 @@ - - + \ No newline at end of file diff --git a/src/com/lluc/practicaIA1/AzamonGoalTest.java b/src/com/lluc/practicaIA1/AzamonGoalTest.java new file mode 100644 index 0000000..729e894 --- /dev/null +++ b/src/com/lluc/practicaIA1/AzamonGoalTest.java @@ -0,0 +1,11 @@ +package com.lluc.practicaIA1; + +import aima.search.framework.GoalTest; + +public class AzamonGoalTest implements GoalTest { + + public boolean isGoalState(Object state){ + + return false; + } +} \ No newline at end of file diff --git a/src/com/lluc/practicaIA1/AzamonHeuristicFunction1.java b/src/com/lluc/practicaIA1/AzamonHeuristicFunction1.java new file mode 100644 index 0000000..7187a65 --- /dev/null +++ b/src/com/lluc/practicaIA1/AzamonHeuristicFunction1.java @@ -0,0 +1,11 @@ +package com.lluc.practicaIA1; + +import aima.search.framework.HeuristicFunction; + +public class AzamonHeuristicFunction1 implements HeuristicFunction{ + public double getHeuristicValue(Object o) { + Estado estado = (Estado) o; + return estado.heuristicoCoste(); + //return estado.heuristicoCosteFelicidad(); + } +} diff --git a/src/com/lluc/practicaIA1/AzamonHeuristicFunction2.java b/src/com/lluc/practicaIA1/AzamonHeuristicFunction2.java new file mode 100644 index 0000000..efc3620 --- /dev/null +++ b/src/com/lluc/practicaIA1/AzamonHeuristicFunction2.java @@ -0,0 +1,11 @@ +package com.lluc.practicaIA1; + +import aima.search.framework.HeuristicFunction; + +public class AzamonHeuristicFunction2 implements HeuristicFunction{ + public double getHeuristicValue(Object o) { + Estado estado = (Estado) o; + //return estado.heuristicoCoste(); + return estado.heuristicoCosteFelicidad(); + } +} \ No newline at end of file diff --git a/src/com/lluc/practicaIA1/AzamonSuccessorFunction.java b/src/com/lluc/practicaIA1/AzamonSuccessorFunction.java new file mode 100644 index 0000000..76413a3 --- /dev/null +++ b/src/com/lluc/practicaIA1/AzamonSuccessorFunction.java @@ -0,0 +1,42 @@ +package com.lluc.practicaIA1; +import IA.Azamon.Paquetes; +import IA.Azamon.Transporte; +import IA.probTSP.ProbTSPBoard; +import aima.search.framework.Successor; +import aima.search.framework.SuccessorFunction; + +import java.util.*; + +public class AzamonSuccessorFunction implements SuccessorFunction { + public List getSuccessors(Object a) { + ArrayList retVal = new ArrayList(); + Estado estado_actual = (Estado) a; + Paquetes paquetes = estado_actual.get_paquetes(); + Transporte transporte = estado_actual.get_transporte(); + for (int i = 0; i < paquetes.size(); i++) { + for (int j = i + 1; j < paquetes.size(); j++) { + Estado newState = new Estado(estado_actual); + + if(newState.swap(i, j)){ + //String S = ("INTERCAMBIO " + " " + i + " " + j + " " + newState.toStringSimple()); + String S = ("INTERCAMBIO " + " " + i + " " + j + " " + newState.toString()); + retVal.add(new Successor(S, newState)); + } + } + } + + for (int i = 0; i < paquetes.size(); ++i) { + for (int j = 0; j < transporte.size(); ++j) { + Estado newState = new Estado(estado_actual); + if(newState.moure_paquete(i, j)) { + //String S = "MOVIDO paquete: " + i + " a la oferta " + j + newState.toStringSimple(); + String S = "MOVIDO paquete: " + i + " a la oferta " + j + newState.toString(); + retVal.add(new Successor(S, newState)); + } + } + } + + + return retVal; + } +} diff --git a/src/com/lluc/practicaIA1/AzamonSuccessorFunctionSA.java b/src/com/lluc/practicaIA1/AzamonSuccessorFunctionSA.java new file mode 100644 index 0000000..fc1518f --- /dev/null +++ b/src/com/lluc/practicaIA1/AzamonSuccessorFunctionSA.java @@ -0,0 +1,43 @@ +package com.lluc.practicaIA1; + +import IA.Azamon.Paquetes; +import IA.Azamon.Transporte; +import IA.probTSP.ProbTSPBoard; +import IA.probTSP.ProbTSPHeuristicFunction; +import aima.search.framework.Successor; +import aima.search.framework.SuccessorFunction; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class AzamonSuccessorFunctionSA /*implements SuccessorFunction*/ { + public List getSuccessors(int npaq, Paquetes paquetes, Transporte transporte) { + ArrayList retVal = new ArrayList(); + //ProbTSPHeuristicFunction TSPHF = new ProbTSPHeuristicFunction(); + Random myRandom=new Random(); + int i,j; + + // Nos ahorramos generar todos los sucesores escogiendo un par de paquetes al azar + + i=myRandom.nextInt(npaq); + + do{ + j=myRandom.nextInt(npaq); + } while (i==j); + + + //ProbTSPBoard newBoard = new ProbTSPBoard(board.getNCities(), board.getPath(), board.getDists()); + Estado newState = new Estado(); + + if(newState.swap(i, j)) { + + //double v = TSPHF.getHeuristicValue(newBoard); + String S = ("INTERCAMBIO " + " " + i + " " + j + " " + newState.toString()); + + retVal.add(new Successor(S, newState)); + } + + return retVal; + } +} diff --git a/src/com/lluc/practicaIA1/Estado.java b/src/com/lluc/practicaIA1/Estado.java index 32bddf2..d6825f9 100644 --- a/src/com/lluc/practicaIA1/Estado.java +++ b/src/com/lluc/practicaIA1/Estado.java @@ -10,24 +10,51 @@ public class Estado { - int vecPaquetes[]; - double vecOfertas[]; - double coste = 0; - double felicidad = 0; + public static Paquetes paquetes; + public static Transporte transporte; + public static double pesos_maximos = 0; + public int vecPaquetes[]; + public double vecOfertas[]; + public double coste = 0; + public double felicidad = 0; - Estado(Paquetes paquetes, Transporte transporte) { + Estado() { + //Seguramente esto esta mal, pero hace el apanyo, ya veremos vecPaquetes = new int[paquetes.size()]; vecOfertas = new double[transporte.size()]; for (int i = 0; i < transporte.size(); ++i) { vecOfertas[i] = transporte.get(i).getPesomax(); - } + pesos_maximos += transporte.get(i).getPesomax(); + } + + - generarSolucion1(paquetes, transporte); - imprimir(paquetes, transporte); + generarSolucion1(); + imprimir(); } - void generarSolucion1(Paquetes paquetes, Transporte transporte) { + Estado(Estado a) { + //Seguramente esto esta mal, pero hace el apanyo, ya veremos + vecPaquetes = new int[paquetes.size()]; + int n_paquetes = paquetes.size(); + for (int i = 0; i < n_paquetes; ++i) { + this.vecPaquetes[i] = a.vecPaquetes[i]; + } + int n_ofertas = transporte.size(); + vecOfertas = new double[n_ofertas]; + for(int i = 0; i < n_ofertas; ++i) { + this.vecOfertas[i] = a.vecOfertas[i]; + } + this.coste = a.coste; + this.felicidad = a.felicidad; + } + + public Paquetes get_paquetes() {return paquetes;} + public Transporte get_transporte() {return transporte;} + + + void generarSolucion1() { int iOferta = 0; int iPaquete = 0; Oferta oferta = transporte.get(iOferta); @@ -59,14 +86,223 @@ else if (paquete.getPrioridad() == Paquete.PR3 && oferta.getDias() < 4) { } public double heuristicoCoste() { - return -coste; + return +coste; + } + + public double heuristicoCosteFelicidad() { + return -felicidad + coste; + } + + public boolean moure_paquete(int ip, int oferta_desti) { + Paquete p = paquetes.get(ip); + double peso_paquete = p.getPeso(); + + //si intenta moure a la mateixa oferta retorna error + if (vecPaquetes[ip] == oferta_desti) return false; + + vecOfertas[vecPaquetes[ip]] += peso_paquete; + vecOfertas[oferta_desti] -= peso_paquete; + + Oferta oferta_des = transporte.get(oferta_desti); + Oferta oferta_og = transporte.get(vecPaquetes[ip]); + + if (0 > vecOfertas[oferta_desti]) return false; + + coste += oferta_des.getPrecio()*peso_paquete; + coste -= oferta_og.getPrecio()*peso_paquete; + + int ofertadesti_tempal = 0; + if(oferta_des.getDias() == 3 || oferta_des.getDias() == 4) ofertadesti_tempal = 1; + else if (oferta_des.getDias() == 5) ofertadesti_tempal = 2; + + int ofertaog_tempal = 0; + if(oferta_og.getDias() == 3 || oferta_og.getDias() == 4) ofertaog_tempal = 1; + else if (oferta_og.getDias() == 5) ofertaog_tempal = 2; + + //precio guardar en almacen + coste -= ofertaog_tempal* 0.25 * peso_paquete; + coste += ofertadesti_tempal* 0.25 * peso_paquete; + + if(p.getPrioridad() == Paquete.PR1) { + if(oferta_des.getDias() > 1) return false; + } + else if(p.getPrioridad() == Paquete.PR2) { + if(oferta_des.getDias() > 3) return false; + } + + int antelacion_original = 0; + if(p.getPrioridad() == Paquete.PR2) { + if(oferta_og.getDias() == 1) antelacion_original = 1; + } + else if(p.getPrioridad() == Paquete.PR3) { + if(oferta_og.getDias() == 1) antelacion_original = 2; + if(oferta_og.getDias() == 2 || oferta_og.getDias() == 3) antelacion_original = 1; + } + + felicidad -= antelacion_original; + + int nueva_antelacion = 0; + + if(p.getPrioridad() == Paquete.PR2) { + if(oferta_des.getDias() == 1) nueva_antelacion = 1; + } + else if(p.getPrioridad() == Paquete.PR3) { + if(oferta_des.getDias() == 1) nueva_antelacion = 2; + if(oferta_des.getDias() == 2 || oferta_des.getDias() == 3) nueva_antelacion = 1; + } + + felicidad += nueva_antelacion; + + vecPaquetes[ip] = oferta_desti; + + return true; + } + + public boolean swap(int paquete_1, int paquete_2) { + int ofertap1 = vecPaquetes[paquete_1]; + int ofertap2 = vecPaquetes[paquete_2]; + + //si la asignació d'oferta es la mateixa per els dos paquets no la contemplem + if(ofertap1 == ofertap2) return false; - public double heuristicoCoseFelicidad() { - return felicidad - coste; + double peso_paquete1 = paquetes.get(paquete_1).getPeso(); + double peso_paquete2 = paquetes.get(paquete_2).getPeso(); + + vecOfertas[ofertap1] += peso_paquete1 - peso_paquete2; + vecOfertas[ofertap2] -= peso_paquete1 - peso_paquete2; + + Oferta oferta1 = transporte.get(ofertap1); + Oferta oferta2 = transporte.get(ofertap2); + + if (0 > vecOfertas[ofertap1]) return false; + if (0 > vecOfertas[ofertap2]) return false; + + //Calculamos los costes segun el precio de la oferta + coste -= oferta1.getPrecio()*peso_paquete1 + oferta2.getPrecio()*peso_paquete2; + coste += oferta1.getPrecio()*peso_paquete2 + oferta2.getPrecio()*peso_paquete1; + + int dias2 = oferta2.getDias(); + int dias1 = oferta1.getDias(); + + Paquete paquete1 = paquetes.get(paquete_1); + Paquete paquete2 = paquetes.get(paquete_2); + + + //comprobamos is la nueva asignacion cumple la demanda de dias + if(paquete1.getPrioridad() == Paquete.PR1) { + if(oferta2.getDias() != 1) return false; + } + else if(paquete1.getPrioridad() == Paquete.PR2) { + if(oferta2.getDias() > 3) return false; + } + + if(paquete2.getPrioridad() == Paquete.PR1) { + if(oferta1.getDias() != 1) return false; + } + else if(paquete2.getPrioridad() == Paquete.PR2) { + if(oferta1.getDias() > 3) return false; + } + + //calcular con que antelacion iban a llegar los paquetes en la distribucion original + + int antelacion_original1 = 0; + int antelacion_original2 = 0; + + if(paquete1.getPrioridad() == Paquete.PR2) { + if(oferta1.getDias() == 1) antelacion_original1 = 1; + } + else if(paquete1.getPrioridad() == Paquete.PR3) { + if(oferta1.getDias() == 1) antelacion_original1 = 2; + if(oferta1.getDias() == 2 || oferta1.getDias() == 3) antelacion_original1 = 1; + } + + if(paquete2.getPrioridad() == Paquete.PR2) { + if(oferta2.getDias() == 1) antelacion_original2 = 1; + } + else if(paquete2.getPrioridad() == Paquete.PR3) { + if(oferta2.getDias() == 1) antelacion_original2 = 2; + if(oferta2.getDias() == 2 || oferta2.getDias() == 3) antelacion_original2 = 1; + } + + felicidad -= antelacion_original2 + antelacion_original1; + + //calculamos la nueva antelacion con la que llegaran los paquetes segun las asignaciones hechas + + int antelacion_postcambio1 = 0; + int antelacion_postcambio2 = 0; + + if(paquete1.getPrioridad() == Paquete.PR2) { + if(oferta2.getDias() == 1) antelacion_postcambio1 = 1; + } + else if(paquete1.getPrioridad() == Paquete.PR3) { + if(oferta2.getDias() == 1) antelacion_postcambio1 = 2; + if(oferta2.getDias() == 2 || oferta2.getDias() == 3) antelacion_postcambio1 = 1; + } + + + if(paquete2.getPrioridad() == Paquete.PR2) { + if(oferta1.getDias() == 1) antelacion_postcambio2 = 1; + } + else if(paquete2.getPrioridad() == Paquete.PR3) { + if(oferta1.getDias() == 1) antelacion_postcambio2 = 2; + if(oferta1.getDias() == 2 || oferta2.getDias() == 3) antelacion_postcambio2 = 1; + } + + felicidad += antelacion_postcambio1 + antelacion_postcambio2; + + //Calculamos los costes segun el cambio de tiempo que están en almacenaje + int oferta1_tempal = 0; + if(oferta1.getDias() == 3 || oferta1.getDias() == 4) oferta1_tempal = 1; + else if (oferta1.getDias() == 5) oferta1_tempal = 2; + + int oferta2_tempal = 0; + if(oferta2.getDias() == 3 || oferta2.getDias() == 4) oferta2_tempal = 1; + else if (oferta2.getDias() == 5) oferta2_tempal = 2; + + /*Aquests valors assignats a oferta1_tempal i oferta2_tempal es basen en el contingut del pdf + El pdf dice que si una oferta es de 3 a 4 dias, se llevan el paquete en un dia + si es de 5 dias se lleva el paquete en dos dias + si es de 1 a 2 dias, se llevan el paquete ese mismo dia, por lo tanto no lo incluyo en el coste? + */ + + coste -= oferta1_tempal*0.25 * peso_paquete1 + oferta2_tempal*0.25 * peso_paquete2; + coste += oferta1_tempal*0.25 * peso_paquete2 + oferta2_tempal*0.25 * peso_paquete1; + + vecPaquetes[paquete_1] = ofertap2; + vecPaquetes[paquete_2] = ofertap1; + return true; } - public void imprimir(Paquetes paquetes, Transporte transporte) { + //IMPRIMIR COMO TABLA + public void imprimir_tabla() { + for (int i = 0; i < vecOfertas.length; ++i) { + double peso_acumulado = 0.00; + System.out.println("---------------------------------------------------------------------------------------------------------"); + System.out.print("| Oferta: " + i + /*+ " Peso maximo de la oferta: " + transporte.get(i).getPesomax() + ", Peso_acumulado(" + peso_acumulado + "kg)*/" |"); + System.out.println("dias: " + transporte.get(i).getDias()); + System.out.println("precio: " + transporte.get(i).getPrecio()); + System.out.println("peso maximo: " + transporte.get(i).getPesomax()); + //System.out.println(transporte.get(i).toString()); + for (int j = 0; j < vecPaquetes.length; ++j) { + if (vecPaquetes[j] == i) { + peso_acumulado += paquetes.get(j).getPeso(); + System.out.print(" Paquete: " + j + ", Peso(" + paquetes.get(j).getPeso() + " kg) "); + //System.out.println(paquetes.get(j).toString()); + } + } + System.out.println(); + System.out.println(" Peso_acumulado(" + peso_acumulado + "kg) |"); + System.out.println("Peso libre " + vecOfertas[i] + "kg |"); + } + System.out.println("Coste total: " + coste); + } + + //IMPRIMIR ORIGINAL + public void imprimir() { + System.out.println("peso maximo: " + pesos_maximos); + System.out.println("coste: " + coste); + for (int i = 0; i < vecOfertas.length; ++i) { System.out.println("Oferta: " + i + " peso libre " + vecOfertas[i]); System.out.println(transporte.get(i).toString()); @@ -78,4 +314,36 @@ public void imprimir(Paquetes paquetes, Transporte transporte) { } } } + public String toString() { + //String s = "coste: " + coste; + String s = ""; + double peso_libre = 0; + for (int i = 0; i < vecOfertas.length; ++i) { + double peso_acumulado = 0.00; + s += "--------------------------------------------------------------------------------------------------------- \n"; + s += "| Oferta: " + i /*+ " Peso maximo de la oferta: " + transporte.get(i).getPesomax() */; + s += ("\n dias: " + transporte.get(i).getDias()); + s += ("\n precio: " + transporte.get(i).getPrecio()); + s += ("\n peso maximo: " + transporte.get(i).getPesomax()); + //System.out.println(transporte.get(i).toString()); + for (int j = 0; j < vecPaquetes.length; ++j) { + if (vecPaquetes[j] == i) { + peso_acumulado += paquetes.get(j).getPeso(); + s += " Paquete: " + j + ", Peso(" + paquetes.get(j).getPeso() + "), prioridad: " + paquetes.get(j).getPrioridad(); + //System.out.println(paquetes.get(j).toString()); + } + } + s += "\n Peso_acumulado(" + peso_acumulado + " kg) |"; + s += "\n Peso libre: " + vecOfertas[i] + "kg |"; + peso_libre += vecOfertas[i]; + } + s += "peso_libre_total: " + peso_libre + "\n"; + s += "coste: " + coste + "\n"; + return s; + } + + public String toStringSimple() { + String s = "Coste: " + coste; + return s; + } } diff --git a/src/com/lluc/practicaIA1/Main.java b/src/com/lluc/practicaIA1/Main.java index 4cbb857..49f165e 100644 --- a/src/com/lluc/practicaIA1/Main.java +++ b/src/com/lluc/practicaIA1/Main.java @@ -4,25 +4,99 @@ import IA.Azamon.Paquetes; import IA.Azamon.Transporte; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; +import java.util.*; + +import aima.search.framework.*; +import aima.search.informed.HillClimbingSearch; +import aima.search.informed.SimulatedAnnealingSearch; public class Main { public static void main(String[] args) { - - int npaq = 5; - int seed = 1; - double ratio = 2; + System.out.println("introduce el número de paquetes"); + Scanner scanner = new Scanner(System.in); + int npaq = scanner.nextInt(); + System.out.println("introduce la semilla"); + scanner = new Scanner(System.in); + int seed = scanner.nextInt(); + System.out.println("introduce el ratio"); + scanner = new Scanner(System.in); + double ratio = scanner.nextDouble(); Paquetes paquetes = new Paquetes(npaq, seed); Transporte transporte = new Transporte(paquetes, ratio, seed); - + Estado.paquetes = paquetes; + Estado.transporte = transporte; paquetes.sort(new Comparator() { @Override public int compare(Paquete p1, Paquete p2) { return p1.getPrioridad() - p2.getPrioridad(); } }); - Estado inicial = new Estado(paquetes, transporte); + Estado inicial = new Estado(); + + // Seleccionar uno + inicial.imprimir_tabla(); + azamonHillClimbingSearch(inicial); + //azamonSimulatedAnnealingSearch(inicial); + } + + private static void azamonHillClimbingSearch(Estado estado) { + System.out.println("\nAzamon HillClimbing -->"); + try { + AzamonSuccessorFunction successorFunction = new AzamonSuccessorFunction(); + AzamonGoalTest goalTest = new AzamonGoalTest(); + AzamonHeuristicFunction1 heuristicFunction1 = new AzamonHeuristicFunction1(); + Problem problem = new Problem(estado, successorFunction, goalTest, heuristicFunction1); + Search search = new HillClimbingSearch(); + SearchAgent agent = new SearchAgent(problem,search); + + System.out.println(); + printActions(agent.getActions()); + printInstrumentation(agent.getInstrumentation()); + + } catch (Exception e) { + e.printStackTrace(); + } } + /* + private static void azamonSimulatedAnnealingSearch(Estado estado) { + try { + AzamonSuccessorFunctionSA successorFunction = new AzamonSuccessorFunctionSA(); + AzamonGoalTest goalTest = new AzamonGoalTest(); + AzamonHeuristicFunction1 heuristicFunction1 = new AzamonHeuristicFunction1(); + Problem problem = new Problem(estado, successorFunction, goalTest, heuristicFunction1); + Search search = new SimulatedAnnealingSearch(2000,100,5,0.001); + SearchAgent agent = new SearchAgent(problem, search); + + System.out.println(); + printActions(agent.getActions()); + printInstrumentation(agent.getInstrumentation()); + } catch (Exception e) { + e.printStackTrace(); + } + } + */ + private static void printInstrumentation(Properties properties) { + Iterator keys = properties.keySet().iterator(); + while (keys.hasNext()) { + String key = (String) keys.next(); + String property = properties.getProperty(key); + System.out.println(key + " $ " + property); + } + + } + + private static void printActions(List actions) { + + for (int i = 0; i < actions.size(); i++) { + String action = (String) actions.get(i); + System.out.println(action); + } + + /* + int n = actions.size() - 1; + String action = (String) actions.get(n); + System.out.println(action); + */ + } + }