예제 #1
0
Colony::Colony(int population_size)
{
   readInstance();
   this->population_size = population_size;

   this->pheromone =  new double*[points_number];
   for(int i = 0; i < points_number; ++i){
       this->pheromone[i] = new double[points_number];
   }
   for(int i = 0; i < points_number; ++i)
    for(int j = 0; j < points_number; ++j)
        pheromone[i][j] = 0;
   this->edges = new Colony::Edges*[points_number];
   for(int i = 0; i < points_number; ++i){
      this->edges[i] = new Colony::Edges[points_number];
   }

   for(int i = 0 ; i < points_number; ++i)
      for(int j = 0; j < points_number; ++j){
          this->edges[i][j].visited = false;
          this->edges[i][j].probability = 0;
      }

    this->ants = new Ant*[population_size];
    for(int i = 0; i < population_size; ++i)
        this->ants[i] = new Ant();

    for(int i = 0; i < points_number; ++i){
        for(int j = 0; j < points_number; ++j){
            edges[i][j].distance = sqrt(pow(points[i]->getX() - points[j]->getX(), 2) +
            pow(points[i]->getY() - points[j]->getY(), 2));
        }
    }
    firstConstruction();
}
예제 #2
0
파일: main.c 프로젝트: andlt/MC658
int main(int argc, char **argv)
{
   TSPInstance *instance;
   double solutionCost;
   int i, *solution;
   clock_t time;

   if(argc < 2)
   {
      printf("Usage: %s <instance>\n", argv[0]);
      return 0;
   }

   instance = readInstance(argv[1]);

   solution = (int*)malloc(instance->n*sizeof(int));     

   for (i = 0; i < instance->n; i++)
      solution[i] = 0;

   time = clock();

   solutionCost = solve(instance, solution);

   printf("\n");

   verifyAndPrintSolution(instance, solution, solutionCost);

   printf("Running time: %.2f\n\n", ((clock() - time) / (float)CLOCKS_PER_SEC));

   for (i = 0; i < instance->n; i++)
      free(instance->costs[i]);

   free(instance->costs);
   free(instance);
   free(solution);

   return 0;
}
int main(int argc, char**argv) {

	assert(argc == 2);
	ifstream f(argv[1]);
	
	InstanceData instance = readInstance(f);
	cout << "Problem is " << instance.A.nrow << " by " << instance.A.ncol << " with " << instance.A.nzval.size() << " nonzeros\n";
	
	vector<BenchmarkOperation> benchmarks{ 
		{ doPrice, "Matrix-transpose-vector product with non-basic columns" },
		{ doPriceHypersparse, "Hyper-sparse matrix-transpose-vector product" },
		{ doTwoPassRatioTest, "Two-pass dual ratio test" },
		{ doTwoPassRatioTestHypersparse, "Hyper-sparse two-pass dual ratio test" },
		{ doUpdateDuals, "Update dual iterate with cost shifting" },
		{ doUpdateDualsHypersparse, "Hyper-sparse update dual iterate with cost shifting" },
	};
	vector<chrono::nanoseconds> timings(benchmarks.size(), chrono::nanoseconds::zero());

	int nruns = 0;
	while (true) {
		IterationData dat = readIteration(f,instance);
		if (!dat.valid) break;
		for (size_t i = 0; i < benchmarks.size(); i++) {
			timings[i] += benchmarks[i].func(instance,dat);
		}
		nruns++;
	}

	cout << nruns << " simulated iterations\n";
	for (size_t i = 0; i < benchmarks.size(); i++) {
		cout << benchmarks[i].name << ": " << timings[i].count()/1000000000. << " sec\n";
	}

	return 0;

}