int main(int argc, char *argv[]) {
   Point p;
   int hi;
   while(4 == scanf("%d%d%d%d",&N,&M,&S,&V)) {
      for(int i = 0; i < N; ++i) edges[i].clear();
      v_left  = VI(N + 1, -1);
      v_right = VI(M + 1, -1);
      gophers.clear();
      holes.clear();
      hi = (V*S)*(V*S);
      for(int i = 0; i < N; ++i) {
         scanf("%lf%lf",&p.first,&p.second);
         gophers.push_back(p);
      }
      for(int i = 0; i < M; ++i) {
         scanf("%lf%lf",&p.first,&p.second);
         holes.push_back(p);
      }
      for(int i = 0; i < N; ++i) {
         for(int j = 0; j < M; ++j) {
            if(dist(gophers[i],holes[j]) < hi) 
               edges[i].push_back(j);
         }
      }
      printf("%d\n",match());
   }
   return 0;
}
Exemple #2
0
 void test_container_with (VP &v1) const {
     // Container type tests in addition to expression types
     // Insert and erase
     v1.insert_element (0,0, 55);
     v1.erase_element (1,1);
     v1.clear ();
 }
Exemple #3
0
int main(){
	srand(time(NULL)); //没有这个每次的运行结果将相同
	int N,T,S;
	double pc,pm;
	printf("注意: 此系统数据都是随机生成的,所以每次运行的城市坐标可能不同,结果也可能不同!!\n\n");
	printf("请输入TSP问题城市数目,GA算法迭代次数,种群大小,交叉概率,变异概率\n");
	while(cin>>N>>T>>S>>pc>>pm){ 
		clock_t Time=clock();
		city.clear();
		printf("城市坐标如下:\n");
		for(int i=0;i<N;i++){ //坐标随机生成
			double a=rand()%5000, b=rand()%5000;
			city.push_back(Point(a,b));
			printf("(%5.0lf,%5.0lf)\n",a,b);
		}
		double mi=1000000000.0; //记录最小距离和
		Population p(N,S,pc,pm); //产生种群
		for(int i=0;i<T;i++){   //迭代T次
			p.getNext();
			mi=min(mi,p.getBest().dis); //更新最小距离和
		}
		permut=p.getBest().v;  //终止状态种群的最佳个体
		printf("路径为: ");
		for(int i=0;i<permut.size();i++){
			if( i!=0 ) printf("-->");
			printf("%d",permut[i]);
			if( i==permut.size()-1 ) puts("");
		}
		printf("计算中出现过的最小距离和为: %.1lf  最终距离和为: %.1lf\n",mi,p.getBest().dis);
		printf("计算耗时: %.3lf 秒\n",(clock()-Time)/1000.0);

		OpenGLInit();
		glutDisplayFunc(draw);
		glutMainLoop();
	}
}