Initial commit with Madagascar 2016-01-22

upstream
Patrick Lühne 5 years ago committed by Patrick Lühne
commit 21571c20a1
No known key found for this signature in database
GPG Key ID: 5F3611E97A70ABF
  1. 109
      Cground.c
  2. 74
      Makefile
  3. 17
      README
  4. 784
      asyntax.c
  5. 188
      asyntax.h
  6. 1
      build
  7. 491
      clausedb.c
  8. 91
      clausedb.h
  9. 1840
      clausesets.c
  10. 12
      clausesets.h
  11. 259
      cleanup.c
  12. 4
      cleanup.h
  13. 4
      dimacs.h
  14. 157
      dimacsinput.c
  15. 4
      dimacsinput.h
  16. 812
      ground.c
  17. 828
      heuristics2.c
  18. 265
      interface.h
  19. 196
      intsets.c
  20. 75
      intsets.h
  21. 605
      invariants.c
  22. 7
      invariants.h
  23. 335
      learn2.c
  24. 161
      lexer.lex
  25. 755
      main.c
  26. 71
      main.h
  27. 4
      makedate
  28. 1867
      operators.c
  29. 167
      operators.h
  30. 291
      ordintsets.c
  31. 26
      ordintsets.h
  32. 211
      parser.y
  33. 1
      plan
  34. 291
      printplan.c
  35. 8
      printplan.h
  36. 201
      scc.c
  37. 12
      scc.h
  38. 123
      shortcuts.c
  39. 296
      tables.c
  40. 39
      tables.h
  41. 2938
      translate2sat.c
  42. 40
      translate2sat.h
  43. 364
      varvals.c
  44. 1
      zPOSTF
  45. 1
      zPREF

@ -0,0 +1,109 @@
cfma Cgroundfma(Sfma *,int *);
void Cgroundfmalist(Sfmalist *fs,int *ptr,int *b) {
while(fs != NULL) {
*(ptr++) = Cgroundfma(fs->hd,b);
fs = fs->tl;
}
}
cfma Cgroundfma(Sfma *sf,int *b) {
int *vals;
int i,cnt;
Sfmalist *fs;
cfma f;
switch(Sfmatypeof(sf)) {
case STRUE: return cTRUE;
case SFALSE: return cFALSE;
case Sconj:
f = (cfma)malloc(sizeof(int *) * (sf->cnt + 1));
Cgroundfmalist(sf->juncts,f+1,b);
f[0] = 1+(sf->cnt << 1);
return f;
case Sdisj:
f = (cfma)malloc(sizeof(int *) * (sf->cnt + 1));
Cgroundfmalist(sf->juncts,f+1,b);
f[0] = (sf->cnt << 1);
return f;
case Seq:
if(bvalue(sf->p1,b) == bvalue(sf->p2,b)) {
return cTRUE;
} else {
return cFALSE;
}
case Sneq:
if(bvalue(sf->p1,b) == bvalue(sf->p2,b)) {
return cFALSE;
} else {
return cTRUE;
}
case Spatom: return cPATOM(atomindex(sf->a,b));
case Snatom: return cNATOM(atomindex(sf->a,b));
case Sforall: /* Iterate over all values of the variable. */
cnt = getdomainsize(sf->ss->t);
f = (cfma)malloc(sizeof(int *) * (cnt + 1));
f[0] = (cnt << 1) + 1;
vals = getdomain(sf->ss->t);
for(i=0;i<cnt;i++) {
b[-1-sf->ss->v] = vals[i];
f[i+1] = Cgroundfma(sf->f,b);
}
return f;
case Sforsome: /* Iterate over all values of the variable. */
cnt = getdomainsize(sf->ss->t);
f = (cfma)malloc(sizeof(int *) * (cnt + 1));
f[0] = (cnt << 1);
vals = getdomain(sf->ss->t);
for(i=0;i<cnt;i++) {
b[-1-sf->ss->v] = vals[i];
f[i+1] = Cgroundfma(sf->f,b);
}
return f;
}
}
void printcfma(cfma f) {
int i;
if(((int)f)&1) { /* Atom */
switch(((int)f)&7) {
case cTRUEtag: printf("TRUE"); break;
case cFALSEtag: printf("FALSE"); break;
case cPATOMtag: printatomi((((int)f) >> 3)); break;
case cNATOMtag: printf("NOT "); printatomi((((int)f) >> 3)); break;
}
} else {
int cnt;
if(((int)(*f))&1) printf("(AND"); else printf("(OR");
cnt = ((int)(*f)) >> 1;
for(i=0;i<cnt;i++) {
printf(" ");
printcfma(f[i+1]);
}
printf(")");
}
printf("\n");
}

@ -0,0 +1,74 @@
# 2012 (C) Jussi Rintanen, jrintanen.jr@gmail.com
# Uncomment for Madagascar with the planning heuristic as default (Mp)
#VERSION = -DMPDOWNLOAD
#EXECUTABLE=Mp
# Uncomment for Madagascar C with the planning heuristic as default (MpC)
VERSION = -DCMPDOWNLOAD
EXECUTABLE=MpC
# Uncomment for Madagascar with VSIDS as default (M)
#VERSION = -DVSIDS
#EXECUTABLE=M
#ARCH=-m32
INSTRUMENT = #-g -ggdb -pg
CONFIGURATION= -DLBD -DREPRTHREE -DWEIGHTS #-DFUIP #-DMULTICORE #-DSPREAD -DCOSTS -DCFMA -DCP3
#FEATURES= -fopenmp
#LINKFEATURES= -fopenmp
# The following options are specific to GCC. Disable when necessary (e.g. in OS X).
GCCOPTIMIZE= $(ARCH) -O3 -fprefetch-loop-arrays -funroll-loops -ftree-loop-im -ftracer -maccumulate-outgoing-args -momit-leaf-frame-pointer #-falign-functions=64
CFLAGS = $(VERSION) $(FEATURES) $(CONFIGURATION) $(INSTRUMENT) $(GCCOPTIMIZE) -w #-Wall
PARSERGENERATOR=bison
PARSERC = parser.tab.c
PARSERH = parser.tab.h
PARSER=parser
#PARSERGENERATOR=yacc
#PARSERC = y.tab.c
#PARSERH = y.tab.h
#PARSER=y
CC = gcc
#LINKFLAGS = -L . -lcp3 -lpthread -lz -lrt #-static
#LINKFLAGS = -s
LINKFLAGS = $(ARCH) -static
OBJ = $(PARSER).tab.o main.o asyntax.o lex.yy.o tables.o operators.o invariants.o intsets.o cleanup.o translate2sat.o scc.o clausesets.o printplan.o clausedb.o dimacsinput.o ground.o
HDR = main.h asyntax.h tables.h operators.h invariants.h intsets.h cleanup.h scc.h intsets.h translate2sat.h ordintsets.h clausedb.h interface.h printplan.h dimacsinput.h
all: nplan
nplan: date lex.yy.c Makefile $(PARSERC) $(OBJ) $(HDR)
$(CC) $(LINKFLAGS) $(LINKFEATURES) $(INSTRUMENT) $(OBJ) -lm -o $(EXECUTABLE)
clausesets.o: heuristics2.c varvals.c learn2.c
ground.o: Cground.c
%.o: %.c Makefile $(HDR)
$(CC) $(CFLAGS) $(AMD64FLAGS) -c $<
date:
./makedate
main.o: zPRINTDATE
$(PARSERC): parser.y
$(PARSERGENERATOR) -d parser.y
$(PARSERH): parser.y
$(PARSERGENERATOR) -d parser.y
lex.yy.c: lexer.lex $(PARSERH) $(PARSERH)
flex lexer.lex
clean:
rm -f $(OBJ) $(PARSERC) $(PARSERH)
tar:
tar cvf MADAGASCAR.TAR README plan build asyntax.c asyntax.h clausedb.c clausedb.h clausesets.c clausesets.h cleanup.c cleanup.h dimacs.h dimacsinput.c dimacsinput.h ground.c Cground.c heuristics2.c interface.h intsets.c intsets.h invariants.c invariants.h lexer.lex main.c main.h makedate Makefile operators.c operators.h ordintsets.c ordintsets.h parser.y printplan.c printplan.h scc.c scc.h tables.c tables.h translate2sat.c translate2sat.h varvals.c learn2.c shortcuts.c zPOSTF zPREF

@ -0,0 +1,17 @@
2010, 2011, 2012, 2013, 2014, 2015 (C) Jussi Rintanen
Compilation:
Choose between M, Mp and MpC by commenting/uncommenting the lines for
VERSION and EXECUTABLE in Makefile
make
The command line for the executables consist of a number of options and
the names of input file names. With an empty command line you get the list
of options together with information on the default configuration.
MpC often consumes all available memory, so it is critical to make sure that
-m N flag is set sensibly. Too high values lead to paging, and too low values
may mean that plans are not found. The default can be adjusted in main.c as
the default value of the flagMemoryLimit variable.

@ -0,0 +1,784 @@
/* 2012 (C) Jussi Rintanen */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "asyntax.h"
#include "tables.h"
#include "intsets.h"
#include "ordintsets.h"
#include "operators.h"
#include "main.h"
#define noDEBUG 1
#include "parser.tab.h"
//void printlitarr(int *ptr) {
// if(*ptr == -1) { printf("NOTHING TO PRINT"); }
// while(*ptr != -1) {
// if((*ptr)&1) printf("NOT "); else printf(".");
// printatomi((*ptr) >> 1);
// ptr ++;
// }
// printf("\n");
//}
/* DESTRUCTIVE negation of a formula */
Sfma *Sneg(Sfma *f) {
Sfmalist *l;
switch(f->t) {
case STRUE: f->t = SFALSE; break;
case SFALSE: f->t = STRUE; break;
case Spatom: f->t = Snatom; break;
case Snatom: f->t = Spatom; break;
case Sconj:
f->t = Sdisj;
l = f->juncts;
while(l != NULL) {
Sneg(l->hd);
l = l->tl;
}
break;
case Sdisj:
f->t = Sconj;
l = f->juncts;
while(l != NULL) {
Sneg(l->hd);
l = l->tl;
}
break;
case Sforall: f->t = Sforsome; Sneg(f->f); break;
case Sforsome: f->t = Sforall; Sneg(f->f); break;
case Seq: f->t = Sneq; break;
case Sneq: f->t = Seq; break;
}
return f;
}
/* constructors for schematic formulae */
Sfma* Sdisjunction(Sfmalist *fs) {
Sfma *f = (Sfma*)statmalloc(20,sizeof(Sfma));
f->t = Sdisj;
f->juncts = fs;
return f;
}
Sfma* Sconjunction(Sfmalist *fs) {
Sfma *f = (Sfma*)statmalloc(21,sizeof(Sfma));
f->t = Sconj;
f->juncts = fs;
return f;
}
Sfma* Satom(atom a) {
Sfma *f = (Sfma*)statmalloc(22,sizeof(Sfma));
f->t = Spatom;
f->a = a;
return f;
}
Sfma* Sfalse() {
Sfma *f = (Sfma*)statmalloc(23,sizeof(Sfma));
f->t = SFALSE;
return f;
}
Sfma* Strue() {
Sfma *f = (Sfma*)statmalloc(24,sizeof(Sfma));
f->t = STRUE;
return f;
}
Sfma* Sfmaforall(typedvarlist *ss, Sfma *f) {
Sfma *f1 = (Sfma*)statmalloc(25,sizeof(Sfma));
f1->t = Sforall;
f1->ss = ss;
f1->f = f;
return f1;
}
Sfma* SconstantTRUE() {
Sfma *f = (Sfma*)statmalloc(26,sizeof(Sfma));
f->t = STRUE;
return f;
}
Sfma* Sfmaforsome(typedvarlist *ss, Sfma *f) {
Sfma *f1 = (Sfma*)statmalloc(27,sizeof(Sfma));
f1->t = Sforsome;
f1->ss = ss;
f1->f = f;
return f1;
}
Sfma* SfmaEQ(int p1, int p2) {
Sfma *f1 = (Sfma*)statmalloc(28,sizeof(Sfma));
f1->t = Seq;
f1->p1 = p1;
f1->p2 = p2;
return f1;
}
/******* Accessors ********/
Sfmatype Sfmatypeof(Sfma *f) {
return f->t;
}
//atom *makeatom(int pr,intlist *pars) {
// atom a = (atom)statmalloc(29,sizeof(atom));
// a->pred = pr;
// a->params = pars;
// return a;
//}
/* Printing */
void printSfmalist(Sfmalist *);
void printSefflist(Sefflist *);
void printatom(atom a) {
int n,i;
printf("%s(",symbol(a[0]));
n = a[1];
for(i=2;i<n+2;i++) {
if(a[i] < 0) printf("#%i",-1-(a[i]));
else printf("%s",symbol(a[i]));
if(i<n+1) printf(",");
}
printf(")");
}
void printtypedvars(typedvarlist *ss) {
printf(" (");
while(ss != NULL) {
printf("%s:%s",symbol(ss->v),symbol(ss->t));
if(ss->tl != NULL) printf(" ");
ss = ss->tl;
}
printf(")");
}
void printSfma(Sfma *f) {
switch(Sfmatypeof(f)) {
case STRUE: printf("TRUE"); break;
case SFALSE: printf("FALSE"); break;
case Seq: printf(" (= %s %s)",symbol(f->p1),symbol(f->p2)); break;
case Sneq: printf(" (not (= %s %s))",symbol(f->p1),symbol(f->p2)); break;
case Spatom: printatom(f->a); break;
case Snatom: printf("(not "); printatom(f->a); printf(")"); break;
case Sdisj: printf("(or "); printSfmalist(f->juncts); printf(")"); break;
case Sconj: printf("(and "); printSfmalist(f->juncts); printf(")"); break;
case Sforall: printf("(forall "); printtypedvars(f->ss); printSfma(f->f); printf(")"); break;
case Sforsome: printf("(exists "); printtypedvars(f->ss); printSfma(f->f); printf(")"); break;
}
}
void printSfmalist(Sfmalist *fs) {
while(fs != NULL) {
printSfma(fs->hd);
printf(" ");
fs = fs->tl;
}
}
void printSeff(Seff *);
void printSefflist(Sefflist *fs) {
while(fs != NULL) {
printSeff(fs->hd);
printf(" ");
fs = fs->tl;
}
}
void printSeff(Seff *e) {
switch(e->t) {
case SEpatom: printatom(e->a); break;
case SEnatom: printf("(not "); printatom(e->a); printf(")"); break;
case SEconj: printf("(and "); printSefflist(e->juncts); printf(")"); break;
case SEforall: printf("(forall "); printtypedvars(e->ss); printSeff(e->effect); printf(")"); break;
case SEwhen:
printf("(when ");
printSfma(e->cond);
printf(" ");
printSeff(e->effect);
printf(")");
break;
}
}
void printSaction(Saction *a) {
typedvarlist *l;
printf(":action %s(",symbol(a->name));
l = a->params;
while(l != NULL) {
printf("%s",symbol(l->v));
if(l->t) printf(":%s",symbol(l->t));
else printf(":UNIV");
if(l->tl != NULL) printf(" ");
l = l->tl;
}
printf(") (COST %i)\n",a->cost);
printSfma(a->precon);
printf("\n");
printSeff(a->effect);
printf("\n\n");
}
/* constructors for schematic effects */
Seff* SPeffatom(atom a) {
Seff *e = (Seff *)statmalloc(30,sizeof(Seff));
e->t = SEpatom;
e->a = a;
return e;
}
Seff* SNeffatom(atom a) {
Seff *e = (Seff *)statmalloc(31,sizeof(Seff));
e->t = SEnatom;
e->a = a;
return e;
}
Seff* Seffconjunction(Sefflist *efs) {
Seff *e = (Seff *)statmalloc(32,sizeof(Seff));
e->t = SEconj;
e->juncts = efs;
return e;
}
Seff* Seffwhen(Sfma *c,Seff *e) {
Seff *e1 = (Seff *)statmalloc(33,sizeof(Seff));
e1->t = SEwhen;
e1->cond = c;
e1->effect = e;
return e1;
}
Seff* Seffforall(typedvarlist *p,Seff *e) {
Seff *e1 = (Seff *)statmalloc(34,sizeof(Seff));
e1->t = SEforall;
e1->ss = p;
e1->effect = e;
return e1;
}
int listlen(intlist *l) {
int len = 0;
while(l != NULL) {
len = len+1;
l = l->tl;
}
return len;
}
/* Create atom */
atom newatom(int s,intlist *p) {
int len,i;
int *a;
len = listlen(p);
a = (atom)statmalloc(35,sizeof(int) * (len+2));
a[0] = s;
a[1] = len;
i = 2;
while(p != NULL) {
a[i++] = p->hd;
p = p->tl;
}
return a;
}
/* PDDL domain definitions */
int nOfTypes;
#define MAXOBTYPES 1000
obtype Stypes[MAXOBTYPES];
int *AStypes[MAXOBTYPES];
int *AStypesCARD[MAXOBTYPES];
#define MAXSCHEMATICACTIONS 10000
Sfma *Sgoal;
void initPDDL() {
nOfSActions = 0;
maxSActions = MAXSCHEMATICACTIONS;
Sactions = (Saction *)statmalloc(36,sizeof(Saction) * maxSActions);
nOfTypes = 0;
Sgoal = (Sfma *)0;
Sactions[0].precon = NULL;
Sactions[0].effect = NULL;
Sactions[0].params = NULL;
Sactions[0].cost = 0.0;
}
/* Definitions */
/* Typed var lists */
typedvarlist *TVappend(typedvarlist *l1,typedvarlist *l2) {
if(l1 == NULL) {
return l2;
} else {
typedvarlist *l3 = TVappend(l1->tl,l2);
typedvarlist *l4 = (typedvarlist *)statmalloc(37,sizeof(typedvarlist));
l4->v = l1->v;
l4->t = l1->t;
l4->tl = l3;
return l4;
}
}
/* For a (possibly untyped) list of variables, assign a type */
typedvarlist *withtype(int t,intlist *ss) {
typedvarlist *l;
if(ss == NULL) return NULL;
l = (typedvarlist *)statmalloc(38,sizeof(typedvarlist));
l->v = ss->hd;
l->t = t;
l->tl = withtype(t,ss->tl);
return l;
}
/* Add a new action */
void checkSactionsSize() {
if(nOfSActions >= maxSActions-1) {
maxSActions = maxSActions * 2;
Sactions = (Saction *)realloc(Sactions,maxSActions * sizeof(Saction));
assert(Sactions != NULL);
}
}
void addnewaction(int name) {
nOfSActions += 1;
checkSactionsSize();
Sactions[nOfSActions-1].name = name;
if(Sactions[nOfSActions-1].effect == NULL) {
fprintf(stderr,"ERROR: action has not effect.\n");
exit(1);
}
if(Sactions[nOfSActions-1].precon == NULL) {
Sactions[nOfSActions-1].precon = SconstantTRUE();
}
/* Next action */
Sactions[nOfSActions].precon = NULL;
Sactions[nOfSActions].effect = NULL;
Sactions[nOfSActions].params = NULL;
Sactions[nOfSActions].cost = 0.0;
}
/* The following three are called by the parser BEFORE addnewaction */
void addactionparameters(typedvarlist *params) {
Sactions[nOfSActions].params = params;
}
void addactionprecond(Sfma *p) {
Sactions[nOfSActions].precon = p;
}
void addactioncost(int cost) {
// printf("Action cost %i.\n",cost);
Sactions[nOfSActions].cost = cost;
}
/* Go through the predicates in an action effect and mark non-static ones. */
void checkifstatic(Seff *e) {
atom a;
Sefflist *es;
switch(e->t) {
case SEpatom:
case SEnatom:
a = e->a;
setnonstatic(a[0]);
break;
case SEconj:
es = e->juncts;
while(es != NULL) {
checkifstatic(es->hd);
es = es->tl;
}
break;
case SEwhen:
case SEforall:
checkifstatic(e->effect); break;
default:
break;
}
}
void addactioneffect(Seff *e) {
Sactions[nOfSActions].effect = e;
checkifstatic(e);
}
/* Requirements */
void checkrequirements(intlist *l) {
while(l != NULL) {
if(strcmp(symbol(l->hd),":strips") == 0) {
} else if(strcmp(symbol(l->hd),":conditional-effects") == 0) {
} else if(strcmp(symbol(l->hd),":adl") == 0) {
} else if(strcmp(symbol(l->hd),":typing") == 0) {
} else if(strcmp(symbol(l->hd),":equality") == 0) {
} else if(strcmp(symbol(l->hd),":typing") == 0) {
} else if(strcmp(symbol(l->hd),":conditional-effects") == 0) {
} else if(strcmp(symbol(l->hd),":negative-preconditions") == 0) {
} else if(strcmp(symbol(l->hd),":quantified-preconditions") == 0) {
} else if(strcmp(symbol(l->hd),":action-costs") == 0) {
} else {
fprintf(stderr,"WARNING: unsupported :requirement %s\n",symbol(l->hd));
}
if(strcmp(symbol(l->hd),":action-costs") == 0) {
fprintf(stderr,"WARNING: will ignore action costs\n");
}
l = l->tl;
}
}
/* Handling types and objects */
int member(int i,intlist *l) {
while(l != NULL) {
if(l->hd == i) return 1;
l = l->tl;
}
return 0;
}
/* Destructive addition of a non-duplicate element to a NON-EMPTY list */
intlist *addtolist(int s,intlist *l) {
if(member(s,l)) return l;
return intcons(s,l);
}
void addobject(int v,int t) {
int i;
i = 0;
while(i<nOfTypes) {
if(t == Stypes[i].typename) { /* Add to type */
Stypes[i].elements = addtolist(v,Stypes[i].elements);
return;
}
i+=1;
}
nOfTypes += 1;
Stypes[nOfTypes-1].typename = t;
Stypes[nOfTypes-1].elements = intcons(v,EMPTYLIST);
Stypes[nOfTypes-1].subtypes = EMPTYLIST;
Stypes[nOfTypes-1].supertypes = EMPTYLIST;
assert(nOfTypes < MAXOBTYPES);
}
/* Predicate definition */
void storepredicates() {
/* We don't use the predicate definition for anything. */
/* It could be used for some form of type-checking. */
}
/* Constant definitions */
void storeconstants(typedvarlist *cs) { /* Note: Same as 'storeobjects'. */
while(cs != NULL) {
addobject(cs->v,UNIVTYPE);
addobject(cs->v,cs->t);
cs = cs->tl;
}
}
/* Type definitions */
void addsubtype(int t1,int t2) {
int i;
i = 0;
while(i<nOfTypes) {
if(Stypes[i].typename == t2) {
Stypes[i].subtypes = addtolist(t1,Stypes[i].subtypes);
return;
}
i = i + 1;
}
nOfTypes += 1;
Stypes[i].typename = t2;
Stypes[i].supertypes = EMPTYLIST;
Stypes[i].elements = EMPTYLIST;
Stypes[i].subtypes = intcons(t1,EMPTYLIST);
}
void addsupertype(int t1,int t2) {
int i;
i = 0;
while(i<nOfTypes) {
if(Stypes[i].typename == t1) {
Stypes[i].supertypes = addtolist(t2,Stypes[i].supertypes);
return;
}
i = i + 1;
}
nOfTypes += 1;
Stypes[i].typename = t1;
Stypes[i].supertypes = intcons(t2,EMPTYLIST);
Stypes[i].subtypes = EMPTYLIST;
Stypes[i].elements = EMPTYLIST;
}
void extendsubtyperelation(int t1,int t2) {
addsubtype(t1,t2);
addsupertype(t1,t2);
}
void storetypes(typedvarlist *ts) {
while(ts != NULL) {
extendsubtyperelation(ts->v,ts->t);
ts = ts->tl;
}
}
void processtypes() {
int i;
intlist *il,*il2;
/* Extend subtypes and supertypes to non-immediate ones. */
for(i=0;i<nOfTypes;i++) {
il = Stypes[i].subtypes;
while(il != NULL) {
il2 = Stypes[i].supertypes;
while(il2 != NULL) {
addsubtype(il->hd,il2->hd);
addsupertype(il->hd,il2->hd);
il2 = il2->tl;
}
il = il->tl;
}
}
if(flagShowInput) {
for(i=0;i<nOfTypes;i++) {
printf("TYPE %s:\n",symbol(Stypes[i].typename));
printf(" ELEMENTS:");
il = Stypes[i].elements;
while(il != NULL) {
printf(" %s",symbol(il->hd));
il = il->tl;
}
printf("\n");
printf(" SUBTYPES:");
il = Stypes[i].subtypes;
while(il != NULL) {
printf(" %s",symbol(il->hd));
il = il->tl;
}
printf("\n");
printf(" SUPERTYPES:");
il = Stypes[i].supertypes;
while(il != NULL) {
printf(" %s",symbol(il->hd));
il = il->tl;
}
printf("\n");
}
}
/* Add objects of a type to all its supertypes. */
for(i=0;i<nOfTypes;i++) {
il = Stypes[i].elements;
while(il != NULL) {
il2 = Stypes[i].supertypes;
while(il2 != NULL) {
addobject(il->hd,il2->hd);
il2 = il2->tl;
}
il = il->tl;
}
}
}
/* PDDL problem definitions */
/* Add objects to a type. */
void storeobjects(typedvarlist *cs) {
while(cs != NULL) {
addobject(cs->v,UNIVTYPE);
addobject(cs->v,cs->t);
cs = cs->tl;
}
}
void storeinit(atomlist *a) {
int cnt,i;
cnt = listlen(a);
Sinit = (atom *)malloc((cnt+1) * sizeof(atom));
for(i=0;i<cnt;i++) {
Sinit[i] = a->hd;
a = a->tl;
}
Sinit[cnt] = NULL;
}
void storegoal(Sfma *f) {
Sgoal = f;
}
/* Domain name */
int domain,problem;
void storedomain(int s) { domain = s; }
void checkdomain(int s) {
if(s != domain) {
fprintf(stderr,"WARNING: problem domain '%s' does not match domain name '%s'\n",symbol(s),symbol(domain));
}
}
char *domainname() { return symbol(domain); }
void addproblem(int s) { problem = s; }
char *problemname() { return symbol(problem); }
/* Lists */
Sfmalist *Sfmacons(Sfma *h,Sfmalist *t) {
Sfmalist *r = (Sfmalist *)statmalloc(39,sizeof(Sfmalist));
r->hd = h;
r->tl = t;
return r;
}
Sefflist *Seffcons(Seff *h,Sefflist *t) {
Sefflist *r = (Sefflist *)statmalloc(40,sizeof(Sefflist));
r->hd = h;
r->tl = t;
return r;
}
intlist *intcons(int h,intlist *t) {
intlist *r = (intlist *)statmalloc(41,sizeof(intlist));
r->hd = h;
r->tl = t;
return r;
}
ptrlist *ptrcons(int *h,ptrlist *t) {
ptrlist *r = (ptrlist *)statmalloc(42,sizeof(ptrlist));
r->hd = h;
r->tl = t;
return r;
}
atomlist *atomcons(atom h,atomlist *t) {
atomlist *r = (atomlist *)statmalloc(43,sizeof(atomlist));
r->hd = h;
r->tl = t;
return r;
}
/* Reading and processing an input file */
void showstatistics() {
int i;
printf("%3i action schemata\n",nOfSActions);
for(i=0;i<nOfSActions;i++) {
printSaction(&(Sactions[i]));
}
printf("%3i types\n",nOfTypes);
for(i=0;i<nOfTypes;i++) {
intlist *ss;
printf("%s consists of",symbol(Stypes[i].typename));
ss = Stypes[i].elements;
while(ss != NULL) {
printf(" %s",symbol(ss->hd));
ss = ss->tl;
}
printf("\n");
}
}
/* Turn object lists Stypes to object arrays AStypes. */
void constructtypearrays() {
int i,*ptr,cnt;
intlist *l;
for(i=0;i<nOfTypes;i++) {
cnt = listlen(Stypes[i].elements);
AStypesCARD[i] = cnt;
AStypes[i] = (int *)malloc((1+cnt) * sizeof(int));
l = Stypes[i].elements;
// printf("%s has elements ",symbol(Stypes[i].typename));
ptr = AStypes[i];
while(l != NULL) {
*ptr = l->hd;
// printf(" %s",symbol(*ptr));
l = l->tl;
ptr = ptr + 1;
}
// printf("\n");
*ptr = -1;
}
}
void readfile() {
linenumber = 1;
if(nOfInputFiles == 0) {
printf("Reading from standard input\n");
lexeropenstdin();
} else {
lexeropen(inputfiles[0]);
}
errorstring = "";
initPDDL();
initsymboltable();
UNIVTYPE = symbolindex("***UNIVTYPE***");
yyparse();
processtypes();
constructtypearrays();
if(flagShowInput) showstatistics();
}
void yyerror( char *s) {
printf("%s; %s on line %i.\n",s,errorstring,linenumber);
exit(1);
}
/*******************************************************************/
/********************* Bindings and domains ************************/
/*******************************************************************/
/* elements associated with a type */
int *getdomain(int type) {
int j;
for(j=0;j<nOfTypes;j++) {
if(Stypes[j].typename == type) return AStypes[j];
}
fprintf(stderr,"WARNING: type %s not defined\n",symbol(type));
exit(1);
return NULL;
}
int getdomainsize(int type) {
int j;
for(j=0;j<nOfTypes;j++) {
if(Stypes[j].typename == type) return AStypesCARD[j];
}
fprintf(stderr,"WARNING: type %s not defined\n",symbol(type));
exit(1);
return 0;
}

@ -0,0 +1,188 @@
/* 2012 (C) Jussi Rintanen */
#define feNEG(a) ((a)^1)
#define fePLIT(a) ((a) << 1)
#define feNLIT(a) (feNEG(fePLIT(a)))
#define feVAR(l) ((l) >> 1)
/* An atomic fact (or schema) P(t1 t2 t3 ... tn) */
typedef struct _intlist { int hd; struct _intlist *tl; } intlist;
typedef struct _ptrlist { int *hd; struct _ptrlist *tl; } ptrlist;
typedef struct _stringlist { char *hd; struct _stringlist *tl; } stringlist;
typedef struct _typedvarlist { int v; int t; struct _typedvarlist *tl; } typedvarlist;
/* An atom is represented as an int vector.
a[0] is the predicate
a[1] is the number of parameters n
a[2..n+2] are the parameters */
typedef int *atom;
/******************* Schematic formulae ******************/
/* Definition */
typedef enum {
STRUE,SFALSE,
Spatom, Snatom,
Sconj, Sdisj,
Sforall, Sforsome,
Seq, Sneq } Sfmatype;
typedef struct _Sfma {
Sfmatype t;
union {
atom a;
typedvarlist *ss; /* parameters for quantification */
int p1;
struct _Sfmalist0 { struct _Sfma *hd; struct _Sfmalist0 *tl; } *juncts;
};
#ifdef CFMA
int cnt;
#endif
int p2;
struct _Sfma *f;
} Sfma;
typedef struct _Sfmalist { Sfma *hd; struct _Sfmalist *tl; } Sfmalist;
/* Constructors formulas */
Sfma *Sfalse();
Sfma *Strue();
Sfma *Sconjunction(Sfmalist *);
Sfma *Sdisjunction(Sfmalist *);
Sfma *Satom(atom);
Sfma *Sneg(Sfma *);
Sfma *SfmaEQ(int,int);
Sfma *Sfmaforall(typedvarlist *,Sfma *);
Sfma *Sfmaforsome(typedvarlist *,Sfma *);
Sfma *Sgoal;
/* Accessors */
Sfmatype Sfmatypeof(Sfma *);
/******************** Schematic effects *********************/
typedef enum { SEpatom, SEnatom, SEwhen, SEconj, SEforall } Sefftype;
/* schematic effects */
typedef struct _Seff {
Sefftype t;
union {
atom a;
Sfma *cond; /* condition for when */
struct _Sefflist0 { struct _Seff *hd; struct _Sefflist0 *tl; } *juncts; /* list of effects for conj */
typedvarlist *ss; /* parameter in forall quantification */
};
struct _Seff *effect; /* effect for when, forall */
} Seff;
/* Lists */
typedef struct _Sefflist { Seff *hd; struct _Sefflist* tl; } Sefflist;
typedef struct _atomlist { atom hd; struct _atomlist* tl; } atomlist;
Sfmalist *Sfmacons(Sfma *,Sfmalist *);
Sefflist *Seffcons(Seff *,Sefflist *);
intlist *intcons(int,intlist *);
atomlist *atomcons(atom,atomlist *);
ptrlist *ptrcons(int *,ptrlist *);
#define EMPTYLIST NULL
/* Domain */
void storedomain(int);
void checkdomain(int);
char *domainname();
void storeconstants(typedvarlist *);
void storetypes(typedvarlist *);
void storepredicates();
void checkrequirements(intlist *);
/* Problem */
void addproblem(int);
char *problemname();
void storeinit(atomlist *);
void storegoal(Sfma *);
atom *Sinit;
/* Type variables */
int UNIVTYPE;
typedvarlist *withtype(int,intlist *);
typedvarlist *TVappend(typedvarlist *,typedvarlist *);
/* An operator schema */
typedef struct _Saction {
int name;
typedvarlist *params;
int cost;
Sfma *precon;
Seff *effect;
} Saction;
int maxSActions;
Saction *Sactions;
int nOfSActions;
void checkSactionsSize();
atom newatom(int,intlist *);
/* Types, with elements. */
typedef struct _obtype {
int typename;
intlist *elements;
intlist *supertypes;
intlist *subtypes;
} obtype;
int *getdomain(int);
int getdomainsize(int);
void bindingaslist(int *,int *,int);
void storeobjects(typedvarlist *);
void showatom(atom);
int linenumber;
char *errorstring;
void readfile();
/* Constructors */
/* schematic effects */
Seff* Seffconjunction(Sefflist *);
Seff* Seffwhen(Sfma*, Seff*);
Seff* Seffforall(typedvarlist *,Seff *);
Seff* SPeffatom(atom);
Seff* SNeffatom(atom);
/* create new schematic op */
void addnewaction(int);
void addactionparameters(typedvarlist *);
void addactionprecond(Sfma *);
void addactioneffect(Seff *);
void addactioncost(int);
/* Grounding */
void preprocessoperators();
void groundoperators();
void simplifysillyconditionals();

@ -0,0 +1 @@
make

@ -0,0 +1,491 @@
/* 2012 (C) Jussi Rintanen, jrintanen.jr@gmail.com */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "main.h"
#include "interface.h"
#include "clausedb.h"
#include "clausesets.h"
#include "printplan.h"
#include "asyntax.h"
#include "ordintsets.h"
#include "operators.h"
#include "translate2sat.h"
#define noDEBUG
#define noASSERTS
#define noALIGNMENT /* There is a problem: the padding is not handled by GC! */
typedef struct _clausedblist {
int *block;
int permanent;
int blockptr;
struct _clausedblist *nextblock;
} clausedblist;
#if defined(__LP64__)
#define BLOCKSIZE 1024*1024*8
#else
#define BLOCKSIZE 1024*1024*2
#endif
clausedblist *cdb;
int CDBclauses;
/* Given an int *, calculate the number of sizeof(int) to the
next 64 byte alignment boundary. This is to align data structures
with cache line boundaries.
*/
int ptr2intpad(int *ptr) {
int alignment = (((int)ptr)&63) >> 2;
if(alignment) return 16-alignment;
else return 0;
}
void check_malloc_success(void *ptr,int i) {
if(ptr == NULL) {
fprintf(stderr,"ERROR: Could not allocate more memory %i.\n",i);
exit(1);
}
}
/* Clauses in the clause data base:
location content
-3 activity
-2 SAT instance number
-1 # of literals in clause
0 1st literal
1 2nd literal
. .
. .
n-1 last literal
n -1
WARNING: These should always be accessed with the indices PREFIX_xxxx
defined in clausedb.h.
*/
void initclausedb() {
cdb = (clausedblist *)malloc(sizeof(struct _clausedblist));
check_malloc_success(cdb,1);
cdb->block = (int *)malloc(BLOCKSIZE*sizeof(int));
check_malloc_success(cdb->block,2);
allocatedbyCDB = BLOCKSIZE*sizeof(int);
cdb->blockptr = 0;
cdb->permanent = 1;
cdb->nextblock = NULL;
#ifdef DEBUG
printf("FIRST CBD BLOCK %i\n",(int)cdb);
#endif
CDBclauses = 0;
clausecount = 0;
GCaggressiveness = 0; /* Remove only very old clauses. */
}
/* Update clause activity counter. The pointer is to the first literal. */
void updateactivity(int *c,int act) {
c[PREFIX_ACTIVITY] = act;
}
/* Set the LBD field of a clause. */
void setLBD(int *c,int lbd) {
c[PREFIX_LBD] = lbd;
}
/* Allocate a clause. If permflag is 1, space allocated for
the clause won't be freed or reused. */
int *allocc(int inst,int len,int permflag) {
clausedblist *cls,*temp;
int *ptr;
#ifdef ALIGNMENT
int alignment;
#endif
#ifdef MULTICORE
#pragma omp critical
#endif
{
CDBclauses += 1;
clausecount += 1;
cls = cdb;
while(cls != NULL
&& (cls->permanent != permflag
|| cls->blockptr+len+PREFIXWORDS+5 > BLOCKSIZE))
{
cls = cls->nextblock;
}
if(cls == NULL) { /* Allocate a new block. */
#ifdef DEBUG
printf("NEW CDB BLOCK (total of %i clauses now).\n",CDBclauses);
#endif
temp = cdb;
cdb = (clausedblist *)malloc(sizeof(struct _clausedblist));
check_malloc_success(cdb,3);
cdb->block = (int *)malloc(BLOCKSIZE*sizeof(int));
check_malloc_success(cdb->block,4);
allocatedbyCDB += BLOCKSIZE*sizeof(int);
cdb->permanent = permflag;
cdb->nextblock = temp;
cdb->blockptr = 0;
cls = cdb;
printf("\t\t\t\tAllocated %i MB %s(total %i MB)\n",
BLOCKSIZE/1024/1024*sizeof(int),
(permflag ? "permanent " : ""),
(int)(memoryused()));
}
#ifdef DEBUG
printf("Allocating clause %i of length %i\n",cdb->blockptr,len);
#endif
/* Allocate it from an existing block. */
#ifdef DEBUG
printf("Allocating clause %i of length %i\n",cls->blockptr,len);
#endif
/* Clauses should be aligned with cache line boundaries (16x4Bs?).
Add something to cls->blockptr to make it align.
*/
#ifdef ALIGNMENT
cls->blockptr += ptr2intpad(&(cls->block[cls->blockptr]));
#endif
ptr = &(cls->block[cls->blockptr+PREFIXWORDS]);
}
cls->block[cls->blockptr+PREFIXWORDS+PREFIX_ACTIVITY] = 0;
cls->block[cls->blockptr+PREFIXWORDS+PREFIX_LBD] = 0;
cls->block[cls->blockptr+PREFIXWORDS+PREFIX_INSTANCE] = inst;
cls->block[cls->blockptr+PREFIXWORDS+PREFIX_CLAUSELEN] = len;
cls->block[cls->blockptr+len+PREFIXWORDS] = -1;
cls->blockptr += len+1+PREFIXWORDS;
return ptr;
}
/* Extract information from a clause pointed to by ptr (the first literal.) */
int clauselen(int *ptr) {
return ptr[PREFIX_CLAUSELEN];
}
int SATinstance(int *ptr) {
return ptr[PREFIX_INSTANCE];
}
/* Allocate space for a non-permanent clause. */
int *allocpermclause(int inst,int len) { return allocc(inst,len,1); }
int *allocclause(int inst,int len) { return allocc(inst,len,0); }
/* The following has not been tested after the -2 and -3 fields were added. */
void showclauses(satinstance sati) {
clausedblist *cls;
int i,j,b;
printf("All clauses in clause db:\n");
cls = cdb;
b=0;
while(cls != NULL) {
i = 0;
while(i < cls->blockptr) {
printf("Clause at %i.%i:",