コード例 #1
0
std::vector<std::pair<population::size_type,std::vector<population::individual_type>::size_type> >
	random_r_policy::select(const std::vector<population::individual_type> &immigrants, const population &dest) const
{
	const population::size_type rate_limit = std::min<population::size_type>(get_n_individuals(dest),boost::numeric_cast<population::size_type>(immigrants.size()));
	// Temporary vectors to store sorted indices of the populations.
	std::vector<population::size_type> immigrants_idx(boost::numeric_cast<std::vector<population::size_type>::size_type>(immigrants.size()));
	std::vector<population::size_type> dest_idx(boost::numeric_cast<std::vector<population::size_type>::size_type>(dest.size()));
	// Fill in the arrays of indices.
	iota(immigrants_idx.begin(),immigrants_idx.end(),population::size_type(0));
	iota(dest_idx.begin(),dest_idx.end(),population::size_type(0));
	// Permute the indices (immigrants).
	for (population::size_type i = 0; i < rate_limit; ++i) {
		population::size_type next_idx = i + (m_urng() % (rate_limit - i));
		if (next_idx != i) {
			std::swap(immigrants_idx[i], immigrants_idx[next_idx]);
		}
	}
	// Permute the indices (destination).
	for (population::size_type i = 0; i < rate_limit; ++i) {
		population::size_type next_idx = i + (m_urng() % (dest.size() - i));
		if (next_idx != i) {
			std::swap(dest_idx[i], dest_idx[next_idx]);
		}
	}
	// Return value.
	std::vector<std::pair<population::size_type,std::vector<population::individual_type>::size_type> >
		retval;
	for (population::size_type i = 0; i < rate_limit; ++i) {
		retval.push_back(std::make_pair(dest_idx[i],immigrants_idx[i]));
	}
	return retval;
}
コード例 #2
0
ファイル: image.hpp プロジェクト: TUTProCon2014/utils
 static std::enable_if_t<is_divided_image<T>(),
 void> foreach(T const & pb, F f)
 {
     for(auto i: iota(0, pb.div_y()))
         for(auto j: iota(0, pb.div_x()))
             f(i, j);
 }
コード例 #3
0
TEST(MapFilterReduce, Reduce2)
{
  int a[5]{ 0 };
  iota(a, a+5, 10);
  ASSERT_THAT(a, ElementsAre(10, 11, 12, 13, 14));
  auto sum = accumulate(a, a+5, 0, adder());
}
コード例 #4
0
ファイル: Battlefield.cpp プロジェクト: CraigularB/battle-sim
void Battlefield::draw() const
{
    std::vector<int> entityIds(entities_.size());
    iota(std::begin(entityIds), std::end(entityIds), 0);

    // Arrange entities logically by z-order.
    sort(std::begin(entityIds), std::end(entityIds), [&] (int a, int b)
         { return getEntity(a).z < getEntity(b).z; });

    sdlClear(displayArea_);
    SdlSetClipRect(displayArea_, [&] {
        for (auto id : entityIds) {
            const auto &e = getEntity(id);
            if (e.visible) {
                if (e.frame < 0) {
                    sdlBlit(e.img, sPixelFromHex(e.hex) + e.pOffset);
                }
                else {
                    sdlBlitFrame(e.img, e.frame, e.numFrames,
                                 sPixelFromHex(e.hex) + e.pOffset);
                }
            }
        }
    });
}
コード例 #5
0
void getAllUnitShifts(const Mat& rgbImg, vector<Mat> &shifts)
    {
    vector<int> indexes(9);
    iota(indexes.begin(), indexes.end(), 0); // (0..8)
    indexes.erase(indexes.begin() + 4); // (0..3, 5..8)

    vector<CvPoint> points;
    transform(indexes.begin(), indexes.end(), back_inserter(points), [](int i) { return cvPoint(i/3, i%3); });
    // (0, 0) -> [1,0,0; 0,0,0; 0,0,0]
    // (0, 1) -> [0,0,0; 1,0,0; 0,0,0]
    // (0, 2) -> [0,0,0; 0,0,0; 1,0,0]
    // (1, 0) -> [0,1,0; 0,0,0; 0,0,0]
    // (1, 1) -> [0,0,0; 0,1,0; 0,0,0] <-- erased (identical shift)
    // (1, 2) -> [0,0,0; 0,0,0; 0,1,0]
    // (2, 0) -> [0,0,1; 0,0,0; 0,0,0]
    // (2, 1) -> [0,0,0; 0,0,1; 0,0,0]
    // (2, 2) -> [0,0,0; 0,0,0; 0,0,1]

    transform(points.begin(), points.end(), back_inserter(shifts),
        [rgbImg] (const CvPoint &delta)
            {
            Mat kernel(3, 3, rgbImg.depth(), Scalar().all(0));
            kernel.at<float>(1, 1) = 1.0f;
            Mat shift = Mat(rgbImg.rows, rgbImg.cols, rgbImg.type(), Scalar().all(0));
            filter2D(rgbImg, shift, -1 , kernel, delta, 0, BORDER_CONSTANT);
            return shift;
            });
    }
コード例 #6
0
ファイル: ct.c プロジェクト: EdKeith/core
static A jttayamp(J jt,A w,B nf,A x,A h){A y;B ng=!nf;I j,n;V*v=VAV(h);
 ASSERT(AR(x)<=(nf?v->lr:v->rr),EVRANK);
 switch(v->id){
  case CPLUS:  R tpoly(over(x,one));
  case CMINUS: R tpoly(nf?over(x,num[-1]):over(negate(x),one));
  case CSTAR:  R tpoly(over(zero,x));
  case CDIV:   ASSERT(ng,EVDOMAIN); R tpoly(over(zero,recip(x)));
  case CJDOT:  R tpoly(nf?over(x,a0j1):over(jdot1(x),one));
  case CPOLY:  ASSERT(nf,EVDOMAIN); R tpoly(BOX&AT(x)?poly1(x):x);
  case CHGEOM: ASSERT(nf,EVDOMAIN); RE(j=i0(x)); ASSERT(0<=j,EVDOMAIN);
               y=IX(j);
               R tpoly(divide(hgcoeff(y,h),fact(y)));
  case CBANG:  ASSERT(nf,EVDOMAIN); RE(j=i0(x)); ASSERT(0<=j,EVDOMAIN); 
               R tpoly(divide(poly1(box(iota(x))),fact(x)));
  case CEXP:   if(nf)R eva(x,"(^.x)&^ % !");
               RE(n=i0(x));   
               R 0<=n?tpoly(over(reshape(x,zero),one)):atop(ds(CDIV),amp(h,sc(-n))); 
  case CFIT:   ASSERT(nf&&CPOLY==ID(v->f),EVDOMAIN);
               y=over(x,IX(IC(x)));
               R tpoly(mdiv(df2(x,y,h),atab(CEXP,y,IX(IC(x)))));
  case CCIRCLE:
   switch(i0(x)){
    case 1:    R eval("{&0 1 0 _1@(4&|) % !");
    case -3:   R eval("{&0 1 0 _1@(4&|) % ]");
    case 2:    R eval("{&1 0 _1 0@(4&|) % !");
    case 5:    R eval("2&|    % !");
    case -7:   R eval("2&|    % ]");
    case 6:    R eval("2&|@>: % !");
    case -1:   R eval("(2&|              % ]) * ([: */ (1&+ % 2&+)@(i.@<.&.-:))\"0");
    case -5:   R eval("({&0 1 0 _1@(4&|) % ]) * ([: */ (1&+ % 2&+)@(i.@<.&.-:))\"0");
 }}
 ASSERT(0,EVDOMAIN);
}
コード例 #7
0
void iota_vector(hpx::partitioned_vector<T>& v, T val)
{
    auto first = v.begin();
    auto last = v.end();

    typedef hpx::traits::segmented_iterator_traits<decltype(first)> traits;
    typedef typename traits::segment_iterator segment_iterator;
    typedef typename traits::local_iterator local_iterator_type;

    segment_iterator sit = traits::segment(first);
    segment_iterator send = traits::segment(last);

    T temp_val = val;

    for (; sit != send; ++sit)
    {
        local_iterator_type beg = traits::begin(sit);
        local_iterator_type end = traits::end(sit);

        hpx::parallel::v1::detail::dispatch(traits::get_id(sit),
            iota(), hpx::parallel::seq, std::true_type(), beg, end, temp_val
        );

        temp_val = T(temp_val + std::distance(beg, end));
    }
}
コード例 #8
0
int main(int, char** argv)
{
    mtl::vampir_trace<9999> tracer;
    typedef double value_type;
       
    std::string program_dir= mtl::io::directory_name(argv[0]),
  	        matrix_file= mtl::io::join(program_dir, "../../mtl/test/matrix_market/square3.mtx");
// 		matrix_file= mtl::io::join(program_dir, "../../mtl/test/matrix_market/obstacle_small.mtx");
// 	        matrix_file= mtl::io::join(program_dir, "../../../../../branches/data/matrix_market/obstacle_q1q1_e64/obstacle_q1q1_e64_r00800.mtx");

    
    mtl::matrix::element_structure<value_type> A;
    read_el_matrix(matrix_file, A);
    A.make_compact();

    const int size= A.get_total_vars();
    mtl::dense_vector<value_type>              x(size, 1), b(size), ident(size); 
    iota(ident);
    b= 7.0;
     
    for (int i= 0; i < 100; i++) {
	b+= A * x;
	if (size <= 100)
	    std::cout << "b = " << b << '\n';
    }

    if (size <= 100)
	std::cout << "b = " << b << '\n';

    return 0;
}
コード例 #9
0
	/**
	 * @param connections given a list of connections include two cities and cost
	 * @return a list of connections from results
	 */
	vector<Connection> lowestCost(vector<Connection>& connections) {
		sort(connections.begin(), connections.end(), Comp());
		unordered_map<string, int> labels;
		int n = 0;
		for (const auto & i : connections) {
			if (!labels.count(i.city1)) {
				labels[i.city1] = n;
				++n;
			}
			if (!labels.count(i.city2)) {
				labels[i.city2] = n;
				++n;
			}
		}
		vector<int> roots(n);
		iota(roots.begin(), roots.end(), 0);
		vector<Connection> result;
		for (const auto & i : connections) {
			int label1 = labels[i.city1], label2 = labels[i.city2];
			int root1 = getRoot(roots, label1), root2 = getRoot(roots, label2);
			if (root1 != root2) {
				roots[root1] = root2;
				--n;
				result.push_back(i);
			}
		}
		return n == 1 ? result : vector<Connection>();
	}
コード例 #10
0
void KeccakPermutationOnWords(UINT64 *state)
{
    unsigned int i;

    //displayStateAsWords(3, "Same, as words", state);

    for(i=0; i<nrRounds; i++) {
        //displayRoundNumber(3, i);

        theta(state);
        //displayStateAsWords(3, "After theta", state);

        rho(state);
        //displayStateAsWords(3, "After rho", state);

        pi(state);
        //displayStateAsWords(3, "After pi", state);

        chi(state);
        //displayStateAsWords(3, "After chi", state);

        iota(state, i);
        //displayStateAsWords(3, "After iota", state);
    }
}
コード例 #11
0
ファイル: greedy.cpp プロジェクト: lautaroalvarez/facultad
coloreo greedy_secuencial_1aN(grafo& g) {
	coloreo c(g, -1);
	vector<int> nodos(g.n());
	iota(nodos.begin(), nodos.end(), 0);
	c.colorear_secuencial(nodos);
	return c;
}
コード例 #12
0
int main() {
    std::vector<int> v(20);
    iota(v.begin(),v.end(),1);
    std::cout << sum(v.begin(),v.end(),X{}) << '\n';
    std::cout << add("hallo\n",2);
    std::cout << add(2,"hallo\n");
}
コード例 #13
0
 vector<int> countSmaller(vector<int>& nums) {
     int n = nums.size();
     vector<int> results(n, 0);
     vector<int> indices(n, 0);
     iota(indices.begin(), indices.end(), 0);
     merge_countSmaller(indices, 0, n, results, nums);
     return results;
 }
コード例 #14
0
ファイル: greedy.cpp プロジェクト: lautaroalvarez/facultad
coloreo greedy_random(grafo& g) {
	vector<int> nodos(g.n());
	iota(nodos.begin(), nodos.end(), 0);
	random_shuffle(nodos.begin(), nodos.end());
	coloreo c(g, -1);
	c.colorear_secuencial(nodos);
	return c;
}
コード例 #15
0
ファイル: test_numeric.cpp プロジェクト: MagnusTiberius/code
TEST(Numeric, iota)
{
  int a[5] = { 0 };
  iota(a, a+5, 10);
  ASSERT_THAT(a, ElementsAre(10, 11, 12, 13, 14));
  auto add = [=](double memo, double x) { return memo + x; };
  auto sum = accumulate(a, a+5, 0, add);
}
コード例 #16
0
ファイル: main.cpp プロジェクト: CCJY/coliru
int main()
{
	std::vector<int> c(5);
	iota(begin(c), end(c), 0);
	increment_and_println(c);
	std::vector<int> d{c};
	increment_and_println(d);
    increment_and_println(std::vector<int>{0, 1, 2, 3, 4});
}
コード例 #17
0
        const_iterator()
            : t0(0), t1(0), t2(0), i(0)

            {
                iota(std::begin(ops),
                     std::end(ops),
                     0);
                start_scope();
            }
コード例 #18
0
ファイル: iterswp1.cpp プロジェクト: ABratovic/open-watcom-v2
int main ()
{
  vector <int> v1 (6);
  iota (v1.begin (), v1.end (), 0);
  iter_swap (v1.begin (), v1.begin () + 3);
  ostream_iterator <int> iter (cout, " ");
  copy (v1.begin (), v1.end (), iter);
  cout << endl;
  return 0;
}
 bool equationsPossible(vector<string>& equations) {        
   iota(begin(parents_), end(parents_), 0);    
   for (const auto& eq : equations)     
     if (eq[1] == '=')
       parents_[find(eq[0])] = find(eq[3]);
   for (const auto& eq : equations)     
     if (eq[1] == '!' && find(eq[0]) == find(eq[3]))        
         return false;
   return true;
 }
コード例 #20
0
        explicit
        const_iterator(int count0)
            : t0(0), count0(count0), t1(0), t2(0), i(0)

            {
                iota(std::begin(ops),
                     std::end(ops),
                     0);
                start_scope();
            }
コード例 #21
0
ファイル: keccak_coproc.c プロジェクト: hoangt/PandA-bambu
void keccak_coproc(UINT64 *A)
{
    unsigned int i;
    for(i=0;i<nrRounds;i++) { 
        theta(A);
        rho(A);
        pi(A);
        chi(A);
        iota(A,i);
    }
}
コード例 #22
0
ファイル: iterswp1.cpp プロジェクト: stormbrew/stir
int iterswp1_test(int, char**)
{
  std::cout<<"Results of iterswp1_test:"<<std::endl;
  std::vector <int> v1(6);
  iota(v1.begin(), v1.end(), 0);
  std::iter_swap(v1.begin(), v1.begin() + 3);
  std::ostream_iterator <int> iter(std::cout, " ");
  std::copy(v1.begin(), v1.end(), iter);
  std::cout << std::endl;
  return 0;
}
コード例 #23
0
ファイル: PerlinNoise.cpp プロジェクト: Blanel/agi_project_2
PerlinNoise::PerlinNoise(u32 seed)
{
	p.resize(256);
	mt19937 rng;
	rng.seed(seed);

	iota(begin(p), end(p), 0);
	shuffle(begin(p), end(p), rng);

	p.insert(end(p), begin(p), end(p));
}
コード例 #24
0
ファイル: partsum1.cpp プロジェクト: ABratovic/open-watcom-v2
int main ()
{
  vector <int> v1 (10);
  iota (v1.begin (), v1.end (), 0);
  vector <int> v2 (v1.size());
  partial_sum (v1.begin (), v1.end (), v2.begin ());
  ostream_iterator <int> iter (cout, " ");
  copy (v1.begin (), v1.end (), iter);
  cout << endl;
  copy (v2.begin (), v2.end (), iter);
  cout << endl;
  return 0;
}
コード例 #25
0
ファイル: mismtch1.cpp プロジェクト: stormbrew/stir
int mismtch1_test(int, char**)
{
    std::cout<<"Results of mismtch1_test:"<<std::endl;
    typedef std::vector<int> IntVec;
    IntVec v1(10);
    IntVec v2(v1.size());
    iota(v1.begin(), v1.end(), 0);
    iota(v2.begin(), v2.end(), 0);
    std::pair <IntVec::iterator, IntVec::iterator> result =
        std::mismatch(v1.begin(), v1.end(), v2.begin());
    if(result.first == v1.end() && result.second == v2.end())
        std::cout << "v1 and v2 are the same" << std::endl;
    else
        std::cout << "mismatch at index: " <<(result.first - v1.begin()) << std::endl;
    v2[v2.size()/2] = 42;
    result = std::mismatch(v1.begin(), v1.end(), v2.begin());
    if(result.first == v1.end() && result.second == v2.end())
        std::cout << "v1 and v2 are the same" << std::endl;
    else
        std::cout << "mismatch at index: " <<(result.first - v1.begin()) << std::endl;
    return 0;
}
コード例 #26
0
    bool validTree(int n, vector<pair<int, int>>& edges) {
        int sz = edges.size();
        if(sz != n-1) return false;
        vector<int> inC(n, 0);
        iota(inC.begin(), inC.end(), 0);
        for(int i = 0 ;  i < sz; i ++){
            int ac = findU(edges[i].first, inC), bc = findU(edges[i].second, inC);
            if(ac == bc) return false;
            inC[ac] = bc;
        }
        return true;

    }
コード例 #27
0
 int maxChunksToSorted(vector<int>& arr) {
     int n = arr.size();
     vector<int> index(n);
     iota(index.begin(), index.end(), 0);
     sort(index.begin(), index.end(), [&arr](int i1, int i2){return arr[i1] == arr[i2] ? i1 < i2 : arr[i1] < arr[i2];});
     
     int maxNum = 0, count = 0;
     for (int i = 0; i < index.size(); ++i) {
         maxNum = max(maxNum, index[i]);
         if (maxNum == i) ++count;
     }
     
     return count;
 }
コード例 #28
0
ファイル: partsum2.cpp プロジェクト: stormbrew/stir
int partsum2_test(int, char**)
{
  std::cout<<"Results of partsum2_test:"<<std::endl;
  std::vector <int> v1(5);
  iota(v1.begin(), v1.end(), 1);
  std::vector <int> v2(v1.size());
  std::partial_sum(v1.begin(), v1.end(), v2.begin(), std::multiplies<int>());
  std::ostream_iterator <int> iter(std::cout, " ");
  std::copy(v1.begin(), v1.end(), iter);
  std::cout << std::endl;
  std::copy(v2.begin(), v2.end(), iter);
  std::cout << std::endl;
  return 0;
}
コード例 #29
0
ファイル: fractab.cpp プロジェクト: daut-morina/HSR-Prog3
void fractab(std::ostream &out, unsigned int size)
{
    std::vector<float> numbers(size);

    iota(numbers.begin(), numbers.end(), 1);

    for_each(numbers.begin(), numbers.end(), [&](int line) {
        for_each(numbers.begin(), numbers.end(), [&](int column) {
            out << (float) line / column << "\t";
        });

        out << "\n";
    });
}
コード例 #30
0
 /**
  * @param s a string
  * @return an integer
  */
 int minCut(string s) {
     vector<deque<bool>> is_palindrome(s.size(), deque<bool>(s.size(), false));
     vector<int> T(s.size() + 1);
     iota(T.rbegin(), T.rend(), -1);
     for (int i = s.size() - 1; i >= 0; --i) {
         for (int j = i; j < s.size(); ++j) {
             if (s[i] == s[j] && (j - i < 2 || is_palindrome[i + 1][j - 1])) {
                 is_palindrome[i][j] = true;
                 T[i] = min(T[i], 1 + T[j + 1]);
             }
         }
     }
     return T[0];
 }