From: Alexander Fedotov Date: Sat, 9 Apr 2016 21:35:09 +0000 (+0100) Subject: helper maps X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=b18ff9447389e6879994f90d458b5a0e993755f3;p=mc1516pa.git helper maps --- diff --git a/modelchecker/coord.c b/modelchecker/coord.c index 586095f..12b428d 100644 --- a/modelchecker/coord.c +++ b/modelchecker/coord.c @@ -17,6 +17,95 @@ #include "coord.h" #include "sokoban.h" +typedef struct { + int x; + int y; +} xy; + +typedef struct { + int var[3]; +} bddvar; + +typedef struct { + xy key; + bddvar value; + UT_hash_handle hh; +} xy_bddvar_map; + +typedef struct { + int key; + xy value; + UT_hash_handle hh; +} bddvar_xy_map; + +typedef struct { + xy_bddvar_map f; + bddvar_xy_map t; +} bimap; + +xy_bddvar_map *getxy(int x, int y, xy_bddvar_map *map) +{ + xy_bddvar_map k, *r = NULL; + memset(&k, 0, sizeof(xy_bddvar_map)); + k.key.x = x; + k.key.y = y; + HASH_FIND(hh, map, &k.key, sizeof(xy), r); + return r; +} + +bddvar_xy_map *getbdd(int key, bddvar_xy_map *map) +{ + bddvar_xy_map k, *r = NULL; + memset(&k, 0, sizeof(bddvar_xy_map)); + k.key = key; + HASH_FIND(hh, map, &k.key, sizeof(int), r); + return r; +} + +xy_bddvar_map *create_xy_bddvar_map(sokoban_screen *screen) +{ + int varcount = 0; + sokoban_screen *r; + xy_bddvar_map *xybdd = NULL; + for(r=screen; r != NULL; r = (sokoban_screen *)(r->hh.next)){ + xy_bddvar_map *f = NULL; + //bddvar_xy_map *t = NULL; + + f = (xy_bddvar_map *)malloc(sizeof(xy_bddvar_map)); + memset(f, 0, sizeof(xy_bddvar_map)); + f->key.x = r->coord.x; + f->key.y = r->coord.y; + printf("test!: %d %d\n", r->coord.x, r->coord.y); + f->value.var[0] = varcount; + f->value.var[1] = varcount + 1; + f->value.var[2] = varcount + 2; + HASH_ADD(hh, xybdd, key, sizeof(xy), f); + varcount = varcount + 3; + } + return xybdd; +} + +bddvar_xy_map *create_bddvar_xy_map(sokoban_screen *screen) +{ + int varcount = 0; + sokoban_screen *r; + bddvar_xy_map *bddxy = NULL; + for(r=screen; r != NULL; r = (sokoban_screen *)(r->hh.next)){ + for (int i = 0; i <3; i++){ + bddvar_xy_map *f = NULL; + //bddvar_xy_map *t = NULL; + + f = (bddvar_xy_map *)malloc(sizeof(bddvar_xy_map)); + memset(f, 0, sizeof(bddvar_xy_map)); + f->key = varcount + i; + f->value.x = r->coord.x; + f->value.y = r->coord.y; + HASH_ADD(hh, bddxy, key, sizeof(int), f); + } + varcount = varcount + 3; + } + return bddxy; +} /* * Each coordinate has three related boolean variables. The combination of those boolean variables @@ -170,6 +259,16 @@ BDD encode_screen(sokoban_screen *screen) break; } } + /* + xy_bddvar_map *map = NULL; + map = create_xy_bddvar_map(screen); + xy_bddvar_map *m = getxy(1, 1, map); + bddvar_xy_map *map2 = NULL; + map2 = create_bddvar_xy_map(screen); + bddvar_xy_map *m2 = getbdd(2, map2); + printf("Test1: %d %d\n", m->value.var[0], m->value.var[1]); + printf("Test2: %d %d\n", m2->value.x, m2->value.y); + */ printf("%d tiles were encoded\n", tile_index); return state; }