Ejemplo n.º 1
0
void prox(prob_vars * vars, all_data * data, prox_data * p_data)
{
	memcpy(vars->x_t,vars->x,sizeof(double)*data->n*(data->T+1));
	subArray(vars->x_t,vars->z,data->n*(data->T+1));
	memcpy(vars->u_t,vars->u,sizeof(double)*data->m*(data->T+1));
	subArray(vars->u_t,vars->y,data->m*(data->T+1));
//	#pragma omp parallel for
	for(int i=0;i<data->m*(data->T+1);i++){
		if(vars->u_t[i]>p_data->umax) vars->u_t[i]=p_data->umax;
		else if(vars->u_t[i]<p_data->umin) vars->u_t[i]=p_data->umin;
	}
}
Ejemplo n.º 2
0
void subArray(int W[], int V[], int k, int l, int n)
{
	int i;
	
	if (k == n-1)
	{
        //n是整个数组的长度,k是整个子集的上一位字符,当k == n-1时,意味着已经是最后一个了。
        priArray[l-1] = k;
        counter += 1;
        sumOfWeightAndValue(W, V, counter, l);
		printArray(W, l);
	}
	else
	{
		for ( i= k; i <= n-1; ++i)
		{
			priArray[l-1] = i;
            counter += 1;
            sumOfWeightAndValue(W, V, counter, l);
			printArray(W, l);
			subArray(W, V, i+1, l+1,n);
		}
	}
	
}
Ejemplo n.º 3
0
void censorBSONObjRecursive(const BSONObj& params,          // Object we are censoring
                            const std::string& parentPath,  // Set if this is a sub object
                            bool isArray,
                            BSONObjBuilder* result) {
    BSONObjIterator paramsIterator(params);
    while (paramsIterator.more()) {
        BSONElement param = paramsIterator.next();
        std::string dottedName =
            (parentPath.empty() ? param.fieldName()
                                : isArray ? parentPath : parentPath + '.' + param.fieldName());
        if (param.type() == Array) {
            BSONObjBuilder subArray(result->subarrayStart(param.fieldName()));
            censorBSONObjRecursive(param.Obj(), dottedName, true, &subArray);
            subArray.done();
        } else if (param.type() == Object) {
            BSONObjBuilder subObj(result->subobjStart(param.fieldName()));
            censorBSONObjRecursive(param.Obj(), dottedName, false, &subObj);
            subObj.done();
        } else if (param.type() == String) {
            if (_isPasswordArgument(dottedName.c_str())) {
                result->append(param.fieldName(), "<password>");
            } else {
                result->append(param);
            }
        } else {
            result->append(param);
        }
    }
}
Ejemplo n.º 4
0
void prox(prob_vars * vars, all_data * data, prox_data * p_data)
{
	double v[data->m*(data->T+1)];
	memcpy(v,vars->u,sizeof(double)*data->m*(data->T+1));
	subArray(v,vars->y,data->m*(data->T+1));

	memcpy(vars->x_t,vars->x,sizeof(double)*data->n*(data->T+1));
	subArray(vars->x_t,vars->z,data->n*(data->T+1));

	double nm,fac;
//	#pragma omp parallel for private(nm,fac)
	for(int i=0;i<data->T+1;i++){
		nm = nrm(&v[i*data->m],data->m);
		fac = 1-fminl(1/(1+data->rho),p_data->M/(data->rho*nm));
		for(int j=0;j<data->m;j++){
			vars->u_t[i*data->m+j]=fac*v[i*data->m+j];
		}
	}
}
Ejemplo n.º 5
0
void wordtree::subArray(word ** & arr, branch * b, int & cs, int & ds) const {
	if (b->val) {
		if (ds == cs) {
			ds = makeBigger(arr,cs);
		}
		arr[cs++] = b->val;
	}
	for (int i = 0; i < l; i++) {
		if (b->abc[i]) {
			subArray(arr, b->abc[i], cs, ds);
		}
	}
}
Ejemplo n.º 6
0
void prox(prob_vars * vars, all_data * data, prox_data * p_data)
{
	memcpy(vars->x_t,vars->x,data->n*(data->T+1)*sizeof(double));
	subArray(vars->x_t,vars->z,data->n*(data->T+1));

	memcpy(vars->u_t,vars->u,data->m*(data->T+1)*sizeof(double));
	subArray(vars->u_t,vars->y,data->m*(data->T+1));

	/* The proximal step using bisection (x_t, u_t) */
	int idx;
	#pragma omp parallel for private(idx)
	for ( int t = 0; t < data->T+1; t++ ) {
		for ( int j = 0; j < p_data->numsource; j++ ) {	
			idx = t*data->m + p_data->idx_source[j];
			/* Saturate the inputs */
			vars->u_t[idx] =  -fminl(-fminl(vars->u_t[idx],p_data->U), 0);
		}

		for ( int i = 0; i < data->n; i++ ){  /* For every node... */
			idx = t*data->n+i;
			bisection(data,&(vars->u_t[t*data->m]), &(vars->x_t[idx]), p_data, i);
		}
	}
}
Ejemplo n.º 7
0
int main()
{
	int i;
    int max;
	
	int array[4] = {7, 3 , 4, 5};
    int value[4] = {42, 12, 40, 25};
    
    //0是所有数组的子集
    printf("The No.1 is: 0\n");
    subArrayWeight[0] = 0;
    subArrayValue[0] = 0;
    counter = 1;
	
	for (i = 0; i < 4; i++)
	{
        initArray(4);
		//递归算法需要保证从第一个元素开始的所有的元素都被遍历到
		priArray[0] = i;
        counter ++;
        sumOfWeightAndValue(array, value, counter, 1);
		printArray(array, 1);
		subArray(array, value, i+1, 2, 4);	
	}
    
    printf("\nThere are %d SubArray.\n", counter);
    
    for (i = 0; i < 16; i++)
    {
        printf("The Weight of %d is %d and the value is %d\n", i+1 , subArrayWeight[i], subArrayValue[i]);
    }
    
    max = searchMax();
    printf("\nThe most valuable package is No.%d, the max value is %d.\n", max+1, subArrayValue[max]);
    
	return 0;
}