static void append(InputIterator first1, InputIterator last1, const Distance length1, InputIterator first2, InputIterator last2, const Distance length2, OutputIterator result) { const auto min = std::min(length1, length2); if (min < 3) { throw std::length_error("Chromosome too short."); } random::RandomEngine eng = random::default_engine(); std::uniform_int_distribution<typename std::remove_const<decltype(min)>::type> dist1(0, min - 2); const auto separator1 = dist1(eng); std::uniform_int_distribution<typename std::remove_const<decltype(min)>::type> dist2(separator1 + 1, length2 - 1); const auto separator2 = dist2(eng); Chromosome offspring(length2); std::copy_n(first1, separator1, begin(offspring)); std::copy_n(first2 + separator1, separator2 - separator1, begin(offspring) + separator1); std::copy_n(first1 + separator2, length2 - separator2, begin(offspring) + separator2); *result++ = offspring; }
bool operator()( Tree &t1 , Tree &t2 ) { typedef typename Tree::cursor cursor; std::uniform_int_distribution< size_t > dist1( 0 , t1.size() - 1 ); std::uniform_int_distribution< size_t > dist2( 0 , t2.size() - 1 ); for( size_t iter = 0 ; iter < m_max_iterations ; ++iter ) { cursor n1 = t1.rank_is( dist1( m_rng ) ); cursor n2 = t2.rank_is( dist2( m_rng ) ); if( cursor_equal( n1 , n2 ) ) { continue; } size_t nh1 = n1.level() + n2.height(); size_t nh2 = n2.level() + n1.height(); if( ( nh1 <= m_max_height ) && ( nh2 <= m_max_height ) ) { swap_subtrees( t1 , n1 , t2 , n2 ); return true; } } return false; }
static int find_link_leftright(LINK far *link, int num_link, int curr_link, int left) { int ctr, curr_c2, best_c2 = 0, temp_c2, best_dist = 0, temp_dist; LINK far *curr, far *temp, far *best; curr = &link[curr_link]; best = NULL; curr_c2 = curr->c + curr->width - 1; for (ctr=0, temp=link; ctr<num_link; ctr++, temp++) { temp_c2 = temp->c + temp->width - 1; if ( ctr != curr_link && ( (left && temp_c2 < (int)curr->c) || (!left && (int)temp->c > curr_c2) ) ) { temp_dist = dist1(curr->r, temp->r); if (best != NULL) { if ( best_dist == 0 && temp_dist == 0 ) /* if both on curr's line... */ { if ( ( left && dist1(curr->c, best_c2) > dist1(curr->c, temp_c2) ) || ( !left && dist1(curr_c2, best->c) > dist1(curr_c2, temp->c) ) ) best = NULL; } else { if ( best_dist >= temp_dist ) /* if temp is closer... */ best = NULL; } } /* if (best...) */ if (best == NULL) { best = temp; best_dist = temp_dist; best_c2 = temp_c2; } } } /* for */ return ( (best==NULL) ? -1 : (int)(best-link) ); }
static int find_link_updown(LINK far *link, int num_link, int curr_link, int up) { int ctr, curr_c2, best_overlap = 0, temp_overlap; LINK far *curr, far *temp, far *best; int temp_dist; curr = &link[curr_link]; best = NULL; curr_c2 = curr->c + curr->width - 1; for (ctr=0, temp=link; ctr<num_link; ctr++, temp++) { if ( ctr != curr_link && ( (up && temp->r < curr->r) || (!up && temp->r > curr->r) ) ) { temp_overlap = overlap(curr->c, curr_c2, temp->c, temp->c+temp->width-1); /* if >= 3 lines between, prioritize on vertical distance: */ if ((temp_dist = dist1(temp->r, curr->r)) >= 4) temp_overlap -= temp_dist * 100; if (best != NULL) { if ( best_overlap >= 0 && temp_overlap >= 0 ) { /* if they're both under curr set to closest in y dir */ if ( dist1(best->r, curr->r) > temp_dist ) best = NULL; } else { if ( best_overlap < temp_overlap ) best = NULL; } } if (best == NULL) { best = temp; best_overlap = temp_overlap; } } } return ( (best==NULL) ? -1 : (int)(best-link) ); }
int main(void) { FILE *file; int i; int cases; file=fopen("input.txt", "r"); if(file==NULL) exit(1); fscanf(file, "%d", &cases); for(i=0;i<cases;i++) { int x1, y1, x2, y2, px, py; fscanf(file, "%d %d %d %d %d %d", &x1, &y1, &x2, &y2, &px, &py); if(inside(x1, y1, x2, y2, px, py) || onedge(x1, y1, x2, y2, px, py)) printf("0 0\n"); else printf("%d %d\n", dist1(x1, y1, x2, y2, px, py), dist2(x1, y1, x2, y2, px, py)); } fclose(file); }
void Graph::teleportRabbit() { Vertex* destination = nullptr; while(destination == nullptr || destination == getCowVertex() || destination == getRabbitVertex()) { std::random_device dev; std::default_random_engine dre(dev()); std::uniform_int_distribution<int> dist1(0, this->getVertices()->size() - 1); int index = dist1(dre); destination = this->getVertices()->at(index); } this->rabbit->setDestination(destination); while(this->rabbit->getRoute()->size() > 0) { this->rabbit->getRoute()->pop_back(); } this->setRabbitVertex(destination); }
FerryDriver (NewtonBody* const body, const dVector& pivot, NewtonBody* const triggerPort0, NewtonBody* const triggerPort1) :CustomKinematicController (body, pivot) ,m_triggerPort0(triggerPort0) ,m_triggerPort1(triggerPort1) ,m_state(m_driving) { dMatrix matrix0; dMatrix matrix1; NewtonBodyGetMatrix(m_triggerPort0, &matrix0[0][0]); NewtonBodyGetMatrix(m_triggerPort1, &matrix1[0][0]); dVector dist0 (matrix0.m_posit - pivot); dVector dist1 (matrix1.m_posit - pivot); //dist0.m_y = 0.0f; //dist1.m_y = 0.0f; if ((dist0 % dist0) < (dist1 % dist1)) { m_target = matrix0.m_posit; m_currentPort = m_triggerPort0; } else { m_target = matrix1.m_posit; m_currentPort = m_triggerPort1; } //m_target.m_y = pivot.m_y; }
void test8() { const int N = 100000; std::mt19937 gen1; std::mt19937 gen2; std::binomial_distribution<> dist1(5, 0.1); std::binomial_distribution<unsigned> dist2(5, 0.1); for(int i = 0; i < N; ++i) { int r1 = dist1(gen1); unsigned r2 = dist2(gen2); assert(r1 >= 0); assert(static_cast<unsigned>(r1) == r2); } }
int main() { double dist(double x1, double y1, double x2, double y2); double dist1(struct Point a, struct Point b); double a = 6, b = 2, c = 2, d = 1; printf("The value is %lf",dist (a, b, c, d)); printf("The value is %lf",dist1 (x,y)); return 0; }
void Module::BeginContact(b2Contact* contact) { auto ba = contact->GetFixtureA()->GetBody(); auto bb = contact->GetFixtureB()->GetBody(); auto oa = static_cast<object::Object*>(ba->GetUserData()); auto ob = static_cast<object::Object*>(bb->GetUserData()); if (!oa->is<plugin::cell::CellBase>() || !ob->is<plugin::cell::CellBase>()) return; auto& ca = static_cast<object::Object*>(ba->GetUserData())->castThrow<plugin::cell::CellBase>(); auto& cb = static_cast<object::Object*>(bb->GetUserData())->castThrow<plugin::cell::CellBase>(); auto radius1 = ca.getShapes()[0].getCircle().radius; auto radius2 = cb.getShapes()[0].getCircle().radius; for (unsigned int i = 0; i < m_bonds.size(); i++) { std::bernoulli_distribution dist1( getAssociationPropensity(m_step, radius1.value(), radius2.value(), ca.getMoleculeCount(m_bonds[i].receptor), cb.getMoleculeCount(m_bonds[i].ligand), m_bonds[i].aConst)); if (dist1(g_gen)) { Log::debug("Joined: ", ba, ", ", bb); m_toJoin.push_back(JointDef{ba, bb, m_bonds[i].dConst}); continue; } std::bernoulli_distribution dist2( getAssociationPropensity(m_step, radius1.value(), radius2.value(), cb.getMoleculeCount(m_bonds[i].receptor), ca.getMoleculeCount(m_bonds[i].ligand), m_bonds[i].aConst)); if (dist2(g_gen)) { Log::debug("Joined: ", ba, ", ", bb); m_toJoin.push_back(JointDef{ba, bb, m_bonds[i].dConst}); continue; } } }
void PairCopulaInvHfun_VecPar(int family, const double *theta, double *U, double *V, double *u, unsigned int n) { unsigned int i; switch(family){ case 1: case 2: case 8: case 11: case 13: case 14: case 15: { // 1 Parameter: AMH, AsymFGM, FGM, Gumbel, Joe, PartialFrank, Plackett double UU, VV; for (i=0;i<n;i++) { UU = CheckBounds(U[i]); VV = CheckBounds(V[i]); u[i] = invhfun_bisect(family,theta[i],UU,VV,n); } break; } case 3: case 4: case 5: case 6: case 12: case 16: case 17: { // 2 Parameters: BB1, BB6, BB7, BB8, IteratedFGM, Tawn1, Tawn2 double UU, VV; for (i=0;i<n;i++) { UU = CheckBounds(U[i]); VV = CheckBounds(V[i]); u[i] = invhfun_bisect(family,theta[i],theta[i+n],UU,VV,n); } break; } case 18: { // 3 Parameters: Tawn double UU, VV; for (i=0;i<n;i++) { UU = CheckBounds(U[i]); VV = CheckBounds(V[i]); u[i] = invhfun_bisect(family,theta[i],theta[i+n],theta[i+2*n],UU,VV,n); } break; } case 0: { // Indep for (i=0;i<n;i++) { *(u+i) = U[i]; } break; } case 7: { //Clayton double h1,h2,UU,VV,uu; for (i=0;i<n;i++) { h1 = -1/ theta[i]; h2 = -theta[i]/(1+theta[i]); UU = CheckBounds(U[i]); VV = CheckBounds(V[i]); uu = pow(pow(VV,-theta[i])*(pow(UU,h2)-1)+1,h1); *(u+i) = CheckBounds(uu); } break; } case 9: { // Frank double h1,h2,h3,h4,VV,UU,uu; for (i=0;i<n;i++) { h1 = exp(-theta[i]); h2 = expm1(-theta[i]); h3 = -1/ theta[i]; UU = CheckBounds(U[i]); VV = CheckBounds(V[i]); h4 = pow(h1,VV); uu = h3*log(1+h2/(h4*(1/UU-1)+1)); *(u+i) = CheckBounds(uu); } break; } case 10: { // Gaussian double x, y, h1,UU,VV,uu; for (i=0;i<n;i++) { h1 = sqrt(1-pow(theta[i],2)); boost::math::normal dist(0,1); UU = CheckBounds(U[i]); VV = CheckBounds(V[i]); x = boost::math::quantile(dist, UU); y = boost::math::quantile(dist, VV); uu = boost::math::cdf(dist, x*h1+theta[i]*y); *(u+i) = CheckBounds(uu); } break; } case 19: { // t double x, y, h1, nu1,UU,VV,uu; for (i=0;i<n;i++) { h1 = 1-pow(theta[i],2); nu1 = theta[i+n]+1; boost::math::students_t dist1(theta[i+n]); boost::math::students_t dist2(nu1); UU = CheckBounds(U[i]); VV = CheckBounds(V[i]); x = boost::math::quantile(dist2, UU); y = boost::math::quantile(dist1, VV); uu = boost::math::cdf(dist1, x*sqrt((theta[i+n]+pow(y,2))*h1/nu1)+theta[i]*y); *(u+i) = CheckBounds(uu); } break; } } return; }
int _tmain(int argc, _TCHAR* argv[]) { // seed value auto curTime = std::chrono::system_clock::now(); auto duration = curTime.time_since_epoch(); auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count(); std::mt19937 mtRand(millis); std::uniform_int_distribution<__int64> dist1(0, 1); char element[4][4]; for (int i = 0; i < 4; ++i) for (int j = 0; j < 4; ++j) element[i][j] = '0'; for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { element[i][j] = dist1(mtRand) ? '*' : element[i][j]; if (element[i][j] == '*') { for (int i2 = i - 1; i2 < i + 1; ++i2) { for (int j2 = j - 1; j2 < j + 1; ++j2) { if (j2 > -1 && i2 > -1) { if (element[i2][j2] != '*') { element[i2][j2] += 1; } } } } } } } for (int i3 = 0; i3 < 4; ++i3) { for (int j3 = 0; j3 < 4; ++j3) { std::cout << element[i3][j3]; } std::cout << std::endl; } //for (int i = 0; i < 4; ++i) //{ // for (int k = 0; k < 4; ++k) // { // //element[i][k] = *std::to_string(dist1(mtRand)).c_str(); // //element[i][k] = dist1(mtRand) ? '*' : '.'; // // std::cout << i << k << ' '; // //std::cout << element[i][k] << ' '; // } // std::cout << std::endl; //} system("pause"); return 0; }