dd_MatrixPtr FromEigen (const cref_matrix_t& input) { if (dd_debug) { std::cout << "from eigen input " << input << std::endl; } dd_debug = false; dd_MatrixPtr M=NULL; dd_rowrange i; dd_colrange j; dd_rowrange m_input = (dd_rowrange)(input.rows()); dd_colrange d_input = (dd_colrange)(7); dd_RepresentationType rep=dd_Generator; mytype value; dd_NumberType NT = dd_Real;; dd_init(value); M=dd_CreateMatrix(m_input, d_input); M->representation=rep; M->numbtype=NT; for (i = 1; i <= input.rows(); i++) { dd_set_d(value, 0); dd_set(M->matrix[i-1][0],value); for (j = 2; j <= d_input; j++) { dd_set_d(value, input(i-1,j-2)); dd_set(M->matrix[i-1][j-1],value); } } dd_clear(value); return M; }
void dd_MLSetMatrixWithString(dd_rowrange m, dd_colrange d, char line[], dd_MatrixPtr M) { dd_rowrange i=0; dd_colrange j=0; char *next,*copy; const char ct[]=", {}\n"; /* allows separators ","," ","{","}". */ mytype value; double dval; dd_init(value); copy=(char *)malloc(strlen(line) + 4048); /* some extra space as buffer. Somehow linux version needs this */ strcpy(copy,line); next=strtok(copy,ct); i=0; j=0; do { #if defined GMPRATIONAL dd_sread_rational_value(next, value); #else dval=atof(next); dd_set_d(value,dval); #endif dd_WriteNumber(stderr,value); dd_set(M->matrix[i][j],value); j++; if (j == d) { i++; j=0; } } while ((next=strtok(NULL,ct))!=NULL); free(copy); dd_clear(value); return; }
void dd_set_global_constants() { dd_init(dd_zero); dd_init(dd_minuszero); dd_init(dd_one); dd_init(dd_minusone); dd_init(dd_purezero); time(&dd_statStartTime); /* cddlib starting time */ dd_statBApivots=0; /* basis finding pivots */ dd_statCCpivots=0; /* criss-cross pivots */ dd_statDS1pivots=0; /* phase 1 pivots */ dd_statDS2pivots=0; /* phase 2 pivots */ dd_statACpivots=0; /* anticycling (cc) pivots */ dd_choiceLPSolverDefault=dd_DualSimplex; /* Default LP solver Algorithm */ dd_choiceRedcheckAlgorithm=dd_DualSimplex; /* Redundancy Checking Algorithm */ dd_choiceLexicoPivotQ=dd_TRUE; /* whether to use the lexicographic pivot */ #if defined GMPRATIONAL dd_statBSpivots=0; /* basis status checking pivots */ mpq_set_ui(dd_zero,0U,1U); mpq_set_ui(dd_purezero,0U,1U); mpq_set_ui(dd_one,1U,1U); mpq_set_si(dd_minusone,-1L,1U); ddf_set_global_constants(); #elif defined GMPFLOAT mpf_set_d(dd_zero,dd_almostzero); mpf_set_ui(dd_purezero,0U); mpf_set_ui(dd_one,1U); mpf_set_si(dd_minusone,-1L,1U); #else dd_zero[0]= dd_almostzero; /*real zero */ dd_purezero[0]= 0.0; dd_one[0]= 1L; dd_minusone[0]= -1L; #endif dd_neg(dd_minuszero,dd_zero); }
SEXP redundant(SEXP m, SEXP h) { GetRNGstate(); if (! isString(m)) error("'m' must be character"); if (! isMatrix(m)) error("'m' must be matrix"); if (! isLogical(h)) error("'h' must be logical"); if (LENGTH(h) != 1) error("'h' must be scalar"); SEXP m_dim; PROTECT(m_dim = getAttrib(m, R_DimSymbol)); int nrow = INTEGER(m_dim)[0]; int ncol = INTEGER(m_dim)[1]; UNPROTECT(1); #ifdef WOOF printf("nrow = %d\n", nrow); printf("ncol = %d\n", ncol); #endif /* WOOF */ if (nrow < 2) error("less than 2 rows, cannot be redundant"); if (ncol <= 2) error("no cols in m[ , - c(1, 2)]"); for (int i = 0; i < nrow; i++) { const char *foo = CHAR(STRING_ELT(m, i)); if (strlen(foo) != 1) error("column one of 'm' not zero-or-one valued"); if (! (foo[0] == '0' || foo[0] == '1')) error("column one of 'm' not zero-or-one valued"); } if (! LOGICAL(h)[0]) for (int i = nrow; i < 2 * nrow; i++) { const char *foo = CHAR(STRING_ELT(m, i)); if (strlen(foo) != 1) error("column two of 'm' not zero-or-one valued"); if (! (foo[0] == '0' || foo[0] == '1')) error("column two of 'm' not zero-or-one valued"); } dd_set_global_constants(); /* note actual type of "value" is mpq_t (defined in cddmp.h) */ mytype value; dd_init(value); dd_MatrixPtr mf = dd_CreateMatrix(nrow, ncol - 1); /* note our matrix has one more column than Fukuda's */ /* representation */ if(LOGICAL(h)[0]) mf->representation = dd_Inequality; else mf->representation = dd_Generator; mf->numbtype = dd_Rational; /* linearity */ for (int i = 0; i < nrow; i++) { const char *foo = CHAR(STRING_ELT(m, i)); if (foo[0] == '1') set_addelem(mf->linset, i + 1); /* note conversion from zero-origin to one-origin indexing */ } /* matrix */ for (int j = 1, k = nrow; j < ncol; j++) for (int i = 0; i < nrow; i++, k++) { const char *rat_str = CHAR(STRING_ELT(m, k)); if (mpq_set_str(value, rat_str, 10) == -1) ERROR_WITH_CLEANUP_3("error converting string to GMP rational"); mpq_canonicalize(value); dd_set(mf->matrix[i][j - 1], value); /* note our matrix has one more column than Fukuda's */ } dd_rowset impl_linset, redset; dd_rowindex newpos; dd_ErrorType err = dd_NoError; dd_MatrixCanonicalize(&mf, &impl_linset, &redset, &newpos, &err); if (err != dd_NoError) { rr_WriteErrorMessages(err); ERROR_WITH_CLEANUP_6("failed"); } int mrow = mf->rowsize; int mcol = mf->colsize; if (mcol + 1 != ncol) ERROR_WITH_CLEANUP_6("Cannot happen! computed matrix has" " wrong number of columns"); #ifdef WOOF printf("mrow = %d\n", mrow); printf("mcol = %d\n", mcol); #endif /* WOOF */ SEXP bar; PROTECT(bar = allocMatrix(STRSXP, mrow, ncol)); /* linearity output */ for (int i = 0; i < mrow; i++) if (set_member(i + 1, mf->linset)) SET_STRING_ELT(bar, i, mkChar("1")); else SET_STRING_ELT(bar, i, mkChar("0")); /* note conversion from zero-origin to one-origin indexing */ /* matrix output */ for (int j = 1, k = mrow; j < ncol; j++) for (int i = 0; i < mrow; i++, k++) { dd_set(value, mf->matrix[i][j - 1]); /* note our matrix has one more column than Fukuda's */ char *zstr = NULL; zstr = mpq_get_str(zstr, 10, value); SET_STRING_ELT(bar, k, mkChar(zstr)); free(zstr); } if (mf->representation == dd_Inequality) { SEXP attr_name, attr_value; PROTECT(attr_name = ScalarString(mkChar("representation"))); PROTECT(attr_value = ScalarString(mkChar("H"))); setAttrib(bar, attr_name, attr_value); UNPROTECT(2); } if (mf->representation == dd_Generator) { SEXP attr_name, attr_value; PROTECT(attr_name = ScalarString(mkChar("representation"))); PROTECT(attr_value = ScalarString(mkChar("V"))); setAttrib(bar, attr_name, attr_value); UNPROTECT(2); } int impl_size = set_card(impl_linset); int red_size = set_card(redset); int nresult = 1; int iresult = 1; SEXP baz = NULL; if (impl_size > 0) { PROTECT(baz = rr_set_fwrite(impl_linset)); nresult++; } SEXP qux = NULL; if (red_size > 0) { PROTECT(qux = rr_set_fwrite(redset)); nresult++; } SEXP fred = NULL; { PROTECT(fred = allocVector(INTSXP, nrow)); for (int i = 1; i <= nrow; i++) INTEGER(fred)[i - 1] = newpos[i]; nresult++; } #ifdef WOOF fprintf(stderr, "impl_size = %d\n", impl_size); fprintf(stderr, "red_size = %d\n", red_size); fprintf(stderr, "nresult = %d\n", nresult); if (baz) fprintf(stderr, "LENGTH(baz) = %d\n", LENGTH(baz)); if (qux) fprintf(stderr, "LENGTH(qux) = %d\n", LENGTH(qux)); #endif /* WOOF */ SEXP result, resultnames; PROTECT(result = allocVector(VECSXP, nresult)); PROTECT(resultnames = allocVector(STRSXP, nresult)); SET_STRING_ELT(resultnames, 0, mkChar("output")); SET_VECTOR_ELT(result, 0, bar); if (baz) { SET_STRING_ELT(resultnames, iresult, mkChar("implied.linearity")); SET_VECTOR_ELT(result, iresult, baz); iresult++; } if (qux) { SET_STRING_ELT(resultnames, iresult, mkChar("redundant")); SET_VECTOR_ELT(result, iresult, qux); iresult++; } { SET_STRING_ELT(resultnames, iresult, mkChar("new.position")); SET_VECTOR_ELT(result, iresult, fred); iresult++; } namesgets(result, resultnames); set_free(redset); set_free(impl_linset); free(newpos); dd_FreeMatrix(mf); dd_clear(value); dd_free_global_constants(); PutRNGstate(); UNPROTECT(nresult + 2); return result; }
SEXP allfaces(SEXP hrep) { GetRNGstate(); if (! isMatrix(hrep)) error("'hrep' must be matrix"); if (! isString(hrep)) error("'hrep' must be character"); SEXP hrep_dim; PROTECT(hrep_dim = getAttrib(hrep, R_DimSymbol)); int nrow = INTEGER(hrep_dim)[0]; int ncol = INTEGER(hrep_dim)[1]; UNPROTECT(1); if (nrow <= 0) error("no rows in 'hrep'"); if (ncol <= 3) error("three or fewer cols in hrep"); for (int i = 0; i < nrow; ++i) { const char *foo = CHAR(STRING_ELT(hrep, i)); if (strlen(foo) != 1) error("column one of 'hrep' not zero-or-one valued"); if (! (foo[0] == '0' || foo[0] == '1')) error("column one of 'hrep' not zero-or-one valued"); } dd_set_global_constants(); /* note actual type of "value" is mpq_t (defined in cddmp.h) */ mytype value; dd_init(value); dd_MatrixPtr mf = dd_CreateMatrix(nrow, ncol - 1); /* note our matrix has one more column than Fukuda's */ mf->representation = dd_Inequality; mf->numbtype = dd_Rational; /* linearity */ for (int i = 0; i < nrow; ++i) { const char *foo = CHAR(STRING_ELT(hrep, i)); if (foo[0] == '1') set_addelem(mf->linset, i + 1); /* note conversion from zero-origin to one-origin indexing */ } /* matrix */ for (int j = 1, k = nrow; j < ncol; ++j) for (int i = 0; i < nrow; ++i, ++k) { const char *rat_str = CHAR(STRING_ELT(hrep, k)); if (mpq_set_str(value, rat_str, 10) == -1) { dd_FreeMatrix(mf); dd_clear(value); dd_free_global_constants(); error("error converting string to GMP rational"); } mpq_canonicalize(value); dd_set(mf->matrix[i][j - 1], value); /* note our matrix has one more column than Fukuda's */ } SEXP result; PROTECT(result = FaceEnum(mf)); dd_FreeMatrix(mf); dd_clear(value); dd_free_global_constants(); if (result == R_NilValue) error("failed"); PutRNGstate(); UNPROTECT(1); return result; }
static dd_ErrorType FaceEnumHelper(dd_MatrixPtr M, dd_rowset R, dd_rowset S) { dd_ErrorType err; dd_rowset LL, ImL, RR, SS, Lbasis; dd_rowrange iprev = 0; dd_colrange dim; dd_LPSolutionPtr lps = NULL; set_initialize(&LL, M->rowsize); set_initialize(&RR, M->rowsize); set_initialize(&SS, M->rowsize); set_copy(LL, M->linset); set_copy(RR, R); set_copy(SS, S); /* note actual type of "value" is mpq_t (defined in cddmp.h) */ mytype value; dd_init(value); err = dd_NoError; dd_boolean foo = dd_ExistsRestrictedFace(M, R, S, &err); if (err != dd_NoError) { #ifdef MOO fprintf(stderr, "err from dd_ExistsRestrictedFace\n"); fprintf(stderr, "err = %d\n", err); #endif /* MOO */ set_free(LL); set_free(RR); set_free(SS); dd_clear(value); return err; } if (foo) { set_uni(M->linset, M->linset, R); err = dd_NoError; dd_FindRelativeInterior(M, &ImL, &Lbasis, &lps, &err); if (err != dd_NoError) { #ifdef MOO fprintf(stderr, "err from dd_FindRelativeInterior\n"); fprintf(stderr, "err = %d\n", err); #endif /* MOO */ dd_FreeLPSolution(lps); set_free(ImL); set_free(Lbasis); set_free(LL); set_free(RR); set_free(SS); dd_clear(value); return err; } dim = M->colsize - set_card(Lbasis) - 1; set_uni(M->linset, M->linset, ImL); SEXP mydim, myactive, myrip; PROTECT(mydim = ScalarInteger(dim)); PROTECT(myactive = rr_set_fwrite(M->linset)); int myd = (lps->d) - 2; PROTECT(myrip = allocVector(STRSXP, myd)); for (int j = 1; j <= myd; j++) { dd_set(value, lps->sol[j]); char *zstr = NULL; zstr = mpq_get_str(zstr, 10, value); SET_STRING_ELT(myrip, j - 1, mkChar(zstr)); free(zstr); } REPROTECT(dimlist = CONS(mydim, dimlist), dimidx); REPROTECT(riplist = CONS(myrip, riplist), ripidx); REPROTECT(activelist = CONS(myactive, activelist), activeidx); UNPROTECT(3); dd_FreeLPSolution(lps); set_free(ImL); set_free(Lbasis); if (dim > 0) { for (int i = 1; i <= M->rowsize; i++) { if ((! set_member(i, M->linset)) && (! set_member(i, S))) { set_addelem(RR, i); if (iprev) { set_delelem(RR, iprev); set_delelem(M->linset, iprev); set_addelem(SS, iprev); } iprev = i; err = FaceEnumHelper(M, RR, SS); if (err != dd_NoError) { #ifdef MOO fprintf(stderr, "err from FaceEnumHelper\n"); fprintf(stderr, "err = %d\n", err); #endif /* MOO */ set_copy(M->linset, LL); set_free(LL); set_free(RR); set_free(SS); dd_clear(value); return err; } } } } } set_copy(M->linset, LL); set_free(LL); set_free(RR); set_free(SS); dd_clear(value); return dd_NoError; }
dd_MatrixPtr dd_BlockElimination(dd_MatrixPtr M, dd_colset delset, dd_ErrorType *error) /* Eliminate the variables (columns) delset by the Block Elimination with dd_DoubleDescription algorithm. Given (where y is to be eliminated): c1 + A1 x + B1 y >= 0 c2 + A2 x + B2 y = 0 1. First construct the dual system: z1^T B1 + z2^T B2 = 0, z1 >= 0. 2. Compute the generators of the dual. 3. Then take the linear combination of the original system with each generator. 4. Remove redundant inequalies. */ { dd_MatrixPtr Mdual=NULL, Mproj=NULL, Gdual=NULL; dd_rowrange i,h,m,mproj,mdual,linsize; dd_colrange j,k,d,dproj,ddual,delsize; dd_colindex delindex; mytype temp,prod; dd_PolyhedraPtr dualpoly; dd_ErrorType err=dd_NoError; dd_boolean localdebug=dd_FALSE; *error=dd_NoError; m= M->rowsize; d= M->colsize; delindex=(long*)calloc(d+1,sizeof(long)); dd_init(temp); dd_init(prod); k=0; delsize=0; for (j=1; j<=d; j++){ if (set_member(j, delset)){ k++; delsize++; delindex[k]=j; /* stores the kth deletion column index */ } } if (localdebug) dd_WriteMatrix(stdout, M); linsize=set_card(M->linset); ddual=m+1; mdual=delsize + m - linsize; /* #equalitions + dimension of z1 */ /* setup the dual matrix */ Mdual=dd_CreateMatrix(mdual, ddual); Mdual->representation=dd_Inequality; for (i = 1; i <= delsize; i++){ set_addelem(Mdual->linset,i); /* equality */ for (j = 1; j <= m; j++) { dd_set(Mdual->matrix[i-1][j], M->matrix[j-1][delindex[i]-1]); } } k=0; for (i = 1; i <= m; i++){ if (!set_member(i, M->linset)){ /* set nonnegativity for the dual variable associated with each non-linearity inequality. */ k++; dd_set(Mdual->matrix[delsize+k-1][i], dd_one); } } /* 2. Compute the generators of the dual system. */ dualpoly=dd_DDMatrix2Poly(Mdual, &err); Gdual=dd_CopyGenerators(dualpoly); /* 3. Take the linear combination of the original system with each generator. */ dproj=d-delsize; mproj=Gdual->rowsize; Mproj=dd_CreateMatrix(mproj, dproj); Mproj->representation=dd_Inequality; set_copy(Mproj->linset, Gdual->linset); for (i=1; i<=mproj; i++){ k=0; for (j=1; j<=d; j++){ if (!set_member(j, delset)){ k++; /* new index of the variable x_j */ dd_set(prod, dd_purezero); for (h = 1; h <= m; h++){ dd_mul(temp,M->matrix[h-1][j-1],Gdual->matrix[i-1][h]); dd_add(prod,prod,temp); } dd_set(Mproj->matrix[i-1][k-1],prod); } } } if (localdebug) printf("Size of the projection system: %ld x %ld\n", mproj, dproj); dd_FreePolyhedra(dualpoly); free(delindex); dd_clear(temp); dd_clear(prod); dd_FreeMatrix(Mdual); dd_FreeMatrix(Gdual); return Mproj; }
dd_MatrixPtr dd_FourierElimination(dd_MatrixPtr M,dd_ErrorType *error) /* Eliminate the last variable (column) from the given H-matrix using the standard Fourier Elimination. */ { dd_MatrixPtr Mnew=NULL; dd_rowrange i,inew,ip,in,iz,m,mpos=0,mneg=0,mzero=0,mnew; dd_colrange j,d,dnew; dd_rowindex posrowindex, negrowindex,zerorowindex; mytype temp1,temp2; dd_boolean localdebug=dd_FALSE; *error=dd_NoError; m= M->rowsize; d= M->colsize; if (d<=1){ *error=dd_ColIndexOutOfRange; if (localdebug) { printf("The number of column is too small: %ld for Fourier's Elimination.\n",d); } goto _L99; } if (M->representation==dd_Generator){ *error=dd_NotAvailForV; if (localdebug) { printf("Fourier's Elimination cannot be applied to a V-polyhedron.\n"); } goto _L99; } if (set_card(M->linset)>0){ *error=dd_CannotHandleLinearity; if (localdebug) { printf("The Fourier Elimination function does not handle equality in this version.\n"); } goto _L99; } /* Create temporary spaces to be removed at the end of this function */ posrowindex=(long*)calloc(m+1,sizeof(long)); negrowindex=(long*)calloc(m+1,sizeof(long)); zerorowindex=(long*)calloc(m+1,sizeof(long)); dd_init(temp1); dd_init(temp2); for (i = 1; i <= m; i++) { if (dd_Positive(M->matrix[i-1][d-1])){ mpos++; posrowindex[mpos]=i; } else if (dd_Negative(M->matrix[i-1][d-1])) { mneg++; negrowindex[mneg]=i; } else { mzero++; zerorowindex[mzero]=i; } } /*of i*/ if (localdebug) { dd_WriteMatrix(stdout, M); printf("No of (+ - 0) rows = (%ld, %ld, %ld)\n", mpos,mneg, mzero); } /* The present code generates so many redundant inequalities and thus is quite useless, except for very small examples */ mnew=mzero+mpos*mneg; /* the total number of rows after elimination */ dnew=d-1; Mnew=dd_CreateMatrix(mnew, dnew); dd_CopyArow(Mnew->rowvec, M->rowvec, dnew); /* set_copy(Mnew->linset,M->linset); */ Mnew->numbtype=M->numbtype; Mnew->representation=M->representation; Mnew->objective=M->objective; /* Copy the inequalities independent of x_d to the top of the new matrix. */ for (iz = 1; iz <= mzero; iz++){ for (j = 1; j <= dnew; j++) { dd_set(Mnew->matrix[iz-1][j-1], M->matrix[zerorowindex[iz]-1][j-1]); } } /* Create the new inequalities by combining x_d positive and negative ones. */ inew=mzero; /* the index of the last x_d zero inequality */ for (ip = 1; ip <= mpos; ip++){ for (in = 1; in <= mneg; in++){ inew++; dd_neg(temp1, M->matrix[negrowindex[in]-1][d-1]); for (j = 1; j <= dnew; j++) { dd_LinearComb(temp2,M->matrix[posrowindex[ip]-1][j-1],temp1,\ M->matrix[negrowindex[in]-1][j-1],\ M->matrix[posrowindex[ip]-1][d-1]); dd_set(Mnew->matrix[inew-1][j-1],temp2); } dd_Normalize(dnew,Mnew->matrix[inew-1]); } } free(posrowindex); free(negrowindex); free(zerorowindex); dd_clear(temp1); dd_clear(temp2); _L99: return Mnew; }
int dd_SetMode(int xres, int yres, int bpp, bool windowflag) { HRESULT hr; if (!dd_initd) dd_init(); //do this now for the gamewindow, because this is the first time we know what size to make the gamewindow if(!dd_bGameWindowRectInitialized) { RECT r; dd_gameWindow->adjust(xres,yres,&r); int base_win_x_res = getInitialWindowXres(); int base_win_y_res = getInitialWindowYres(); /// this is for the windowsize verge.cfg vars. if( base_win_x_res > 0 && base_win_y_res > 0 ) { int win_offset_x = (r.right-r.left) - xres; int win_offset_y = (r.bottom-r.top) - yres; dd_gameWindow->winw = win_offset_x+base_win_x_res; dd_gameWindow->winh = win_offset_y+base_win_y_res; } else { dd_gameWindow->winw = r.right-r.left; dd_gameWindow->winh = r.bottom-r.top; } WINDOWPLACEMENT wp; wp.length = sizeof(WINDOWPLACEMENT); GetWindowPlacement(dd_gameWindow->hwnd,&wp); wp.rcNormalPosition.left = GetSystemMetrics(SM_CXSCREEN)/2-xres/2; wp.rcNormalPosition.top = GetSystemMetrics(SM_CYSCREEN)/2-yres/2; wp.rcNormalPosition.right = wp.rcNormalPosition.left + dd_gameWindow->winw; wp.rcNormalPosition.bottom = wp.rcNormalPosition.top + dd_gameWindow->winh; SetWindowPlacement(dd_gameWindow->hwnd,&wp); dd_bGameWindowRectInitialized = true; } //must deactivate all auxwindows if(vid_window && !windowflag) for(std::vector<dd_Window*>::iterator it = dd_windows.begin(); it != dd_windows.end(); it++) { if(!(*it)->bGameWindow) (*it)->deactivate(); } if (!windowflag) { //if we are switching into fullscreen, we are going to lose these sizes and positions //save them now so we can restore them when we flip back to windowmode if(vid_window) { WINDOWPLACEMENT wp; wp.length = sizeof(WINDOWPLACEMENT); GetWindowPlacement(dd_gameWindow->hwnd,&wp); dd_gameWindow->winx = wp.rcNormalPosition.left; dd_gameWindow->winy = wp.rcNormalPosition.top; dd_gameWindow->winw = wp.rcNormalPosition.right - wp.rcNormalPosition.left; dd_gameWindow->winh = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top; dd_bWasMaximized = (wp.showCmd == SW_SHOWMAXIMIZED); } //ShowWindow(dd_gameWindow->hwnd,SW_SHOWMAXIMIZED); ShowWindow(dd_gameWindow->hwnd,SW_HIDE); int ret = dd_gameWindow->set_fullscreen(xres,yres,bpp); if(!ret) return 0; ShowWindow(dd_gameWindow->hwnd,SW_SHOW); dd_gameWindow->xres = xres; dd_gameWindow->yres = yres; vid_xres = xres; vid_yres = yres; vid_window = false; dd_bHasBeenFullscreen = true; dd_RegisterBlitters(); return ret; } else { DX_RELEASE(dx_ps); DX_RELEASE(dx_win_ps); if (bpp != DesktopBPP) return 0; if (!vid_window) dx_dd->RestoreDisplayMode(); dx_dd->SetCooperativeLevel(dd_gameWindow->hwnd, DDSCL_NORMAL); hr = dx_dd->CreateSurface(&dx_win_psd, &dx_win_ps, NULL); if (hr != DD_OK) { return 0; } int ret = dd_gameWindow->set_win(xres,yres,bpp); if(!ret) return 0; if(dd_bHasBeenFullscreen) { WINDOWPLACEMENT wp; wp.length = sizeof(WINDOWPLACEMENT); GetWindowPlacement(dd_gameWindow->hwnd,&wp); wp.rcNormalPosition.left = dd_gameWindow->winx; wp.rcNormalPosition.top = dd_gameWindow->winy; wp.rcNormalPosition.right = wp.rcNormalPosition.left + dd_gameWindow->winw; wp.rcNormalPosition.bottom = wp.rcNormalPosition.top + dd_gameWindow->winh; SetWindowPlacement(dd_gameWindow->hwnd,&wp); if(dd_bWasMaximized) ShowWindow(dd_gameWindow->hwnd,SW_SHOWMAXIMIZED); } //must activate all auxwindows if(!vid_window) for(std::vector<dd_Window*>::iterator it = dd_windows.begin(); it != dd_windows.end(); it++) if(!(*it)->bGameWindow) (*it)->activate(); //bring the gamewindow back to the front SetWindowPos(dd_gameWindow->hwnd,HWND_TOP,0,0,0,0,SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); dd_gameWindow->xres = xres; dd_gameWindow->yres = yres; vid_xres = xres; vid_yres = yres; vid_window = true; dd_RegisterBlitters(); return 1; } return 0; }
// Creates and initializes a device. struct cen64_device *device_create(struct cen64_device *device, const struct rom_file *ddipl, const struct rom_file *ddrom, const struct rom_file *pifrom, const struct rom_file *cart, const struct save_file *eeprom, const struct save_file *sram, const struct save_file *flashram, const struct controller *controller, bool no_audio, bool no_video) { // Initialize the bus. device->bus.ai = &device->ai; device->bus.dd = &device->dd; device->bus.pi = &device->pi; device->bus.ri = &device->ri; device->bus.si = &device->si; device->bus.vi = &device->vi; device->bus.rdp = &device->rdp; device->bus.rsp = &device->rsp; device->bus.vr4300 = &device->vr4300; // Initialize the bus. if (bus_init(&device->bus)) { debug("create_device: Failed to initialize the bus.\n"); return NULL; } // Initialize the AI. if (ai_init(&device->ai, &device->bus, no_audio)) { debug("create_device: Failed to initialize the AI.\n"); return NULL; } // Initialize the DD. if (dd_init(&device->dd, &device->bus, ddipl->ptr, ddrom->ptr, ddrom->size)) { debug("create_device: Failed to initialize the DD.\n"); return NULL; } // Initialize the PI. if (pi_init(&device->pi, &device->bus, cart->ptr, cart->size, sram, flashram)) { debug("create_device: Failed to initialize the PI.\n"); return NULL; } // Initialize the RI. if (ri_init(&device->ri, &device->bus)) { debug("create_device: Failed to initialize the RI.\n"); return NULL; } // Initialize the SI. if (si_init(&device->si, &device->bus, pifrom->ptr, cart->ptr, ddipl->ptr != NULL, eeprom->ptr, eeprom->size, controller)) { debug("create_device: Failed to initialize the SI.\n"); return NULL; } // Initialize the VI. if (vi_init(&device->vi, &device->bus, no_video)) { debug("create_device: Failed to initialize the VI.\n"); return NULL; } // Initialize the RDP. if (rdp_init(&device->rdp, &device->bus)) { debug("create_device: Failed to initialize the RDP.\n"); return NULL; } // Initialize the RSP. if (rsp_init(&device->rsp, &device->bus)) { debug("create_device: Failed to initialize the RSP.\n"); return NULL; } // Initialize the VR4300. if (vr4300_init(&device->vr4300, &device->bus)) { debug("create_device: Failed to initialize the VR4300.\n"); return NULL; } return device; }
int main(int argc, char *argv[]) { dd_MatrixPtr M=NULL,M1=NULL,M2=NULL; dd_colrange j,s,d; dd_ErrorType err=dd_NoError; dd_rowset redset,impl_linset; dd_rowindex newpos; mytype val; dd_DataFileType inputfile; FILE *reading=NULL; dd_set_global_constants(); /* First, this must be called. */ dd_init(val); if (argc>1) strcpy(inputfile,argv[1]); if (argc<=1 || !SetInputFile(&reading,argv[1])){ dd_WriteProgramDescription(stdout); fprintf(stdout,"\ncddlib test program to apply Fourier's Elimination to an H-polyhedron.\n"); dd_SetInputFile(&reading,inputfile, &err); } if (err==dd_NoError) { M=dd_PolyFile2Matrix(reading, &err); } else { fprintf(stderr,"Input file not found\n"); goto _L99; } if (err!=dd_NoError) goto _L99; d=M->colsize; M2=dd_CopyMatrix(M); printf("How many variables to elminate? (max %ld): ",d-1); scanf("%ld",&s); if (s>0 && s < d){ for (j=1; j<=s; j++){ M1=dd_FourierElimination(M2, &err); printf("\nRemove the variable %ld. The resulting redundant system.\n",d-j); dd_WriteMatrix(stdout, M1); dd_MatrixCanonicalize(&M1, &impl_linset, &redset, &newpos, &err); if (err!=dd_NoError) goto _L99; fprintf(stdout, "\nRedundant rows: "); set_fwrite(stdout, redset); dd_FreeMatrix(M2); M2=M1; set_free(redset); set_free(impl_linset); free(newpos); } printf("\nNonredundant representation:\n"); dd_WriteMatrix(stdout, M1); } else { printf("Value out of range\n"); } dd_FreeMatrix(M); dd_FreeMatrix(M1); dd_clear(val); _L99:; /* if (err!=dd_NoError) dd_WriteErrorMessages(stderr,err); */ dd_free_global_constants(); /* At the end, this should be called. */ return 0; }
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hwnd; char buf[2048]; int tmp; HANDLE lib; void pascal (*regxx)(HANDLE); void pascal (*regxy)(HANDLE); HANDLE mutex; /* create_pnglib(); exit(1); */ parse_cmd(lpCmdLine); mutex=CreateMutex(NULL,0,"MOAB"); if (mutex==NULL || GetLastError()==ERROR_ALREADY_EXISTS && strcmp(host_addr,"192.168.42.1")) { MessageBox(0,"Another instance of "MNAME" is already running.","Error",MB_OK|MB_ICONSTOP); return 0; } lib=LoadLibrary("CTL3D32.DLL"); if (lib) { regxx=(void pascal *)GetProcAddress(lib,"Ctl3dRegister"); if (regxx) regxx(GetCurrentProcess()); ctl3don=(void pascal *)GetProcAddress(lib,"Ctl3dSubclassDlg"); regxy=(void pascal *)GetProcAddress(lib,"Ctl3dUnregister"); } else { regxy=NULL; ctl3don=NULL; } dlg_col=GetSysColor(COLOR_BTNFACE); dlg_back=CreateSolidBrush(dlg_col); dlg_fcol=GetSysColor(COLOR_WINDOWTEXT); hwnd=InitWindow(hInstance,nCmdShow); load_options(); init_engine(); options(); if (quit) exit(0); init_sound(hwnd); if ((tmp=dd_init(hwnd,MODEX,MODEY))!=0) { sprintf(buf,"|DDERROR=%d",-tmp); say(buf); Sleep(1000); sprintf(buf, "DirectX init failed with code %d.\n" "DDError=%s\n" "Client Version %d.%02d.%02d\n" "MAXX=%d, MAXY=%d\n" "R=%04X, G=%04X, B=%04X\n" "RGBM=%d\n" "MAXCACHE=%d\n", -tmp,DDERR,VERSION>>16,(VERSION>>8)&255,VERSION&255,MAXX,MAXY,RED,GREEN,BLUE,RGBM,MAXCACHE); MessageBox(hwnd,buf,"DirectX init failed.",MB_ICONSTOP|MB_OK); exit(1); }
SEXP impliedLinearity(SEXP m, SEXP h) { GetRNGstate(); if (! isMatrix(m)) error("'m' must be matrix"); if (! isLogical(h)) error("'h' must be logical"); if (LENGTH(h) != 1) error("'h' must be scalar"); if (! isString(m)) error("'m' must be character"); SEXP m_dim; PROTECT(m_dim = getAttrib(m, R_DimSymbol)); int nrow = INTEGER(m_dim)[0]; int ncol = INTEGER(m_dim)[1]; UNPROTECT(1); if (nrow <= 1) error("no use if only one row"); if (ncol <= 3) error("no use if only one col"); for (int i = 0; i < nrow; i++) { const char *foo = CHAR(STRING_ELT(m, i)); if (strlen(foo) != 1) error("column one of 'm' not zero-or-one valued"); if (! (foo[0] == '0' || foo[0] == '1')) error("column one of 'm' not zero-or-one valued"); } if (! LOGICAL(h)[0]) for (int i = nrow; i < 2 * nrow; i++) { const char *foo = CHAR(STRING_ELT(m, i)); if (strlen(foo) != 1) error("column two of 'm' not zero-or-one valued"); if (! (foo[0] == '0' || foo[0] == '1')) error("column two of 'm' not zero-or-one valued"); } dd_set_global_constants(); /* note actual type of "value" is mpq_t (defined in cddmp.h) */ mytype value; dd_init(value); dd_MatrixPtr mf = dd_CreateMatrix(nrow, ncol - 1); /* note our matrix has one more column than Fukuda's */ /* representation */ if(LOGICAL(h)[0]) mf->representation = dd_Inequality; else mf->representation = dd_Generator; mf->numbtype = dd_Rational; /* linearity */ for (int i = 0; i < nrow; i++) { const char *foo = CHAR(STRING_ELT(m, i)); if (foo[0] == '1') set_addelem(mf->linset, i + 1); /* note conversion from zero-origin to one-origin indexing */ } /* matrix */ for (int j = 1, k = nrow; j < ncol; j++) for (int i = 0; i < nrow; i++, k++) { const char *rat_str = CHAR(STRING_ELT(m, k)); if (mpq_set_str(value, rat_str, 10) == -1) { dd_FreeMatrix(mf); dd_clear(value); dd_free_global_constants(); error("error converting string to GMP rational"); } mpq_canonicalize(value); dd_set(mf->matrix[i][j - 1], value); /* note our matrix has one more column than Fukuda's */ } dd_ErrorType err = dd_NoError; dd_rowset out = dd_ImplicitLinearityRows(mf, &err); if (err != dd_NoError) { rr_WriteErrorMessages(err); set_free(out); dd_FreeMatrix(mf); dd_clear(value); dd_free_global_constants(); error("failed"); } SEXP foo; PROTECT(foo = rr_set_fwrite(out)); set_free(out); dd_FreeMatrix(mf); dd_clear(value); dd_free_global_constants(); PutRNGstate(); UNPROTECT(1); return foo; }
struct dump_dir *dd_opendir(const char *dir, int flags) { struct dump_dir *dd = dd_init(); dir = dd->dd_dirname = rm_trailing_slashes(dir); struct stat stat_buf; if (stat(dir, &stat_buf) != 0) goto cant_access; /* & 0666 should remove the executable bit */ dd->mode = (stat_buf.st_mode & 0666); errno = 0; if (dd_lock(dd, WAIT_FOR_OTHER_PROCESS_USLEEP, flags) < 0) { if ((flags & DD_OPEN_READONLY) && errno == EACCES) { /* Directory is not writable. If it seems to be readable, * return "read only" dd, not NULL */ if (stat(dir, &stat_buf) == 0 && S_ISDIR(stat_buf.st_mode) && access(dir, R_OK) == 0 ) { if(dd_check(dd) != NULL) { dd_close(dd); dd = NULL; } return dd; } } if (errno == EISDIR) { /* EISDIR: dd_lock can lock the dir, but it sees no time file there, * even after it retried many times. It must be an ordinary directory! * * Without this check, e.g. abrt-action-print happily prints any current * directory when run without arguments, because its option -d DIR * defaults to "."! */ error_msg("'%s' is not a problem directory", dir); } else { cant_access: if (errno == ENOENT || errno == ENOTDIR) { if (!(flags & DD_FAIL_QUIETLY_ENOENT)) error_msg("'%s' does not exist", dir); } else { if (!(flags & DD_FAIL_QUIETLY_EACCES)) perror_msg("Can't access '%s'", dir); } } dd_close(dd); return NULL; } dd->dd_uid = (uid_t)-1L; dd->dd_gid = (gid_t)-1L; if (geteuid() == 0) { /* In case caller would want to create more files, he'll need uid:gid */ struct stat stat_buf; if (stat(dir, &stat_buf) != 0 || !S_ISDIR(stat_buf.st_mode)) { error_msg("Can't stat '%s', or it is not a directory", dir); dd_close(dd); return NULL; } dd->dd_uid = stat_buf.st_uid; dd->dd_gid = stat_buf.st_gid; } return dd; }
* this hook runs under 0:0 * * create_dump_dir_from_problem_data() function: * Currently known callers: * abrt server: uid=uid of user's executable * this runs under 0:0 * - clinets: python hook, ruby hook * abrt dbus: uid=uid of user's executable * this runs under 0:0 * - clients: setroubleshootd, abrt python */ struct dump_dir *dd_create(const char *dir, uid_t uid, mode_t mode) { /* a little trick to copy read bits from file mode to exec bit of dir mode*/ mode_t dir_mode = mode | ((mode & 0444) >> 2); struct dump_dir *dd = dd_init(); dd->mode = mode; /* Unlike dd_opendir, can't use realpath: the directory doesn't exist yet, * realpath will always return NULL. We don't really have to: * dd_opendir(".") makes sense, dd_create(".") does not. */ dir = dd->dd_dirname = rm_trailing_slashes(dir); const char *last_component = strrchr(dir, '/'); if (last_component) last_component++; else last_component = dir; if (dot_or_dotdot(last_component))