-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGeneradorExtension1.java
More file actions
152 lines (133 loc) · 5.92 KB
/
GeneradorExtension1.java
File metadata and controls
152 lines (133 loc) · 5.92 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import java.io.*;
import java.util.ArrayList;
import java.util.Random;
public class GeneradorExtension1 {
static BufferedWriter writer;
static ArrayList<String> Libros = new ArrayList<String>();
static ArrayList<ArrayList<String>> Predecesores = new ArrayList<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("GproblemaExtension1.pddl", true));
generaLibros();
defineObjects();
init();
goal();
writer.close();
}
public static void defineObjects() throws IOException {
writer.write("(define (problem extension1) (:domain extension1)\n");
writer.write("(:objects\n");
for(int i=0; i<Libros.size();++i)
{
writer.write(" "+Libros.get(i));
}
writer.write(" - libro\n");
writer.write(" enero febrero marzo abril mayo junio julio agosto septiembre octubre noviembre diciembre - mes");
writer.write("\n)\n");
}
public static void init() throws IOException{
writer.write("(:init \n");
writer.write(";Juego de Prueba meses\n");
writer.write(" (= (mesANumero enero) 1)\n" + //
" (= (mesANumero febrero) 2)\n" + //
" (= (mesANumero marzo) 3)\n" + //
" (= (mesANumero abril) 4)\n" + //
" (= (mesANumero mayo) 5)\n" + //
" (= (mesANumero junio) 6)\n" + //
" (= (mesANumero julio) 7)\n" + //
" (= (mesANumero agosto) 8)\n" + //
" (= (mesANumero septiembre) 9)\n" + //
" (= (mesANumero octubre) 10)\n" + //
" (= (mesANumero noviembre) 11)\n" + //
" (= (mesANumero diciembre) 12)\n");
writer.write(";Juego de Prueba de mes libro Planificado\n");
for(int i=0; i<Libros.size();++i)
{
writer.write(" (= (mesLibroPlanificado "+Libros.get(i)+") 0)\n");
}
generaPredecesores();
writer.write(";Juego de Prueba de Predecesores\n");
for(int i=0; i<Predecesores.size();++i)
{
ArrayList<String> PredecesoresLibros = Predecesores.get(i);
for(int j=0;j<PredecesoresLibros.size()-1;++j)
{
writer.write(" (esPredecesor "+ PredecesoresLibros.get(j+1)+" "+PredecesoresLibros.get(0)+")\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");
}
//generar libros con mas de 1 predecensia
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 numPredLibro = rand.nextInt(5);
int libro = rand.nextInt(Libros.size()); //Escojo un libro de forma aleatoria
ArrayList<String> PredecesoresLibros = new ArrayList<String>();
PredecesoresLibros.add(Libros.get(libro)); //Añadimos el libro al que le vamos a calcular sus predecesores
for(int j=1;j<numPredLibro;++j)
{
//calculamos los predecesores del libro escogido de forma aleatoria
int predecesor = rand.nextInt(Libros.size());
PredecesoresLibros.add(Libros.get(predecesor));
}
Predecesores.add(PredecesoresLibros);
LibrosAux.add(Libros.get(libro)); //Añadimos los libros que vamos a quitar para generar los leidos
Libros.remove(libro); //Lo eliminamos de libros para no generar ciclos de dependencia
}
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 no 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(50);
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
}
}