Exemple #1
0
City City::create(const QString &cityNameZh, const QString &cityNameEn, const QString &cityDesc, const QString &createdBy, const QString &updatedBy)
{
    CityObject obj;
    obj.city_name_zh = cityNameZh;
    obj.city_name_en = cityNameEn;
    obj.city_desc = cityDesc;
    obj.created_by = createdBy;
    obj.updated_by = updatedBy;
    if (!obj.create()) {
        return City();
    }
    return City(obj);
}
Exemple #2
0
int main()
{
    std::array<std::string,3> fileName = 
        {"cities_3.data", "cities_10.data", "cities_50.data"};
    std::array<std::string,3> filePathDistance = 
        {"shortest_3_DKT.txt", "shortest_10_DKT.txt", "shortest_50_DKT.txt"};
    for (int i = 0; i < fileName.size(); i++) {
        int nodes = lines_count(fileName[i]); 
        //distance matrix
        std::vector<std::vector<int>> d = input2vector(fileName[i]);
        std::ofstream fileOut1;
        fileOut1.open(filePathDistance[i]);
        std::ofstream fileOut2;
        fileOut2.open("timer_DKT.txt", std::ios_base::app);
        std::chrono::time_point<std::chrono::system_clock> start, end;
        start = std::chrono::system_clock::now();
        for (int i = 1; i <= nodes; i++){
            for (int j = i+1; j <= nodes; j++){
                int infinity = 1234567;//know from the input file
                //set all to infinity
                std::vector<City> city(nodes,City(infinity,false,0)); 
                int shortest = Dijkstra(nodes,i,j,city,d);
                path_recon_to_file(fileOut1, i, j, nodes, city);
                fileOut1 << "\t\t" << shortest;
                fileOut1 << std::endl;
            }           
        }
        end = std::chrono::system_clock::now();
        std::chrono::duration<double> elapsed_seconds = end-start;
        fileOut2 << std::fixed << std::setprecision(0)<< fileName[i] << "\t";//fix precision
        fileOut2 << std::fixed << std::setprecision(14)<<elapsed_seconds.count(); 
        fileOut2 << std::endl;
        std::cout << "elapsed time to find shortest route with Dijkstra for " << fileName[i] << " is: " << std::fixed << std::setprecision(14)<<elapsed_seconds.count() << " seconds" << std::endl;
    }
}
Exemple #3
0
void Cities::createCity(const City::Name &cityName) {
  if (doesCityExist(cityName)) {
    Server::debug()("Can't create city: a city with that name already exists",
                    Color::CHAT_ERROR);
    return;
  }
  _container[cityName] = City(cityName);
}
Exemple #4
0
//--------------------------------------------------------------
void testApp::setup()
{
	ofSetFrameRate(60);

	ofBackground(0, 0, 0);
	
	//ofEnableAlphaBlending();
	ofEnableSmoothing();
	
	//glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	//glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
	//glClearDepth(1.0f);				// Depth buffer setup

	//glDepthFunc(GL_LESS);
	//glEnable(GL_DEPTH_TEST);
	//glShadeModel(GL_SMOOTH);		// Enable smooth shading

	//glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really nice perspective calculations

	setupQuesoGlc();
	
	// load font with extended parameters:
	// font name, size, anti-aliased, full character set
	//inputFont.loadFont("verdana.ttf", 60, true, true);
	//displayFont.loadFont("Osaka.ttf", 15, true, true);
	input = "";
	
	earth = new Earth(200.0f);
	earth->init();
	earth->initQuadric();

	rotX = 0.0f;
	rotY = 0.0f;
	rotZ = 0.0f;
	speedX = 0.0f;
	speedY = 0.0f;
	speedZ = 0.0f;
	eyeX = 0.0f;
	eyeY = 0.0f;
	eyeZ = -1.0f;
	showXYZ  = false;
	current = 0;
	error = "Error!";
	
	for (int j = 0; j < maxLongitude; ++j) {
		for (int i = 0; i < maxLatitude; ++i) {
			points[maxLatitude * j + i] = new MyPoint(double(i) * maxLatitude - 180.0,
													  double(j) * (360.0 / maxLongitude),
													  *earth);
		}
	}

	string _cities[] = {"tokyo"};
	for (int i = 0; i < 1; ++i) {
		cities.push_back(City(_cities[i], *earth));
	}
}
Exemple #5
0
void Cities::read(FILE *f)
{
    char buffer[1000];
    while (fgets(buffer, sizeof(buffer), f) != NULL) {
        int id, x, y;
        sscanf(buffer, "%d %d %d", &id, &x, &y);
        city_vec.push_back(City(x, y));
    }
}
Exemple #6
0
//--------------------------------------------------------------
void testApp::keyPressed(int key)
{
	int len = input.length();
	switch(key) {
/*	case ' ':
		input += "%20";
		break;
	case 'x':
		showXYZ = (showXYZ) ? false : true;
		break;
	case 'q':
		eyeZ += 0.005f;
		break;
	case 'w':
		eyeZ -= 0.005f;
		break;
*/
	case OF_KEY_LEFT:
		if (--current < 0) current = cities.size() - 1;
		break;
	case OF_KEY_RIGHT:
		if (++current >= cities.size()) current = 0;
		break;
	case OF_KEY_UP:
		eyeZ -= 0.001f;
		break;
	case OF_KEY_DOWN:
		eyeZ += 0.001f;
		break;
	case OF_KEY_PAGE_UP:
		//eyeY += 0.005f;
		break;
	case OF_KEY_PAGE_DOWN:
		//eyeY -= 0.005f;
		break;
	case OF_KEY_BACKSPACE:
		if (len) input.erase(len-1);
		break;
	case OF_KEY_RETURN:
		input = replace_all(input, " ", "%20");
		try {
			cities.push_back(City(input, *earth));
			input.erase(0);
			current = cities.size() - 1;
		} catch (runtime_error e) {
			cout << e.what() << endl;
			input.erase(0);
			showError = true;
		}
		break;
	default:
		showError = false;
		input += key;
		break;
	}
}
GameStateEditor::GameStateEditor(Game* game)
{
	this->game = game;
	sf::Vector2f pos = sf::Vector2f(this->game->window.getSize());
	this->guiView.setSize(pos);
	this->gameView.setSize(pos);
	pos *= 0.5f;
	this->guiView.setCenter(pos);
	this->gameView.setCenter(pos);

    this->city = City("city", this->game->tileSize, this->game->tileAtlas);
	this->city.shuffleTiles();

    /* Create gui elements */
	this->guiSystem.emplace("rightClickMenu", Gui(sf::Vector2f(196, 16), 2, false, this->game->stylesheets.at("button"),
		{
			std::make_pair("Flatten $" 			+ this->game->tileAtlas["grass"].getCost(), "grass"),
			std::make_pair("Forest $" 			+ this->game->tileAtlas["forest"].getCost(), "forest" ),
			std::make_pair("Residential Zone $" + this->game->tileAtlas["residential"].getCost(), "residential"),
			std::make_pair("Commercial Zone $" 	+ this->game->tileAtlas["commercial"].getCost(), "commercial"),
			std::make_pair("Industrial Zone $" 	+ this->game->tileAtlas["industrial"].getCost(), "industrial"),
			std::make_pair("Road $" 			+ this->game->tileAtlas["road"].getCost(), "road")
		}));

	this->guiSystem.emplace("selectionCostText", Gui(sf::Vector2f(196, 16), 0, false, this->game->stylesheets.at("text"),
		{ std::make_pair("", "") }));

	this->guiSystem.emplace("infoBar", Gui(sf::Vector2f(this->game->window.getSize().x / 5 , 16), 2, true, this->game->stylesheets.at("button"),
		{ std::make_pair("time", "time"),
		std::make_pair("funds", "funds"),
		std::make_pair("population", "population"),
		std::make_pair("employment", "employment"),
		std::make_pair("current tile", "tile") }));
	this->guiSystem.at("infoBar").setPosition(sf::Vector2f(0, this->game->window.getSize().y - 16));
	this->guiSystem.at("infoBar").show();

	this->zoomLevel = 1.0f;

	/* Centre the camera on the city.map */
	sf::Vector2f centre(this->city.map.width, this->city.map.height*0.5);
	centre *= float(this->city.map.tileSize);
	gameView.setCenter(centre);

    this->selectionStart = sf::Vector2i(0, 0);
    this->selectionEnd = sf::Vector2i(0, 0);

    this->currentTile = &this->game->tileAtlas.at("grass");
	this->actionState = ActionState::NONE;
}
Exemple #8
0
int main(){
	vector<City> tsp; 
	city_parser("input-test2.txt", tsp); 	
	FILE * o_f;
	o_f = fopen("output-test2.txt", "w");



	City  data_set[6] = City();
 	data_set[0] = City(1,15,3); 
	data_set[1] = City(2,9,0);
	data_set[2] = City(3,2,8);
	data_set[3] = City(4,11,6);  
	data_set[4] = City(5,2,2);
	data_set[5] = City(6,8,9);

//	for(int i = 0; i< tsp.size(); ++i)
//		tsp[i].Print("before");

	vector<City> hull_points = quickHull(tsp); 

	int remove_index = 0;  

	for(int i =0; i <hull_points.size();i++){
		remove_index =  find(tsp.begin(), tsp.end(), hull_points[i]) -  tsp.begin();
		tsp.erase(tsp.begin() + remove_index);
	}	
//	for(int i = 0; i< tsp.size(); ++i)
//		tsp[i].Print("after"); 

//	for(int i =0; i <hull_points.size();++i)
//		hull_points[i].Print("tsp"); 

	hull_sort(hull_points, 0);
	vector<Line> hull_lines = draw_lines(hull_points, tsp);	


//	for(int i = 0; i <tsp.size();i++)
//		tsp[i].Print();

/*	for(int i =0; i<hull_points.size();i++)
		hull_points[i].Print();
*/

	vector< pair<Line, vector<City> > > closest_lines = determine_closest_lines(hull_lines, tsp);

//	for(int i = 0; i < tsp.size(); i++)	
//		closest_lines[i].second.push_back(tsp[i]);

	for(int i =0; i < closest_lines.size(); i++){
		int *lengths = new int[closest_lines[i].second.size()];
		 for(int j=0; j<closest_lines[i].second.size();j++){
                        Vec2 temp = closest_lines[i].first.points().Unit(); 
			lengths[j] = closest_lines[i].second[j].point().Dot(temp);
		 }
		quickCitySort(closest_lines[i].second, lengths, 0, closest_lines[i].second.size()-1); 
	}


//	for(int i =0; i<closest_lines.size();i++){
//		hull_points[i].Print(); 
//		for(int j=0; j <closest_lines[i].second.size(); j++){
//			closest_lines[i].second[j].Print(); 
//		}
//	}		
 
// compute our walk. 
	float tot_len = 0; 
	vector<City> walk; 
	for(int i = 0; i < closest_lines.size();++i){
		walk.push_back(hull_points[i]); 
		for(int j = 0; j < closest_lines[i].second.size(); ++j){
			walk.push_back(closest_lines[i].second[j]); 
		}
	}

//compute total length
	Vec2 temp;
	float tempy; 
	for(int i =0; i < walk.size(); i++){
		float a0 = walk[i].point().x();
		float b0 = walk[i-1].point().x();
		float a1 = walk[i].point().y();
		float b1 = walk[i-1].point().y();
		float dx = a0 - b0;
		float dy = a1 - b1;
		tempy = rint(sqrt(dx*dx + dy*dy));
		tot_len += tempy;
	}

//print solutionte total length
	fprintf(o_f, " %i\n",int(tot_len)); 
        for(int i =0; i < walk.size(); i++){
                        walk[i].Print("",o_f);
	}
//
	cout << "total path length is: " << tot_len <<" units of space" <<endl; 
 

return 0;
} 
Exemple #9
0
City City::get(int cityId)
{
    TSqlORMapper<CityObject> mapper;
    return City(mapper.findByPrimaryKey(cityId));
}