Exemplo n.º 1
0
pair<int,int> testSpeedTSP(StarbucksMap& SB, double time_limit, bool use_matrix) {
	int n = 3;
	int totalTime = 0;
	
	/** code for graphing
	//std::pair<num, timeRun> TimePair;
	//vector<TimePair> timePairVec;
	*/
    vector< pair<int, int>> timePairVec; // code for graphing
	
	while (true) {
		  vector<Store> R = SB.randomSet(n);
		  Graph* G = createStarbucksGraph(R, use_matrix);

		  int startTime = timeGetTime();
		  pair<vector<NodeID>, EdgeWeight> p = TSP(G);
		  int newTime = timeGetTime() - startTime;
		  cout << "TSP Speed: Finished " << n << " cities in " << newTime/1000.0 << " seconds." << endl;
		  
		  timePairVec.push_back( std::make_pair( n, (newTime/1000.0) )); //code for graphing
		 
		  if (newTime/1000.0 > time_limit)
			  break;
		  totalTime = newTime;
		  n++;
	}
	
	return make_pair(n,totalTime);
}
Exemplo n.º 2
0
pair<int,int> testSpeedTSP(StarbucksMap& SB, double time_limit, bool use_matrix) {
	int n = 3;
	int totalTime = 0;
	while (true) {
		  vector<Store> R = SB.randomSet(n);
		  Graph* G = createStarbucksGraph(R, use_matrix);

		  int startTime = timeGetTime();
		  pair<vector<NodeID>, EdgeWeight> p = TSP(G);
		  int newTime = timeGetTime() - startTime;
		  cout << "TSP Speed: Finished " << n << " cities in " << newTime/1000.0 << " seconds." << endl;
		  if (newTime/1000.0 > time_limit)
			  break;
		  totalTime = newTime;
		  n++;
	}
	return make_pair(n,totalTime);
}
Exemplo n.º 3
0
void testSingleTSP(StarbucksMap& SB, int size, bool use_matrix) {
  vector<Store> R = SB.randomSet(size);
  Graph* G = createStarbucksGraph(R, use_matrix);
  pair<vector<NodeID>, EdgeWeight> p = TSP(G);

  EdgeWeight actual = 0;
  for (int i=0; i < size-1; i++)
    actual += G->weight(p.first[i], p.first[i+1]);
  actual += G->weight(p.first[size-1], p.first[0]);

  cout << "Best cycle length: " << p.second << " ";
  if (fabs(p.second - actual) > 0.00000001)
    cout << "(ERROR -- the length returned is not equal to the actual length)";
  else
    cout << "(Path length matches)" << endl;
  cout << "\n\n";
  for (int i=0; i < size; i++)
    cout << R[p.first[i]] << "\n";
  deleteStarbucksGraph(G, use_matrix);
}
Exemplo n.º 4
0
pair<int,int> testSpeedTSP(StarbucksMap& SB, double time_limit, bool use_matrix) {
	int n = 3;
	int totalTime = 0;
	while (true) {
		  vector<Store> R = SB.randomSet(n);
		  Graph* G = createStarbucksGraph(R, use_matrix);

		  int startTime = timeGetTime();
		  pair<vector<NodeID>, EdgeWeight> p = TSP(G, false); //Uses brute force version
		  int newTime = timeGetTime() - startTime;
		  cout << "TSP Speed: Finished " << n << " cities in " << newTime/1000.0 << " seconds." << endl;

		  int startTimeTwo = timeGetTime();
		  pair<vector<NodeID>, EdgeWeight> q = TSP(G, true); //Uses heuristic first attempt version
		  int newTimeTwo = timeGetTime() - startTimeTwo;
		  cout << "TSP Speed: Finished " << n << " cities in " << newTimeTwo/1000.0 << " seconds. (Heuristic Version)" << endl;

		  if (newTime/1000.0 > time_limit)
			 // break;
		  totalTime = newTime;
		  n++;
	}
	return make_pair(n,totalTime);
}