-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.c
142 lines (114 loc) · 4.78 KB
/
parser.c
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
#ifndef CHOCOCINO
#ifndef SUBMIT
#ifndef AGILE
#ifndef OPTIMAL
#ifndef SATISFICING
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char matrix[100][100];
int main(void){
int p=0;
while(scanf(" %s", matrix[p++]) == 1);
FILE *domain = fopen("domain.pddl", "w");
FILE *problem = fopen("problem.pddl", "w");
fprintf(problem, "(define (problem fisrt)\n\t(:domain lightsOut)\n\t(:objects\n\t");
int maxColumns=-1;
for (int i=0;i<p-1;i++){
int j=0;
while(matrix[i][j++] != '\0');
maxColumns = maxColumns > j ? maxColumns : j;}
int lenColumns[p-1];
for(int i=0;i<p-1;i++) lenColumns[i] = strlen(matrix[i]);
for(int i=0;i<p-1;i++)
for(int j=0;j<lenColumns[i]/2;j++)
fprintf( problem, "loc%d-%d ", i,j);
fprintf( problem, " - location)\n\t (:init\n\t");
for(int i=0;i<p-1;i++){
int h=0;
int k=1;
fprintf(problem, "\n");
for(int j=0;j<lenColumns[i];j++){
if(matrix[i][k] == 'W'){
fprintf(problem, "(white loc%d-%d) ",i,j);}
if(matrix[i][k] == 'R'){
fprintf(problem, "(red loc%d-%d) ",i,j);}
if(matrix[i][k] == 'B'){
fprintf(problem, "(blue loc%d-%d) ",i,j);}
if(matrix[i][k] == 'G'){
fprintf(problem, "(green loc%d-%d) ",i,j);}
if(matrix[i][h] == '*')
fprintf(problem, "(broken1 loc%d-%d) ",i,j);
if(matrix[i][h] == '_')
fprintf(problem, "(broken2 loc%d-%d) ",i,j);
if(matrix[i][h] == '|')
fprintf(problem, "(broken3 loc%d-%d) ",i,j);
if(matrix[i][h] == '#')
fprintf(problem, "(broken4 loc%d-%d) ",i,j);
h+=2; k+=2;
}
}
fprintf(problem, "\n");
for(int i=0;i<p-1;i++){
fprintf(problem, "\n");
for(int ii=0;ii<lenColumns[i]/2;ii++){
fprintf(problem, "\n");
for(int j=0;j < lenColumns[i]/2;j++){
if(ii != j) fprintf(problem, "(line loc%d-%d loc%d-%d) ", i,ii,i,j);
}
}
}
fprintf(problem, "\n");
for(int i=0;i<maxColumns/2;i++){
fprintf(problem, "\n");
for(int ii=0;ii<p-1;ii++){
fprintf(problem, "\n");
for(int j=0;j<p-1;j++){
if(j != ii) {
if(i <= lenColumns[ii]/2-1 && i <= lenColumns[j]/2-1) fprintf(problem, "(column loc%d-%d loc%d-%d) ",ii,i,j,i);
}
}
}
}
fprintf(problem, ")\n\t(:goal (and\n\t");
for(int i=0;i<p-1;i++){
fprintf(problem, "\n");
for(int j=0;j<lenColumns[i]/2;j++)
fprintf(problem, "(white loc%d-%d) ",i,j); }
fprintf(problem, ")))\n");
fprintf(domain," (define (domain lightsOut) (:requirements :strips :typing :equality) (:types location - object) (:predicates (red ?y-x - location) (green ?y-x - location) (blue ?y-x - location) (white ?y-x - location) (line ?y-x ?w-z - location) (column ?y-x ?w-z - location) (broken1 ?y-x - location) (broken2 ?y-x - location) (broken3 ?y-x - location) (broken4 ?y-x - location)) (:action click :parameters( ?y-x - location) :precondition ( and) :effect (and (when (not (broken1 ?y-x)) (and (when (red ?y-x) (and (not (red ?y-x)) (green ?y-x))) (when (green ?y-x) (and (not (green ?y-x)) (blue ?y-x))) (when (blue ?y-x) (and (not (blue ?y-x)) (white ?y-x))) (when (white ?y-x) (and (not (white ?y-x)) (red ?y-x))))) (forall (?w-z - location) (and (when (and (line ?y-x ?w-z) (not (= ?y-x ?w-z)) (not (broken3 ?w-z)) (not (broken4 ?w-z))) (and (when (red ?w-z) (and (not (red ?w-z)) (green ?w-z))) (when (green ?w-z) (and (not (green ?w-z)) (blue ?w-z))) (when (blue ?w-z) (and (not (blue ?w-z)) (white ?w-z))) (when (white ?w-z) (and (not (white ?w-z)) (red ?w-z))))) (when (and (column ?y-x ?w-z) (not (= ?y-x ?w-z)) (not (broken2 ?w-z)) (not (broken4 ?w-z))) (and (when (red ?w-z) (and (not (red ?w-z)) (green ?w-z))) (when (green ?w-z) (and (not (green ?w-z)) (blue ?w-z))) (when (blue ?w-z) (and (not (blue ?w-z)) (white ?w-z))) (when (white ?w-z) (and (not (white ?w-z)) (red ?w-z))))))))))");
fclose(domain);
fclose(problem);
#ifdef SUBMIT
#ifdef AGILE
system("/tmp/dir/software/planners/madagascar/M -Q domain.pddl problem.pddl | grep -i click > out");
system("grep -Eo '(click [a-zA-Z][a-zA-Z][a-zA-Z][0-9]+[0-9]+)' < out > out2");
system("sed 's/^[0-9]* : (click loc\\([0-9]*\\)-\\([0-9]*\\))/\\(click \\1 \\2\\);/' out > outFile");
#endif
#ifdef OPTIMAL
#endif
#ifdef SATISFICING
#endif
system("sed '$ s/.$//' outFile > outFile2");
system("cat outFile2");
#endif
#ifdef CHOCOCINO
#ifdef AGILE
system("/home/software/planners/madagascar/M -Q domain.pddl problem.pddl | grep -i click > out");
system("grep -Eo '(click [a-zA-Z][a-zA-Z][a-zA-Z][0-9]+[0-9]+)' < out > out2");
system("sed 's/^[0-9]* : (click loc\\([0-9]*\\)-\\([0-9]*\\))/\\(click \\1 \\2\\);/' out > outFile");
#endif
#ifdef OPTIMAL
#endif
#ifdef SATISFICING
#endif
system("sed '$ s/.$//' outFile > outFile2");
system("cat outFile2");
return 0;
}
#endif
#endif
#endif
#endif
#endif
#endif