-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGeneradorBasico.java
More file actions
120 lines (100 loc) · 4.19 KB
/
GeneradorBasico.java
File metadata and controls
120 lines (100 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import java.io.*;
import java.util.ArrayList;
import java.util.Random;
public class GeneradorBasico {
static BufferedWriter writer;
static ArrayList<String> Libros = new ArrayList<String>();
static ArrayList<String> Predecesores = new ArrayList<String>();
static ArrayList<String> Leidos = new ArrayList<String>();
static ArrayList<String> Aplanificar = new ArrayList<String>();
public static void main(String[] args) throws IOException {
writer = new BufferedWriter(new FileWriter("GproblemaNivelBasico.pddl", true));
generaLibros();
defineObjects();
init();
goal();
writer.close();
}
public static void defineObjects() throws IOException {
writer.write("(define (problem nivelBasico) (:domain nivelBasico)\n");
writer.write("(:objects\n");
for(int i=0; i<Libros.size();++i)
{
writer.write(" "+Libros.get(i));
}
writer.write(" - libro");
writer.write("\n)\n");
}
public static void init() throws IOException{
writer.write("(:init \n");
generaPredecesores();
writer.write(";Juego de Prueba de Predecesores\n");
for(int i=0; i<Predecesores.size()-1;++i)
{
writer.write(" (esPredecesor "+Predecesores.get(i)+" "+Predecesores.get(i+1)+")\n");
}
generaLeidos();
writer.write(";Juego de Prueba de Leidos\n");
for(int i=0; i<Leidos.size();++i)
{
writer.write(" (libroLeido "+Leidos.get(i)+")\n");
}
generaAplanificar();
writer.write(";Juego de Prueba de Aplanificar\n");
for(int i=0; i<Aplanificar.size();++i)
{
writer.write(" (libroAPlanificar "+Aplanificar.get(i)+")\n");
}
writer.write(")\n");
}
private static void generaPredecesores(){
Random rand = new Random();
int numPred = rand.nextInt(Libros.size());
ArrayList<String> LibrosAux = new ArrayList<String>();
for(int i=0; i<numPred ; ++i)
{
int libro = rand.nextInt(Libros.size()); //Escojo un libro de forma aleatoria
Predecesores.add(Libros.get(libro)); //lo meto en el array de predecesores
LibrosAux.add(Libros.get(libro)); //Añadimos los libros que vamos a quitar para generar los leidos
Libros.remove(libro); //lo quito del array de libros para que no vuelva a salir
}
Libros.addAll(LibrosAux); //Añadimos los libros previamente borrados
}
private static void generaLeidos(){
Random rand = new Random();
int numPred = rand.nextInt(Libros.size());
for(int i=0; i<numPred ; ++i)
{
int libro = rand.nextInt(Libros.size()); //Escojo un libro de forma aleatoria
Leidos.add(Libros.get(libro)); //lo meto en el array de Leidos
Libros.remove(libro); //lo quito del array de libros para que no vuelva a salir
}
}
private static void generaAplanificar(){
Random rand = new Random();
int numPred = rand.nextInt(Libros.size());
for(int i=0; i<numPred ; ++i)
{
int libro = rand.nextInt(Libros.size()); //Escojo un libro de forma aleatoria de los nos leidos
Aplanificar.add(Libros.get(libro)); //lo meto en el array de Aplanificar
Libros.remove(libro); //lo quito del array de libros para que no vuelva a salir
}
}
private static void generaLibros(){
Random rand = new Random();
int libro = rand.nextInt(150);
for(int i=0; i<libro ; ++i)
{
String str = "book" + i;
Libros.add(str);
}
}
public static void goal() throws IOException{
writer.write("(:goal (not (exists (?l - libro) \n" + //
" (and (libroAPlanificar ?l) (not (libroPlanificado ?l)))\n" + //
" )\n" + //
" )\n" + //
" )\n");
writer.write(")"); //cierra el define
}
}