Ejemplo n.º 1
0
void ManagerBase::notifyDealCard(Seat* s, const Card& c)
{
    Message m(MsgType::DealCard);
    auto msg = m.get<DealCardMsg>();
    msg->set_seat(s->seat());
    msg->set_card(c.value());
    Message oth(MsgType::DealCard);
    msg = oth.get<DealCardMsg>();
    msg->set_seat(s->seat());
    msg->set_card(Card::Null);
    notify(&m, s->seat(), &oth);
}
Ejemplo n.º 2
0
mxArray * ZH_set_Vlist(const dd_SetFamilyPtr Inc, const dd_SetFamilyPtr Adj)
{
	mxArray *A, *row;
	double *r;
	dd_bigrange i, j;  /* unsigned long int */
	dd_bigrange cur;
	set_type s, adj;
	int count, total;
	int num;

	if(Inc){
		num = (int) Inc->famsize;
		A = mxCreateCellMatrix(num,1);
		for (i=0;i<Inc->famsize;i++){
			set_initialize(&s, Inc->set[i][0]);
			set_copy(s, Inc->set[i]);
			count=0;
			if (set_card(s)>0) {
				/*get the first element in the set*/
				for (j=1;j<=s[0];j++){
					if (set_member(j,s)) break;
				}
				cur = j;
				total = set_card(s);
				row = mxCreateDoubleMatrix(1,total,mxREAL);
				r = mxGetPr(row);
				while (count <= total){
					/* write to the output */
					set_delelem(s, cur);
					r[count++]=(double)cur;
					/* find its neighbor in list */
					adj = Adj->set[cur-1]; 
					for (j=1; j<=s[0]; j++){
						if ((set_member(j,adj)==1 )&&(set_member(j,s)==1)) {
							break;
						}
					}
					if (j<=s[0])
						cur = j;
					else
						break;
				}
				mxSetCell(A, i, row);
			}
		}
		return A;
	}
    return 0;  
}
Ejemplo n.º 3
0
mxArray * FT_set_H_MatrixPtr(const dd_MatrixPtr M)
{
	mxArray * P;	
	mxArray * tmpa;	
	mxArray * tmpb;	
	mxArray * tmpl;
	int i, j;
	double * a;
	double * b;
	double * l;
	int k=0;

	dd_rowrange ii;

 	if ((M !=NULL) &&
 	    (M->representation == dd_Inequality)) {
    		const char *f[] = {"A", "B", "lin"};
    		int dims[] = {1};

    		P = mxCreateStructArray(1, dims, 3, f);
		if (set_card(M->linset)) {
			tmpl = mxCreateDoubleMatrix(1, set_card(M->linset), mxREAL);
			l = mxGetPr(tmpl);		
    			for (ii=1; ii<=M->rowsize; ii++) {
      				if (set_member(ii, M->linset)) {
      					l[k] = (int)ii;
      					k ++;
      				}
      			}
      			mxSetField(P, 0, "lin", tmpl);
		}

		tmpb = mxCreateDoubleMatrix(M->rowsize, 1, mxREAL);
		b = mxGetPr(tmpb);
		tmpa = mxCreateDoubleMatrix(M->rowsize, M->colsize - 1, mxREAL);
		a = mxGetPr(tmpa);
	  	for (i = 0 ; i < (int)(M->rowsize); i++) {
	  		b[i] = dd_get_d(M->matrix[i][0]);
    			for (j = 0; j < (int)(M->colsize) - 1; j++) {
      				a[i + j * (int)(M->rowsize)] = - dd_get_d(M->matrix[i][j + 1]);
      			}
      		}
      		mxSetField(P, 0, "A", tmpa);
      		mxSetField(P, 0, "B", tmpb);
      		return P;
	}
	return 0;
}
Ejemplo n.º 4
0
mxArray * FT_set_SetFamilyPtr(const dd_SetFamilyPtr F)
{
	mxArray * A, * tmp;
	double * r;
	int i, j, k;
	int num;
	
	if (F) {
		num = (int)(F->famsize);
		A = mxCreateCellMatrix(num, 1); 
		for (i=0; i<(int)(F->famsize); i++) {
			num = (int)set_card(F->set[i]);
			tmp = mxCreateDoubleMatrix(1, num, mxREAL);
			r = mxGetPr(tmp);
			k = 0;
			for (j = 1; j <= *(F->set[i]); j++) {
				if (set_member(j,F->set[i]))
					r[k++] = j;
			}
			mxSetCell(A, i, tmp);
		}
		return A;
	}
	return 0;
}
Ejemplo n.º 5
0
void implicit_linear(int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[])
{
    dd_MatrixPtr H;
    dd_rowset rows;
    dd_ErrorType err;
    if (nrhs  == 1 && nlhs <= 2 && mxIsStruct(prhs[0])) {
        H = FT_get_H_MatrixPtr(prhs[0]);		
        dd_set_global_constants();  /* First, this must be called. */
        rows = dd_ImplicitLinearityRows(H, &err);

        if (err == dd_NoError) {
            int total, element, i;
            double* pr;

            total = set_card(rows);
            plhs[0] = mxCreateDoubleMatrix(total, 1, mxREAL);
            pr = mxGetPr(plhs[0]);
            
            for (i=1, element=0; i<=rows[0]; i++){
                if (set_member(i, rows)) {
                    pr[element++] = (double)i;
                }
            }
        } else {
            dd_WriteErrorMessages(stdout,err);
            mexErrMsgTxt("CDD returned an error, see above(!) for details");
        }
        dd_FreeMatrix(H);
        set_free(rows);
        return;
    } else {
        mexErrMsgTxt("hull expects a V input struct and produces an H output struct");
    }
    
}
Ejemplo n.º 6
0
void dd_MLWriteSet(set_type S)
{
  long j;

  MLPutFunction(stdlink,"List",set_card(S));
  for (j=1; j <= S[0]; j++) {
    if (set_member(j, S)) MLPutLongInteger(stdlink, j);
  }
}
Ejemplo n.º 7
0
void ManagerBase::notifyFixMaster(const ClaimMaster& cm)
{
    Message m(MsgType::FixMaster);
    auto msg = m.get<FixMasterMsg>();
    msg->set_seat(cm.seat);
    msg->set_card(cm.card.value());
    msg->set_pair(cm.pair);
    msg->set_king(cm.king.value());
    notify(&m);
}
Ejemplo n.º 8
0
float NVClockX::getSensorValue(FakeSMCSensor *sensor)
{
    switch (sensor->getGroup()) {
        case kNVCLockDiodeTemperatureSensor:
            if (set_card(sensor->getIndex()) && nv_card->caps & GPU_TEMP_MONITORING)
                return nv_card->get_gpu_temp(nv_card->sensor);
            break;
        case kNVCLockBoardTemperatureSensor:
            if (set_card(sensor->getIndex())) {
                if (nv_card->caps & BOARD_TEMP_MONITORING)
                    return nv_card->get_board_temp(nv_card->sensor);
                else 
                    return nv_card->get_gpu_temp(nv_card->sensor);
            }
            break;
            
        case kFakeSMCTachometerSensor:
            if (set_card(sensor->getIndex())) {
                if (nv_card->caps & I2C_FANSPEED_MONITORING)
                    return nv_card->get_i2c_fanspeed_rpm(nv_card->sensor);
                else if (nv_card->caps & GPU_FANSPEED_MONITORING)
                    return nv_card->get_fanspeed();
            }
            break;
            
        case kNVCLockCoreFrequencySensor:
            return nv_card->get_gpu_speed();
            break;
        
        case kNVCLockMemoryFrequencySensor:
            return nv_card->get_memory_speed();
            break;
            
        case kNVCLockShaderFrequencySensor:
            return nv_card->get_shader_speed();
            break;
    }
    
    return 0;
}
Ejemplo n.º 9
0
IOReturn FanSensor::OnKeyRead(const char* key, char* data) {
	if(!set_card(key[1]-'0'))
	{
		char buf[80];
		printf("Error: %s\n", get_error(buf, 80));
		return kIOReturnSuccess;
	}
	if(nv_card->caps & I2C_FANSPEED_MONITORING)
	{
		UInt16 rpm=nv_card->get_i2c_fanspeed_rpm(nv_card->sensor);
		data[0]=(rpm<<2)>>8;
		data[1]=(rpm<<2)&0xff;
	}
Ejemplo n.º 10
0
void dd_MLWriteSetFamily(dd_SetFamilyPtr F)
{
  long i,j;

  if (F!=NULL){
    MLPutFunction(stdlink,"List",F->famsize);
    for (i=0; i < F->famsize; i++) {
      MLPutFunction(stdlink,"List",set_card(F->set[i]));
      for (j=1; j <= F->setsize; j++) {
        if (set_member(j, F->set[i])) MLPutLongInteger(stdlink, j);
      }
    }
  }
}
Ejemplo n.º 11
0
int main()
{
	pcd pointer, *dp, fanswm;
	pcd dipai[3];		
	
	pointer = card;
	dp = dipai;
	
	set_card(pointer, 14, 4);
	set_card_ddz_ji(pointer, 14, 4);
	
	print_card(pointer, 14, 4);
	print_card2(pointer, 14, 4);
	print_card_ji(pointer);
	
	fapai(player, 3, 17, pointer, dp);
	
	print_player(player,3,17);
	print_dipai(dp);
	
	all_player_sort(player, 3, 17);
	print_player_no_hua(player,3,17);
	
}
Ejemplo n.º 12
0
IOReturn TemperatureSensor::OnKeyRead(const char* key, char* data) {
	if(!set_card(key[2]-'0')){
		char buf[80];
		printf("Error: %s\n", get_error(buf, 80));
		return kIOReturnSuccess;
	}
	switch(key[3]){
		case 'D':
			if(nv_card->caps & (GPU_TEMP_MONITORING)){
				data[0]=nv_card->get_gpu_temp(nv_card->sensor);
				data[1]=0;
				return kIOReturnSuccess;
			}
			break;
		case 'H':
			if(nv_card->caps & (BOARD_TEMP_MONITORING)) {
				data[0]=nv_card->get_board_temp(nv_card->sensor);
				data[1]=0;
				return kIOReturnSuccess;
			}
	}
	printf("Error: temperature monitoring isn't supported on your videocard.\n");
	return kIOReturnSuccess;
}
Ejemplo n.º 13
0
mxArray * FT_set_V_MatrixPtr(const dd_MatrixPtr M)
{
	mxArray * P;
	int mr, mv, m, i, j;
	int ir, iv;
	mxArray * tmpv;	
	mxArray * tmpr;	
	mxArray * tmpvpos;	
	mxArray * tmprpos;	
	mxArray * tmpl;	
	
	double * v;
	double * r; 
	double * vpos; 
	double * rpos; 
	double * l; 

	int k=0;
	dd_rowrange ii;
		
 	if ((M !=NULL) &&
 	    (M->representation == dd_Generator)) {
    		const char *f[] = {"V", "R", "rpos", "vpos", "lin"};
    		int dims[] = {1};

    		P = mxCreateStructArray(1, dims, 5, f);
		if (set_card(M->linset)) {
			tmpl = mxCreateDoubleMatrix(1, set_card(M->linset), mxREAL);
			l = mxGetPr(tmpl);		
    			for (ii=1; ii<=M->rowsize; ii++) {
      				if (set_member(ii, M->linset)) {
      					l[k] = (double)ii;
      					k ++;
      				}
      			}
      			mxSetField(P, 0, "lin", tmpl);
		}
		/* Count the rays and vertices */
		mr = 0;
		mv = 0;
		for (i = 0 ; i < (int)(M->rowsize); i++) {
			if (dd_get_d(M->matrix[i][0]) == 0) {
				mr++;
			} else { 
				mv++;
			}
		}
		m = mr + mv;
		/* Allocate the space in MATLAB */
		tmpr = mxCreateDoubleMatrix(mr, M->colsize - 1, mxREAL);
		r = mxGetPr(tmpr);
		tmpv = mxCreateDoubleMatrix(mv, M->colsize - 1, mxREAL);
		v = mxGetPr(tmpv);
		tmprpos = mxCreateDoubleMatrix(mr, 1, mxREAL);
		rpos = mxGetPr(tmprpos);
		tmpvpos = mxCreateDoubleMatrix(mv, 1, mxREAL);
		vpos = mxGetPr(tmpvpos);
		ir = 0; iv = 0;
	  	for (i = 0 ; i < m; i++) {
			if (dd_get_d(M->matrix[i][0]) == 0) {
				/* This is a ray */
    				for (j = 0; j < (int)(M->colsize) - 1; j++) {
      					r[ir + j * mr] = dd_get_d(M->matrix[i][j + 1]);
      				}
      				rpos[ir] = i + 1;
				ir++;
			} else { 
				/* This is a vertex*/
    				for (j = 0; j < (int)(M->colsize) - 1; j++) {
      					v[iv + j * mv] = dd_get_d(M->matrix[i][j + 1]);
      				}
      				vpos[iv] = i + 1;
				iv++;
			}

      		}		
      		mxSetField(P, 0, "V", tmpv);
      		mxSetField(P, 0, "R", tmpr);
      		mxSetField(P, 0, "vpos", tmpvpos);
      		mxSetField(P, 0, "rpos", tmprpos);
      		return P;
	}
	return 0;
}
Ejemplo n.º 14
0
bool NVClockX::start(IOService * provider)
{
	HWSensorsDebugLog("Starting...");
	
	if (!super::start(provider)) 
        return false;
    
    if ((videoCard = (IOPCIDevice*)provider)) 
    {
        if (videoCard->setMemoryEnable(true)) 
        {
            if ((nvio = videoCard->mapDeviceMemoryWithIndex(0))) 
            {
                IOVirtualAddress addr = nvio->getVirtualAddress();
                
                if (OSData * data = OSDynamicCast(OSData, videoCard->getProperty("device-id"))) 
                {
                    nvclock.card[nvclock.num_cards].device_id=*(UInt32*)data->getBytesNoCopy();
                    
                    
                    nvclock.card[nvclock.num_cards].arch = get_gpu_arch(nvclock.card[nvclock.num_cards].device_id);
                    nvclock.card[nvclock.num_cards].number = nvclock.num_cards;
                    nvclock.card[nvclock.num_cards].card_name = (char*)get_card_name(nvclock.card[nvclock.num_cards].device_id, &nvclock.card[nvclock.num_cards].gpu);
                    nvclock.card[nvclock.num_cards].state = 0;
                    
                    //nvclock.card[nvclock.num_cards].reg_address = addr;
                    
                    //map_mem_card(&nvclock.card[nvclock.num_cards], addr);
                    // Map the registers of the nVidia chip 
                    // normally pmc is till 0x2000 but extended it for nv40 
                    nvclock.card[nvclock.num_cards].PEXTDEV = (volatile unsigned int*)(addr + 0x101000);
                    nvclock.card[nvclock.num_cards].PFB     = (volatile unsigned int*)(addr + 0x100000);
                    nvclock.card[nvclock.num_cards].PMC     = (volatile unsigned int*)(addr + 0x000000);
                    nvclock.card[nvclock.num_cards].PCIO    = (volatile unsigned char*)(addr + 0x601000);
                    nvclock.card[nvclock.num_cards].PDISPLAY= (volatile unsigned int*)(addr + NV_PDISPLAY_OFFSET);
                    nvclock.card[nvclock.num_cards].PRAMDAC = (volatile unsigned int*)(addr + 0x680000);
                    nvclock.card[nvclock.num_cards].PRAMIN  = (volatile unsigned int*)(addr + NV_PRAMIN_OFFSET);
                    nvclock.card[nvclock.num_cards].PROM    = (volatile unsigned char*)(addr + 0x300000);
                    
                    // On Geforce 8xxx cards it appears that the pci config header has been moved 
                    if(nvclock.card[nvclock.num_cards].arch & NV5X)
                        nvclock.card[nvclock.num_cards].PBUS = (volatile unsigned int*)(addr + 0x88000);
                    else
                        nvclock.card[nvclock.num_cards].PBUS = nvclock.card[nvclock.num_cards].PMC + 0x1800/4;
                    
                    nvclock.card[nvclock.num_cards].mem_mapped = 1;
                    
                    HWSensorsInfoLog("%s device-id=0x%x arch=0x%x", 
                                     nvclock.card[nvclock.num_cards].card_name, 
                                     nvclock.card[nvclock.num_cards].device_id, 
                                     nvclock.card[nvclock.num_cards].arch);
                    
                    nvclock.num_cards++;
                }
                else HWSensorsWarningLog("device-id property not found");                
            }
            else {
                HWSensorsWarningLog("failed to map device's memory");
                return false;
            }
        }
    }else {
        HWSensorsWarningLog("failed to assign PCI device");
        return false;
    }
    
	char key[7];
	
	nvclock.dpy = NULL;
	
	for (int index = 0; index < nvclock.num_cards; index++) {
		/* set the card object to the requested card */
		if (!set_card(index)){
			char buffer[256];
			HWSensorsWarningLog("%s", get_error(buffer, 256));
			return false;
		}

        OSData *bios = OSDynamicCast(OSData, videoCard->getProperty("vbios"));

        nvclock.card[index].bios = read_bios(bios ? bios->getBytesNoCopy() : NULL);
        
		/* Check if the card is supported, if not print a message. */
		if(nvclock.card[index].gpu == UNKNOWN){
			HWSensorsWarningLog("it seems your card isn't officialy supported yet");
			HWSensorsWarningLog("please tell the author the pci_id of the card for further investigation");
			HWSensorsWarningLog("continuing anyway");
		}
        
        SInt8 cardIndex = getVacantGPUIndex();
        
        if (cardIndex < 0) {
            HWSensorsWarningLog("failed to obtain vacant GPU index");
            return false;
        }
        
		if(nv_card->caps & (GPU_TEMP_MONITORING)) {
            HWSensorsInfoLog("registering temperature sensors");
            
            if(nv_card->caps & BOARD_TEMP_MONITORING) {
                snprintf(key, 5, KEY_FORMAT_GPU_DIODE_TEMPERATURE, cardIndex);
                addSensor(key, TYPE_SP78, 2, kNVCLockDiodeTemperatureSensor, index);
                
				snprintf(key, 5, KEY_FORMAT_GPU_HEATSINK_TEMPERATURE, cardIndex);
				addSensor(key, TYPE_SP78, 2, kNVCLockBoardTemperatureSensor, index);
			}
            else {
                snprintf(key, 5, KEY_FORMAT_GPU_PROXIMITY_TEMPERATURE, cardIndex);
                addSensor(key, TYPE_SP78, 2, kNVCLockBoardTemperatureSensor, index);
            }
		}
		
		if (nv_card->caps & I2C_FANSPEED_MONITORING || nv_card->caps & GPU_FANSPEED_MONITORING){
            HWSensorsInfoLog("registering tachometer sensors");
            
            char title[6]; 
            
            snprintf (title, 6, "GPU %X", cardIndex);
            
			addTachometer(index, title);
		}
		
        HWSensorsInfoLog("registering frequency sensors");
        
        snprintf(key, 5, KEY_FAKESMC_FORMAT_GPU_FREQUENCY, index);
        addSensor(key, TYPE_UI32, TYPE_UI32_SIZE, kNVCLockCoreFrequencySensor, index);
        
        snprintf(key, 5, KEY_FAKESMC_FORMAT_GPU_MEMORY_FREQUENCY, index);
        addSensor(key, TYPE_UI32, TYPE_UI32_SIZE, kNVCLockMemoryFrequencySensor, index);
        
        snprintf(key, 5, KEY_FAKESMC_FORMAT_GPU_SHADER_FREQUENCY, index);
        addSensor(key, TYPE_UI32, TYPE_UI32_SIZE, kNVCLockMemoryFrequencySensor, index);
		
		/*OSNumber* fanKey = OSDynamicCast(OSNumber, getProperty("FanSpeedPercentage"));
         
         if((fanKey!=NULL)&(nv_card->set_fanspeed!=NULL)) {
         HWSensorsInfoLog("Changing fan speed to %d", fanKey->unsigned8BitValue());
         nv_card->set_fanspeed(fanKey->unsigned8BitValue());
         }
         
         OSNumber* speedKey=OSDynamicCast(OSNumber, getProperty("GPUSpeed"));
         
         if ((speedKey!=NULL)&(nv_card->caps&GPU_OVERCLOCKING)) {
         HWSensorsInfoLog("Default speed %d", (UInt16)nv_card->get_gpu_speed());
         //HWSensorsInfoLog("%d", speedKey->unsigned16BitValue());
         nv_card->set_gpu_speed(speedKey->unsigned16BitValue());
         HWSensorsInfoLog("Overclocked to %d", (UInt16)nv_card->get_gpu_speed());
         }*/
	}
    
    registerService();
	
	return true;
}
Ejemplo n.º 15
0
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;
}
Ejemplo n.º 16
0
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;
}
Ejemplo n.º 17
0
bool		PTnVmon::start	(IOService* provider) {
	bool result=IOService::start(provider);
	int card_number=0;
	
	nvclock.dpy = NULL;
	
	char* key = (char*)IOMalloc(5);
	
	max_card=probe_devices();
	
	if(!max_card){
		char buf[80];
		printf("Error: %s\n", get_error(buf, 80));
		return 0;
	}
	
	for (card_number=0; card_number<max_card; card_number++) {
		/* set the card object to the requested card */
		if(!set_card(card_number)){
			char buf[80];
			printf("Error: %s\n", get_error(buf, 80));
			return 0;
		}
	
		nvbios* bios=read_bios("");
		nvclock.card[card_number].bios=bios;
		
		/* Check if the card is supported, if not print a message. */
		if(nvclock.card[card_number].gpu == UNKNOWN){
			printf("It seems your card isn't officialy supported in FakeSMCnVclockPort yet.\n");
			printf("Please tell the author the pci_id of the card for further investigation.\n");
			printf("Continuing anyway\n");
		}

	
		if(nv_card->caps & (GPU_TEMP_MONITORING)){
			snprintf(key, 5, KEY_FORMAT_GPU_DIODE_TEMPERATURE, card_number);
			tempSensor[card_number]=new TemperatureSensor(key, TYPE_SP78, 2);
		
			if(nv_card->caps & (BOARD_TEMP_MONITORING)) {
				snprintf(key, 5, KEY_FORMAT_GPU_BOARD_TEMPERATURE, card_number);
				boardSensor[card_number]=new TemperatureSensor(key, TYPE_SP78, 2);
			}
		}
		
		
		
		if(nv_card->caps & (I2C_FANSPEED_MONITORING | GPU_FANSPEED_MONITORING)){
			int id=GetNextUnusedKey(KEY_FORMAT_FAN_ID, key);
			int ac=GetNextUnusedKey(KEY_FORMAT_FAN_SPEED, key);
			if (id!=-1 || ac!=-1) {
				int no=id>ac ? id : ac;
				char name[6]; 
				snprintf (name, 6, "GPU %d", card_number);
				snprintf(key, 5, KEY_FORMAT_FAN_ID, no);
				FakeSMCAddKey(key, TYPE_CH8, 4, name);			
				snprintf(key, 5, KEY_FORMAT_FAN_SPEED, no);
				fanSensor[card_number]=new FanSensor(key, TYPE_FPE2, 2);
				UpdateFNum();
			}
		}
		snprintf(key, 5, "FGC%d", card_number);
		gpuFreqSensor[card_number]=new FrequencySensor(key, "freq", 2);
	}
	IOFree(key, 5);
	return result;
}
Ejemplo n.º 18
0
u_cccr(char *pre, char *pos)
{
char    *q, *get_rand();
int     i, j, n, max, seq, nseq;
int     u, k, t;
OSET    *r, *p = &set_aux, *get_const_set();

   Operador = U_CCCR;
   if (g_tab_operador[Operador].percent == 0)
        return;

   u = sym.no;
   max = g_tab_operador[Operador].maximum;
   if (max == 0)
        max--;

   if (expre_pos.topo >= 0)
   {

       expre_completa(&expre_pos);     /* completa expressao */
       ex_aux = expre_pos;

       for (i = 0; i <= expre_pos.topo; i++)
       {            /* procura referencia do tipo desejado */

           if (! EH_CONST(expre_pos.no[i].tipo) || 
		expre_pos.no[i].tipo == STRING)    /* compatibility to 1.4 */
               continue;

           expre_exec_tipo(&expre_pos, expre_pos.no[i].final, i, tipo, ptar);

           r = get_const_set(tipo, ptar, &t);
	   t = expre_pos.no[i].tipo;

           set_dup(r, p);
           nseq = set_card(p);
           for (n = max,q = get_rand(p, Operador);
                     q != NULL && n != 0; q = get_rand(p, Operador), n--)
           {
                seq = set_inn(r, q);
                expre_substitui(&expre_pos, i, q, t);
                if (! expre_valida(&expre_pos))
                {
                   nseq = 0;
                   expre_pos = ex_aux;
                   break;
                }
                if (compara_expre(&expre_pos, &ex_aux))
                {
                   n++;
                   expre_pos = ex_aux;
                   continue;
                }

                monta_in_expre(&expre_pos, 0, expre_pos.topo);
                sprintf(bufmen, "%s %s ", pre, expre_pos.buf);
                strcat(bufmen, pos);
                add_descritor(sym.inicio, sym.comprimento, u, bufmen);
                sorteia_grupoU(Operador, Seq[Operador]+seq);

                expre_pos = ex_aux;

           }
           set_free(p);
           Seq[Operador] += nseq;
        }
   }
Ejemplo n.º 19
0
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;
}
Ejemplo n.º 20
0
Archivo: redund.c Proyecto: cran/rcdd
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;
}
Ejemplo n.º 21
0
u_ocor(char *pre, char *pos)
{

 char *q, *get_rand();
 int i, u, n, j, max, seq, nseq;
 OSET r, x, *p = &set_aux; 
 
 seq = 0;
 troca = OP_1_CAST;
 por = OP_1_CAST;

 Operador = U_OCOR;
 if (g_tab_operador[Operador].percent==0) return;

  set_new_inic(&r,"char\0unsigned char\0int\0float\0unsigned\0unsigned int\0short\0short int\0long\0long int\0unsigned long\0unsigned long int\0double\0long float\0");

   set_new_inic(&x, "char\0unsigned char\0int\0float\0unsigned\0short\0long\0unsigned long\0double\0");

 
 u = sym.no;
 max = g_tab_operador[Operador].maximum; 
 if (max ==0) max--;
 

   if (expre_pos.topo >= 0)
     {
       ex_aux = expre_pos;

       for (i = 0; i <= ex_aux.topo; i++)
         {		/* procura operador do tipo desejado */
	   if (ex_aux.no[i].tipo != troca ||
		 set_inn(&r, NOME((&ex_aux), i)) < 0) 
			continue;

 
           set_dup(&x, p);
           nseq = set_card(p);
           

           for (n = max, q = get_rand(p, Operador); 
		q != NULL && n != 0;	q = get_rand(p, Operador),n--)
            {	/* troca pelos outros operadores */

               	if (expre_pos.no[i].tipo == por && 
                    strcmp(NOME((&expre_pos), i), q) == 0)
		{
			n++;
		 	continue;
		}
		seq = set_inn(&x, q);

		expre_pos.no[i].tipo = por;
		expre_pos.no[i].nome = expre_pos.livre;
		strcpy(&(expre_pos.buf[expre_pos.livre]), q);
		expre_pos.livre += strlen(q)+1;
 
		if (expre_valida(&expre_pos))
		{
		  monta_in_expre(&expre_pos, 0, expre_pos.topo); /* monta infixa */
		  strcpy(bufmen, pre);
		  strcat(bufmen, expre_pos.buf);
                  sprintf(bufmen, "%s %s ",pre, expre_pos.buf);
		  strcat(bufmen, pos);
		  add_descritor(sym.inicio, sym.comprimento, u, bufmen);
  		  sorteia_grupoU(Operador, Seq[Operador] + seq);
	         }
		 else
		   n++;
		 expre_pos = ex_aux;
            }
	    set_free(p); 
            Seq[Operador] += nseq;
           }
	set_free(&r); set_free(&x);

      }
}
Card::Card(Rank kard_rank, Color kard_color)
{
	
	set_card(kard_rank, kard_color);
	
}