Example #1
0
void getdist(char ch[],int** dist)
{
	int s[M],dingwei[M];
    int n,number,u;
    int i,j,k,min,distance=0;
	
	getData (dist);
	
	n=getCityCode(ch);
	
	u=1;	
   number=n;

for(i=0;i<M;i++)
s[i]=0;
	for(j=0;j<M;j++)
	{
		for(i=0;i<M;i++)
		  {
        
			dingwei[i]=dist[number][i];
		  }
		  s[number]=1;        
      printf("%s->",getCityName(number));
											
			min=MAX;												
			for(k=0;k<M;k++)					
			{
			  if(s[k]==0&&min>dingwei[k])   
			  {
				min=dingwei[k];
				number=k;
			  }
			  if(u==M)
				  min=dingwei[n];
			 
			}
			u++;
							
			
			distance+=min;
			
			 
			
	}
	
	 printf("%s",getCityName(n));
	 printf("\n距离为:%d\n",distance);

}
Example #2
0
int initialize(FILE *f)
{
	int	i, j, maximum = 0;
	cities = getNextInteger(f);
	for (i = 0; i < cities; i++)
	{
		for (j = 0; j < cities; j++)
		{
			if (i == j)
			{
				distance[i][j] = 0;
				continue;
			}
			else
			{
				distance[i][j] = getNextInteger(f);
				maximum = max(maximum, distance[i][j]);
			}
		}
	}
	days = getNextInteger(f);
	for (i = 0; i < cities; i++)
		for (j = 0; j < days; j++)
			wait[i][j] = getNextInteger(f);
	for (i = 0; i < cities; i++)
		getCityName(f, cityNames[i]);
	return maximum;
}
Example #3
0
//check whether the game is over
int checkGameState(Agent agents[],Graph g,int cycle,int maxCycles){
  if(cycle >= maxCycles) {
    printf("GAME OVER: YOU LOSE - TIME IS UP\n");
    return OVER;
  } else {
    Vertex currThiefLoc = getCurrentLocation (agents[THIEF]);
    int i = 1;
    while (i <= NUM_DETECTIVES) {
      if (currThiefLoc == getCurrentLocation (agents[i])) {
	printf("D%d caught the thief in %s (%d)\n", i, getCityName(g, currThiefLoc), currThiefLoc);
	printf("YOU WIN - THIEF CAUGHT!\n");
	return WIN;
      }
      i++;
    }
    if ( currThiefLoc == getGoal (agents[THIEF]) ) {
      printf("T got away to  %s (%d)\n", getCityName(g, currThiefLoc), currThiefLoc);      
      printf("GAME OVER: YOU LOSE - THIEF GOT TO GETAWAY\n");
      return LOSE;
    }
    return CONTINUE;
  }
}
Example #4
0
/*!
 * \brief Returns the sorted optimal path, starting from City 1.
 * \param city A string that represents city elements in the path.
 * \param separator A string that represents separators between cities in the path.
 * \return A string, containing sorted optimal path.
 *
 *  The resulting path will be in the form \a city+\a separator+\a city+...+\a separator+\a city.
 *  \c \%1 in \a city will be replaced by the city number.
 */
std::string CTSPSolver::getSortedPath(const std::string &separator) const {
    if (!root || route.empty() || (route.size() != nCities))
        return std::string();

    int i = 0; // We start from City 1
    std::list<std::string> path;
    path.push_back("City 1");

    while ((i = route.at(i)) != 0) {
        path.push_back(getCityName("City", i+1));
    }

    // And finish in City 1, too
    path.push_back("City 1");

    return ListJoin(path, separator);
}
Example #5
0
QString getFactoryName(int factoryId, int cityId, int factoryDirection)
{
  QDomDocument doc("mydocument");
  QFile *file = new QFile("languagedata.xml");
  QString factoryName = "-----";
  QString fId;
  fId.sprintf("IDS_FACT_%03d", factoryId);

  if (!file->open(QIODevice::ReadOnly))
    return " ";
  if (!doc.setContent(file))
  {
    file->close();
    return " ";
  }

  QDomNodeList list = doc.elementsByTagName("tu");
  for(int i = 0; i < list.count(); i++)
  {
    QDomNode tu = list.at(i);
    if(tu.hasAttributes() && tu.hasChildNodes())
    {
      QString attrib = tu.attributes().namedItem("tuid").nodeValue();
      if(attrib == fId)
      {
        QDomNodeList child = tu.childNodes();
        factoryName = child.at(2).toElement().text();
        file->close();
        factoryName = factoryName + " " + getCityName(cityId) + " " + getFactoryDirection(factoryDirection);
        return factoryName;
      }
    }
  }
  file->close();
  return factoryName;
}