Exemplo n.º 1
0
int main(int argc, string argv[])
{
  string *datafields, *bodyfields, times, ifmt, rfmt;
  stream istr;
  bodyptr btab = NULL;
  int nbody;
  real tnow;
  string intags[MaxBodyFields];

  initparam(argv, defv);
  istr = stropen(getparam("in"), "r");
  get_history(istr);
  datafields = burststring(getparam("fields"), ", ");
  if (set_member(datafields, TimeTag))
    bodyfields = set_diff(datafields, set_cons(TimeTag, NULL));
  else
    bodyfields = datafields;
  layout_body(bodyfields, Precision, NDIM);
  times = getparam("times");
  ifmt = getparam("ifmt");
  rfmt = getparam("rfmt");
  print_header(datafields, getparam("hfmt"), getparam("keyhead"),
	       burststring(getparam("auxhead"), ", "));
  while (get_snap_t(istr, &btab, &nbody, &tnow, intags, FALSE, times)) {
    if (! set_subset(intags, bodyfields))
      error("%s: one or more required fields not found\n", getargv0());
    print_data(btab, nbody, tnow, datafields, ifmt, rfmt);
    skip_history(istr);
  }
  return (0);
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    int i, size = 100, *x;
    struct set *s, *t, *u;
    
    if (argc > 1)
	size = atoi(argv[1]);
    
    srand(time(NULL));

    s = set_create(size, sizeof(int), cmpint);
    t = set_create(size, sizeof(int), cmpint);
    if (s == NULL || t == NULL){
	printf("Unable to create the test set\n");
	return 1;
    }

    printf("Inserting into first set...\n");
    for (i = 0; i < size; i++){
	int y = rand() % size;

	printf("%d ", y);
	set_insert(s, &y);
    }
    printf("\n\n");

    printf("The set contains:\n");
    for (set_reset(s), x = set_next(s); x != NULL; x = set_next(s)) 
	printf("%d ", *x);
    printf("\n\n");

    printf("Inserting into second set...\n");
    for (i = 0; i < size; i++){
	int y = rand() % size;

	printf("%d ", y);
	set_insert(t, &y);
    }
    printf("\n\n");

    printf("The set contains:\n");
    for (set_reset(t), x = set_next(t); x != NULL; x = set_next(t)) 
	printf("%d ", *x);
    printf("\n\n");

    u = set_union(s, t);
    printf("The union of the two sets is:\n");
    for (set_reset(u), x = set_next(u); x != NULL; x = set_next(u)) 
	printf("%d ", *x);
    printf("\n\n");
    set_destroy(u);

    u = set_diff(s, t);
    printf("The difference of the two sets is:\n");
    for (set_reset(u), x = set_next(u); x != NULL; x = set_next(u)) 
	printf("%d ", *x);
    printf("\n\n");
    
    return 0;
}
Exemplo n.º 3
0
Arquivo: cofactor.c Projeto: spl/ivy
/* cofactor -- compute the cofactor of a cover with respect to a cube */
pcube *cofactor(pset *T, register pset c)
{
    pcube temp = cube.temp[0], *Tc_save, *Tc, *T1;
    register pcube p;
    int listlen;

    listlen = CUBELISTSIZE(T) + 5;

    /* Allocate a new list of cube pointers (max size is previous size) */
    Tc_save = Tc = ALLOC(pcube, listlen);

    /* pass on which variables have been cofactored against */
    *Tc++ = set_or(new_cube(), T[0], set_diff(temp, cube.fullset, c));
    Tc++;

    /* Loop for each cube in the list, determine suitability, and save */
    for(T1 = T+2; (p = *T1++) != NULL; ) {
	if (p != c) {

#ifdef NO_INLINE
	if (! cdist0(p, c)) goto false;
#else
    {register int w,last;register unsigned int x;if((last=cube.inword)!=-1)
    {x=p[last]&c[last];if(~(x|x>>1)&cube.inmask)goto false;for(w=1;w<last;w++)
    {x=p[w]&c[w];if(~(x|x>>1)&DISJOINT)goto false;}}}{register int w,var,last;
    register pcube mask;for(var=cube.num_binary_vars;var<cube.num_vars;var++){
    mask=cube.var_mask[var];last=cube.last_word[var];for(w=cube.first_word[var
    ];w<=last;w++)if(p[w]&c[w]&mask[w])goto nextvar;goto false;nextvar:;}}
#endif

	    *Tc++ = p;
	false: ;
	}
    }
Exemplo n.º 4
0
range* range_from_diff(range_request* rr,
                       const range* r1, const range* r2)
{
    range* r3 = range_new(rr);
    apr_pool_t* pool = range_request_pool(rr);
    
    r3->nodes = set_diff(pool, r1->nodes, r2->nodes);
    r3->quoted = r1->quoted || r2->quoted;
    return r3;
}
Exemplo n.º 5
0
STATIC mp_obj_t set_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
    mp_obj_t args[] = {lhs, rhs};
    switch (op) {
    case RT_BINARY_OP_OR:
        return set_union(lhs, rhs);
    case RT_BINARY_OP_XOR:
        return set_symmetric_difference(lhs, rhs);
    case RT_BINARY_OP_AND:
        return set_intersect(lhs, rhs);
    case RT_BINARY_OP_SUBTRACT:
        return set_diff(2, args);
    case RT_BINARY_OP_INPLACE_OR:
        return set_union(lhs, rhs);
    case RT_BINARY_OP_INPLACE_XOR:
        return set_symmetric_difference(lhs, rhs);
    case RT_BINARY_OP_INPLACE_AND:
        return set_intersect(lhs, rhs);
    case RT_BINARY_OP_INPLACE_SUBTRACT:
        return set_diff(2, args);
    case RT_BINARY_OP_LESS:
        return set_issubset_proper(lhs, rhs);
    case RT_BINARY_OP_MORE:
        return set_issuperset_proper(lhs, rhs);
    case RT_BINARY_OP_EQUAL:
        return set_equal(lhs, rhs);
    case RT_BINARY_OP_LESS_EQUAL:
        return set_issubset(lhs, rhs);
    case RT_BINARY_OP_MORE_EQUAL:
        return set_issuperset(lhs, rhs);
    case RT_BINARY_OP_NOT_EQUAL:
        return MP_BOOL(set_equal(lhs, rhs) == mp_const_false);
    case RT_BINARY_OP_IN:
    {
        mp_obj_set_t *o = lhs;
        mp_obj_t elem = mp_set_lookup(&o->set, rhs, MP_MAP_LOOKUP);
        return MP_BOOL(elem != NULL);
    }
    default:
        // op not supported
        return NULL;
    }
}
Exemplo n.º 6
0
Arquivo: stg1.c Projeto: acalvoa/SNAKE
void get_difficult(){
	while(1){
		int key = read_key();
		if(key == 49){
			set_diff(0);
			break;
		}
		else if(key == 50){
			set_diff(1);
			break;
		}
		else if(key == 51){
			set_diff(2);
			break;
		}
		else if(key == 52){
			set_diff(3);
			break;
		}	
	}
}
Exemplo n.º 7
0
void expand1_gasp(pset_family F, pset_family D, pset_family R, pset_family Foriginal, int c1index, pset_family *G)
{
register int c2index;
register pset p, last, c2under;
pset RAISE, FREESET, temp, *FD, c2essential;
pset_family F1;
if (debug & 0x0008) {
printf("\nEXPAND1_GASP:    \t%s\n", pc1(((F)->data + (F)->wsize * ( c1index))));
}
RAISE = set_clear(((unsigned int *) malloc(sizeof(unsigned int) * ( ((cube.size) <= 32 ? 2 : (((((cube.size)-1) >> 5) + 1) + 1))))), cube.size);
FREESET = set_clear(((unsigned int *) malloc(sizeof(unsigned int) * ( ((cube.size) <= 32 ? 2 : (((((cube.size)-1) >> 5) + 1) + 1))))), cube.size);
temp = set_clear(((unsigned int *) malloc(sizeof(unsigned int) * ( ((cube.size) <= 32 ? 2 : (((((cube.size)-1) >> 5) + 1) + 1))))), cube.size);
R->active_count = R->count;
for( p=R->data, last= p+R->count*R->wsize; p< last; p+=R->wsize) {
(p[0] |= ( 0x2000));
}
F->active_count = F->count;
for( c2under=F->data, c2index=0; c2index<F->count; c2under+=F->wsize, c2index++) {
if (c1index == c2index || (c2under[0] & ( 0x8000))) {
F->active_count--;
(c2under[0] &= ~ ( 0x2000));
} else {
(c2under[0] |= ( 0x2000));
}
}
(void) set_copy(RAISE, ((F)->data + (F)->wsize * ( c1index)));
(void) set_diff(FREESET, cube.fullset, RAISE);
essen_parts(R, F, RAISE, FREESET);
essen_raising(R, RAISE, FREESET);
for( c2under=F->data, c2index=0; c2index<F->count; c2under+=F->wsize, c2index++) {
if ((c2under[0] & ( 0x2000))) {
if (setp_implies(c2under, RAISE) ||
feasibly_covered(R, c2under, RAISE, temp)) {
F1 = sf_save(Foriginal);
(void) set_copy(((F1)->data + (F1)->wsize * ( c1index)), ((F)->data + (F)->wsize * ( c1index)));
FD = cube2list(F1, D);
c2essential = reduce_cube(FD, ((F1)->data + (F1)->wsize * ( c2index)));
((FD[0]) ? (free((char *) (FD[0])), (FD[0]) = 0) : 0); ((FD) ? (free((char *) (FD)), (FD) = 0) : 0);;
sf_free(F1);
if (feasibly_covered(R, c2essential, RAISE, temp)) {
(void) set_or(temp, RAISE, c2essential);
(temp[0] &= ~ ( 0x8000));	*G = sf_addset(*G, temp);
}
((c2essential) ? (free((char *) (c2essential)), (c2essential) = 0) : 0);
}
}
}
((RAISE) ? (free((char *) (RAISE)), (RAISE) = 0) : 0);
((FREESET) ? (free((char *) (FREESET)), (FREESET) = 0) : 0);
((temp) ? (free((char *) (temp)), (temp) = 0) : 0);
}
Exemplo n.º 8
0
/* else return FALSE.                                 */
bool
Is_Any_Connect(pcover WSS, pcover P)
{
	register int i, ind;
	register pset q, x=new_cube(), r=new_cube();
	int pos_p;
	
	foreachi_set(P, i, q){
		ind = Get_Var_Ind(q, 0);
		set_copy(x, GETSET(WSS, ind));
		set_diff(r, x, q);
		if (!setp_empty(r))
			return TRUE;
	}
Exemplo n.º 9
0
static bool
primes_consensus_special_cases(pset *T, pset_family *Tnew)
  /* will be disposed if answer is determined */
  /* returned only if answer determined */
{
  register pcube *T1, p, ceil, cof=T[0];
  pcube last;
  pcover A;

  /* Check for no cubes in the cover */
  if (T[2] == NULL) {
    *Tnew = new_cover(0);
    free_cubelist(T);
    return TRUE;
  }

  /* Check for only a single cube in the cover */
  if (T[3] == NULL) {
    *Tnew = sf_addset(new_cover(1), set_or(cof, cof, T[2]));
    free_cubelist(T);
    return TRUE;
  }

  /* Check for a row of all 1's (implies function is a tautology) */
  for(T1 = T+2; (p = *T1++) != NULL; ) {
    if (full_row(p, cof)) {
      *Tnew = sf_addset(new_cover(1), cube.fullset);
      free_cubelist(T);
      return TRUE;
    }
  }

  /* Check for a column of all 0's which can be factored out */
  ceil = set_save(cof);
  for(T1 = T+2; (p = *T1++) != NULL; ) {
    INLINEset_or(ceil, ceil, p);
  }
  if (! setp_equal(ceil, cube.fullset)) {
    p = new_cube();
    (void) set_diff(p, cube.fullset, ceil);
    (void) set_or(cof, cof, p);
    free_cube(p);

    A = primes_consensus(T);
    foreach_set(A, last, p) {
      INLINEset_and(p, p, ceil);
    }
Exemplo n.º 10
0
void checktags(string *otags, string *produce)
{
  string *missing, *mp;
  char buf[512];

  missing = set_diff(produce, otags);
  if (set_length(missing) > 0) {
    buf[0] = (char) NULL;
    for (mp = missing; *mp != NULL; mp++) {
      if (mp != missing)
	strcat(buf, ",");
      strcat(buf, *mp);
    }
    error("%s: missing %s data\n", getargv0(), buf);
  }
  free(missing);
}
Exemplo n.º 11
0
SEXP checkVars(SEXP DT, SEXP id, SEXP measure, Rboolean verbose) {
    int i, ncol=LENGTH(DT), targetcols=0, protecti=0, u=0, v=0;
    SEXP thiscol, idcols = R_NilValue, valuecols = R_NilValue, tmp, booltmp, unqtmp, ans;
    SEXP dtnames = getAttrib(DT, R_NamesSymbol);
    
    if (isNull(id) && isNull(measure)) {
        for (i=0; i<ncol; i++) {
            thiscol = VECTOR_ELT(DT, i);
            if ((isInteger(thiscol) || isNumeric(thiscol) || isLogical(thiscol)) && !isFactor(thiscol)) targetcols++;
        }
        PROTECT(idcols = allocVector(INTSXP, ncol-targetcols)); protecti++;
        PROTECT(valuecols = allocVector(INTSXP, targetcols)); protecti++;
        for (i=0; i<ncol; i++) {
            thiscol = VECTOR_ELT(DT, i);
            if ((isInteger(thiscol) || isNumeric(thiscol) || isLogical(thiscol)) && !isFactor(thiscol)) {
                INTEGER(valuecols)[u++] = i+1;
            } else
                INTEGER(idcols)[v++] = i+1;
        }
        warning("To be consistent with reshape2's melt, id.vars and measure.vars are internally guessed when both are 'NULL'. All non-numeric/integer/logical type columns are conisdered id.vars, which in this case are columns '%s'. Consider providing at least one of 'id' or 'measure' vars in future.", CHAR(STRING_ELT(concat(dtnames, idcols), 0)));
    } else if (!isNull(id) && isNull(measure)) {
        switch(TYPEOF(id)) {
            case STRSXP  : PROTECT(tmp = chmatch(id, dtnames, 0, FALSE)); protecti++; break;
            case REALSXP : PROTECT(tmp = coerceVector(id, INTSXP)); protecti++; break;
            case INTSXP  : PROTECT(tmp = id); protecti++; break;
            default : error("Unknown 'id.var' type %s, must be character or integer vector", type2char(TYPEOF(id)));
        }
        PROTECT(booltmp = duplicated(tmp, FALSE)); protecti++;
        for (i=0; i<length(tmp); i++) {
            if (INTEGER(tmp)[i] <= 0) error("Column '%s' not found in 'data'", CHAR(STRING_ELT(id, i)));
            else if (INTEGER(tmp)[i] > ncol) error("id.var value exceeds ncol(data)");
            else if (!LOGICAL(booltmp)[i]) targetcols++;
            else continue;
        }
        PROTECT(unqtmp = allocVector(INTSXP, targetcols)); protecti++;
        u = 0;
        for (i=0; i<length(booltmp); i++) {
            if (!LOGICAL(booltmp)[i]) {
                INTEGER(unqtmp)[u++] = INTEGER(tmp)[i];
            }
        }
        PROTECT(valuecols = set_diff(unqtmp, ncol)); protecti++;
        PROTECT(idcols = tmp); protecti++;
        if (verbose) Rprintf("'measure.var' is missing. Assigning all columns other than 'id.var' columns which are %s as 'measure.var'.\n", CHAR(STRING_ELT(concat(dtnames, idcols), 0)));
    } else if (isNull(id) && !isNull(measure)) {
        switch(TYPEOF(measure)) {
            case STRSXP  : PROTECT(tmp = chmatch(measure, dtnames, 0, FALSE)); protecti++; break;
            case REALSXP : PROTECT(tmp = coerceVector(measure, INTSXP)); protecti++; break;
            case INTSXP  : PROTECT(tmp = measure); protecti++; break;
            default : error("Unknown 'measure.var' type %s, must be character or integer vector", type2char(TYPEOF(measure)));
        }
        PROTECT(booltmp = duplicated(tmp, FALSE)); protecti++;
        for (i=0; i<length(tmp); i++) {
            if (INTEGER(tmp)[i] <= 0) error("Column '%s' not found in 'data'", CHAR(STRING_ELT(id, i)));
            else if (INTEGER(tmp)[i] > ncol) error("measure.var value exceeds ncol(data)");
            else if (!LOGICAL(booltmp)[i]) targetcols++;
            else continue;
        }
        PROTECT(unqtmp = allocVector(INTSXP, targetcols)); protecti++;
        u = 0;
        for (i=0; i<length(booltmp); i++) {
            if (!LOGICAL(booltmp)[i]) {
                INTEGER(unqtmp)[u++] = INTEGER(tmp)[i];
            }
        }
        PROTECT(idcols = set_diff(unqtmp, ncol)); protecti++;
        PROTECT(valuecols = tmp); protecti++;
        if (verbose) Rprintf("'id.var' is missing. Assigning all columns other than 'measure.var' columns as 'id.var'. Assigned 'id.var's are %s.\n", CHAR(STRING_ELT(concat(dtnames, idcols), 0)));
    } else if (!isNull(id) && !isNull(measure)) {
        switch(TYPEOF(id)) {
            case STRSXP  : PROTECT(tmp = chmatch(id, dtnames, 0, FALSE)); protecti++; break;
            case REALSXP : PROTECT(tmp = coerceVector(id, INTSXP)); protecti++; break;
            case INTSXP  : PROTECT(tmp = id); protecti++; break;
            default : error("Unknown 'id.var' type %s, must be character or integer vector", type2char(TYPEOF(id)));
        }
        for (i=0; i<length(tmp); i++) {
            if (INTEGER(tmp)[i] <= 0) error("Column '%s' or not found in 'data'", CHAR(STRING_ELT(id, i)));
            else if (INTEGER(tmp)[i] > ncol) error("measure.var value exceeds ncol(data)");
        }
        PROTECT(idcols = allocVector(INTSXP, length(tmp))); protecti++;
        idcols = tmp;
        switch(TYPEOF(measure)) {
            case STRSXP  : PROTECT(tmp = chmatch(measure, dtnames, 0, FALSE)); protecti++; break;
            case REALSXP : PROTECT(tmp = coerceVector(measure, INTSXP)); protecti++; break;
            case INTSXP  : PROTECT(tmp = measure); protecti++; break;
            default : error("Unknown 'measure.var' type %s, must be character or integer vector", type2char(TYPEOF(measure)));
        }
        for (i=0; i<length(tmp); i++) {
            if (INTEGER(tmp)[i] <= 0) error("Column '%s' not found in 'data'", CHAR(STRING_ELT(id, i)));
            else if (INTEGER(tmp)[i] > ncol) error("measure.var value exceeds ncol(data)");
        }
        PROTECT(valuecols = allocVector(INTSXP, length(measure))); protecti++;
        valuecols = tmp;
    }

    PROTECT(ans = allocVector(VECSXP, 2)); protecti++;
    SET_VECTOR_ELT(ans, 0, idcols);
    SET_VECTOR_ELT(ans, 1, valuecols);
    UNPROTECT(protecti);
    return(ans);
}
Exemplo n.º 12
0
#include "dryad_treap.h"

_(logic \bool mutable_treap(BNode * x) = x != NULL ==> \mutable(x) && \writable(x))
_(dryad)
BNode * treap_remove_root_rec(BNode * x)
  _(requires x != NULL)
  _(requires treap(x))
  _(requires \intset_lt(treap_keys(x->left), treap_keys(x->right)))
  _(requires \intset_disjoint(treap_prios(x->left), treap_prios(x->right)))
  _(requires \intset_disjoint(treap_keys(x->left), treap_keys(x->right)))
  _(ensures treap(\result))
  _(ensures \intset_subset(treap_prios(\result), \old(treap_prios(x))))
  _(ensures treap_reach(\result) == \oset_diff(\old(treap_reach(x)), \oset_singleton(x)))
  _(ensures treap_keys(\result) == \intset_diff(\old(treap_keys(x)), \intset_singleton(x->key)))
  _(ensures treap_keys(\result) == \intset_union(\old(treap_keys(x->left)), \old(treap_keys(x->right))))  
  _(ensures treap_prios(\result) == \intset_union(\old(treap_prios(x->left)), \old(treap_prios(x->right))))  
{
  _(assume mutable_treap(x))
  _(assume \malloc_root(x))

  if(x->left == NULL && x->right == NULL) {
    free(x);
    return NULL;
  } else if (x->left == NULL) {
    BNode * right = x->right;
    free(x);
    return right;
  } else if (x->right == NULL) {
    BNode * left = x->left;
    free(x);
    return left;
Exemplo n.º 13
0
int main(void)
{
     char player1 = CROSS;
     char player2 = NOUGHT;

     char winner;
     char currnt_player = player1;
     char board[NUM_ALL];
     char *br;
     bool ended = false;
     int nrounds = 0;
     int mode;

     int wplayer1 = 0;
     int wplayer2 = 0;
     int nreplays = 0;
     int nstalemates = 0;


     mode = select_mode();
     if (mode == 1) {
        max_depth = set_diff();
     }
     while (!ended) {

        if (nrounds == 0) {
           for (int i = 0; i < NUM_ALL; ++i) {
              board[i] = ' ';
            }
            br = &board[0];
            simulate(br);
        }
        if (mode == 1) {
           if (currnt_player == player1) {
              human_turn(br, currnt_player, &nrounds);
           } else {
              computer_turn(br, player1, currnt_player, &nrounds);
           }
        } else {
           if (currnt_player == player1) {
              human_turn(br, currnt_player, &nrounds);
           } else {
              human_turn(br, currnt_player, &nrounds);
           }
        }

        currnt_player = player_next(currnt_player, player1, player2);
        simulate(br);
        winner = game_winner(br, player1, player2);
        ended = game_ended(winner, nrounds);

        if (ended) {
           ++nreplays;
           if (winner == player1) {
              ++wplayer1;
           } else if (winner == player2) {
              ++wplayer2;
           } else {
              ++nstalemates;
           }
           rover_stats(winner, player1, player2, wplayer1,
                       wplayer2, nreplays, nstalemates, mode);
           if (restart()) {
              if (winner == CROSS) {
                 if (player1 == CROSS) {
                    currnt_player = player1;
                 } else {
                    currnt_player = player2;
                 }
              } else if (winner == NOUGHT) {
                 if (player1 == NOUGHT) {
                    player1 = CROSS;
                    player2 = NOUGHT;
                    currnt_player = player1;
                 } else {
                    player1 = NOUGHT;
                    player2 = CROSS;
                    currnt_player = player2;
                 }
              } else {
                 if (player1 == CROSS) {
                    currnt_player = player1;
                 } else {
                    currnt_player = player2;
                 }
              }
              nround_announce(winner, player1, player2, currnt_player);
              nrounds = 0;
              winner = NO_MATCH;
              ended = false;
           } else {
              gover_stats(wplayer1, wplayer2, nreplays, nstalemates, mode);
           }
        }
     }
     return 0;
}
Exemplo n.º 14
0
Arquivo: compl.c Projeto: GtTmy/pyeda
static bool
compl_special_cases(set **T, set_family_t **Tbar)
{
    set **T1, *p, *ceil, *cof=T[0];
    set_family_t *A, *ceil_compl;

    // Check for no cubes in the cover
    if (T[2] == NULL) {
        *Tbar = sf_addset(sf_new(1, CUBE.size), CUBE.fullset);
        free_cubelist(T);
        return TRUE;
    }

    // Check for only a single cube in the cover
    if (T[3] == NULL) {
        *Tbar = compl_cube(set_or(cof, cof, T[2]));
        free_cubelist(T);
        return TRUE;
    }

    // Check for a row of all 1's (implies complement is null)
    for (T1 = T+2; (p = *T1++) != NULL; ) {
        if (full_row(p, cof)) {
            *Tbar = sf_new(0, CUBE.size);
            free_cubelist(T);
            return TRUE;
        }
    }

    // Check for a column of all 0's which can be factored out
    ceil = set_save(cof);
    for (T1 = T+2; (p = *T1++) != NULL; ) {
        set_or(ceil, ceil, p);
    }
    if (! setp_equal(ceil, CUBE.fullset)) {
        ceil_compl = compl_cube(ceil);
        set_or(cof, cof, set_diff(ceil, CUBE.fullset, ceil));
        set_free(ceil);
        *Tbar = sf_append(complement(T), ceil_compl);
        return TRUE;
    }
    set_free(ceil);

    // Collect column counts, determine unate variables, etc.
    massive_count(T);

    // If single active variable not factored out above, then tautology!
    if (CDATA.vars_active == 1) {
        *Tbar = sf_new(0, CUBE.size);
        free_cubelist(T);
        return TRUE;

    // Check for unate cover
    } else if (CDATA.vars_unate == CDATA.vars_active) {
        A = map_cover_to_unate(T);
        free_cubelist(T);
        A = unate_compl(A);
        *Tbar = map_unate_to_cover(A);
        sf_free(A);
        return TRUE;

    // Not much we can do about it
    } else {
        return MAYBE;
    }
}
Exemplo n.º 15
0
		std::list<int> notExplored(int size) {
			std::list<int> range(size);
			std::iota(range.begin(), range.end(), 0);

			return set_diff(range, _shortTermMemory);
		}
Exemplo n.º 16
0
	void viewer_rt::load_xyz (boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> > cloud,int window, bool diff_in){
		
		//Check if the cloud is empty
		if (cloud->empty ())
			return;
		
		
		
		if (window > 4) window=4; 
		if (diff_in) set_diff ();

		//Fork the program
		pid = fork();
		vector_pid.push_back(pid);
		name_process.push_back("LOAD_XYZ");
	   
		if (pid == -1)
			std::cout << "[VIEWER_RT] ERROR MAKING FORK" << std::endl;
		
    
    
		//Child process
		else if (pid == 0) {
			
			if (vector_pid.size () >1)
				waitpid(vector_pid[vector_pid.size ()-1],&status,0);
			
			
			
			//Set pipe message
			int request=LOAD_XYZ_CLOUD+window;
			
			
			
	
			//Objects
			pcl::PCDWriter writer;



	
			//Request resources
			operation.sem_num = WRITE_PCD;
			operation.sem_op = -1;
			semop(semid,&operation,1);
			
			
			
			
			//Solicitation issued
			write(pipe_flags[1], &request, 1);
			writer.write<pcl::PointXYZ> ("temp.pcd", *cloud, false);
	
			
			
			
			//Request for the resorces of viewer
			operation.sem_num = 5;
			operation.sem_op = 1;
			semop(semid,&operation,1);




			//Wait for the load	
			operation.sem_num = REQUEST_LOAD_CLOUD;
			operation.sem_op = -1;
			semop(semid,&operation,1);
			
			
			
			
			//Freeing resources
			operation.sem_num = WRITE_PCD;
			operation.sem_op = 1;
			semop(semid,&operation,1);
	
	
	
	
			//End execution
			exit(EXIT_SUCCESS);
		}

		return;
		
	}
Exemplo n.º 17
0
static bool compl_special_cases(pset *T, pset_family *Tbar)
  /* will be disposed if answer is determined */
  /* returned only if answer determined */
{
  register pcube *T1, p, ceil, cof=T[0];
  pcover A, ceil_compl;

  /* Check for no cubes in the cover */
  if (T[2] == NULL) {
    *Tbar = sf_addset(new_cover(1), cube.fullset);
    free_cubelist(T);
    return TRUE;
  }

  /* Check for only a single cube in the cover */
  if (T[3] == NULL) {
    *Tbar = compl_cube(set_or(cof, cof, T[2]));
    free_cubelist(T);
    return TRUE;
  }

  /* Check for a row of all 1's (implies complement is null) */
  for(T1 = T+2; (p = *T1++) != NULL; ) {
    if (full_row(p, cof)) {
      *Tbar = new_cover(0);
      free_cubelist(T);
      return TRUE;
    }
  }

  /* Check for a column of all 0's which can be factored out */
  ceil = set_save(cof);
  for(T1 = T+2; (p = *T1++) != NULL; ) {
    INLINEset_or(ceil, ceil, p);
  }
  if (! setp_equal(ceil, cube.fullset)) {
    ceil_compl = compl_cube(ceil);
    (void) set_or(cof, cof, set_diff(ceil, cube.fullset, ceil));
    set_free(ceil);
    *Tbar = sf_append(complement(T), ceil_compl);
    return TRUE;
  }
  set_free(ceil);

  /* Collect column counts, determine unate variables, etc. */
  massive_count(T);

  /* If single active variable not factored out above, then tautology ! */
  if (cdata.vars_active == 1) {
    *Tbar = new_cover(0);
    free_cubelist(T);
    return TRUE;

    /* Check for unate cover */
  } else if (cdata.vars_unate == cdata.vars_active) {
    A = map_cover_to_unate(T);
    free_cubelist(T);
    A = unate_compl(A);
    *Tbar = map_unate_to_cover(A);
    sf_free(A);
    return TRUE;

    /* Not much we can do about it */
  } else {
    return MAYBE;
  }
}
Exemplo n.º 18
0
 pointer operator->() const {
     set_diff();
     return &m_diff;
 }
Exemplo n.º 19
0
STATIC mp_obj_t set_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
    mp_obj_t args[] = {lhs, rhs};
    #if MICROPY_PY_BUILTINS_FROZENSET
    bool update = MP_OBJ_IS_TYPE(lhs, &mp_type_set);
    #else
    bool update = true;
    #endif
    if (op != MP_BINARY_OP_CONTAINS && !is_set_or_frozenset(rhs)) {
        // For all ops except containment the RHS must be a set/frozenset
        return MP_OBJ_NULL;
    }
    switch (op) {
        case MP_BINARY_OP_OR:
            return set_union(lhs, rhs);
        case MP_BINARY_OP_XOR:
            return set_symmetric_difference(lhs, rhs);
        case MP_BINARY_OP_AND:
            return set_intersect(lhs, rhs);
        case MP_BINARY_OP_SUBTRACT:
            return set_diff(2, args);
        case MP_BINARY_OP_INPLACE_OR:
            if (update) {
                set_update(2, args);
                return lhs;
            } else {
                return set_union(lhs, rhs);
            }
        case MP_BINARY_OP_INPLACE_XOR:
            if (update) {
                set_symmetric_difference_update(lhs, rhs);
                return lhs;
            } else {
                return set_symmetric_difference(lhs, rhs);
            }
        case MP_BINARY_OP_INPLACE_AND:
            rhs = set_intersect_int(lhs, rhs, update);
            if (update) {
                return lhs;
            } else {
                return rhs;
            }
        case MP_BINARY_OP_INPLACE_SUBTRACT:
            return set_diff_int(2, args, update);
        case MP_BINARY_OP_LESS:
            return set_issubset_proper(lhs, rhs);
        case MP_BINARY_OP_MORE:
            return set_issuperset_proper(lhs, rhs);
        case MP_BINARY_OP_EQUAL:
            return set_equal(lhs, rhs);
        case MP_BINARY_OP_LESS_EQUAL:
            return set_issubset(lhs, rhs);
        case MP_BINARY_OP_MORE_EQUAL:
            return set_issuperset(lhs, rhs);
        case MP_BINARY_OP_CONTAINS: {
            mp_obj_set_t *o = MP_OBJ_TO_PTR(lhs);
            mp_obj_t elem = mp_set_lookup(&o->set, rhs, MP_MAP_LOOKUP);
            return mp_obj_new_bool(elem != MP_OBJ_NULL);
        }
        default:
            return MP_OBJ_NULL; // op not supported
    }
}
Exemplo n.º 20
0
void test_set(void)
{
  int i;
  void* S = set_create(100, NULL, NULL);
  fprintf(stdout, "call function : %s\n", __func__);
  set_object(S);

  fprintf(stdout, "\ntest function - set_insert ===>\n");
  {
    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      double* d = (double*)malloc(sizeof(double));
      *d = (i + 1) * rand() % 1000 * 0.456;
      fprintf(stdout, "\tinsert {object=>0x%p, vlaue=>%.3f}\n", d, *d);
      set_insert(S, d);
    }
    set_object(S);

    set_for_each(S, set_member_show_double, NULL);
    set_for_each(S, set_member_destroy, NULL);
    set_object(S);
    set_clear(S);
  }
  set_object(S);

  fprintf(stdout, "\ntest function - set_remove ===>\n");
  {
    double* remove_member = NULL;
    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      double* d = (double*)malloc(sizeof(double));
      *d = (i + 1) * rand() % 1000 * 0.456;
      fprintf(stdout, "\tinsert {object=>0x%p, vlaue=>%.3f}\n", d, *d);
      set_insert(S, d);

      if (0 == i)
        remove_member = d;
    }
    set_object(S);
    set_for_each(S, set_member_show_double, NULL);

    set_remove(S, remove_member);
    set_object(S);
    set_for_each(S, set_member_show_double, NULL);

    set_for_each(S, set_member_destroy, NULL);
    set_object(S);
    set_clear(S);
  }
  set_object(S);

  fprintf(stdout, "\ntest function - set_release ===>\n");
  set_release(&S);
  set_object(S);


  fprintf(stdout, "\n\ntest function - set operations ===>\n");
  {
    void* s = set_create(100, NULL, NULL);
    void* t = set_create(100, NULL, NULL);
    void* oper_s;

    for (i = 0; i < 7; ++i)
    {
      double* d = (double*)malloc(sizeof(double));
      *d = (i + 1) * (i + 1) * 0.234;
      fprintf(stdout, "\tinsert s {object=>0x%p, value=>%.3f}\n", d, *d);
      if (i < 5)
        set_insert(s, d);
      set_insert(t, d);        
    }

    fprintf(stdout, "  show 's' set object:\n");
    set_object(s);
    set_for_each(s, set_member_show_double, NULL);
    fprintf(stdout, "  show 't' set object:\n");
    set_object(t);
    set_for_each(t, set_member_show_double, NULL);

    /* set_union */
    fprintf(stdout, "  test function - set_union ===>\n");
    oper_s = set_union(NULL, t);
    fprintf(stdout, "    s = NULL, t = t:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release union(s=NULL,t=t):\n");
    set_object(oper_s);
    /* *** */
    oper_s = set_union(s, NULL);
    fprintf(stdout, "    s = s, t = NULL:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release union(s=s,t=NULL):\n");
    set_object(oper_s);
    /* *** */
    oper_s = set_union(s, t);
    fprintf(stdout, "    s = s, t = t:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release union(s=s,t=t):\n");
    set_object(oper_s);

    /* set_inter */
    fprintf(stdout, "  test function - set_inter ===>\n");
    oper_s = set_inter(NULL, t);
    fprintf(stdout, "    s = NULL, t = t:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release inter(s=NULL,t=t):\n");
    set_object(oper_s);
    /* *** */
    oper_s = set_inter(s, NULL);
    fprintf(stdout, "    s = s, t = NULL:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release inter(s=s,t=NULL):\n");
    set_object(oper_s);
    /* *** */
    oper_s = set_inter(s, t);
    fprintf(stdout, "    s = s, t = t:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release inter(s=s,t=t):\n");
    set_object(oper_s);

    /* set_minus */
    fprintf(stdout, "  test function - set_minus ===>\n");
    oper_s = set_minus(NULL, t);
    fprintf(stdout, "    s = NULL, t = t:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release minus(s=NULL,t=t):\n");
    set_object(oper_s);
    /* *** */
    oper_s = set_minus(s, NULL);
    fprintf(stdout, "    s = s, t = NULL:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release minus(s=s,t=NULL):\n");
    set_object(oper_s);
    /* *** */
    oper_s = set_minus(s, t);
    fprintf(stdout, "    s = s, t = t:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release minus(s=s,t=t):\n");
    set_object(oper_s);

    /* set_diff */
    fprintf(stdout, "  test function - set_diff ===>\n");
    oper_s = set_diff(NULL, t);
    fprintf(stdout, "    s = NULL, t = t:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release diff(s=NULL,t=t):\n");
    set_object(oper_s);
    /* *** */
    oper_s = set_diff(s, NULL);
    fprintf(stdout, "    s = s, t = NULL:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release diff(s=s,t=NULL):\n");
    set_object(oper_s);
    /* *** */
    oper_s = set_diff(s, t);
    fprintf(stdout, "    s = s, t = t:\n");
    set_object(oper_s);
    set_for_each(oper_s, set_member_show_double, NULL);
    set_clear(oper_s);
    set_release(&oper_s);
    fprintf(stdout, "    after release diff(s=s,t=t):\n");
    set_object(oper_s);


    fprintf(stdout, "  release 's' and 't' object:\n");
    set_for_each(t, set_member_destroy, NULL);
    set_clear(s);
    set_clear(t);
    set_release(&s);
    set_release(&t);
    fprintf(stdout, "  show 's' set object:\n");
    set_object(s);
    fprintf(stdout, "  show 't' set object:\n");
    set_object(t);
  }
}
Exemplo n.º 21
0
void test(string args)
{
    args = splitArg(args, 1);
    if(streql(args, "") || streql(args, "-H"))
    {
        print("\nThis file is in charge of testing the data types embedded in Q-OS.",black);
        print("\nAccepted Arguments:\n-list\tTests the list.c file\n-set \ttests the set.c file", black);
        print("\n-strb\ttests the strbuilder.c file\n-y   \tshould return the current year...",black);
    }
    else if(streql(args, "-LIST"))//For testing lists
    {
        newline();
        list_t test_list = list_init();
        test_list.autoShrink = true;

        for(uint8 i = 0; i < 4; i++)
        {
            list_add(&test_list, "1");
            list_add(&test_list, "2");
            list_add(&test_list, "3");
            list_add(&test_list, "4");
            list_add(&test_list, "5");
            list_add(&test_list, "6");
            list_add(&test_list, "7");
            list_add(&test_list, "8");
            list_add(&test_list, "9");
            list_add(&test_list, "10");
            list_add(&test_list, "11");
            list_add(&test_list, "12");
            list_add(&test_list, "13");
            list_add(&test_list, "14");
            list_add(&test_list, "15");
            list_add(&test_list, "16");
        }
        list_add(&test_list, "Pointless");

        println("Done sizing up", white);
        printint(test_list.capt, white);

        element_t t;
        for(uint8 i = 0; i < 64; i++)
        {
            t = list_shift(&test_list);
        }
        println("\nLast item deleted should be \"16\"", white);
        println(t.udata.strdata, white);
        println("\nDeleting all but element \"Pointless\"", white);
        for(uint8 i = 0; i < test_list.size; i++)
        {
            println(list_get(test_list, i), white);
        }
        println("Done resizing up", white);
        printint(test_list.capt, white);
        list_destroy(&test_list);
    }
    else if(streql(args,"-SET"))
    {
        set_t test_set = set_init();
        for(uint8 i = 0; i < 4; i++)
        {
            set_add(&test_set, "0");
            set_add(&test_set, "1");
            set_add(&test_set, "2");
            set_add(&test_set, "3");
            set_add(&test_set, "4");
            set_add(&test_set, "5");
            set_add(&test_set, "6");
            set_add(&test_set, "7");
            set_add(&test_set, "8");
            set_add(&test_set, "9");
            set_add(&test_set, "10");
            set_add(&test_set, "11");
            set_add(&test_set, "12");
            set_add(&test_set, "13");
            set_add(&test_set, "14");
            set_add(&test_set, "15");
            set_add(&test_set, "16");
            print("\nIteration: ", white);
            printint(i, white);
        }
        println("\n\nInsertion::Output should be 17", white);
        printint(test_set.size, white);

        set_t tmp = set_init();
        set_add(&tmp, "Union item");
        set_union(&test_set, &tmp);
        println("\n\nUnion::Output should be 18", white);
        printint(test_set.size, white);

        set_intersect(&test_set, &tmp);
        println("\n\nIntersect::Output should be 1", white);
        printint(test_set.size, white);

        println("\n\nPreparing for diff test", white);
        set_add(&test_set, "1");
        set_add(&test_set, "2");
        set_add(&test_set, "3");
        set_add(&tmp, "2");
        set_add(&tmp, "3");
        set_add(&tmp, "4");
        set_diff(&test_set, &tmp);
        println("Diff::Output should be 2", white);
        printint(test_set.size, white);

        set_destroy(&tmp);
        set_destroy(&test_set);
    }
    else if(streql(args, "-STRB"))
    {
        static const string bak = "Hello, world ";
        static const uint32 bln = 13;
        strbuilder_t test_strb = strbuilder_init();

        strbuilder_append(&test_strb, bak);
        strbuilder_append(&test_strb, "Hello, 2nd world");
        println("\nTesting backup text. Output should 1", red);
        printint(streql(bak, test_strb.prevTxt), green);
        println("\nOutput should be \"Hello, world Hello, 2nd world\"", red);
        println(strbuilder_tostr(test_strb), green);
        println("\nRemoving greeters from first world", red);
        strbuilder_delete(&test_strb, 0, bln);
        println("\nOutput should be \"Hello, 2nd world\"", red);
        println(strbuilder_tostr(test_strb), green);
        strbuilder_flip(&test_strb);
        println("\nOutput should be \"dlrow dn2 ,olleH\"", red);
        println(strbuilder_tostr(test_strb), green);
        list_t tmp = strbuilder_split(test_strb, " ");
        println("\nOutput should be last str split by spaces", red);
        for(uint8 i = 0; i < tmp.size; i++)
        {
            println(list_get(tmp, i), white);
        }
        list_destroy(&tmp);
        strbuilder_destroy(&test_strb);
    }
    else if(streql(args,"-Y"))
    {
       //getTime() test
       printint(getTime("year"),white);
    }
}
Exemplo n.º 22
0
void setCover(Universe *Uni,int num_houses) {



	Heap *Q = createHeap();

	set_t *covered = create_set(num_houses);
	

	for(int i=0;i<Uni->size_of_universe;i++) {
		insert_in_heap(Q,i,Uni->sets[i].covered_items,max_func);
	}

	
 
	while(covered->covered_items < num_houses) {

		
		if(isEmpty(Q)) {
			break;
		}

		HeapItem max = removeTop(Q,max_func);
		

		
		//updating the covered set
		for(int i=0;i<Uni->sets[max.dataIndex].covered_items;i++) {

			//if its not covered 
			if(!covered->set[Uni->sets[max.dataIndex].set[i]]) {
					//set to the house being covered 
					covered->set[Uni->sets[max.dataIndex].set[i]] = 1;
					//increment number of covered houses
					covered->covered_items++;
			}
		}
	
		//flag the current set to be covered 
		Uni->sets[max.dataIndex].covered = 1;
				
 		//update the other sets
		for(int i=0;i<Uni->size_of_universe;i++) {

				//if they are not already covered
				if(!Uni->sets[i].covered) {

					//find set diff and update the heap
					int diff = set_diff(&Uni->sets[i],covered);
					changeKey(Q,i,diff,max_func);
				}
				
		}
		
	}

	if(covered->covered_items < num_houses) {
		fprintf(stderr, "Not enough houses to cover all houses.\n");
		exit(EXIT_FAILURE);
	}
	
	for(int i=0; i<Uni->size_of_universe;i++) {
		if(Uni->sets[i].covered) {
			printf("%d\n",i);
		}
	}


	destroyHeap(Q);
	free_set(covered);
	free_Universe(Uni);


}
Exemplo n.º 23
0
 reference operator*() const {
     set_diff();
     return m_diff;
 }