void OpenSMOKE_SensitivityAnalysis::GiveMe_SensitivityCoefficients(const double deltat)
{
	// Implicit Method
	if (iImplicit == true)
	{
		JAlfa *= deltat;
		Sum(JAlfa, Sold, &Sold);
		Jacobian *= -deltat;
		Sum(I,Jacobian, &Jacobian);

		BzzFactorizedGauss AFactorized(Jacobian);
		Solve(&AFactorized, Sold, &S);
	}
/*	else
	// Explicit Method
	{
		Product(JacobianOld, Sold, &S);
		Sum(JacobianOld, JalfaOld, &JacobianOld);

		JacobianOld	*= deltat;
				
		Sum(Sold, JacobianOld, &S);
	}*/

	// Update old value
	Sold = S;
}
Exemplo n.º 2
0
int main()
{
    int N = 50;
    
    int PenDrive = 4000;
    int *Arquivos = (int*)malloc(sizeof(int) * N);
    GenerateFiles(Arquivos, N, 300);

    int *Arq = Sort(Arquivos,N);


    printf("Total espeaço: %i\n", PenDrive);
    printa(Arq, N);

    int soma = 0, i=0;
    soma = Sum(Arq,N);
    printf("Total Arquivos (MB): %i \n",soma);

    for(i=0;i<N ;i++)
        if(PenDrive >= Arq[i]){
            printf("+ %i MB\n", Arq[i]);
            PenDrive -= Arq[i];
            Arq[i] = 0;
        }

    printf("Sobrou (MB): %i \n",PenDrive);

    soma= Sum(Arq,N);
    printf("Sobrou %i MB nos Arquivos!\n",soma);
    return 0;
}
Exemplo n.º 3
0
vector<vector<int> > FourSum::fourSum(vector<int> &num, int target) {
	vector<Sum> doubleSum;
	vector<vector<int> > result;
	
	for (int i = 0; i < num.size(); i++) {
		for (int j = i + 1; j < num.size(); j++) {
			Sum sum = Sum(num[i]+num[j], i, j);
			doubleSum.push_back(sum);
		}
	}
	sort(doubleSum.begin(), doubleSum.end());
	for (vector<Sum>::iterator i = doubleSum.begin(); i != doubleSum.end(); i++) {
		vector<Sum>::iterator start = lower_bound(doubleSum.begin(), doubleSum.end(), Sum(target-(i->value)));
		if (start != doubleSum.end() && (start->value) + (i->value) == target) {
			vector<Sum>::iterator iter = start;
			while (iter != doubleSum.end() && (iter->value) == (start->value)) {
				if ((iter->x != i->x) && (iter->x != i->y) && (iter->y != i->x) && (iter->y != i->y)) {
					vector<int> elem;
					elem.push_back(num[iter->x]);
					elem.push_back(num[iter->y]);
					elem.push_back(num[i->x]);
					elem.push_back(num[i->y]);
					sort(elem.begin(), elem.end());
					if (find(result.begin(), result.end(), elem) == result.end())
						result.push_back(elem);
				}
				iter++;
			}
		}
	}
	return result;
}
void OpenSMOKE_KPP_SingleReactor::SolveCSTR_Corrector_Linearized(const double deltat, BzzMatrix &tmpMatrix)
{
	// Reactions	
	kinetics->UpdateProperties(omega_, temperature_, pressure_, R_);
	Product(volume_, R_, &RV_);
	GetJacobian(omega_, tmpMatrix);				// A = d(RV)/domega * Volume/mtot;

	// The formulation is the same, both for deferred=on and deferred=off
	// The difference is the Jacobian calculation (see GetJacobian function)
	if (data_->PredictorCorrector_DeferredConvection() == false || 
		data_->PredictorCorrector_DeferredConvection() == true)
	{
		// Rigth hand side
		Product(-M_, omega_, &rhs_);		//	outflow
		Sum(&rhs_, RV_);				//	reaction
		Sum(&rhs_, mInTot_);			//  inflow
		rhs_ *= deltat/mass_;		
	
		// Matrix
		tmpMatrix *= -deltat;			
		for(int i=1;i<=numberOfSpecies;i++)
			tmpMatrix[i][i] += 1.;
	
		// Linear System solution
		BzzFactorizedGauss AGauss(tmpMatrix);
		Solve(AGauss, &rhs_);

		// Updating
		omega_ += rhs_;
	}
}
void OpenSMOKE_KPP_SingleReactor::ODESystemContinousReactor(BzzVector &omega, double t, BzzVector &domega)
{
	if (data_->PredictorCorrector_DeferredConvection() == true || 
		data_->networkStatus() == KPP_NETWORK_STATUS_SEQUENTIAL_CSTR )
	{
		// Formation rates
		kinetics->UpdateProperties(omega, temperature_, pressure_, R_);
		Product(volume_, R_, &RV_);

		// mass*domegaj = -mOut*omegaj + mjIn + Rj*V
		Product(-M_, omega, &domega);
		Sum(&domega, RV_);
		Sum(&domega, mInTot_);
		domega /= mass_;
	}
	else
	{
		// Formation rates
		kinetics->UpdateProperties(omega, temperature_, pressure_, R_);
		Product(volume_, R_, &RV_);

		// mass*domegaj = -mOut*omegaj(n) + mjIn + Rj*V
		domega = RV_;
		Sum(&domega, mInTot_);
		Difference(&domega, mOut_x_omega_old_);
		domega /= mass_;
	}
}
Exemplo n.º 6
0
int main()
{
	freopen("t.in", "r", stdin);
	scanf("%d\n", &n);
	for(int i = 1, a, b; i < n; i ++)
	{
		scanf("%d %d\n", &a, &b);
		Add_Edge(a, b);
		Add_Edge(b, a);
	}
	dfs(1);
	for(int i = 1; i <= n; i ++)
		Update(start[i], exist[start[i]] ^= 1);
	scanf("%d\n", &m);
	while(m --)
	{
		char ctrl;
		int x;
		scanf("%c %d\n", &ctrl, &x);
		if(ctrl == 'C')
		{
			int v;
			exist[start[x]] ^= 1;
			if(exist[start[x]]) v = 1;
			else v = -1;
			Update(start[x], v);
		}
		else
			printf("%d\n", Sum(over[x]) - Sum(start[x] - 1));
	}
}
Exemplo n.º 7
0
static void CompressBlock(JPEGCompressor *self,int comp,
const JPEGBlock *current,const JPEGBlock *north,const JPEGBlock *west,
const JPEGQuantizationTable *quantization)
{
	// Calculate EOB context.
	int average;
	if(!north&&!west) average=0;
	else if(!north) average=Sum(0,west);
	else if(!west) average=Sum(0,north);
	else average=(Sum(0,north)+Sum(0,west)+1)/2;

	int eobcontext=Min(Category(average),12);

	// Write EOB bits using binary tree.
	WriteBitString(&self->encoder,current->eob,6,
	self->eobbins[comp][eobcontext],
	self->eobshift);

	// Compress AC components in decreasing order, if any.
	for(unsigned int k=current->eob;k>=1;k--)
	{
		CompressACComponent(self,comp,k,k!=current->eob,current,north,west,quantization);
	}

	// Compress DC component.
	CompressDCComponent(self,comp,current,north,west,quantization);
}
Exemplo n.º 8
0
int main() {
    int n;
    while (scanf("%d", &n) && n < 3) {
        if (n == 0) {
            scanf("%d", &size);
            memset(C, 0, sizeof(C));
        } else if (n == 1) {
            int x, y, a;
            scanf("%d %d %d", &x, &y, &a);
            x += 1;
            y += 1;
            A[x][y] += a;
            Add(x, y, a);
        } else if (n == 2) {
            int l, b, r, t;
            scanf("%d %d %d %d", &l, &b, &r, &t);
            l += 1;
            b += 1;
            r += 1;
            t += 1;
//            printf("%d\n", Sum(max(l, r), max(b, t)) - Sum(min(l, r), max(b, t)));
            printf("%d\n", Sum(r, t) + Sum(l - 1, b - 1) - Sum(r, b - 1) - Sum(l - 1, t));
        }
        for (int i = 0; i <= 10; i++) {
            for (int j = 0; j <= 10; ++j) {
                printf("%d ", C[i][j]);
            }
            printf("\n");
        }
        printf("\n");
    }
}
 //s is the previous sum from the ancestors
 int Sum(TreeNode* root, int s)
 {
     if(!root) return 0;
     //reaches the leaf, calculate this path sum
     if((!root->left)&&(!root->right)) return s*10+root->val;
     //recurse into the left and right subtree
     return Sum(root->left,s*10+root->val)+Sum(root->right,s*10+root->val);
 }
TEST(Util, SumTest) {
    VVReal tmp;
    Init(2, 2, 1.0, &tmp);
    EXPECT_DOUBLE_EQ(4, Sum(tmp));
    VVVReal tmp2;
    Init(2, 2, 2, 2.0, &tmp2);
    EXPECT_DOUBLE_EQ(16, Sum(tmp2));
}
Exemplo n.º 11
0
func Flacker()
{
  if(Not(Random(15))) And(CastObjects(SU3V,Sum(1,Random(1)),Sum(5,Random(15)),Sum(-14,Random(28)),Sum(1,Random(2))),Sound("Spark*"));
  if(Not(Random(2))) return(0);
  if(Random(6)) return(ObjectSetAction(Local(0),"Neon")&&SetAction("FlackerAn"));
  if(Random(6)) return(ObjectSetAction(Local(0),"Aus")&&SetAction("FlackerAus"));
  return(1);
}
Exemplo n.º 12
0
void LayerConv::CalcWeights(Layer *prev_layer, int passnum) {
  StartTimer();

  if (passnum < 2) return;
  Mat weights_der;
  if (passnum == 2) {
    weights_der.attach(weights_.der());
  } else if (passnum == 3) {
    weights_der.attach(weights_.der2());    
  }
  #if COMP_REGIME != 2
    std::vector< std::vector<Mat> > prev_activ, filters_der, deriv;
    InitMaps(prev_layer->activ_mat_, prev_layer->mapsize_, prev_activ); 
    InitMaps(weights_der, filtersize_, filters_der);
    InitMaps(deriv_mat_, mapsize_, deriv);
    size_t i,j;
    int k;
    //#pragma omp parallel{ //for num_threads(12) private(fil_der)
    for (i = 0; i < outputmaps_; ++i) {
      for (j = 0; j < prev_layer->outputmaps_; ++j) {

        Mat fil_der(filtersize_);
        fil_der.assign(0);      
        #if COMP_REGIME == 1
        #endif
        for (k = 0; k < batchsize_; ++k) {
          Mat ker_mat(filtersize_);
          Filter(prev_activ[k][j], deriv[k][i], padding_, false, ker_mat);      
          #if COMP_REGIME == 1
            //#pragma omp critical
          #endif
          fil_der += ker_mat; 
                   
        }
        filters_der[i][j] = fil_der;        
      }        
    }    
  #else // GPU    
    WeightActs(prev_layer->activ_mat_, deriv_mat_, weights_der,
               prev_layer->mapsize_, filtersize_[0], 
               padding_[0], sum_width_, !unshared_);        
  #endif
  weights_der /= (ftype) batchsize_;
  weights_der.Validate();
  if (passnum == 2) {
    mexAssert(deriv_mat_.order() == false, "deriv_mat_.order() should be false");
    if (!unshared_) {
      deriv_mat_.reshape(batchsize_ * deriv_mat_.size2() / outputmaps_, outputmaps_);
      Sum(deriv_mat_, biases_.der(), 1);
      deriv_mat_.reshape(batchsize_, deriv_mat_.size1() * outputmaps_ / batchsize_);        
    } else {
      Sum(deriv_mat_, biases_.der(), 1);      
    }
    (biases_.der() /= (ftype) batchsize_) *= bias_coef_;
    biases_.der().Validate();
  }
  MeasureTime("CalcWeights Conv Layer",2);
}
	wxInt32 FindTotal(wxInt32 player)
	{
		wxInt32 total = 0;
		total += Sum(shPlayableTradeCards, player);
		total += Sum(shPlayableScienceCards, player);
		total += Sum(shPlayablePoliticsCards, player);

		return total;
	}
Exemplo n.º 14
0
inline void Tupdate(int x)
{
    Size(x)=Size(Lch(x))+1+Size(Rch(x));
    Sum(x)=Sum(Lch(x))+Val(x)+Sum(Rch(x));
    Lms(x)=max(Lms(Lch(x)),Sum(Lch(x))+Val(x)+Lms(Rch(x)));
    Rms(x)=max(Rms(Rch(x)),Rms(Lch(x))+Val(x)+Sum(Rch(x)));
    Ms(x)=Rms(Lch(x))+Val(x)+Lms(Rch(x));
    if (Lch(x))    Ms(x)=max(Ms(x),Ms(Lch(x)));
    if (Rch(x))    Ms(x)=max(Ms(x),Ms(Rch(x)));
}
Exemplo n.º 15
0
void Code4() {
  int i_array[] = {1, 2, 3};
  std::cout << Sum(i_array, 0) << "\n";
  std::vector<int> i_vec = {4, 5, 6};
  std::cout << Sum(i_vec, 0) << "\n";
  std::vector<std::string> str_vec = {
    "ふるいけや", "かわずとびこむ", "みずのおと"
  };
  std::cout << Sum(str_vec, std::string("")) << "\n";
}
Exemplo n.º 16
0
void pull( Treap * a ){
	a->sum = Sum( a->l ) + Sum( a->r ) + a->val;
	a->lsum = Sum( a->l ) + a->val + max( 0 , lSum( a->r ) );
	if( a->l ) a->lsum = max( lSum( a->l ) , a->lsum );
	a->rsum = Sum( a->r ) + a->val + max( 0 , rSum( a->l ) );
	if( a->r ) a->rsum = max( rSum( a->r ) , a->rsum );
	a->maxsum = max( 0 , rSum( a->l ) ) + a->val + max( 0 , lSum( a->r ) );
	a->maxsum = max( a->maxsum , max( maxSum( a->l ) , maxSum( a->r ) ) );
	a->sz = Size( a->l ) + Size( a->r ) + 1;
}
Exemplo n.º 17
0
//---------------------------------------------------------------------------
wxSize wxMultiCellSizer::CalcMin()
{
    if (m_children.GetCount() == 0)
        return wxSize(10,10);

    GetMinimums();
    int m_minWidth = Sum(m_maxWidth, m_cell_count.GetWidth());
    int m_minHeight = Sum(m_maxHeight, m_cell_count.GetHeight());
    return wxSize( m_minWidth, m_minHeight );
}
Exemplo n.º 18
0
 Value Sum(int ql, int qr, int v, int l, int r) {
   assert(0 <= l && l <= ql && ql <= qr && qr <= r && r < size_);
   if (ql == l && qr == r) {
     return tree_[v];
   }
   int mid = (l + r) / 2;
   if (qr <= mid) return Sum(ql, qr, 2 * v + 1, l, mid);
   if (ql >= mid + 1) return Sum(ql, qr, 2 * v + 2, mid + 1, r);
   return join(Sum(ql, mid, 2 * v + 1, l, mid),
               Sum(mid + 1, qr, 2 * v + 2, mid + 1, r));
 }
Exemplo n.º 19
0
int Sum(struct node *root, int sum)
{
   if(root==NULL) 
    return 0;
   
   sum = sum *10 + root->data;
   if(root->left == NULL && root->right==NULL)
    return sum;
   else
    return Sum(root->left, sum) + Sum(root->right, sum);

}
Exemplo n.º 20
0
Mistral2_Expression* Mistral2_Sum::add(Mistral2Solver *solver, bool top_level){
  if(!has_been_added()) {
#ifdef _DEBUGWRAP
    std::cout << "add sum constraint" << std::endl;
#endif
    _solver = solver;
    
    // _v * _w + o = _x
    // _v * _w - _x = -o 

    
    int i, n=_vars.size();  
    Mistral::VarArray scope(n);
    Mistral::Vector<int> w;
    bool weighted = false;
    bool boolean = true;
    w.initialise(n, n);

    for(i=0; i<n; ++i) {

      _vars.get_item(i)->add(_solver,false);
      if(_weights.size() > i)
	w[i] = _weights.get_item(i);
      else
	w[i] = 1;
      scope[i] = _vars.get_item(i)->_self;

      if(w[i] != 1) weighted = true;
      if(!scope[i].is_boolean()) boolean = false;
    }
    //w[n] = _weights.get_item(n);
 

    if(boolean) {
      if(weighted)
	_self = BoolSum(scope, w);
      else
	_self = BoolSum(scope, w);
    } else {
      if(weighted)
	_self = Sum(scope, w, -Mistral::INFTY, Mistral::INFTY, _offset);
      else
	_self = Sum(scope, w, -Mistral::INFTY, Mistral::INFTY, _offset);
    }
    
    if( top_level ) {
      _solver->solver->add( _self );
    } 
  }

  return this;
}
Exemplo n.º 21
0
 CryptoPP::ECP::Point Mul (const CryptoPP::ECP::Point& p, const CryptoPP::Integer& e) const
 {
     CryptoPP::ECP::Point res {0, 1};
     if (!e.IsZero ())
     {
         auto bitCount = e.BitCount ();
         for (int i = bitCount - 1; i >= 0; i--)
         {
             res = Sum (res, res);
             if (e.GetBit (i)) res = Sum (res, p);
         }
     }   
     return res;
 } 
double OpenSMOKE_KPP_SingleReactor::Residuals(BzzVector& omega, BzzVector& residuals)
{
	kinetics->UpdateProperties(omega, temperature_, pressure_, R_);
	Product(volume_, R_, &RV_);

	Product(-M_, omega, &residuals);		
	Sum(&residuals, RV_);				
	Sum(&residuals, mInTot_);	

	Product(-1, &residuals);

	double F = residuals.GetSumAbsElements() / double(numberOfSpecies);

	return F;
}
namespace DefaultArguments {

const int z = int();
constexpr int Sum(int a = 0, const int &b = 0, const int *c = &z, char d = 0) {
  return a + b + *c + d;
}
const int four = 4;
constexpr int eight = 8;
constexpr const int twentyseven = 27;
static_assert(Sum() == 0, "");
static_assert(Sum(1) == 1, "");
static_assert(Sum(1, four) == 5, "");
static_assert(Sum(1, eight, &twentyseven) == 36, "");
static_assert(Sum(1, 2, &four, eight) == 15, "");

}
Exemplo n.º 24
0
int main()
{
	int abundant[28000];
	int i,j,s=0,c=0;
	for(i=1;i<=28200;i++)
	{
		if(Sum(i)>i) 
		{
			//printf("%d ",i);
			abundant[c]=i;c++;
		}
	}
	//C will come out to be the size of array.C-1 wil be last abundant no.
	int HASH[28200];
	//HASH=(int *)malloc(c*sizeof(int));
	for(i=0;i<28200;i++) HASH[i]=0;
	for(i=0;i<c;i++)
	{
		for(j=0;j<c;j++)
		{
			s=abundant[i]+abundant[j];
			if(s<=28200) HASH[s]=1;
		}
	}
	long long sum=0;
	//print the no. wich cannot be break into 2 abundant no.
	for(i=0;i<28200;i++)
	{
		if(HASH[i]==0) sum=sum+i;//printf("%d ",i);
	}
	printf("%lld",sum);
	
	
}
Exemplo n.º 25
0
int main()
{
    scanf("%d",&N);
    for (int i=1;i<=N;++i)
    {
        scanf("%d",&Val(i));
        Sum(i)=Ms(i)=Lms(i)=Rms(i)=Val(i);
        Par(i)=i-1,Rch(i-1)=i,Size(i)=N-i+1;
        splay(root,i);
    }
    splay(root,1),Par(N+1)=1,Lch(1)=N+1,Size(N+1)=1,splay(root,N+1);
    splay(root,N),Par(N+2)=N,Rch(N)=N+2,Size(N+2)=1,splay(root,N+2);
    tot=N+2;
    for (scanf("%d",&Que);Que--;)
    {
        scanf("%s%d",cmd,&x);
        if (cmd[0]=='D')    D(Findkth(root,x+1));
        else
        {
            scanf("%d",&y);
            if (cmd[0]=='Q')    Q(Findkth(root,x),Findkth(root,y+2));
            else
            if (cmd[0]=='I')    I(Findkth(root,x+1),y);
            else    R(Findkth(root,x+1),y);
        }
    }
	print_r(root); printf("\n");
	print_l(root); printf("\n");
    return 0;
}
Exemplo n.º 26
0
	int Sha::_Sum(lua_State* L){
		// check arg
		if((lua_gettop(L)<2) || (lua_isnumber(L, 1)==0) || (lua_isstring(L, 2)==0)){
			lua_pushnil(L);
			lua_pushstring(L, "invalid arg");
			return 2;
		}
		const int64_t type =static_cast<int64_t>(lua_tonumber(L, 1));
		if(!(type>=TYPE_MIN && type<=TYPE_MAX)){
			lua_pushnil(L);
			lua_pushstring(L, "invalid arg, type is out of range");
			return 2;
		}
		size_t s;
		const char* data =lua_tolstring(L, 2, &s);
		ASSERT(data);

		// sum
		char result[SHA512_BUFFER_LENGTH + 1] ={0};
		if(Sum(type, data, s, result)){
			lua_pushstring(L, result);
			return 1;
		}
		else{
			lua_pushnil(L);
			lua_pushstring(L, "Sha::Sum error");
			return 2;
		}
	}
Exemplo n.º 27
0
u64 SumOfDivisorsOfBinomialCoefficient(u64 n, u64 k) {
    if (n == 2) {
        return k == 1 ? 3 : 1;
    } else if (n < 2) {
        return 1;
    }

    Vector primes = GetPrimes(n);
    Vector powers;
    for (auto x: primes) {
        powers.push_back(
            PowerOfDivisor(x, n) -
            PowerOfDivisor(x, k) -
            PowerOfDivisor(x, n - k) 
        );
    }

    u64 result = 1;
    for (u64 i = 0; i < primes.size(); ++i) {
        u64 sum_of_powers = 0;
        u64 x = 1;
        for (u64 p = 0; p <= powers[i]; ++p) {
            sum_of_powers = Sum(sum_of_powers, x);
            x = Mul(x, primes[i]);
        }
        result = Mul(result, sum_of_powers);
    }
    return result;
}
Exemplo n.º 28
0
double Average(const vector<double>& v)
{
	double av = Sum(v);
	if (!v.empty())
		av /= (double)v.size();
	return av;
}
Exemplo n.º 29
0
void * reduce_phase2(const void * _exp)
{
	if(isA(_exp, Integer()))
		return domainCast(_exp, Real());
	else if(isA(_exp, Real()) || isA(_exp, Var()))
		return copy(_exp);
	else if(isA(_exp, Sum()) || isA(_exp, Product()))
	{
		void * s = copy(_exp);
		size_t i;
		for(i = 0; i < size(s); ++i)
		{
			delete(argv(s, i));
			setArgv(s, i, reduce_phase2(argv(_exp, i)));
		}
		return s;
	}
	else if(isA(_exp, Pow()))
	{
		void * p = copy(_exp);
		delete(base(p));
		delete(power(p));
		setBase(p, reduce_phase2(base(_exp)));
		setPower(p, reduce_phase2(power(_exp)));
		return p;
	}
	else if(isOf(_exp, Apply_1()))
	{
		void * f = copy(_exp);
		delete(arg(f));
		setArg(f, reduce_phase2(arg(_exp)));
		return f;
	}
	assert(0);
}
Exemplo n.º 30
0
/* ----------------------------------------------------------------------------
** procedure for making the Abel integration for deconvolution of the image
**        y    <-> array with values for deconvolution and results
**        N    <-  width of the array
**        adl  <-  array with pre-calculated weighting factors
*/
static void 
abel ( float *y, int N, double *adl)
{
    register int n;
    double *rho, *rhop;       /* results and new index                       */
    float  *yp;               /* new indizes for the y-array                 */

    MALLOCARRAY(rho, N);
    if( !rho )
        pm_error( "out of memory" );
    rhop = rho;
    yp  = y;

    for (n=0 ; n<N ; n++)
    {
        *(rhop++) = ((*yp++) - Sum(n,rho,N,adl))/(adl[n*N+n]);
/*    *(rhop++) = ((*yp++) - Sum(n,rho,N))/(dr(n,n+0.5,N));  old version */
        if ( *rhop < 0.0 ) *rhop = 0.0;         /*  error correction !       */
/*   if (n > 2) rhop[n-1] = (rho[n-2]+rho[n-1]+rho[n])/3.0;  stabilization*/
    }
    for (n=0 ; n<N ; n++)
        {
            if (( n>=1 )&&( n<N-1 ))
	       (*y++) = ((rho[n-1]*0.5+rho[n]+rho[n+1]*0.5)/2.0);/*1D median filter*/
            else (*y++) = rho[n];
        }
    free(rho);
}