Guest User

Untitled

a guest
Jan 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. bool
  2. subgrid_consistency (pset_t *subgrid[grid_size])
  3. /*
  4.  * subgrid_consistency check if subgrid is consistent
  5.  *
  6.  * a subgrid is consistent if and only if :
  7.  * _ each color appears once at least in subgrid
  8.  * _ two singleton in subgrid are not the same
  9.  *
  10.  * RETURN VALUE : true if subgrid is consistent, false otherwise
  11.  */
  12. {
  13.   unsigned int i;
  14.   pset_t color_appeared, color_singleton;
  15.   bool singleton = true;//true if each singleton in subgrid appears no more once
  16.   color_appeared = pset_empty();
  17.   color_singleton = pset_empty();
  18.  
  19.   for (i = 0; i < grid_size; i++)
  20.     {
  21.       if (pset_is_singleton(*subgrid[i]))
  22.     {
  23.       if (pset_is_included(*subgrid[i], color_singleton))
  24.         {
  25.           //subgrid[i] is a singleton ever met before
  26.           singleton = false;
  27.           break;
  28.         }
  29.       color_singleton = pset_or(color_singleton, *subgrid[i]);
  30.     }
  31.       color_appeared = pset_or(color_appeared, *subgrid[i]);
  32.     }
  33.  
  34.   return pset_is_included(pset_full(grid_size), color_appeared) && singleton;
  35. }
  36.  
  37.  
  38. bool
  39. grid_consistency (pset_t **grid)
  40. /*
  41.  * grid_consistency check if grid is consistency
  42.  *
  43.  * a grid is consistent if and only if each subgrid is consistent
  44.  *
  45.  * a subgrid is consistent if and only if :
  46.  * _ each color appears once at least in subgrid
  47.  * _ two singleton in subgrid are not the same
  48.  *
  49.  * RETURN VALUE : true if grid is consistent, false otherwise
  50.  */
  51. {
  52.   return subgrid_map(grid, subgrid_consistency);
  53. }
Add Comment
Please, Sign In to add comment