• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ dis函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中dis函数的典型用法代码示例。如果您正苦于以下问题:C++ dis函数的具体用法?C++ dis怎么用?C++ dis使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了dis函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: RTEST

  Object* Proc::call(STATE, CallFrame* call_frame, Arguments& args) {
    bool lambda_style = RTEST(lambda_);
    int flags = 0;

    // Check the arity in lambda mode
    if(lambda_style) {
      flags = CallFrame::cIsLambda;
      int total = block_->code()->total_args()->to_native();
      int required = block_->code()->required_args()->to_native();

      bool arity_ok = false;
      if(Fixnum* fix = try_as<Fixnum>(block_->code()->splat())) {
        switch(fix->to_native()) {
        case -2:
          arity_ok = true;
          break;
        case -4:
          // splat = -4 means { |(a, b)| }
          if(args.total() == 1) {
            Array* ary = 0;
            Object* obj = args.get_argument(0);

            if(!(ary = try_as<Array>(obj))) {
              if(RTEST(obj->respond_to(state, state->symbol("to_ary"), Qfalse))) {
                obj = obj->send(state, call_frame, state->symbol("to_ary"));
                if(!(ary = try_as<Array>(obj))) {
                  Exception::type_error(state, "to_ary must return an Array", call_frame);
                  return 0;
                }
              }
            }

            if(ary) args.use_argument(ary);
          }
          // fall through for arity check
        case -3:
          // splat = -3 is used to distinguish { |a, | } from { |a| }
          if(args.total() == (size_t)required) arity_ok = true;
          break;
        default:
          if(args.total() >= (size_t)required) {
            arity_ok = true;
          }
        }

      /* For blocks taking one argument { |a|  }, in 1.8, there is a warning
       * issued but no exception raised when less than or more than one
       * argument is passed. If more than one is passed, 'a' receives an Array
       * of all the arguments.
       */
      } else if(required == 1 && LANGUAGE_18_ENABLED(state)) {
        arity_ok = true;
      } else {
        arity_ok = args.total() <= (size_t)total &&
                   args.total() >= (size_t)required;
      }

      if(!arity_ok) {
        Exception* exc =
          Exception::make_argument_error(state, required, args.total(),
              state->symbol("__block__"));
        exc->locations(state, Location::from_call_stack(state, call_frame));
        state->thread_state()->raise_exception(exc);
        return NULL;
      }
    }

    Object* ret;
    if(bound_method_->nil_p()) {
      ret = block_->call(state, call_frame, args, flags);
    } else if(NativeMethod* nm = try_as<NativeMethod>(bound_method_)) {
      ret = nm->execute(state, call_frame, nm, G(object), args);
    } else {
      Dispatch dis(state->symbol("__yield__"));
      ret = dis.send(state, call_frame, args);
    }

    return ret;
  }
开发者ID:AndrewVos,项目名称:rubinius,代码行数:79,代码来源:proc.cpp


示例2: Trajectory

int Trajectory(double* X1, double* X2, double* Phi1, double* Phi2, double* K, int numProcs, int myID)
{
    double* Eta = new double[TOT];
    double* P = new double[TOT];
    double* F = new double[TOT];
    double* temK = new double[TOT];
    double* temBuf = new double[TOT];
    double t = sqrt(0.5);
    int flag;
    MPI_Generate(Eta, t, numProcs, myID);
    M(Eta, Phi1, K, numProcs, myID);
    MPI_Generate(Eta, t, numProcs, myID);
    M(Eta, Phi2, K, numProcs, myID);
    MPI_Setzero(X1, numProcs, myID);
    MPI_Setzero(X2, numProcs, myID);
    MPI_Generate(P, 1.0, numProcs, myID);
    MPI_Assign(K, temK, numProcs, myID);
    double hamStart = Hamiltonian(X1, X2, Phi1, Phi2, P, K, numProcs, myID);
    flag = FermionForce(X1, X2, Phi1, Phi2, F, K, numProcs, myID);
    if(!flag)
    {
        MPI_Assign(temK, K, numProcs, myID);
        return 0;
    }
    MPI_Multiply(F, 0.5*dt, temBuf, numProcs, myID);
    MPI_Add(P, temBuf, P, numProcs, myID);
    for(int i = 0; i<(N_md-1); i++)
    {
        MPI_Multiply(P, dt, temBuf, numProcs, myID);
        MPI_Add(K, temBuf, K, numProcs, myID);
        flag = FermionForce(X1, X2, Phi1, Phi2, F, K, numProcs, myID);
        if(!flag)
        {
            MPI_Assign(temK, K, numProcs, myID);
            return 0;
        }
        MPI_Multiply(F, dt, temBuf, numProcs, myID);
        MPI_Add(P, temBuf, P, numProcs, myID);
    }
    MPI_Multiply(P, dt, temBuf, numProcs, myID);
    MPI_Add(K, temBuf, K, numProcs, myID);
    flag = FermionForce(X1, X2, Phi1, Phi2, F, K, numProcs, myID);
    if(!flag)
    {
        MPI_Assign(temK, K, numProcs, myID);
        return 0;
    }
    MPI_Multiply(F, 0.5*dt, temBuf, numProcs, myID);
    MPI_Add(P, temBuf, P, numProcs, myID);
    double hamEnd = Hamiltonian(X1, X2, Phi1, Phi2, P, K, numProcs, myID);
    double r = 0.0;
    if(myID == ROOT)
    {
        random_device rd;
        mt19937 generator(rd());
        uniform_real_distribution<double> dis(0.0, 1.0);
        r = dis(generator);
    }
    MPI_Bcast(&r, 1, MPI_DOUBLE, ROOT, MPI_COMM_WORLD);
    double s = exp(hamStart-hamEnd);
    if(myID == ROOT)
    {
        ofstream file_log("evolution.log", ios_base::app);
        file_log<<"Hamiltoian: "<<hamStart<<" "<<hamEnd<<" "<<r<<" "<<s<<endl;
        file_log.close();
    }
    delete [] Eta;
    delete [] P;
    delete [] F;
    delete [] temK;
    delete [] temBuf;
    if(r<s)
    {
        return 1;
    }
    else
    {
        MPI_Assign(temK, K, numProcs, myID);
        return 0;
    }
}
开发者ID:intuitionofmind,项目名称:graphene,代码行数:81,代码来源:distribution.cpp


示例3: bfs

node_bfs* bfs(nodetype *vertex,int p){
int search,count1=0,l=1,a[100],t=1,count=0,i;
nodetype *s;
node_bfs *head,*m,*tmp,*y;
node *k;
head=NULL;
printf("The starting vertex\n");
scanf("%d",&search);
a[0]=search;
for(i=0;i<p;i++){
s=vertex;
while(search!=s->edge){
s=s->next;
}
//printf("%d\n",s->edge);
if(head==NULL){
head=getnode_bfs(head);
head->level=0;
head->gave_level=-1;
head->edge_value=s->edge;
m=head;
y=head;
}
//printf("%d\n",s->edge);
k=s->adj_edge;
//printf("%d\n",k->value);
while(k!=NULL){
//printf("%d\n",k->value);
while(y!=NULL){
//printf("%d ",y->edge_value);
if(k->value==y->edge_value){
count1++;
}
//printf("%d ",count1);
y=y->front;
}
y=head;
//printf("%d\n",count1);
if(count1==0){
tmp=getnode_bfs(tmp);
tmp->gave_level=s->edge;
a[l++]=k->value;
//printf("%d ",a[l-1]);
while(s->edge!=y->edge_value){
//printf("%d",y->edge_value);
y=y->front;
}
//printf("\n");
tmp->edge_value=k->value;
tmp->level=y->level+1;
m->front=tmp;
m=m->front;
}
y=head;
k=k->next_adj_edge;
//count++;
}
//printf("\n");
search=a[t++];
count1=0;
//dis(head);
//printf("%d\n",search);
}
dis(head);
}
开发者ID:arjun045,项目名称:codechef_programs,代码行数:65,代码来源:BFS_graph.c


示例4: dis

	int math::random_range(int min, int max)
	{ 
		std::uniform_int_distribution<> dis(min, max);
		return dis(gen);
	}
开发者ID:nomadfighter,项目名称:ZFL,代码行数:5,代码来源:math.cpp


示例5: samplePointsGrid

APPROXMVBB_EXPORT void samplePointsGrid(Matrix3Dyn & newPoints,
                      const MatrixBase<Derived> & points,
                      const unsigned int nPoints,
                      OOBB & oobb) {


    if(nPoints >= points.cols() || nPoints < 2) {
        ApproxMVBB_ERRORMSG("Wrong arguements!")
    }

    newPoints.resize(3,nPoints);

    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<unsigned int> dis(0, points.cols()-1);

    //total points = bottomPoints=gridSize^2  + topPoints=gridSize^2
    unsigned int gridSize = std::max( static_cast<unsigned int>( std::sqrt( static_cast<double>(nPoints) / 2.0 )) , 1U );

    // Set z-Axis to longest dimension
    //std::cout << oobb.m_minPoint.transpose() << std::endl;
    oobb.setZAxisLongest();

    unsigned int halfSampleSize = gridSize*gridSize;
    std::vector< std::pair<unsigned int , PREC > > topPoints(halfSampleSize,    std::pair<unsigned int,PREC>{} );    // grid of indices of the top points (indexed from 1 )
    std::vector< std::pair<unsigned int , PREC > > bottomPoints(halfSampleSize, std::pair<unsigned int,PREC>{} ); // grid of indices of the bottom points (indexed from 1 )

    using LongInt = long long int;
    MyMatrix<LongInt>::Array2 idx; // Normalized P
    //std::cout << oobb.extent() << std::endl;
    //std::cout << oobb.m_minPoint.transpose() << std::endl;
    Array2 dxdyInv =  Array2(gridSize,gridSize) / oobb.extent().head<2>(); // in K Frame;
    Vector3 K_p;

    Matrix33 A_KI(oobb.m_q_KI.matrix().transpose());

    // Register points in grid
    auto size = points.cols();
    for(unsigned int i=0; i<size; ++i) {

        K_p = A_KI * points.col(i);
        // get x index in grid
        idx = (  (K_p - oobb.m_minPoint).head<2>().array() * dxdyInv ).template cast<LongInt>();
        // map to grid
        idx(0) = std::max(   std::min( LongInt(gridSize-1), idx(0)),  0LL   );
        idx(1) = std::max(   std::min( LongInt(gridSize-1), idx(1)),  0LL   );
        //std::cout << idx.transpose() << std::endl;
        unsigned int pos = idx(0) + idx(1)*gridSize;

        // Register points in grid
        // if z axis of p is > topPoints[pos]  -> set new top point at pos
        // if z axis of p is < bottom[pos]     -> set new bottom point at pos

        if( topPoints[pos].first == 0) {
            topPoints[pos].first  = bottomPoints[pos].first  = i+1;
            topPoints[pos].second = bottomPoints[pos].second = K_p(2);
        } else {
            if( topPoints[pos].second < K_p(2) ) {
                topPoints[pos].first = i+1;
                topPoints[pos].second = K_p(2);
            }
            if( bottomPoints[pos].second > K_p(2) ) {
                bottomPoints[pos].first = i+1;
                bottomPoints[pos].second = K_p(2);
            }
        }
    }

    // Copy top and bottom points
    unsigned int k=0;

    // k does not overflow -> 2* halfSampleSize = 2*gridSize*gridSize <= nPoints;
    for(unsigned int i=0; i<halfSampleSize; ++i) {
        if( topPoints[i].first != 0 ) {
            // comment in if you want the points top points of the grid
//            Array3 a(i % gridSize,i/gridSize,oobb.m_maxPoint(2)-oobb.m_minPoint(2));
//            a.head<2>()*=dxdyInv.inverse();
            newPoints.col(k++) =  points.col(topPoints[i].first-1);  //  A_KI.transpose()*(oobb.m_minPoint + a.matrix()).eval() ;
            if(topPoints[i].first != bottomPoints[i].first) {
                // comment in if you want the bottom points of the grid
//                Array3 a(i % gridSize,i/gridSize,0);
//                a.head<2>()*=dxdyInv.inverse();
                newPoints.col(k++) = points.col(bottomPoints[i].first-1); //  A_KI.transpose()*(oobb.m_minPoint + a.matrix()).eval() ;
            }
        }
    }
    // Add random points!
    while( k < nPoints) {
        newPoints.col(k++) = points.col( dis(gen) ); //= Vector3(0,0,0);//
    }
}
开发者ID:drmateo,项目名称:ApproxMVBB,代码行数:91,代码来源:ComputeApproxMVBB.hpp


示例6: contain

inline bool contain(const circle &a, const circle &b) {
	return a.radius > dis(a.center, b.center) + b.radius - EPS;
}
开发者ID:ysyshtc,项目名称:Reaper_SCL,代码行数:3,代码来源:page.cpp


示例7: cmp

bool cmp(const point &a,const point &b)
{
    if(fabs(det(p[0],a,b))<eps)
        return dis(p[0],a)<dis(p[0],b);
    return det(p[0],a,b)>0;
}
开发者ID:AssaultKoder95,项目名称:codejam,代码行数:6,代码来源:graham_scan.cpp


示例8: generator

void generator(double a, double b, double& num){
	std::random_device rd;
	std::mt19937 gen(rd());
	std::uniform_real_distribution<> dis(a, b);
	num = dis(gen);
}
开发者ID:poriesto,项目名称:ModelChannel,代码行数:6,代码来源:api.cpp


示例9: main

int main(int argc, char** argv) {
	CommandServer cs(1);
	cs.init();

	CommonNet dis(1);
	dis.init_server(100);

	PROCESS_INFORMATION pi = {0};
	STARTUPINFO si = {0};
	si.cb = sizeof(si);

	HANDLE hnd = GetCurrentProcess();

	printf("Listening\nhandle %d\n", hnd);

	LPSECURITY_ATTRIBUTES lp_attributes;
	LPSECURITY_ATTRIBUTES lpThreadAttributes;
	STARTUPINFO startupInfo = {sizeof(startupInfo)};
	memset(&startupInfo,0,sizeof(STARTUPINFO));
	startupInfo.cb = sizeof(STARTUPINFO);
	startupInfo.dwFlags=0;
	startupInfo.wShowWindow = SW_HIDE;

	PROCESS_INFORMATION processInformation;
	char cmdLine[100];
	string AppName;
	int recv_len = 0;
	char RecvB[100];

	if(argc == 2 || argc == 3) {
		//启动游戏进程
		DWORD id = GetCurrentProcessId();

		int dump_mesh = 0;
		if(argc == 3) dump_mesh = 1;

		sprintf(cmdLine,"%s %d %d %d %d",argv[1], dump_mesh, -1,-1, id);
		printf("cmd line is %s\n", cmdLine);

		bool ret = DetourCreateProcessWithDll(NULL,cmdLine, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
			NULL, NULL, &si, &pi, "game_server.dll", NULL);

		if(!ret) {
			char err_str[200];
			sprintf(err_str, "Game Start %s Failed", AppName.c_str());
			MessageBox(NULL, err_str, "Error", MB_OK);
		}

		return 0;
	}

	while(true) {
		cs.accept_client();
		printf("client has come with connect socket:%d\n", cs.get_connect_socket());

		dis.AcceptClient(1);
		printf("input client connect to socket:%d\n", dis.get_connect_socket());
		
		cs.recv_raw_buffer(AppName, recv_len);
		if(recv_len <= 0) {
			printf("recv error\n");
			break;
		}
		printf("Appname: %s\n", AppName.c_str());


		//启动游戏进程
		DWORD id = GetCurrentProcessId();
		sprintf(cmdLine,"%s %d %d %d %d",AppName.c_str(), 0, cs.get_connect_socket(), dis.get_connect_socket(), id);
		printf("cmd line is %s\n", cmdLine);
		bool ret = DetourCreateProcessWithDll(NULL,cmdLine, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
			NULL, NULL, &si, &pi, "game_server.dll", NULL);

		if(!ret) {
			char err_str[200];
			sprintf(err_str, "Game Start %s Failed", AppName.c_str());
			MessageBox(NULL, err_str, "Error", MB_OK);
		}
	}

	return 0;
}
开发者ID:hustcgcl,项目名称:CloudGaming,代码行数:82,代码来源:loader.cpp


示例10: main

int main(int argc, char* argv[]) {
    std::chrono::time_point<std::chrono::system_clock> start, end;
    start = std::chrono::system_clock::now();
    std::time_t start_time = std::chrono::system_clock::to_time_t(start);
    std::cout << "Started computation at " << std::ctime(&start_time) << std::endl;


    uint8_t board_size = 0;
    unsigned int training_set = 0;
    unsigned int start_cycle = 0;
    unsigned int end_cycle = 0;
    bool uniform = 0;
    bool scaled = 0;
    // Validate command line parameters
    if (argc == 1) {
        // No parameters, use the Macros
        board_size = BOARD_SIZE;
        training_set = TRAINING_SET;
        start_cycle = STARTCYCLE;
        end_cycle = ENDCYCLE;
        uniform = UNIFORM;
        scaled = SCALED;
    } else if (argc == 7) {
        // TODO(wdfraser): Add some better error checking
        board_size = uint8_t(atoi(argv[1]));
        training_set = atoi(argv[2]);
        start_cycle = atoi(argv[3]);
        end_cycle = atoi(argv[4]);
        uniform = atoi(argv[5]) != 0;
        scaled = atoi(argv[6]) != 0;
    } else {
        throw TrainingArgumentError();
    }

    for (unsigned int n = start_cycle; n <= end_cycle; n++) {
        std::vector<GoGameNN> training_networks(NETWORKCOUNT, GoGameNN(board_size, uniform));
        std::vector<int> training_scores(NETWORKCOUNT);

        // Scaling networks used for seeding networks if scaled = true
        std::vector<GoGameNN> scaling_networks;
        // Set Random generator for use when selecting networks for reseeding
        std::random_device rd;
        std::mt19937 gen(rd());
        std::uniform_int_distribution<> dis(0, NETWORKKEEP - 1);

        unsigned int export_count = 0;

        std::string output_directory =
                "size" + std::to_string(board_size) + "set" + std::to_string(training_set) + "/";

        std::ifstream best_networks_in(output_directory + "lastbestnetworks.txt");
        std::ifstream import_networks(output_directory + "import_networks.txt");

        if (scaled) {
            // If scaled network, confirm import_networks is open
            if (!import_networks.is_open()) {
                throw TrainingImportError();
            } else {
                scaling_networks.assign(NETWORKKEEP, GoGameNN(board_size - SEGMENT_DIVISION, uniform));
                // If it is, import example_networks;
                for (unsigned int i = 0; i < NETWORKKEEP; i++) {
                    scaling_networks[i].import_weights_stream(import_networks);
                }
            }
        }

        std::cout << "Generation with " << NETWORKCOUNT << " Neural Networks.\n"
        << "Total Games: " << NETWORKCOUNT * NETWORKCOUNT << std::endl;

        if (best_networks_in.is_open()) {
            std::cout << "Starting generation " << n << ". Last best network file succesfully opened. \n";

            // Read kept networks from file
            for (unsigned int i = 0; i < NETWORKKEEP; i++) {
                training_networks[i].import_weights_stream(best_networks_in);
            }
            for (unsigned int i = 0; i < NETWORKKEEP; i++) {
                training_networks[i + NETWORKKEEP] = training_networks[i];
                training_networks[i + NETWORKKEEP].mutate(MUTATER);
            }
            for (unsigned int i = 0; i < NETWORKKEEP; i++) {
                if (scaled) {
                    // If scaled network, seed network subsections from a random imported network
                    training_networks[i + (NETWORKKEEP * 2)].scale_network(scaling_networks[dis(gen)]);
                } else {
                    training_networks[i + (NETWORKKEEP * 2)].initialize_random();
                }
            }
        } else if (n == 1) {
            std::cout << "Starting first generation. Last best network file failed to open."
            << " Initializing random weights. \n";
            for (GoGameNN &element : training_networks) {
                if (scaled) {
                    // If scaled network, seed network subsections from a random imported network
                    element.scale_network(scaling_networks[dis(gen)]);
                } else {
                    element.initialize_random();
                }
            }
        } else {
//.........这里部分代码省略.........
开发者ID:wduncanfraser,项目名称:scalable_go,代码行数:101,代码来源:scalable_go_training.cpp


示例11: main

int main(void)
{
    rect a, b;
    int da = 0;
    int db = 0;

    scanf("%d %d %d %d", &a.ld.x, &a.ld.y, &a.pg.x, &a.pg.y);
    scanf("%d %d %d %d", &b.ld.x, &b.ld.y, &b.pg.x, &b.pg.y);


    if (dis(a, b) == 1)
	printf("%d\n", area(a) + area(b));
    else {
	if (in(a, b) == 1)
	    printf("%d\n", area(a) > area(b) ? area(a) : area(b));
	else {
	    if (a.pg.x <= b.pg.x && a.pg.y <= b.pg.y) {
		if (a.ld.x <= b.ld.x && b.pg.x >= a.pg.x
		    && a.pg.y == b.pg.y) {
		    da = a.pg.x - b.ld.x;
		    db = a.pg.y - a.ld.y;
		    printf("%d\n", area(a) + area(b) - da * db);
		} else {
		    da = a.pg.x - b.ld.x;
		    db = a.pg.y - b.ld.y;
		    printf("%d\n", area(a) + area(b) - da * db);
		}
	    } else if (a.ld.y == b.ld.y) {
		if (b.pg.x <= a.pg.x && b.pg.y <= a.pg.y) {
		    da = b.pg.x - a.ld.x;
		    db = b.pg.y - b.ld.y;
		    printf("%d\n", area(a) + area(b) - da * db);
		} else {
		    da = a.pg.x - a.ld.x;
		    db = b.pg.y - b.ld.y;
		    printf("%d\n", area(a) + area(b) - da * db);
		}
	    } else if (a.pg.y == b.pg.y) {
		da = b.pg.x - a.ld.x;
		db = a.pg.y - a.ld.y;
		printf("%d\n", area(a) + area(b) - da * db);
	    } else if (a.ld.x == b.ld.x) {
		if (b.pg.x <= a.pg.x && b.pg.y <= a.pg.y) {
		    da = b.pg.x - b.ld.x;
		    db = b.pg.y - a.ld.y;
		    printf("%d\n", area(a) + area(b) - da * db);
		}
		else if(b.pg.x <= a.pg.x && b.pg.y >= a.pg.y){
		  da = b.pg.x - b.ld.x;
		  db = a.pg.y - a.ld.y;
	          printf("%d\n", area(a) + area(b) - da * db);
		} else {
		    da = a.pg.x - a.ld.x;
		    db = b.pg.y - b.ld.y;
		    printf("%d\n", area(a) + area(b) - da * db);
		}
	    } else if (a.pg.x >= b.pg.x && a.pg.y <= b.pg.y
		       && b.ld.y >= a.ld.y) {
		if (a.ld.x <= b.ld.x && b.pg.x <= a.pg.x) {
		    da = b.pg.x - b.ld.x;
		    db = a.pg.y - b.ld.y;
		    printf("%d\n", area(a) + area(b) - da * db);
		} else {
		    da = b.pg.x - a.ld.x;
		    db = a.pg.y - b.ld.y;
		    printf("%d\n", area(a) + area(b) - da * db);
		}
	    } else if (a.ld.x <= b.ld.x && a.pg.x <= b.pg.x) {
		if (a.ld.y <= b.ld.y && b.pg.y <= a.pg.y) {
		    da = a.pg.x - b.ld.x;
		    db = b.pg.y - b.ld.y;
		    printf("%d\n", area(a) + area(b) - da * db);
		} else if (a.ld.y >= b.ld.y && a.pg.y >= b.pg.y) {
		    da = a.pg.x - b.ld.x;
		    db = b.pg.y - a.ld.y;
		    printf("%d\n", area(a) + area(b) - da * db);
		} else
		    fprintf(stderr, "Error2. Nieznany przypadek.\n");
	    } else if (b.ld.x <= a.ld.x && b.pg.x <= a.pg.x) {
		da = b.pg.x - a.ld.x;
		db = b.pg.y - a.ld.y;
		printf("%d\n", area(a) + area(b) - da * db);
	    } else if (a.ld.x <= b.ld.x && b.pg.x <= a.pg.x) {
		da = b.pg.x - b.ld.x;
		db = b.pg.y - a.ld.y;
		printf("%d\n", area(a) + area(b) - da * db);
	    } else
		fprintf(stderr, "Error. Nieznany przypadek.\n");
	}
    }

    return 0;
}
开发者ID:ndg2012,项目名称:jp,代码行数:93,代码来源:SIL.c


示例12: dis

std::string MusicDay::choose_one_string(std::vector<std::string> choices) {
    std::uniform_int_distribution<> dis(0, choices.size() - 1);
    int choice_index = dis(rand_generator);
    std::string choice = choices[choice_index];
    return choice;
}
开发者ID:nodog,项目名称:learnin-cpp-music_day,代码行数:6,代码来源:music_day.cpp


示例13: TEST

TEST(Solution, CouplingFem2)
{
    // problem definition
    const size_t div = 20;
    const double poro = 1.0;
    const double mol_diff = 1e-6;
    const double darcy_vel = 1e-5;

    try {
        //space
        MeshLib::IMesh *msh = MeshGenerator::generateStructuredRegularQuadMesh(2.0, div, .0, .0, .0);
        GeoLib::Rectangle* _rec = new GeoLib::Rectangle(Point(0.0, 0.0, 0.0),  Point(2.0, 2.0, 0.0));
        //time
        //TimeStepFunctionConstant tim(.0, 1e+3, 1e+3);
        TimeStepFunctionConstant tim(.0, 1e+4, 1e+3);
        //material
        Geo::PorousMedia pm;
        pm.hydraulic_conductivity = new NumLib::TXFunctionConstant(1.e-11);
        pm.porosity = new NumLib::TXFunctionConstant(poro);
        Geo::Compound tracer;
        tracer.molecular_diffusion = new NumLib::TXFunctionConstant(mol_diff);
        //problems
        DiscreteSystem dis(msh);
        FemLib::LagrangeFeObjectContainer feObjects(msh);
        Geo::GWFemProblem* pGW = defineGWProblem(dis, *_rec, pm, &feObjects);
        Geo::MassFemProblem* pMass = defineMassTransportProblem(dis, *_rec, pm, tracer, &feObjects);
        pGW->setTimeSteppingFunction(tim);
        pMass->setTimeSteppingFunction(tim);
        //options
        BaseLib::Options optionsGW;
        BaseLib::Options* op_lis = optionsGW.addSubGroup("LinearSolver");
        op_lis->addOption("solver_type", "CG");
        op_lis->addOption("precon_type", "NONE");
        op_lis->addOptionAsNum("error_tolerance", 1e-10);
        op_lis->addOptionAsNum("max_iteration_step", 1000);
        BaseLib::Options* op_nl = optionsGW.addSubGroup("Nonlinear");
        op_nl->addOption("solver_type", "Picard");
        op_nl->addOptionAsNum("error_tolerance", 1e-6);
        op_nl->addOptionAsNum("max_iteration_step", 500);
        BaseLib::Options optionsMT;
        op_lis = optionsMT.addSubGroup("LinearSolver");
        op_lis->addOption("solver_type", "BICG");
        op_lis->addOption("precon_type", "NONE");
        op_lis->addOptionAsNum("error_tolerance", 1e-10);
        op_lis->addOptionAsNum("max_iteration_step", 1000);
        BaseLib::Options* op_nl2 = optionsMT.addSubGroup("Nonlinear");
        op_nl2->addOption("solver_type", "Picard");
        op_nl2->addOptionAsNum("error_tolerance", 1e-6);
        op_nl2->addOptionAsNum("max_iteration_step", 500);
        // unknowns
        MyFunctionHead f_head;
        f_head.define(&dis, pGW, optionsGW);
        f_head.setOutputParameterName(0, "h");
        MyFunctionVelocity f_vel;
        f_vel.define(dis, pm);
        f_vel.setInputParameterName(0, "h");
        f_vel.setOutputParameterName(0, "v");
        MyFunctionConcentration f_c;
        f_c.define(&dis, pMass, optionsMT);
        f_c.setInputParameterName(0, "v");
        f_c.setOutputParameterName(0, "c");


        SerialStaggeredMethod method(1e-5, 100);
        AsyncPartitionedSystem apart1;
        apart1.setAlgorithm(method);
        apart1.resizeOutputParameter(3);
        apart1.setOutputParameterName(0, "h");
        apart1.setOutputParameterName(1, "v");
        apart1.setOutputParameterName(2, "c");
        apart1.addProblem(f_head);
        apart1.addProblem(f_vel);
        apart1.addProblem(f_c);
        apart1.connectParameters();

        TimeSteppingController timestepping;
        timestepping.setTransientSystem(apart1);

        //const double epsilon = 1.e-3;
        timestepping.setBeginning(.0);
        timestepping.solve(tim.getEnd());

        const MyNodalFunctionScalar* r_f_head = apart1.getOutput<MyNodalFunctionScalar>(apart1.getOutputParameterID("h"));
        //const MyIntegrationPointFunctionVector* r_f_v = apart1.getOutput<MyIntegrationPointFunctionVector>(apart1.getOutputParameterID("v"));
        const MyNodalFunctionScalar* r_f_c = apart1.getOutput<MyNodalFunctionScalar>(apart1.getOutputParameterID("c"));
        const IDiscreteVector<double>* vec_h = r_f_head->getDiscreteData();
        //const FEMIntegrationPointFunctionVector2d::DiscreteVectorType* vec_v = r_f_v->getNodalValues();
        const IDiscreteVector<double>* vec_c = r_f_c->getDiscreteData();

        //r_f_head->printout();
        //r_f_v->printout();
//#undef OUTPUT_C
#define OUTPUT_C
        std::vector<double> expectedHead(msh->getNumberOfNodes());
        const double p_left = 2.e+6;
        const double p_right = .0;
        const double x_len = 2.0;
#ifdef OUTPUT_C
        std::cout << std::endl << "expected p=";
#endif
//.........这里部分代码省略.........
开发者ID:HaibingShao,项目名称:ComponentialMultiphase,代码行数:101,代码来源:Test.cpp


示例14: gen_

int Randomizer::Random(int a, int b) {
        std::random_device rd_;
        std::mt19937 gen_(rd_());
	std::uniform_int_distribution<> dis(a, b);
	return dis(gen_);
}
开发者ID:fzg,项目名称:ppd-paris-descartes,代码行数:6,代码来源:Randomizer.cpp


示例15: HGRAD_TET_COMP12_FEM_Test01


//.........这里部分代码省略.........
          DynRankView vals = DynRankView("vals", numFields, numPoints);
          tetBasis.getValues(vals, tetPoints, OPERATOR_VALUE);
          auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals);
          Kokkos::deep_copy(vals_host, vals);

          for (auto i=0;i<numFields;++i) {
            for (auto j=0;j<numPoints;++j) {
              const auto l =  i + j * numFields;
              if (std::abs(vals_host(i,j) - pointBasisValues[l]) > tol) {
                errorFlag++;
                *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";

                // Output the multi-index of the value where the error is:
                *outStream << " At multi-index { ";
                *outStream << i << " ";*outStream << j << " ";
                *outStream << "}  computed value: " << vals_host(i,j)
                           << " but reference value: " << pointBasisValues[l] << "\n";
              }
            }
          }
        }
        
        // Check VALUE of basis functions at random points: resize vals to rank-2 container:\n";
        {
          *outStream << " check VALUE of basis functions at random points\n";
          const auto numRandomPoints = 16384;

          DynRankViewHost tetRandomPointsHost = DynRankViewHost("tetRandomPointsHost", numRandomPoints, 3);
          {
            ordinal_type point = 0;

            std::random_device rd;
            std::mt19937 gen(rd());
            std::uniform_real_distribution<> dis(0, 1);
            while (point < numRandomPoints) {
              const ValueType r = dis(gen), s = dis(gen), t = dis(gen);
              if (r + s + t > 1.0) {
                // do nothing
              } else {
                tetRandomPointsHost(point, 0) = r;
                tetRandomPointsHost(point, 1) = s;
                tetRandomPointsHost(point, 2) = t;
                ++point;
              }
            }
          }
          
          auto tetRandomPoints = Kokkos::create_mirror_view(typename DeviceSpaceType::memory_space(), tetRandomPointsHost);
          Kokkos::deep_copy(tetRandomPoints, tetRandomPointsHost);

          DynRankView vals = DynRankView("vals", numFields, numRandomPoints);
        
          tetBasis.getValues(vals, tetRandomPoints, OPERATOR_VALUE);
          auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals);
          Kokkos::deep_copy(vals_host, vals);
        
          for (auto j=0;j<numRandomPoints;++j) {
            ValueType sum = 0.0;
            for (auto i=0;i<numFields;++i) 
              sum += vals_host(i,j);

            if (std::abs(sum - 1.0) > tol) {
              errorFlag++;
              *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
              
              // Just indicate something bad happened
开发者ID:uppatispr,项目名称:trilinos-official,代码行数:67,代码来源:test_01.hpp


示例16: dis

void Ennemi::initCaracteristics()
{

    se::Config* conf = se::Config::getInstance();

    int vitesseMin, vitesseMax = 1;

    if(conf->get(MIN_SPEED,vitesseMin)&&conf->get(MAX_SPEED,vitesseMax))
    {
        std::uniform_int_distribution<> dis(vitesseMin,vitesseMax);

        speed.x = static_cast<float>(dis(gen));
        speed.y = static_cast<float>(dis(gen));
    }
    else
    {
        speed.x = static_cast<float>(dis(gen));
        speed.y = static_cast<float>(dis(gen));
    }

    nspeed = se::Utils::norm(speed);

    sf::RenderWindow& window = se::GraphicEngine::getInstance()->getRenderWindow();

    std::uniform_int_distribution<> disMod(0,3);
    std::uniform_int_distribution<> varMod(0,100);

    float startX = 0;
    float startY = 0;
    int varPart = varMod(gen);

    switch(disMod(gen))
    {
    case 0 :
        startX = varPart;
        startY = -varPart;
        break;
    case 1 :
        startX = window.getSize().x + varPart;
        startY = varPart;
        break;
    case 2 :
        startX = window.getSize().x + varPart;
        startY = window.getSize().y + varPart;
        break;
    case 3 :
        startX = -varPart;
        startY = window.getSize().y +varPart;
        break;
    default :
        ;
        break;
    }

    myEntity->setPosition(startX,startY);

    myEntity->setOrigin(SIZE,SIZE);

    myShadow->setOrigin(SIZE,SIZE);


}
开发者ID:dwarfman78,项目名称:tanks,代码行数:62,代码来源:Ennemi.cpp


示例17: main

int main()
{
    int n, i, j, ans, sum, k = 0;
    double r1, r2, r3, r4, r;
    double x1, y1, x2, y2, x, y;
    while (scanf("%d", &n), n)
    {
        scanf("%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &r);
        r = 1.0 * r / PI;
        for (i = 0; i < n; i++)
        {
            scanf("%lf%lf", &x, &y);
            d1[i] = dis(x, y, x1, y1);
            d2[i] = dis(x, y, x2, y2);
        }
        for (i = 0, ans = n; i < n; i++)
        {
            r1 = d1[i];
            if (r1 <= r)//涓句涓瑰朵腑涓涓濉璺绂r1,╀纾娉㈣绂讳负r2
            {
                r2 = r - r1;
                for (j = 0, sum = 0; j < n; j++)
                {
                    if (d1[j] <= r1)
                    {
                        sum++;
                    }
                    else if (d2[j] <= r2)
                    {
                        sum++;
                    }
                }
                if (ans > n - sum)
                {
                    ans = n - sum;
                }
            }
            r2 = d2[i];
            if (r2 <= r)
            {
                r1 = r - r2;
                for (j = 0, sum = 0; j < n; j++)
                {
                    if (d1[j] <= r1)
                    {
                        sum++;
                    }
                    else if (d2[j] <= r2)
                    {
                        sum++;
                    }
                }
                if (ans > n - sum)
                {
                    ans = n - sum;
                }
            }
        }
        k++;
        printf("%d. %d\n", k, ans);
    }
    return 0;
}
开发者ID:KiritoTRw,项目名称:OJ-Problems-Source,代码行数:63,代码来源:3356_autoAC.cpp


示例18: random_element

 Iter random_element(Iter start, Iter end, RandomGenerator& g) {
     std::uniform_int_distribution<> dis(0, std::distance(start, end) - 1);
     std::advance(start, dis(g));
     return start;
 }
开发者ID:PiJoules,项目名称:asdfghjkl,代码行数:5,代码来源:Algorithms.cpp


示例19: random

	unsigned int random() {
		return dis(gen) + INT_MAX;
	}
开发者ID:jinnaiyuu,项目名称:15puzzle,代码行数:3,代码来源:zobrist.hpp


示例20: randomInt

int randomInt(int min, int max) {
    thread_local std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<> dis(min, max);
    return dis(gen);
}
开发者ID:chenbk85,项目名称:raft,代码行数:6,代码来源:util.cpp



注:本文中的dis函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ disableInterrupts函数代码示例发布时间:2022-05-31
下一篇:
C++ dirty函数代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap