示例#1
0
void linear::fill_lambda(){ 

#ifdef LOAD
  std::cout << " Reading labmda matrices" << std::endl;
  loadMarket(lambda_x, "lambda_x.mtx");
  loadMarket(lambda_y, "lambda_y.mtx");
#else

  //  div( vectorf,  inter_scalarf );

  std::cout << " Filling lambda matrices" << std::endl;

  std::vector<triplet> ax;            // list of non-zeros coefficients
  std::vector<triplet> ay;            // list of non-zeros coefficients

  int N=0;

  for(F_v_it fv=T.finite_vertices_begin();
      fv!=T.finite_vertices_end();
      fv++)  {

    ++N;

    int vi=fv->idx.val();

    typedef Vertex::vector_link vector_link;

    vector_link nabla=fv->nabla();

    for(
	vector_link::iterator nn= nabla.begin();
	nn!=nabla.end(); ++nn) {

      int vj=nn->first->idx.val();

      Vector_2 nnabla=nn->second;

      ax.push_back( triplet(vi,vj, nnabla.x() ));
      ay.push_back( triplet(vi,vj, nnabla.y() ));

    }

  }

  lambda_x.resize(N,N);
  lambda_y.resize(N,N);

  lambda_x.setFromTriplets(ax.begin(), ax.end());
  lambda_y.setFromTriplets(ay.begin(), ay.end());

#endif

  std::cout << " Filled lambda matrices" << std::endl;
  cout << "matrix size " << lambda_x.rows() << " x " << lambda_x.cols() << endl;

  return;

}
示例#2
0
文件: JGE.cpp 项目: TomK14/w-menu
void JGE::HoldKey(const JButton sym)
{
#if defined (WIN32) || defined (LINUX)
    if (JGE_BTN_FULLSCREEN == sym) JGEToggleFullscreen();
#endif
    if (!held(sym))
    {
        keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, false));
        holds[sym] = REPEAT_DELAY;
    }
    else keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, true));
}
示例#3
0
文件: JGE.cpp 项目: TomK14/w-menu
void JGE::PressKey(const LocalKeySym sym)
{
    const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
    if (rng.first == rng.second)
        keyBuffer.push(triplet(sym, JGE_BTN_NONE, false));
    else for (keycodes_it it = rng.first; it != rng.second; ++it)
    {
#if defined (WIN32) || defined (LINUX)
        if (JGE_BTN_FULLSCREEN == it->second) JGEToggleFullscreen();
#endif
        keyBuffer.push(triplet(*it, held(it->second)));
    }
}
示例#4
0
/* go from triplets to rank array */
uint32_t *ranks(triplet *T, size_t sz, size_t *retsz, bool *unique) {
    /* remember old positions */
    for (size_t i = 0; i < sz; i++) {
        T[i].label = i;
    }
    vprint("T", T, sz);
    lsd_sort(T, sz);
    vprint("Tsort", T, sz);

    uint32_t *ranks = new uint32_t[sz + 2];
    *retsz = sz;
    uint32_t cur_rank = 0;
    triplet prev = triplet(999999, 999999, 999999);
    *unique = true;
    for (size_t i = 0; i < sz; i++) {
        if (prev != T[i]) {
            cur_rank += 1;
            prev = T[i];
        } else {
            *unique = false;
        }
        ranks[T[i].label] = cur_rank;
    }
    return ranks;
}
示例#5
0
文件: JGE.cpp 项目: TomK14/w-menu
void JGE::PressKey(const JButton sym)
{
#if defined (WIN32) || defined (LINUX)
    if (sym == JGE_BTN_FULLSCREEN) JGEToggleFullscreen();
#endif
    keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, held(sym)));
}
示例#6
0
// first sort, then fix a num and search in 2sum
set<vector<int> > find_triplets(vector<int> arr) {
  sort(arr.begin(), arr.end());
  set<vector<int> > triplets;
  vector<int> triplet(3);
  int n = arr.size();
  for (int i = 0;i < n; i++) {
    int j = i + 1;
    int k = n - 1;

    while (j < k) {
      int sum_two = arr[i] + arr[j];
      if (sum_two + arr[k] < 0) {
        j++;
      } else if (sum_two + arr[k] > 0) {
        k--;
      } else {
        triplet[0] = arr[i];
        triplet[1] = arr[j];
        triplet[2] = arr[k];
        triplets.insert(triplet);
        j++;
        k--;
      }
    }
  }
  return triplets;
}
SparseMatrix neighbors_distances_matrix(RandomAccessIterator begin, RandomAccessIterator end,
                                        const Neighbors& neighbors, DistanceCallback callback,
                                        ScalarType& average_distance)
{
	const IndexType k = neighbors[0].size();
	const IndexType n = neighbors.size();
	if ((end-begin)!=n)
		throw std::runtime_error("Wrong size");
	SparseTriplets sparse_triplets;
	sparse_triplets.reserve(k*n);
	average_distance = 0;
	ScalarType current_distance;

	for (IndexType i = 0; i < n; ++i)
	{
		const LocalNeighbors& current_neighbors = neighbors[i];
		for (IndexType j = 0; j < k; ++j)
		{
			current_distance = callback.distance(begin[i], begin[current_neighbors[j]]);
			average_distance += current_distance;
			SparseTriplet triplet(i, current_neighbors[j], current_distance);
			sparse_triplets.push_back(triplet);
		}
	}
	average_distance /= (k*n);
	return sparse_matrix_from_triplets(sparse_triplets, n, n);
}
示例#8
0
 vector<vector<int> > threeSum(vector<int> &num) {
     int n = num.size();
     vector<vector<int>> result;
     vector<int> triplet(3, 0);
     int sum;
     int i, l, r;
     
     sort(num.begin(), num.end());
     for (i = 0; i < n; i++) {
         if (i > 0 && num[i] == num[i-1]) continue;
         l = i+1;
         r = n-1;
         while (l < r) {
             sum = num[i] + num[l] + num[r];
             if (sum == 0) {
                 triplet[0] = num[i];
                 triplet[1] = num[l];
                 triplet[2] = num[r];
                 result.push_back(triplet);
                 do {
                     l++;
                 } while (l < r && num[l] == num[l-1]);
                 do {
                     r--;
                 } while (l < r && num[r] == num[r+1]);
             } else if (sum < 0) {
                 l++;
             } else {
                 r--;
             }
         }
     }
     return result;
 }
示例#9
0
文件: 3Sum.cpp 项目: lxstorm/LeetCode
    vector<vector<int>> threeSum(vector<int>& nums) {
        vector<vector<int>> res;
        vector<int> triplet(3,0);

        sort(nums.begin(), nums.end());
        for(int i = 0;i < nums.size();++i){
            int target = -nums[i];
            int front = i + 1;
            int back = nums.size() - 1;

            while(front < back){
                int sum = nums[front] + nums[back];
                //use if else not 3 if statement because they are parallel;
                if(sum < target)
                    ++front;
                else if(sum > target)
                    --back;
                else{
                    triplet[0] = nums[i];
                    triplet[1] = nums[front];
                    triplet[2] = nums[back];
                    res.push_back(triplet);
                    //only need to note the duplicate when the sum is 0;
                    //front--> with <--back is the right motion;
                    while(front < back && nums[front] == triplet[1] )
                        ++front;
                    while(front < back && nums[back] == triplet[2])
                        --back;
                }
            }
            while(i + 1 < nums.size() && nums[i + 1] == nums[i])//use while not if!
                ++i;
        }
        return res;
    }
示例#10
0
文件: threeSum.cpp 项目: tbian7/pst
    vector<vector<int> > threeSum(vector<int> &num) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        sort(num.begin(), num.end());
		vector<vector<int> > triplets;
		vector<int> triplet(3);
		
		int n = num.size();
		for (int i = 0; i < n - 2; i++)
		{
			if (i > 0 && num[i] == num[i-1])
			{
				continue;
			}
			int twoSum = -num[i];
			int j = i + 1;
			int k = n - 1;
			
			while (j < k)
			{
				int jksum = num[j] + num[k];
				if (jksum < twoSum)
				{
					do
					{
						j++;
					}
					while(num[j] == num[j-1] && j < k);
				}
				else if (jksum > twoSum)
				{
					do
					{
						k--;
					}
					while (num[k] == num[k+1] && j < k);
				}
				else
				{
					triplet[0] = num[i];
					triplet[1] = num[j];
					triplet[2] = num[k];
					triplets.push_back(triplet);
					do
					{
						j++;
					}
					while(num[j] == num[j-1] && j < k);
					do
					{
						k--;
					}
					while (num[k] == num[k+1] && j < k);
				}
			}
		}

		return triplets;
    }
示例#11
0
文件: JGE.cpp 项目: TomK14/w-menu
void JGE::HoldKey_NoRepeat(const JButton sym)
{
#if defined (WIN32) || defined (LINUX)
    if (JGE_BTN_FULLSCREEN == sym) JGEToggleFullscreen();
#endif
    keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, true));
    if (!held(sym))
        holds[sym] = std::numeric_limits<float>::quiet_NaN();
}
示例#12
0
文件: JGE.cpp 项目: TomK14/w-menu
void JGE::HoldKey_NoRepeat(const LocalKeySym sym)
{
    const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
    if (rng.first == rng.second)
        keyBuffer.push(triplet(sym, JGE_BTN_NONE, false));
    else for (keycodes_it it = rng.first; it != rng.second; ++it)
    {
#if defined (WIN32) || defined (LINUX)
        if (JGE_BTN_FULLSCREEN == it->second)
        {
            JGEToggleFullscreen();
            return;
        }
#endif
        keyBuffer.push(triplet(*it, true));
        if (!held(it->second))
            holds[it->second] = std::numeric_limits<float>::quiet_NaN();
    }
}
示例#13
0
vector<vector<int> > threeSum(vector<int> &num) {

    vector<vector<int> > res;

    std::sort(num.begin(), num.end());

    for (int i = 0; i < num.size(); i++) {

        int target = -num[i];
        int front = i + 1;
        int back = num.size() - 1;

        if(target < 0)
        {
            break;
        }

        while (front < back) {

            int sum = num[front] + num[back];

            // Finding answer which start from number num[i]
            if (sum < target)
                front++;

            else if (sum > target)
                back--;

            else {
                vector<int> triplet(3, 0);
                triplet[0] = num[i];
                triplet[1] = num[front];
                triplet[2] = num[back];
                res.push_back(triplet);

                // Processing duplicates of Number 2
                // Rolling the front pointer to the next different number forwards
                while (front < back && num[front] == triplet[1]) front++;

                // Processing duplicates of Number 3
                // Rolling the back pointer to the next different number backwards
                while (front < back && num[back] == triplet[2]) back--;
            }

        }

        // Processing duplicates of Number 1
        while (i + 1 < num.size() && num[i + 1] == num[i])
            i++;

    }

    return res;

}
示例#14
0
		vector<vector<int> > threeSum(vector<int> &num) {
			// Start typing your C/C++ solution below
			// DO NOT write int main() function
			/*vector<vector <int> > v;
			  int s=0;
			  sort(num.begin(),num.end());
			  int i,j, n=num.size();        
			  for(i=0;i<n;i++)
			  {
			  int first = i+1;
			  int last = n-1;
			  while(first < last)
			  {
			  int y = (-num[i]) - num[first];
			  if(num[last] > y)
			  last--;
			  else if(num[last] < y)
			  first++;
			  else
			  {
			  printf("%d %d %d\n",num[i],num[first],num[last]);
			  v[s].push_back(num[i]);
			  v[s].push_back(num[first]);
			  v[s++].push_back(num[last]);
				first++;
				last--;
			  }
			  }
			  }
			  return v;*/
			sort(num.begin(), num.end());
			vector<vector<int> > triplets;
			vector<int> triplet(3);
			int n = num.size();
			for (int i = 0;i < n; i++) {
				int j = i + 1;
				int k = n - 1;
				while (j < k) {
					int sum_two = num[i] + num[j];
					if (sum_two + num[k] < 0) {
						j++;
					} else if (sum_two + num[k] > 0) {
						k--;
					} else {
						triplet[0] = num[i];
						triplet[1] = num[j];
						triplet[2] = num[k];
						triplets.push_back(triplet);
						j++;
						k--;
					}
				}
			}
		}
示例#15
0
void
MatrixEigenSparse<T>::addMatrix ( int* rows, int nrows,
                                 int* cols, int ncols,
                                 value_type* data )
{

    for( int i=0; i < nrows; ++i )
        for( int j=0; j < ncols; ++j )
        {
            M_tripletList.push_back(triplet(rows[i], cols[j], data[i*ncols+j]) );
        }

}
SparseMatrixNeighborsPair angles_matrix_and_neighbors(const Neighbors& neighbors,
                                                      const DenseMatrix& data)
{
	const IndexType k = neighbors[0].size();
	const IndexType n_vectors = data.cols();

	SparseTriplets sparse_triplets;
	sparse_triplets.reserve(k * n_vectors);
	/* I tried to find better naming, but... */
	Neighbors most_collinear_neighbors_of_neighbors;
	most_collinear_neighbors_of_neighbors.reserve(n_vectors);

	for (IndexType i = 0; i < n_vectors; ++i)
	{
		const LocalNeighbors& current_neighbors = neighbors[i];
		LocalNeighbors most_collinear_current_neighbors;
		most_collinear_current_neighbors.reserve(k);

		for (IndexType j = 0; j < k; ++j)
		{
			const LocalNeighbors& neighbors_of_neighbor = neighbors[current_neighbors[j]];
			/* The closer the cos value to -1.0 - the closer the angle to 180.0 */
			ScalarType min_cos_value = 1.0, current_cos_value;
			/* This value will be updated during the seach for most collinear neighbor */
			most_collinear_current_neighbors.push_back(0);

			for (IndexType l = 0; l < k; ++l)
			{
				DenseVector neighbor_to_point = data.col(i) - data.col(current_neighbors[j]);
				DenseVector neighbor_to_its_neighbor = data.col(neighbors_of_neighbor[l])
														- data.col(current_neighbors[j]);
				current_cos_value = neighbor_to_point.dot(neighbor_to_its_neighbor) /
									(neighbor_to_point.norm() *
									 neighbor_to_its_neighbor.norm());
				if (current_cos_value < min_cos_value)
				{
					most_collinear_current_neighbors[j] = neighbors_of_neighbor[l];
					min_cos_value = current_cos_value;
				}
			}

			SparseTriplet triplet(i, most_collinear_current_neighbors[j], min_cos_value);
			sparse_triplets.push_back(triplet);
		}
		most_collinear_neighbors_of_neighbors.push_back(most_collinear_current_neighbors);
	}
	return SparseMatrixNeighborsPair
		(sparse_matrix_from_triplets(sparse_triplets, n_vectors, n_vectors),
		 most_collinear_neighbors_of_neighbors);
}
示例#17
0
文件: JGE.cpp 项目: TomK14/w-menu
void JGE::Update(float dt)
{
    for (map<JButton, float>::iterator it = holds.begin(); it != holds.end(); ++it)
    {
        if (it->second < 0)
        {
            keyBuffer.push(triplet(LOCAL_KEY_NONE, it->first, true));
            it->second = REPEAT_PERIOD;
        }
        it->second -= dt;
    }

    if (mApp != NULL)
        mApp->Update();
    
    oldHolds = holds;
}
 vector<vector<int> > threeSum(vector<int> &num) {
     // Start typing your C/C++ solution below
     // DO NOT write int main() function
     
     int size = num.size();
     vector<vector<int>> ret;
     if( size < 3 )
         return ret;
         
     sort( num.begin(), num.end() );
     vector<int> triplet(3, 0);
     
     for( int i = 0; i < size; i++){
         int j = i +1, k = size -1;
         
         // Avoid duplication
         if( i > 0 && num[i] == num[i-1] )
             continue;
         
         while( j < k ){
             if( num[j] + num[k] + num[i] > 0 ){
                 k--;
             }
             else if( num[j] + num[k] + num[i] < 0 ){
                 j++;
             }
             else{
                 triplet[0] = num[i];
                 triplet[1] = num[j];
                 triplet[2] = num[k];
                 ret.push_back( triplet );
                 
                 do{
                     j++;
                 }while( num[j]==num[j-1] && j < k);
                 do{
                     k--;
                 }while( num[k] == num[k+1] && k > j );
             }
         }
     }
     return ret;
         
 }
示例#19
0
CImage *CImageLABtoXYZ(CImage *cimg)
{
  CImage *ncimg=NULL;
  int p,n,i;


  ncimg = CreateCImage(cimg->C[0]->ncols,cimg->C[0]->nrows);
  n    = ncimg->C[0]->ncols*ncimg->C[0]->nrows;

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

    i = triplet(cimg->C[0]->val[p],cimg->C[1]->val[p],cimg->C[2]->val[p]);
    i = LAB2XYZ(i);
    ncimg->C[0]->val[p]=t0(i);
    ncimg->C[1]->val[p]=t1(i);
    ncimg->C[2]->val[p]=t2(i);
  }

  return(ncimg);
}
示例#20
0
    vector<vector<int> > threeSum(vector<int> arr) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        sort(arr.begin(), arr.end());
        vector <vector<int> > triplets;
        vector<int> triplet(3);
        int n = (int)arr.size();
        for (int i = 0; i < n; i++) {
            int j = i + 1;
            int k = n - 1;
            while (j < k) {
                int sum_two = arr[i] + arr[j];
                if (sum_two + arr[k] < 0) {
                    j++;
                } else if (sum_two + arr[k] > 0) {
                    k--;
                } else {

                    triplet[0] = arr[i];
                    triplet[1] = arr[j];
                    triplet[2] = arr[k];
                    triplets.push_back(triplet);

                    while( arr[j+1] == arr[j] && j+1 < k)
                        j++;

                    j++;

                    while(arr[k-1] == arr[k] && j < k-1)
                        k--;

                    k--;
                }
            }

            while (i+1 < n && arr[i+1] == arr[i])
                i++;
        }
        return triplets;

    }
示例#21
0
文件: threeSum.cpp 项目: tbian7/pst
    vector<vector<int> > threeSum(vector<int> &num) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        sort(num.begin(), num.end());
		set<vector<int> > triplets;
		vector<vector<int> > out;
		vector<int> triplet(3);
		
		int n = num.size();
		for (int i = 0; i < n - 2; i++)
		{
			int twoSum = -num[i];
			int j = i + 1;
			int k = n - 1;
			
			while (j < k)
			{
				int jksum = num[j] + num[k];
				if (jksum < twoSum)
				{
					j++;
				}
				else if (jksum > twoSum)
				{
					k--;
				}
				else
				{
					triplet[0] = num[i];
					triplet[1] = num[j];
					triplet[2] = num[k];
					triplets.insert(triplet);    //not constant time, bad
					j++;
					k--;
				}
			}
		}
		out.assign(triplets.begin(), triplets.end());
		return out;
    }
示例#22
0
文件: threeSum.cpp 项目: tbian7/pst
    vector<vector<int> > threeSum(vector<int> &num) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        sort(num.begin(), num.end());
		vector<vector<int> > triplets;
		vector<int> triplet(3);
		
		int n = num.size();
		for (int i = 0; i < n - 2; i++)
		{
			int twoSum = -num[i];
			int j = i + 1;
			int k = n - 1;
			
			while (j < k)
			{
				int jksum = num[j] + num[k];
				if (jksum < twoSum)
				{
					j++;
				}
				else if (jksum > twoSum)
				{
					k--;
				}
				else
				{
					triplet[0] = num[i];
					triplet[1] = num[j];
					triplet[2] = num[k];
					triplets.push_back(triplet);
					j++;
					k--;
				}
			}
		}
		
		triplets.erase(unique(triplets.begin(), triplets.end()), triplets.end()); // it's ok it's linear time
		return triplets;
    }
示例#23
0
 vector<vector<int> > threeSum(vector<int> &num) {
     vector<vector<int> > rtn;
     if (num.size()<3) return rtn;
     vector<int> triplet(3,0);
     // first sort input vector into ascending order
     sort(num.begin(), num.end());
     int start, mid, end, tmpsum;
     for (start = 0; start<=num.size()-3; start++)
     {
         // note uniqueness
         if (start > 0 && num[start] == num[start - 1])  continue;
         end = num.size()-1;
         mid = start + 1;
         while( mid < end)
         {
             tmpsum = num[start] + num[mid];
             if (tmpsum + num[end]>0)
             {end--;}
             else if (tmpsum + num[end]<0)
             {mid++;}
             else
             {
                 triplet[0] = num[start];
                 triplet[1] = num[mid];
                 triplet[2] = num[end];
                 rtn.push_back(triplet);
                 mid++;
                 end--;
                 // note uniqueness
                 while(num[mid-1]==num[mid] && mid < end)
                 {mid++;}
                 while(num[end+1]==num[end] && mid < end)
                 {end--;}
             }
         }
     }
     return rtn;
 }
示例#24
0
int main()
{
   // check that it'll find nodes exactly MAX away
   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 4, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target,2);
      assert(found.first != exact_dist.end());
      assert(found.second == 2);
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << std::endl;
   }

   // do the same test, except use alternate_triplet as the search key
   {
      // NOTE: stores triplet, but we search with alternate_triplet
      typedef KDTree::KDTree<3, triplet, alternate_tac> alt_tree;

      triplet actual_target(7,0,0);

      alt_tree tree;
      tree.insert( triplet(0, 0, 7) );
      tree.insert( triplet(0, 0, 7) );
      tree.insert( triplet(0, 0, 7) );
      tree.insert( triplet(3, 0, 0) );
      tree.insert( actual_target );
      tree.optimise();

      alternate_triplet target( actual_target );

      std::pair<alt_tree::const_iterator,double> found = tree.find_nearest(target);
      assert(found.first != tree.end());
      std::cout << "Test with alternate search type, found: " << *found.first << ", wanted " << actual_target << std::endl;
      assert(found.second == 0);
      assert(*found.first == actual_target);
   }


   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 2, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

        // call find_nearest without a range value - it found a compile error earlier.
      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target);
      assert(found.first != exact_dist.end());
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << " @ " << found.second << " should be " << std::sqrt(8) << std::endl;
      assert(found.second == std::sqrt(8));
   }

   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 2, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target,std::sqrt(8));
      assert(found.first != exact_dist.end());
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << " @ " << found.second << " should be " << std::sqrt(8) << std::endl;
      assert(found.second == std::sqrt(8));
   }

  tree_type src(std::ptr_fun(tac));

  triplet c0(5, 4, 0); src.insert(c0);
  triplet c1(4, 2, 1); src.insert(c1);
  triplet c2(7, 6, 9); src.insert(c2);
  triplet c3(2, 2, 1); src.insert(c3);
  triplet c4(8, 0, 5); src.insert(c4);
  triplet c5(5, 7, 0); src.insert(c5);
  triplet c6(3, 3, 8); src.insert(c6);
  triplet c7(9, 7, 3); src.insert(c7);
  triplet c8(2, 2, 6); src.insert(c8);
  triplet c9(2, 0, 6); src.insert(c9);

  std::cout << src << std::endl;

  src.erase(c0);
  src.erase(c1);
  src.erase(c3);
  src.erase(c5);

  src.optimise();


  // test the efficient_replace_and_optimise()
  tree_type eff_repl = src;
  {
     std::vector<triplet> vec;
     // erased above as part of test vec.push_back(triplet(5, 4, 0));
     // erased above as part of test vec.push_back(triplet(4, 2, 1));
     vec.push_back(triplet(7, 6, 9));
     // erased above as part of test vec.push_back(triplet(2, 2, 1));
     vec.push_back(triplet(8, 0, 5));
     // erased above as part of test vec.push_back(triplet(5, 7, 0));
     vec.push_back(triplet(3, 3, 8));
     vec.push_back(triplet(9, 7, 3));
     vec.push_back(triplet(2, 2, 6));
     vec.push_back(triplet(2, 0, 6));

     eff_repl.clear();
     eff_repl.efficient_replace_and_optimise(vec);
  }


  std::cout << std::endl << src << std::endl;

  tree_type copied(src);
  std::cout << copied << std::endl;
  tree_type assigned;
  assigned = src;
  std::cout << assigned << std::endl;

  for (int loop = 0; loop != 4; ++loop)
    {
      tree_type * target;
      switch (loop)
	{
	case 0: std::cout << "Testing plain construction" << std::endl;
	  target = &src;
	  break;

	case 1: std::cout << "Testing copy-construction" << std::endl;
	  target = &copied;
	  break;

	case 2: std::cout << "Testing assign-construction" << std::endl;
	  target = &assigned;
	  break;

   default:
	case 4: std::cout << "Testing efficient-replace-and-optimise" << std::endl;
	  target = &eff_repl;
	  break;
	}
      tree_type & t = *target;

      int i=0;
      for (tree_type::const_iterator iter=t.begin(); iter!=t.end(); ++iter, ++i);
      std::cout << "iterator walked through " << i << " nodes in total" << std::endl;
      if (i!=6)
	{
	  std::cerr << "Error: does not tally with the expected number of nodes (6)" << std::endl;
	  return 1;
	}
      i=0;
      for (tree_type::const_reverse_iterator iter=t.rbegin(); iter!=t.rend(); ++iter, ++i);
      std::cout << "reverse_iterator walked through " << i << " nodes in total" << std::endl;
      if (i!=6)
	{
	  std::cerr << "Error: does not tally with the expected number of nodes (6)" << std::endl;
	  return 1;
	}

      triplet s(5, 4, 3);
      std::vector<triplet> v;
      unsigned int const RANGE = 3;

      size_t count = t.count_within_range(s, RANGE);
      std::cout << "counted " << count
		<< " nodes within range " << RANGE << " of " << s << ".\n";
      t.find_within_range(s, RANGE, std::back_inserter(v));

      std::cout << "found   " << v.size() << " nodes within range " << RANGE
		<< " of " << s << ":\n";
      std::vector<triplet>::const_iterator ci = v.begin();
      for (; ci != v.end(); ++ci)
	std::cout << *ci << " ";
      std::cout << "\n" << std::endl;

      std::cout << std::endl << t << std::endl;

      // search for all the nodes at exactly 0 dist away
      for (tree_type::const_iterator target = t.begin(); target != t.end(); ++target)
      {
         std::pair<tree_type::const_iterator,double> found = t.find_nearest(*target,0);
         assert(found.first != t.end());
         assert(*found.first == *target);
         std::cout << "Test find_nearest(), found at exact distance away from " << *target << ", found " << *found.first << std::endl;
      }

      {
         const double small_dist = 0.0001;
         std::pair<tree_type::const_iterator,double> notfound = t.find_nearest(s,small_dist);
         std::cout << "Test find_nearest(), nearest to " << s << " within " << small_dist << " should not be found" << std::endl;

         if (notfound.first != t.end())
         {
            std::cout << "ERROR found a node at dist " << notfound.second << " : " << *notfound.first << std::endl;
            std::cout << "Actual distance = " << s.distance_to(*notfound.first) << std::endl;
         }

         assert(notfound.first == t.end());
      }

      {
         std::pair<tree_type::const_iterator,double> nif = t.find_nearest_if(s,std::numeric_limits<double>::max(),Predicate());
         std::cout << "Test find_nearest_if(), nearest to " << s << " @ " << nif.second << ": " << *nif.first << std::endl;

         std::pair<tree_type::const_iterator,double> cantfind = t.find_nearest_if(s,std::numeric_limits<double>::max(),FalsePredicate());
         std::cout << "Test find_nearest_if(), nearest to " << s << " should never be found (predicate too strong)" << std::endl;
         assert(cantfind.first == t.end());
      }




      {
      std::pair<tree_type::const_iterator,double> found = t.find_nearest(s,std::numeric_limits<double>::max());
      std::cout << "Nearest to " << s << " @ " << found.second << " " << *found.first << std::endl;
      std::cout << "Should be " << found.first->distance_to(s) << std::endl;
      // NOTE: the assert does not check for an exact match, as it is not exact when -O2 or -O3 is
      // switched on.  Some sort of optimisation makes the math inexact.
      assert( fabs(found.second - found.first->distance_to(s)) < std::numeric_limits<double>::epsilon() );
      }

      {
      triplet s2(10, 10, 2);
      std::pair<tree_type::const_iterator,double> found = t.find_nearest(s2,std::numeric_limits<double>::max());
      std::cout << "Nearest to " << s2 << " @ " << found.second << " " << *found.first << std::endl;
      std::cout << "Should be " << found.first->distance_to(s2) << std::endl;
      // NOTE: the assert does not check for an exact match, as it is not exact when -O2 or -O3 is
      // switched on.  Some sort of optimisation makes the math inexact.
      assert( fabs(found.second - found.first->distance_to(s2)) < std::numeric_limits<double>::epsilon() );
      }

      std::cout << std::endl;

      std::cout << t << std::endl;

      // Testing iterators
      {
	std::cout << "Testing iterators" << std::endl;

	t.erase(c2);
	t.erase(c4);
	t.erase(c6);
	t.erase(c7);
	t.erase(c8);
	//    t.erase(c9);

	std::cout << std::endl << t << std::endl;

	std::cout << "Forward iterator test..." << std::endl;
	std::vector<triplet> forwards;
	for (tree_type::iterator i = t.begin(); i != t.end(); ++i)
	  { std::cout << *i << " " << std::flush; forwards.push_back(*i); }
	std::cout << std::endl;
	std::cout << "Reverse iterator test..." << std::endl;
	std::vector<triplet> backwards;
	for (tree_type::reverse_iterator i = t.rbegin(); i != t.rend(); ++i)
	  { std::cout << *i << " " << std::flush; backwards.push_back(*i); }
	std::cout << std::endl;
	std::reverse(backwards.begin(),backwards.end());
	assert(backwards == forwards);
      }
    }


  // Walter reported that the find_within_range() wasn't giving results that were within
  // the specified range... this is the test.
  {
     tree_type tree(std::ptr_fun(tac));
     tree.insert( triplet(28.771200,16.921600,-2.665970) );
     tree.insert( triplet(28.553101,18.649700,-2.155560) );
     tree.insert( triplet(28.107500,20.341400,-1.188940) );
     tree.optimise();

     std::deque< triplet > vectors;
     triplet sv(18.892500,20.341400,-1.188940);
     tree.find_within_range(sv, 10.0f, std::back_inserter(vectors));

     std::cout << std::endl << "Test find_with_range( " << sv << ", 10.0f) found " << vectors.size() << " candidates." << std::endl;

     // double-check the ranges
     for (std::deque<triplet>::iterator v = vectors.begin(); v != vectors.end(); ++v)
     {
        double dist = sv.distance_to(*v);
        std::cout << "  " << *v << " dist=" << dist << std::endl;
        if (dist > 10.0f)
           std::cout << "    This point is too far! But that is by design, its within a 'box' with a 'radius' of 10, not a sphere with a radius of 10" << std::endl;
        // Not a valid test, it can be greater than 10 if the point is in the corners of the box.
        // assert(dist <= 10.0f);
     }
  }


  return 0;
}
示例#25
0
uint32_t *idc3(uint32_t *T, size_t n, size_t *retsz) {
    vprint("args", T, n);
    T[n++] = 0;

    // step 0: construct a sample
    size_t B0len = (n+1)/3;
    #define toC(i) ((i < B0len) ? (1 + 3*i) : (2 + 3*(i-B0len)))

    // step 1: sort sample suffixes
    triplet *R = new triplet[n * 3 / 2 + 3];
    triplet *Rptr = R;
    for (int j = 1; j <= 2; j++) {
        size_t i = j;
        for (; i < n - 2; i += 3) {
            *Rptr++ = triplet(T[i], T[i+1], T[i+2]);
        }
        for (; i < n - 1; i += 3) {
            *Rptr++ = triplet(T[i], T[i+1], 0);
        }
        for (; i < n; i += 3) {
            *Rptr++ = triplet(T[i], 0, 0);
        }
    }
    bool unique = false;
    size_t Rsz = Rptr - R;
    size_t Rrsz, SARsz;
    uint32_t *Rr = ranks(R, Rsz, &Rrsz, &unique);
    vprint("Rr", Rr, Rrsz)
    delete[] R;
    uint32_t *SAR = unique ? toSA(Rr, Rrsz, &SARsz) : idc3(Rr, Rrsz, &SARsz);
    vprint("SAR", SAR, SARsz)
    delete[] Rr;
    uint32_t *rank = new uint32_t[n+2];
    for (size_t i = 1; i < SARsz; i++) {
        rank[toC(SAR[i])] = i;
    }

    // step 2: sort nonsample suffixes
    triplet *SB0 = new triplet[n/3 + 3];
    triplet *SB0ptr = SB0;
    for (size_t i = 0; i < n; i += 3) {
        *SB0ptr++ = triplet(T[i], rank[i+1], i);
    }
    size_t SB0sz = SB0ptr - SB0;
    lsd_sort(SB0, SB0sz);

    // step 3: merge
    uint32_t *Sc = new uint32_t[SARsz - 1];
    size_t Scsz = SARsz - 1;
    uint32_t *buf = new uint32_t[n + 1];
    uint32_t *buf_ptr = buf;
    for (size_t i = 1; i < SARsz; i++) {
        Sc[i-1] = toC(SAR[i]);
    }
    delete[] SAR;
    size_t sbi = 0;
    size_t sci = 0;
    while (sbi < SB0sz && sci < Scsz) {
        uint32_t i = Sc[sci];
        uint32_t j = SB0[sbi].arr[2];
        if (i % 3 == 1) {
            if (T[i] < T[j] || (T[i] == T[j] && rank[i+1] <= rank[j+1])) {
                *buf_ptr++ = i;
                sci++;
            } else {
                *buf_ptr++ = j;
                sbi++;
            }
        } else if (i % 3 == 2) {
            if (LE(T[i], T[i+1], rank[i+2], T[j], T[j+1], rank[j+2])) {
                *buf_ptr++ = i;
                sci++;
            } else {
                *buf_ptr++ = j;
                sbi++;
            }
        } else {
            assert(false);
        }
    }
    while (sci < Scsz) {
        uint32_t i = Sc[sci++];
        *buf_ptr++ = i;
    }
    while (sbi < SB0sz) {
        uint32_t j = SB0[sbi++].arr[2];
        *buf_ptr++ = j;
    }
    delete[] Sc;
    delete[] SB0;
    delete[] rank;
    *retsz = buf_ptr - buf;
    return buf;
}
示例#26
0
int main()
{
   // check that it'll find nodes exactly MAX away
   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 4, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target,2);
      assert(found.first != exact_dist.end());
      assert(found.second == 2);
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << std::endl;
   }

   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 2, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

        // call find_nearest without a range value - it found a compile error earlier.
      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target);
      assert(found.first != exact_dist.end());
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << " @ " << found.second << " should be " << sqrt(8) << std::endl;
      assert(found.second == sqrt(8));
   }

   {
      tree_type exact_dist(std::ptr_fun(tac));
        triplet c0(5, 2, 0);
        exact_dist.insert(c0);
        triplet target(7,4,0);

      std::pair<tree_type::const_iterator,double> found = exact_dist.find_nearest(target,sqrt(8));
      assert(found.first != exact_dist.end());
      std::cout << "Test find_nearest(), found at exact distance away from " << target << ", found " << *found.first << " @ " << found.second << " should be " << sqrt(8) << std::endl;
      assert(found.second == sqrt(8));
   }

  tree_type src(std::ptr_fun(tac));

  triplet c0(5, 4, 0); src.insert(c0);
  triplet c1(4, 2, 1); src.insert(c1);
  triplet c2(7, 6, 9); src.insert(c2);
  triplet c3(2, 2, 1); src.insert(c3);
  triplet c4(8, 0, 5); src.insert(c4);
  triplet c5(5, 7, 0); src.insert(c5);
  triplet c6(3, 3, 8); src.insert(c6);
  triplet c7(9, 7, 3); src.insert(c7);
  triplet c8(2, 2, 6); src.insert(c8);
  triplet c9(2, 0, 6); src.insert(c9);

  std::cout << src << std::endl;

  src.erase(c0);
  src.erase(c1);
  src.erase(c3);
  src.erase(c5);

  src.optimise();


  // test the efficient_replace_and_optimise()
  tree_type eff_repl = src;
  {
     std::vector<triplet> vec;
     // erased above as part of test vec.push_back(triplet(5, 4, 0));
     // erased above as part of test vec.push_back(triplet(4, 2, 1));
     vec.push_back(triplet(7, 6, 9));
     // erased above as part of test vec.push_back(triplet(2, 2, 1));
     vec.push_back(triplet(8, 0, 5));
     // erased above as part of test vec.push_back(triplet(5, 7, 0));
     vec.push_back(triplet(3, 3, 8));
     vec.push_back(triplet(9, 7, 3));
     vec.push_back(triplet(2, 2, 6));
     vec.push_back(triplet(2, 0, 6));

     eff_repl.clear();
     eff_repl.efficient_replace_and_optimise(vec);
  }


  std::cout << std::endl << src << std::endl;

  tree_type copied(src);
  std::cout << copied << std::endl;
  tree_type assigned;
  assigned = src;
  std::cout << assigned << std::endl;

  for (int loop = 0; loop != 4; ++loop)
    {
      tree_type * target;
      switch (loop)
	{
	case 0: std::cout << "Testing plain construction" << std::endl;
	  target = &src;
	  break;

	case 1: std::cout << "Testing copy-construction" << std::endl;
	  target = &copied;
	  break;

	case 2: std::cout << "Testing assign-construction" << std::endl;
	  target = &assigned;
	  break;

   default:
	case 4: std::cout << "Testing efficient-replace-and-optimise" << std::endl;
	  target = &eff_repl;
	  break;
	}
      tree_type & t = *target;

      int i=0;
      for (tree_type::const_iterator iter=t.begin(); iter!=t.end(); ++iter, ++i);
      std::cout << "iterator walked through " << i << " nodes in total" << std::endl;
      if (i!=6)
	{
	  std::cerr << "Error: does not tally with the expected number of nodes (6)" << std::endl;
	  return 1;
	}
      i=0;
      for (tree_type::const_reverse_iterator iter=t.rbegin(); iter!=t.rend(); ++iter, ++i);
      std::cout << "reverse_iterator walked through " << i << " nodes in total" << std::endl;
      if (i!=6)
	{
	  std::cerr << "Error: does not tally with the expected number of nodes (6)" << std::endl;
	  return 1;
	}

      triplet s(5, 4, 3);
      std::vector<triplet> v;
      unsigned int const RANGE = 3;

      size_t count = t.count_within_range(s, RANGE);
      std::cout << "counted " << count
		<< " nodes within range " << RANGE << " of " << s << ".\n";
      t.find_within_range(s, RANGE, std::back_inserter(v));

      std::cout << "found   " << v.size() << " nodes within range " << RANGE
		<< " of " << s << ":\n";
      std::vector<triplet>::const_iterator ci = v.begin();
      for (; ci != v.end(); ++ci)
	std::cout << *ci << " ";
      std::cout << "\n" << std::endl;

      std::cout << std::endl << t << std::endl;

      // search for all the nodes at exactly 0 dist away
      for (tree_type::const_iterator target = t.begin(); target != t.end(); ++target)
      {
         std::pair<tree_type::const_iterator,double> found = t.find_nearest(*target,0);
         assert(found.first != t.end());
         assert(*found.first == *target);
         std::cout << "Test find_nearest(), found at exact distance away from " << *target << ", found " << *found.first << std::endl;
      }

      {
         const double small_dist = 0.0001;
         std::pair<tree_type::const_iterator,double> notfound = t.find_nearest(s,small_dist);
         std::cout << "Test find_nearest(), nearest to " << s << " within " << small_dist << " should not be found" << std::endl;

         if (notfound.first != t.end())
         {
            std::cout << "ERROR found a node at dist " << notfound.second << " : " << *notfound.first << std::endl;
            std::cout << "Actual distance = " << s.distance_to(*notfound.first) << std::endl;
         }

         assert(notfound.first == t.end());
      }

      {
         std::pair<tree_type::const_iterator,double> nif = t.find_nearest_if(s,std::numeric_limits<double>::max(),Predicate());
         std::cout << "Test find_nearest_if(), nearest to " << s << " @ " << nif.second << ": " << *nif.first << std::endl;

         std::pair<tree_type::const_iterator,double> cantfind = t.find_nearest_if(s,std::numeric_limits<double>::max(),FalsePredicate());
         std::cout << "Test find_nearest_if(), nearest to " << s << " should never be found (predicate too strong)" << std::endl;
         assert(cantfind.first == t.end());
      }




      {
      std::pair<tree_type::const_iterator,double> found = t.find_nearest(s,std::numeric_limits<double>::max());
      std::cout << "Nearest to " << s << " @ " << found.second << " " << *found.first << std::endl;
      std::cout << "Should be " << found.first->distance_to(s) << std::endl;
      // NOTE: the assert does not check for an exact match, as it is not exact when -O2 or -O3 is
      // switched on.  Some sort of optimisation makes the math inexact.
      assert( fabs(found.second - found.first->distance_to(s)) < std::numeric_limits<double>::epsilon() );
      }

      {
      triplet s2(10, 10, 2);
      std::pair<tree_type::const_iterator,double> found = t.find_nearest(s2,std::numeric_limits<double>::max());
      std::cout << "Nearest to " << s2 << " @ " << found.second << " " << *found.first << std::endl;
      std::cout << "Should be " << found.first->distance_to(s2) << std::endl;
      // NOTE: the assert does not check for an exact match, as it is not exact when -O2 or -O3 is
      // switched on.  Some sort of optimisation makes the math inexact.
      assert( fabs(found.second - found.first->distance_to(s2)) < std::numeric_limits<double>::epsilon() );
      }

      std::cout << std::endl;

      std::cout << t << std::endl;

      // Testing iterators
      {
	std::cout << "Testing iterators" << std::endl;

	t.erase(c2);
	t.erase(c4);
	t.erase(c6);
	t.erase(c7);
	t.erase(c8);
	//    t.erase(c9);

	std::cout << std::endl << t << std::endl;

	std::cout << "Forward iterator test..." << std::endl;
	std::vector<triplet> forwards;
	for (tree_type::iterator i = t.begin(); i != t.end(); ++i)
	  { std::cout << *i << " " << std::flush; forwards.push_back(*i); }
	std::cout << std::endl;
	std::cout << "Reverse iterator test..." << std::endl;
	std::vector<triplet> backwards;
	for (tree_type::reverse_iterator i = t.rbegin(); i != t.rend(); ++i)
	  { std::cout << *i << " " << std::flush; backwards.push_back(*i); }
	std::cout << std::endl;
	std::reverse(backwards.begin(),backwards.end());
	assert(backwards == forwards);
      }
    }

  return 0;
}
//---------------------------------------------------------------------------
std::vector<boost::shared_ptr<TFormMachine> > CreateMachines(
  TFormSimStagecraftMain * const formParent,
  const int level)
{
  std::vector<boost::shared_ptr<TFormMachine> > machines;

  switch (level)
  {
    case 1:
    {
      boost::shared_ptr<TFormMachine> m1(
          new TFormWallSocket220(0,formParent));
      boost::shared_ptr<TFormMachine> m2(
          new TFormPar64(0,formParent));
      machines.push_back(m1);
      machines.push_back(m2);
    }
    break;
    case 2:
    {
      boost::shared_ptr<TFormMachine> wallSocket220(new TFormWallSocket220(0,formParent));
      boost::shared_ptr<TFormMachine> speaker(new TFormRcf322A(0,formParent));
      boost::shared_ptr<TFormMachine> mic(new TFormShureSm58(0,formParent));
      machines.push_back(mic);
      machines.push_back(speaker);
      machines.push_back(wallSocket220);
    }
    break;
    case 3:
    {
      boost::shared_ptr<TFormMachine> wallSocket220(new TFormWallSocket220(0,formParent));
      boost::shared_ptr<TFormMachine> speaker1(new TFormRcf322A(0,formParent));
      boost::shared_ptr<TFormMachine> speaker2(new TFormRcf322A(0,formParent));
      boost::shared_ptr<TFormMachine> mic(new TFormShureSm58(0,formParent));
      boost::shared_ptr<TFormMachine> triplet(new TFormTriplet(0,formParent));
      boost::shared_ptr<TFormMachine> soundTable(new TFormSimpleSound1(0,formParent));
      machines.push_back(speaker1);
      machines.push_back(mic);
      machines.push_back(speaker2);
      machines.push_back(wallSocket220);
      machines.push_back(soundTable);
      machines.push_back(triplet);
    }
    break;
    case 4:
    {
      boost::shared_ptr<TFormMachine> dimmerpack(new TFormDimblockV3(0,formParent));
      boost::shared_ptr<TFormMachine> lighttable(new TFormSimpleShine1(0,formParent));
      boost::shared_ptr<TFormMachine> wallSocketPower(new TFormWallSocketPower(0,formParent));
      boost::shared_ptr<TFormMachine> wallSocket220(new TFormWallSocket220(0,formParent));
      boost::shared_ptr<TFormMachine> par64_1(new TFormPar64(0,formParent));
      boost::shared_ptr<TFormMachine> par64_2(new TFormPar64(0,formParent));
      boost::shared_ptr<TFormMachine> par64_3(new TFormPar64(0,formParent));
      boost::shared_ptr<TFormMachine> par64_4(new TFormPar64(0,formParent));
      boost::shared_ptr<TFormMachine> par64_5(new TFormPar64(0,formParent));
      machines.push_back(wallSocketPower);
      machines.push_back(dimmerpack);
      machines.push_back(wallSocket220);
      machines.push_back(par64_1);
      machines.push_back(lighttable);
      machines.push_back(par64_2);
      machines.push_back(par64_3);
      machines.push_back(par64_4);
      machines.push_back(par64_5);
    }
    break;
    case 5:
    {
      boost::shared_ptr<TFormMachine> wallSocket220(new TFormWallSocket220(0,formParent));
      boost::shared_ptr<TFormMachine> speaker1(new TFormRcf322A(0,formParent));
      boost::shared_ptr<TFormMachine> speaker2(new TFormRcf322A(0,formParent));
      boost::shared_ptr<TFormMachine> mic1(new TFormShureSm58(0,formParent));
      boost::shared_ptr<TFormMachine> mic2(new TFormShureSm58(0,formParent));
      boost::shared_ptr<TFormMachine> triplet(new TFormTriplet(0,formParent));
      boost::shared_ptr<TFormMachine> soundTable(new TFormSimpleSound2(0,formParent));
      machines.push_back(mic1);
      machines.push_back(triplet);
      machines.push_back(mic2);
      machines.push_back(speaker1);
      machines.push_back(soundTable);
      machines.push_back(speaker2);
      machines.push_back(wallSocket220);
    }
    break;
    case 6:
    {
      boost::shared_ptr<TFormMachine> wallSocket220(new TFormWallSocket220(0,formParent));
      boost::shared_ptr<TFormMachine> mic1(new TFormShureSm58(0,formParent));
      boost::shared_ptr<TFormMachine> speaker1(new TFormRcf322A(0,formParent));
      boost::shared_ptr<TFormMachine> triplet(new TFormTriplet(0,formParent));
      boost::shared_ptr<TFormMachine> soundTable3(new TFormSimpleSound3(0,formParent));
      machines.push_back(mic1);
      machines.push_back(speaker1);
      machines.push_back(wallSocket220);
      machines.push_back(triplet);
      machines.push_back(soundTable3);
    }
    break;
    case 7:
    {
      boost::shared_ptr<TFormMachine> wallSocket220(new TFormWallSocket220(0,formParent));
      boost::shared_ptr<TFormMachine> mic1(new TFormShureSm58(0,formParent));
      boost::shared_ptr<TFormMachine> mic2(new TFormShureSm58(0,formParent));
      boost::shared_ptr<TFormMachine> mic3(new TFormShureSm58(0,formParent));
      boost::shared_ptr<TFormMachine> speaker1(new TFormRcf322A(0,formParent));
      boost::shared_ptr<TFormMachine> speaker2(new TFormRcf322A(0,formParent));
      boost::shared_ptr<TFormMachine> speaker3(new TFormRcf322A(0,formParent));
      boost::shared_ptr<TFormMachine> speaker4(new TFormRcf322A(0,formParent));
      boost::shared_ptr<TFormMachine> octlet(new TFormOctlet(0,formParent));
      boost::shared_ptr<TFormMachine> soundTable3(new TFormSimpleSound3(0,formParent));
      machines.push_back(mic1);
      machines.push_back(mic2);
      machines.push_back(mic3);
      machines.push_back(octlet);
      machines.push_back(speaker1);
      machines.push_back(speaker2);
      machines.push_back(speaker3);
      machines.push_back(speaker4);
      machines.push_back(wallSocket220);
      machines.push_back(soundTable3);
    }
    break;
    case 8:
    {
      //Put a CD on speakers without using a soundtable
      boost::shared_ptr<TFormMachine> wallSocket220(new TFormWallSocket220(0,formParent));
      boost::shared_ptr<TFormMachine> speaker1(new TFormRcf322A(0,formParent));
      boost::shared_ptr<TFormMachine> octlet(new TFormOctlet(0,formParent));
      boost::shared_ptr<TFormCdPlayer> cdPlayer(new TFormCdPlayer(0,formParent));
      boost::shared_ptr<TFormTransitionPieceJackMaleTwoCinchFemale> transitionPiece(
        new TFormTransitionPieceJackMaleTwoCinchFemale(0,formParent));
      machines.push_back(octlet);
      machines.push_back(speaker1);
      machines.push_back(wallSocket220);
      machines.push_back(cdPlayer);
      machines.push_back(transitionPiece);
    }
    break;
    case 9:
    {
      //Put a CD on speakers with using a soundtable
      boost::shared_ptr<TFormMachine> wallSocket220(new TFormWallSocket220(0,formParent));
      boost::shared_ptr<TFormMachine> speaker1(new TFormRcf322A(0,formParent));
      boost::shared_ptr<TFormMachine> octlet(new TFormOctlet(0,formParent));
      boost::shared_ptr<TFormCdPlayer> cdPlayer(new TFormCdPlayer(0,formParent));
      boost::shared_ptr<TFormMachine> soundTable4(new TFormSimpleSound4(0,formParent));
      machines.push_back(octlet);
      machines.push_back(speaker1);
      machines.push_back(cdPlayer);
      machines.push_back(wallSocket220);
      machines.push_back(soundTable4);
    }
    break;
    case 10:
    {
      //Record a CD on MD play
      boost::shared_ptr<TFormMachine> wallSocket220(new TFormWallSocket220(0,formParent));
      boost::shared_ptr<TFormMachine> speaker1(new TFormRcf322A(0,formParent));
      boost::shared_ptr<TFormMachine> octlet(new TFormOctlet(0,formParent));
      //boost::shared_ptr<TFormMachine> soundTable4(new TFormSimpleSound4(0,formParent));
      boost::shared_ptr<TFormMdPlayer> mdPlayer(new TFormMdPlayer(0,formParent));
      boost::shared_ptr<TFormCdPlayer> cdPlayer(new TFormCdPlayer(0,formParent));
      boost::shared_ptr<TFormTransitionPieceJackMaleTwoCinchFemale> transitionPiece(
        new TFormTransitionPieceJackMaleTwoCinchFemale(0,formParent));
      machines.push_back(octlet);
      machines.push_back(speaker1);
      machines.push_back(wallSocket220);
      //machines.push_back(soundTable4);
      machines.push_back(mdPlayer);
      machines.push_back(transitionPiece);
      machines.push_back(cdPlayer);
    }
    break;
    case 11:
    {
      //Record a CD and microphone on MD play
      boost::shared_ptr<TFormMachine> mic1(new TFormShureSm58(0,formParent));
      boost::shared_ptr<TFormMachine> wallSocket220(new TFormWallSocket220(0,formParent));
      boost::shared_ptr<TFormMachine> speaker1(new TFormRcf322A(0,formParent));
      boost::shared_ptr<TFormMachine> octlet(new TFormOctlet(0,formParent));
      boost::shared_ptr<TFormMachine> soundTable4(new TFormSimpleSound4(0,formParent));
      boost::shared_ptr<TFormMdPlayer> mdPlayer(new TFormMdPlayer(0,formParent));
      //boost::shared_ptr<TFormCdPlayer> cdPlayer(new TFormCdPlayer(0,formParent));
      boost::shared_ptr<TFormTransitionPieceJackMaleTwoCinchFemale> transitionPiece(
        new TFormTransitionPieceJackMaleTwoCinchFemale(0,formParent));
      machines.push_back(wallSocket220);
      machines.push_back(speaker1);
      machines.push_back(octlet);
      machines.push_back(mic1);
      machines.push_back(soundTable4);
      machines.push_back(transitionPiece);
      //machines.push_back(cdPlayer);
      machines.push_back(mdPlayer);
    }
    break;
    case 12:
    {
      //Level 12: Learn to use the crossfader
      boost::shared_ptr<TFormMachine> dimmerpack(new TFormDimblockV3(0,formParent));
      boost::shared_ptr<TFormMachine> lighttable(new TFormSimpleShine2(0,formParent));
      boost::shared_ptr<TFormMachine> wallSocketPower(new TFormWallSocketPower(0,formParent));
      boost::shared_ptr<TFormMachine> wallSocket220(new TFormWallSocket220(0,formParent));
      boost::shared_ptr<TFormMachine> par64_1(new TFormPar64(0,formParent));
      boost::shared_ptr<TFormMachine> par64_2(new TFormPar64(0,formParent));
      boost::shared_ptr<TFormMachine> par64_3(new TFormPar64(0,formParent));
      boost::shared_ptr<TFormMachine> par64_4(new TFormPar64(0,formParent));
      boost::shared_ptr<TFormMachine> par64_5(new TFormPar64(0,formParent));
      machines.push_back(wallSocketPower);
      machines.push_back(dimmerpack);
      machines.push_back(wallSocket220);
      machines.push_back(par64_1);
      machines.push_back(lighttable);
      machines.push_back(par64_2);
      machines.push_back(par64_3);
      machines.push_back(par64_4);
      machines.push_back(par64_5);
    }
    break;
    case 13:
    {
      boost::shared_ptr<TFormMachine> wallSocket220(new TFormWallSocket220(0,formParent));
      boost::shared_ptr<TFormMachine> mic(new TFormShureSm58(0,formParent));
      boost::shared_ptr<TFormMachine> speaker(new TFormRcfEvent3000(0,formParent));
      boost::shared_ptr<TFormMachine> amplifier(new TFormEasyAmp(0,formParent));
      machines.push_back(mic);
      machines.push_back(speaker);
      machines.push_back(wallSocket220);
      machines.push_back(amplifier);
    }
    break;
    default: //Do nothing
    break;
  }

  return machines;
}
示例#28
0
void linear::fill_mass() { 

#ifdef LOAD
  std::cout << " Reading mass matrix" << std::endl;
  loadMarket(mass, "mass.mtx");
#else

  std::cout << " Filling mass matrix" << std::endl;

  std::vector<triplet> aa;            // list of non-zeros coefficients

  int N=0;

  for(F_v_it fv=T.finite_vertices_begin();
      fv!=T.finite_vertices_end();
      fv++)  {

    ++N;

    int vi=fv->idx.val();

    typedef Vertex::scalar_link scalar_link;

    scalar_link masss=fv->mass();

    for(
	scalar_link::iterator nn= masss.begin();
	nn!=masss.end(); ++nn) {

      int vj=nn->first->idx.val();
	
      FT mm = nn->second;

      aa.push_back( triplet(vi,vj, mm ));
    }
  }

  mass.resize(N,N);

  mass.setFromTriplets(aa.begin(), aa.end());

  std::cout << " Filled mass matrix" << std::endl;
  cout << "matrix size " << mass.rows() << " x " << mass.cols() << endl;

#endif

  // Only non-direct iterative solvers
#ifndef DIRECT_SOLVER
    solver_mass.setTolerance( TOL );
#endif

    solver_mass.compute(mass);

  if(solver_mass.info()!=Eigen::Success) {
    std::cout << "Failure decomposing mass matrix\n";
  }


  return;

}
示例#29
0
void linear::fill_stiff(void){ 

#ifdef LOAD
  std::cout << " Reading stiffness matrix" << std::endl;
  loadMarket(stiff, "stiff.mtx");
  loadMarket(stiffp1, "stiffp1.mtx");
#else

  std::cout << " Filling stiffness matrix" << std::endl;

  //  int n=simu.no_of_points();

  std::vector<triplet> aa , bb ;            // list of non-zeros coefficients

  int N=0;

  for(F_v_it fv=T.finite_vertices_begin();
      fv!=T.finite_vertices_end();
      fv++)  {

    ++N;

    int vi=fv->idx.val();

    typedef Vertex::scalar_link scalar_link;
    //    typedef std::map<Vertex_handle,Vector_2> vector_link; 
    scalar_link stiffs=fv->stiff();

    for(
	scalar_link::iterator nn= stiffs.begin();
	nn!=stiffs.end(); ++nn) {

      int vj=nn->first->idx.val();
	
      FT ddelta = nn->second; // wrong sign here ???

      // Aqui con Ada
      
      //      cout << vi << " , " << vj << "  " << ddelta << endl;

      aa.push_back( triplet(vi,vj,  -ddelta ));

      if( (vi!=0) && (vj!=0) ) bb.push_back( triplet(vi - 1 , vj -1 ,  -ddelta ));



    }
  }

  stiff.resize(N,N);
  stiff.setFromTriplets(aa.begin(), aa.end());
  std::cout << " Filled stiffness  matrix" << std::endl;
  cout << "matrix size " << stiff.rows() << " x " << stiff.cols() << endl;

  // F_v_it fv=T.finite_vertices_begin();
  // int i0=fv->idx.val();
  // aa.push_back( triplet( N , i0 , 1 ) );  // anchor particle 0 to have fixed pressure
  //    //aa.push_back( triplet( N , 0 , 1 ) );  // anchor particle 0 to have fixed pressure

  // stiffp1.resize(N+1,N+1);
  // stiffp1.setFromTriplets(aa.begin(), aa.end());

  stiffp1.resize(N-1,N-1);
  stiffp1.setFromTriplets(bb.begin(), bb.end());

  std::cout << " Filled stiffness plus 1 matrix" << std::endl;
  cout << "matrix size " << stiffp1.rows() << " x " << stiffp1.cols() << endl;
#endif

  // Only non-direct iterative solvers
#ifndef DIRECT_SOLVER
  solver_stiffp1.setTolerance( TOL );
  solver_stiffp1.setMaxIterations( 40 * N );
#endif

  solver_stiffp1.compute(stiffp1);

  if(solver_stiffp1.info()!=Eigen::Success) {
    std::cout << "Failure decomposing stiff plus 1 matrix\n";
  }

  return;

}
int main()
{
    int flag,number;
    char  input[3];
    //creating 3 node type variables new_node current and head
    node *new_node,*current;
    printf("\nEnter data to First linked list\n");
    //Dynamic initializtion
    new_node=(node *)malloc(sizeof(node));
    printf("\nEnter data to the node: ");
    //Storing some data
    scanf("%d",&new_node->data);
    //head pointing to the new node
    head=new_node;
    new_node->next=NULL;
    length_1++;
    current=new_node;
    printf("\nDo you want to enter new node(yes/no):");
    scanf("%s",input);
    flag=string_test(input);
    //Iterate itself until flag is 1 i. the string entered is yes
    while(flag==1)
    {
        length_1++;
        //calling create_node function to create new node and link it
        current=create_node(current);
        printf("\nDo you want to enter new node(yes/no):");
        scanf("%s",input);
        //calling string_test fuction to check whether the input is yes or no
        flag=string_test(input);
    }
    //Calling the display function and passing head as the value
    display(head);
    printf("\nEnter the data to Second linked list");
    //Dynamic initializtion
    new_node=(node *)malloc(sizeof(node));
    printf("\nEnter data to the node:  ");
    //Storing some data
    scanf("%d",&new_node->data);
    //head pointing to the new node
    head2=new_node;
    new_node->next=NULL;
    length_2++;
    current=new_node;
    printf("\nDo you want to enter new node(yes/no):");
    scanf("%s",input);
    flag=string_test(input);
    //Iterate itself until flag is 1 i. the string entered is yes
    while(flag==1)
    {
        length_2++;
        //calling create_node function to create new node and link it
        current=create_node(current);
        printf("\nDo you want to enter new node(yes/no):");
        scanf("%s",input);
        //calling string_test fuction to check whether the input is yes or no
        flag=string_test(input);
    }
    //Calling the display function and passing head as the value
    display(head2);
    printf("\nEnter the data to Third linked list");
    //Dynamic initializtion
    new_node=(node *)malloc(sizeof(node));
    printf("\nEnter data to the node:  ");
    //Storing some data
    scanf("%d",&new_node->data);
    //head pointing to the new node
    head3=new_node;
    new_node->next=NULL;
    length_3++;
    current=new_node;
    printf("\nDo you want to enter new node(yes/no):");
    scanf("%s",input);
    flag=string_test(input);
    //Iterate itself until flag is 1 i. the string entered is yes
    while(flag==1)
    {
        length_3++;
        //calling create_node function to create new node and link it
        current=create_node(current);
        printf("\nDo you want to enter new node(yes/no):");
        scanf("%s",input);
        //calling string_test fuction to check whether the input is yes or no
        flag=string_test(input);
    }
    //Calling the display function and passing head as the value
    display(head3);
    printf("\nEnter the number to find its triplet:");
    scanf("%d",&number);
    triplet(number);
    return 0;
}