void AbstractGame::paintAllPositions(CDC &dc, PositionSet markedPositions) { CPen *oldPen = dc.SelectObject(&m_positionPen); const size_t n = m_brickPositions.size(); CBrush *oldBrush = dc.SelectObject(&m_occupiedBrush); setTextColor(dc, false); for(UINT pos = 0; pos < n; pos++) { if(isOccupied(pos) && !SET_CONTAINS(markedPositions, pos)) { paintPosition(dc, pos); } } dc.SelectObject(&m_emptyBrush); for(UINT pos = 0; pos < n; pos++) { if(!isOccupied(pos)) { paintPosition(dc, pos); } } if(!SET_ISEMPTY(markedPositions)) { dc.SelectObject(&m_markedBrush); setTextColor(dc, true); for(UINT pos = 0; pos < n; pos++) { if(SET_CONTAINS(markedPositions, pos)) { paintPosition(dc, pos); } } } dc.SelectObject(oldBrush); dc.SelectObject(oldPen); }
int sage_all_clique_max(graph_t *g,int **list){ sage_reset_global_variables(); quiet++; maximal=TRUE; int i,j,l; clique_options *opts = sage_init_clique_opt(); clique_unweighted_find_all(g,/*min_weight*/0,/*max_weight*/0, maximal,opts); free(opts); int size=set_size(sage_clique_list[0]); *list=malloc(sizeof(int)*(size+1)*sage_clique_count); l=0; for (j=0; j<sage_clique_count; j++) { for (i=0; i<SET_MAX_SIZE(sage_clique_list[j]); i++) { if (SET_CONTAINS(sage_clique_list[j],i)) { *((*list)+l)=i; l++; } } set_free(sage_clique_list[j]); *((*list)+l)=-1; l++; } return (1+size)*sage_clique_count; }
void AbstractGame::paintPositions(CDC &dc, PositionSet positions, bool marked) { const size_t n = m_brickPositions.size(); for(UINT pos = 0; pos < n; pos++) { if(SET_CONTAINS(positions, pos)) { paintPosition(dc, pos, marked); } } }
static void rtps_acknack_dump (AckNackSMsg *ap, unsigned flags) { unsigned i; log_printf (RTPS_ID, 0, "%u.%u", ap->reader_sn_state.base.high, ap->reader_sn_state.base.low); if (ap->reader_sn_state.numbits) { log_printf (RTPS_ID, 0, "/%u:", ap->reader_sn_state.numbits); for (i = 0; i < ap->reader_sn_state.numbits; i++) if (SET_CONTAINS (ap->reader_sn_state.bitmap, i)) log_printf (RTPS_ID, 0, " .%u", i + ap->reader_sn_state.base.low); } log_printf (RTPS_ID, 0, ") %c\r\n", (flags & SMF_FINAL) ? 'F' : '-'); }
static void rtps_nack_frag_dump (NackFragSMsg *np) { unsigned i; log_printf (RTPS_ID, 0, "%u.%u %u", np->writer_sn.high, np->writer_sn.low, np->frag_nr_state.base); if (np->frag_nr_state.numbits) { log_printf (RTPS_ID, 0, "/%u:", np->frag_nr_state.numbits); for (i = 0; i < np->frag_nr_state.numbits; i++) if (SET_CONTAINS (np->frag_nr_state.bitmap, i)) log_printf (RTPS_ID, 0, " %u", i + np->frag_nr_state.base); } log_printf (RTPS_ID, 0, ")\r\n"); }
static void rtps_gap_dump (GapSMsg *gp, unsigned flags) { SequenceNumber_t snr; unsigned i; log_printf (RTPS_ID, 0, "%u.%u", gp->gap_start.high, gp->gap_start.low); snr = gp->gap_list.base; SEQNR_DEC (snr); if (SEQNR_GT (snr, gp->gap_start)) log_printf (RTPS_ID, 0, "..%u.%u", snr.high, snr.low); if (gp->gap_list.numbits) log_printf (RTPS_ID, 0, "/%u:", gp->gap_list.numbits); for (i = 0; i < gp->gap_list.numbits; i++) if (SET_CONTAINS (gp->gap_list.bitmap, i)) log_printf (RTPS_ID, 0, " .%u", i + gp->gap_list.base.low); log_printf (RTPS_ID, 0, ") %c%c%c\r\n", (flags & SMF_DATA) ? 'D' : '-', (flags & SMF_KEY) ? 'K' : '-', (flags & SMF_INLINE_QOS) ? 'Q' : '-'); }
// Computes a maximum clique of the graph g and return its size // The table list contains the ID of the vertices int sage_clique_max(graph_t *g,int **list){ sage_reset_global_variables(); quiet++; set_t s; int i,l; clique_options *opts = sage_init_clique_opt(); s=clique_unweighted_find_single(g,/*min_weight*/0, /*max_weight*/0,/*maximal*/TRUE, opts); free(opts); // Writing the answer into a int [] to be read by Sage int size=set_size(s); *list=malloc(sizeof(int)*size); l=0; for (i=0; i<SET_MAX_SIZE(s); i++) { if (SET_CONTAINS(s,i)) { *((*list)+l)=i; l++; } } return size; }
void mark_fragment (FragInfo_t *fip, DataFragSMsg *fragp, Change_t *cp) { DB *dbp; unsigned char *dp, *src; unsigned sleft, f, dleft, left, n; int copy, i; /* Check if fragments can be added to sample buffer. */ dp = fip->data->data; dbp = cp->c_db; src = cp->c_data; if (dbp) sleft = dbp->size - (cp->c_data - dbp->data); else sleft = cp->c_length; f = fragp->frag_start - 1; if (f) { dp += f * fragp->frag_size; dleft = fip->length - (dp - fip->data->data); } else dleft = fip->length; /* Copy each payload fragment to data buffer. */ for (i = 0; i < fragp->num_fragments; i++, f++) { left = fragp->frag_size; if (left > dleft) left = dleft; if (SET_CONTAINS (fip->bitmap, f)) copy = 0; else { SET_ADD (fip->bitmap, f); fip->num_na--; if (fip->num_na && fip->first_na == f) { fip->first_na++; while (SET_CONTAINS (fip->bitmap, fip->first_na)) fip->first_na++; } copy = 1; } while (left) { n = (sleft > dleft) ? dleft : sleft; if (n > left) n = left; if (n) { left -= n; dleft -= n; if (copy) memcpy (dp, src, n); dp += n; } /* Update source pointers. */ sleft -= n; if (sleft) src += n; else if (dbp && left) { dbp = dbp->next; sleft = dbp->size; src = dbp->data; } } } }
/** * Find all of the maximal cliques in the provided matlab matrix, which * should represent an adjacency matrix. Most of this function just * translates from MATLAB input for processing with Cliquer and then * translates the output of Cliquer back into MATLAB data. * * The MATLAB arguments are as follows: * prhs[0] mtxAdj The input adjacency matrix. Only the upper- * triangular part of this is used. * prhs[1] iMinWeight The minimum weight of cliques to find. * prhs[2] iMaxWeight The maximum weight of cliques to find. * prhs[3] bOnlyMaximal If `false` (i.e., zero), return all cliques; * otherwise, return only maximal cliques. * prhs[4] iMaxNumCliques The maximum number of cliques to be returned * (due to a [perceived] limitation of Cliquer). */ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { /* Ensure that an appropriate number of arguments were provided and that an * an appropriate number of return variables were requested. */ if (nrhs != 5) mexErrMsgTxt("Exactly five input arguments are required."); else if (nlhs > 2) mexErrMsgTxt("Too many output arguments were requested."); /* Retrieve and store the size of the input adjacency matrix for size * checking and later use. */ mwSize iRows = mxGetM(prhs[0]); mwSize iCols = mxGetN(prhs[0]); /* Perform size- and type-checking on the input values. */ if ((iRows != iCols) || !mxIsNumeric(prhs[0]) || mxIsComplex(prhs[0])) mexErrMsgTxt("The first argument must be an integer-valued square matrix."); else if (mxGetM(prhs[1]) != 1 || mxGetN(prhs[1]) != 1 || !mxIsNumeric(prhs[1])) mexErrMsgTxt("The second argument must be an integer."); else if (mxGetM(prhs[2]) != 1 || mxGetN(prhs[2]) != 1 || !mxIsNumeric(prhs[2])) mexErrMsgTxt("The third argument must be an integer."); else if (mxGetM(prhs[3]) != 1 || mxGetN(prhs[3]) != 1 || !mxIsLogical(prhs[3])) mexErrMsgTxt("The fourth argument must be a logical scalar."); else if (mxGetM(prhs[4]) != 1 || mxGetN(prhs[4]) != 1 || !mxIsNumeric(prhs[4])) mexErrMsgTxt("The fifth argument must be an integer."); /* Declare variables to hold the input arguments (except the first). Each * of these can be retrieved by indexing `prhs`. */ int iMinWeight = MAX(0, (int) mxGetScalar(prhs[1])); int iMaxWeight = MIN(iCols, (int) mxGetScalar(prhs[2])); int bOnlyMaximal = (mxGetScalar(prhs[3]) == 0) ? FALSE : TRUE; int iMaxNumCliques = (int) mxGetScalar(prhs[4]); /* These variables are for storing the graph corresponding to the input * adjacency matrix, the list of cliques found in that graph, and the return * value for this MATLAB function. */ graph_t *ptrGraph; set_t arrCliqueList[iMaxNumCliques]; double *ptrOutputMatrix; /* Miscellaneous variable declarations. */ int i, j, idx, iNumCliques, iNumCliquesReturned; /* Create a graph from the adjacency matrix `prhs[0]`. */ ptrGraph = MatrixToGraph(mxGetPr(prhs[0]), iCols); /* Find the cliques in the associated graph. */ iNumCliques = FindCliques(ptrGraph, iMinWeight, iMaxWeight, bOnlyMaximal, iMaxNumCliques, arrCliqueList, iMaxNumCliques); /* We are done with the graph. Free the memory used to store it. */ graph_free(ptrGraph); /* Retrieve the number of cliques returned by the function, which is bounded * above by `iMaxNumCliques`. */ iNumCliquesReturned = MIN(iNumCliques, iMaxNumCliques); /* Output the total number of cliques found. */ plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL); mxGetPr(plhs[0])[0] = iNumCliques; /* Create the output matrix, which will have one row for each clique and * one column for each node of the graph. */ plhs[1] = mxCreateDoubleMatrix(iNumCliquesReturned, iCols, mxREAL); ptrOutputMatrix = mxGetPr(plhs[1]); /* Fill in the rows of the output matrix by looping through the cliques * that were found. */ for (i = 0; i < iNumCliquesReturned; i++) { /* Fill in the entries of this row by looping through the corresponding * clique to find the vertices contained in the clique. */ for (j = 0; j < SET_MAX_SIZE(arrCliqueList[i]); j++) { /* The entries of the output matrix are initialized to zeros. If * the vertex 'j' is in clique 'i', place a 1 in the (i, j) entry * of the output matrix. */ if (SET_CONTAINS(arrCliqueList[i], j)) { /* Matrices in Matlab are stored column-wise (i.e., the columns * of the matrix are stacked and stored as a column vector); so, * we must access the output as a 1-dimensional array. The index * of the entry corresponding to the (i, j) position in this * matrix is calculated in 'idx' below. */ idx = j * iNumCliques + i; ptrOutputMatrix[idx] = 1; } } /* Now that we've stored this clique as a row in a matrix, we can free * the memory used to store the clique. */ set_free(arrCliqueList[i]); } return; }
int get_h(C_Graphe &G, char *name, int *UB){ int *som = new int[G.nb_sommets]; for(int i=0 ; i<G.nb_sommets ; i++){som[i] = 0;} int cpt=0; int h=0; int nb; *UB = 0; while (cpt <= G.nb_sommets-1){ graph_t *g; g=(graph_t *)calloc(1,sizeof(graph_t)); g->n = G.nb_sommets; g->edges=(set_t *)calloc(g->n,sizeof(set_t)); for (int i=0; i<g->n; i++){ g->edges[i]=set_new(g->n); } g->weights=(int *)calloc(g->n,sizeof(int)); for(int i=0; i<g->n; i++){ g->weights[i]=1; } for(int i=0; i<g->n; i++){ for(int j=i+1; j<g->n; j++){ if( G.matrice_adjacence[i][j] == 0 && i!=j && som[i]+som[j] == 0 ){ GRAPH_ADD_EDGE(g,i,j); // cout<<"adding edge "<<i<<","<<j<<"\n"; } } } set_t s; s = clique_find_single(g,0,0,FALSE,NULL); nb=0; for(int i=0 ; i<G.nb_sommets ; i++){ if (SET_CONTAINS(s,i)){ som[i] = 1; cpt++; nb++; } } h++; *UB=*UB+nb*h; for (int i=0; i<g->n; i++){ set_free(g->edges[i]); } free(g->edges); free(g->weights); free(g); set_free(s); } for (int i=0; i<G.nb_sommets; i++){ if(som[i] == 0){ h++; break; } } ofstream fichier; ostringstream tmp; //Ouverture fichiers tmp.str("");tmp<<"h.col"; fichier.open(tmp.str().c_str(), ios::out|ios::app); if (!fichier){ cerr << "Erreur à l'ouverture du fichier\n"; return 1; } fichier<<name<<" "<<h<<" "<<*UB<<"\n"; fichier.close(); delete [] som; return h; }
void STABLE_max_heur(C_Graphe &G, int *valeur){ int *som = new int[G.nb_sommets]; for(int i=0 ; i<G.nb_sommets ; i++){som[i] = 0;} int cpt=0; int h=0; int nb; *valeur = 0; while (cpt <= G.nb_sommets-1){ graph_t *g; g=(graph_t *)calloc(1,sizeof(graph_t)); g->n = G.nb_sommets; g->edges=(set_t *)calloc(g->n,sizeof(set_t)); for (int i=0; i<g->n; i++){ g->edges[i]=set_new(g->n); } g->weights=(int *)calloc(g->n,sizeof(int)); for(int i=0; i<g->n; i++){ g->weights[i]=1; } for(int i=0; i<g->n; i++){ for(int j=i+1; j<g->n; j++){ if( G.matrice_adjacence[i][j] == 0 && i!=j && som[i]+som[j] == 0 ){ GRAPH_ADD_EDGE(g,i,j); // cout<<"adding edge "<<i<<","<<j<<"\n"; } } } set_t s; s = clique_find_single(g,0,0,FALSE,NULL); nb=0; for(int i=0 ; i<G.nb_sommets ; i++){ if (SET_CONTAINS(s,i)){ som[i] = 1; cpt++; nb++; } } h++; *valeur=*valeur+nb*h; for (int i=0; i<g->n; i++){ set_free(g->edges[i]); } free(g->edges); free(g->weights); free(g); set_free(s); } for (int i=0; i<G.nb_sommets; i++){ if(som[i] == 0){ h++; *valeur=*valeur+h; break; } } delete [] som; return ; }
int AddClause(ADNFClause dnf, ASet clause) //returns address if really added { int i; AAndClause *cur= dnf; ASet allAtomsIntersection; if (SET_ISFALSE(clause)) //Not adding ( a AND NOT(a) ) return 0; while (cur->next) { cur=cur->next; switch (Contains( &(cur->set), &clause) )// The one in the chain is preferred if they are equal { case 1: //The one in the chain contains the one to be added ( Is more specific) // printf("head %d head->prev->next %d\n", head, head->prev->next); cur= RemoveClause(cur); break; case -1: //The one to be added contains (is more specific than) the one already in the chain #ifdef LOG_LINKEDLIST printf("Clause %d>%d already there in wire %d at stack entry %d\n", clause, cur->set, w, cur->inQueue); #endif break; case 0: //Nothing to see here allAtomsIntersection= SET_INTERSECTION( SET_ALL_ATOMS(cur->set), SET_ALL_ATOMS(clause) ); for (i=0; i<ASET_SIZE_HALF; i++) { if (SET_MEMBER(allAtomsIntersection, i) ) //looking for a and ~a { if ( LOGIC_NORMALIZE(SET_MEMBER(cur->set, i)) != LOGIC_NORMALIZE(SET_MEMBER(clause, i)) ) //one of them has a and the other ~a { ASet f1, f2; if ( SET_MEMBER(clause, i)) { f1=clause; f2=cur->set; } else { f2= clause; f1= cur->set; } // f1 has a and f2 has ~a SET_REMOVE(f2, SET_INDEX_NEGATE(i)); SET_REMOVE(f1, i); //Now neither has either!! if (f1==f2) { RemoveClause(cur); clause= f1; cur= dnf; break; //break out of the for loop. } else { int fa= //1 if it is of form fa + ff'~a, -1 if f~a + ff'a, 0 if neither SET_CONTAINS(f2,f1); if (fa==1) //fa+ ff'~a = fa + ff'a. f1=f, f2=ff' { //if fa is in the chain, we need not touch it! Just simplify ff'~a to ff' if ( SET_MEMBER(cur->set, i)) clause= f2; else // if ff'~a is in the chain, we have to delete it and insert ff' in again. Then fa will be added back. (Is it necessary?) { RemoveClause(cur); AddClause(dnf, f2); } cur= dnf;// Restart the outer while loop break; //from the for loop } else if (fa==-1)//ff'a + f~a= ff' + f~a. f1=ff', f2=f { //if f~a is in the chain, we need not touch it. Just simplify ff'a to ff' if (SET_MEMBER(cur->set, SET_INDEX_NEGATE(i)) ) clause= f1; else // if ff'a is in the chain, we delete it and insert ff' in again. Then f~a will be added again. { RemoveClause(cur); AddClause(dnf, f1); } cur= dnf; break; } }//end if }//end if }//end if }//end for }//end switch } return AddClauseNoQuestionsAsked(cur, clause); }