void MLocationDatabaseFake::createCities() { QMap<QString, QString>* countries = countriesMap(); QMap<QString, QString>::const_iterator iter; for(iter = countries->begin(); iter != countries->end(); iter++) { UErrorCode status = U_ZERO_ERROR; icu::StringEnumeration* tzids = icu::TimeZone::createEnumeration( iter.key().toAscii().data()); const UnicodeString *next; for(next = tzids->snext(status);next;next = tzids->snext(status)) { QString timezone(reinterpret_cast<const QChar*>( next->getBuffer()), next->length()); qDebug() << timezone; /* skip timezone names like: GB-Eire * and hold only ones like: Area/City */ if(!timezone.contains("/")) continue; QString countryName = iter.value(); countryName.replace("\n", ""); addCity(timezone, countryName); } } }
void isFinal(){ int repetitions = 0; int color = 0; int new_read; for( int count = 0 ; count < 20 ; count++ ){ new_read = SensorValue[COLOR]; if( color == new_read ){ repetitions++; } else{ color = new_read; repetitions = 0; } if( repetitions == 5 ){ break; } wait1Msec(50); } if( color == RED ){ final_x = current_x; final_y = current_y; } else if( color == BLUE ){ addCity(); } }
int CountryRegion::CreateData(vector<BufferData> ®Data) { vector<BufferData>::iterator iter = regData.begin(); while (iter != regData.end()) { if ( 2 == (*iter).id.length() ) { addProvince((*iter).name, (*iter).id); } if ( 4 == (*iter).id.length() ) { addCity((*iter).name, (*iter).id, (*iter).upId); } if ( 4 < (*iter).id.length() ) { addCounty((*iter).name, (*iter).id, (*iter).upId); } ++iter; } /* // 增加省 vector<BufferData>::iterator iter = regData.data.begin(); while (iter != regData.data.end()) { if ( 2 == (*iter).id.length() ) { addProvince((*iter).name, (*iter).id); } ++iter; } // 增加市 iter = regData.data.begin(); while (iter != regData.data.end()) { if ( 4 == (*iter).id.length() ) { addCity((*iter).name, (*iter).id, (*iter).upId); } ++iter; } // 增加县 iter = regData.data.begin(); while (iter != regData.data.end()) { if ( 4 < (*iter).id.length() ) { addCounty((*iter).name, (*iter).id, (*iter).upId); } ++iter; } //*/ return 0; }
///////////////////////////////////////////////////////////////////////////// // add a new item to the tree ///////////////////////////////////////////////////////////////////////////// void CUndoDialog::addItem(int iAction, CUndo *pUndo) { switch(iAction) { case UNDO_SETTLE_PLACE: addPlacement(TRUE); break; case UNDO_THIRD_ROAD_PLACE: case UNDO_ROAD_PLACE: addPlacement(FALSE); break; case UNDO_SHIP_PLACE: addPlacement(FALSE, TRUE); break; case UNDO_FIRST_ROLL: addRoll(TRUE, ((CUndoOne *) pUndo)->m_iOne); break; case UNDO_ROLL: addRoll(FALSE, ((CUndoOne *) pUndo)->m_iOne); break; case UNDO_ACTION_START: addActionStart(); break; case UNDO_ACTION: addAction(); break; case UNDO_ROAD: addRoad(((CUndoOne *) pUndo)->m_iOne); break; case UNDO_SHIP: addShip(((CUndoOne *) pUndo)->m_iOne); break; case UNDO_CITY: addCity(); break; case UNDO_MOVE_SHIP: addMoveShip(((CUndoOne *) pUndo)->m_iOne); break; case UNDO_SETTLEMENT: addSettle(); break; case UNDO_BUY_DEVCARD: addDevcard(); break; case UNDO_ROBBER_PLACE: addRobber(); break; case UNDO_PIRATE_PLACE: addPirate(); break; case UNDO_PLAY_VICTORY: addVictory(((CUndoOne *) pUndo)->m_iOne); break; case UNDO_PLAY_MONOPOLY: addMonopoly((CUndoMonopoly *) pUndo); break; case UNDO_PLAY_ROAD: addRoadBuild(); break; case UNDO_PLAY_YEAR: addYearPlenty(((CUndoOne *) pUndo)->m_iOne); break; case UNDO_PLAY_SOLDIER: addSoldier(((CUndoOne *) pUndo)->m_iOne); break; case UNDO_TRADE: addTrade((CUndoTrade *) pUndo); break; case UNDO_STEAL: addSteal(((CUndoOne *) pUndo)->m_iOne); break; case UNDO_LOSECARDS: addLoseCards((CUndoTrade *) pUndo); break; case UNDO_ACTION_END: endTurn(); break; case UNDO_WIN: addWin(((CUndoOne *) pUndo)->m_iOne); break; case UNDO_WASTE: addWaste(((CUndoOne *) pUndo)->m_iOne); break; case UNDO_GOLD: addGold((CUndoGold *) pUndo); break; case UNDO_CHITLESS: addChitless(((CUndoOne *) pUndo)->m_iOne); break; case UNDO_VOLCANO: addVolcano(); break; case UNDO_TRADE_JUNGLE: addJungle((CUndoTrade *) pUndo); break; case UNDO_SPECIAL_BUILD: addSpecialBuild(((CUndoOne *) pUndo)->m_iOne); break; case UNDO_SPECIAL_BUILD_END: addSpecialBuildEnd(); break; default: break; } }
int TreeSearch(struct Graph *graph,int src,int V,int * costMatrix) { struct tour temp3; Stack *s=createStack(1000); struct tour bestTour; //printf("asdsad\n"); struct tour t={0,NULL,0}; struct pathNode *temp11=NULL; struct tour temp={0,NULL,0}; //printf("asdsad\n"); addCity(&t,src,V,costMatrix); //printf("asdsad\n"); push(s,t); //printf("asdsad\n"); while(!isEmpty(s)) { t=pop(s); if(t.cityCount==V) { int lastCost=*(costMatrix+V*t.thePath->lastNode+t.thePath->head->nodeNumber); if(t.totalCost+lastCost<minCost) { minCost=t.totalCost+lastCost; //printTour(&t); } struct pathNode *temp44=t.thePath->head; struct pathNode *temp55=temp44; while(temp44!=NULL) { temp44=temp44->next; free(temp55); temp55=temp44; } free(t.thePath); } else { int i=0; for(i=V-1;i>0;i--) { if(feasible(&t,i)) { addCity(&t,i,V,costMatrix); temp3.thePath=NULL; temp3.totalCost=t.totalCost; temp11=t.thePath->head; while(temp11->next!=NULL) { addCity(&temp3,temp11->nodeNumber,V,costMatrix); temp11=temp11->next; } //printf("asdasdsada\n"); addCity(&temp3,temp11->nodeNumber,V,costMatrix); temp3.cityCount=t.cityCount; push(s,temp3); //printf("Asdsadasdsad\n"); removeLastCity(&t,costMatrix,V); //printf("%lu\n",sizeof(struct tour)); } } struct pathNode *temp44=t.thePath->head; struct pathNode *temp55=temp44; while(temp44!=NULL) { temp44=temp44->next; free(temp55); temp55=temp44; } free(t.thePath); } } return minCost; }
int main(int argc, char *argv[]){ if(argc != 4) printf("usage: ./program city_file edge_file h_file\n"); else{ FILE *cities = fopen(argv[1], "r"); FILE *edges = fopen(argv[2], "r"); FILE *hvals = fopen(argv[3], "r"); //this is our adjacency list CityNode *root = 0, *new_city; NeighborNode *new_neighbor; char line[128]; char *temp, *temp2; //set up all the cities while(fgets(line, 128, cities)){ temp = strtok(line, ":"); char *city = malloc(16 * sizeof(char)); strcpy(city, temp); new_city = initializeCityNode(city, 0); addCity(&root, new_city); } rewind(cities); //set up neighbors while(fgets(line, 128, cities)){ temp = strtok(line, ":"); char *neighbor = malloc(16 * sizeof(char)); while(temp2 = strtok(NULL, ",")){ strcpy(neighbor, temp2); if(strcmp(neighbor, "\n") != 0){ CityNode *dest = getCityNode(root, neighbor); CityNode *src = getCityNode(root, temp); new_neighbor = initializeNeighborNode(dest, 0); addNeighbor(&src, new_neighbor); } } } fclose(cities); //set up edge costs int cost; char from[16], to[16], line2[128]; while(fgets(line2, 128, edges)){ sscanf(line2, "%s %s %d", from, to, &cost); CityNode *src = getCityNode(root, from); NeighborNode *dest = getNeighborNode(src, to); dest->cost = cost; } fclose(edges); //set up h(n) while(fgets(line, 128, hvals)){ sscanf(line, "%s %d", from, &cost); CityNode *src = getCityNode(root, from); src->h_n = cost; } fclose(hvals); //the adjacency list printCityList(root); CityNode *start = getCityNode(root, "arad"); CityNode *end = getCityNode(root, "buch"); printf("\nRunning Depth First Search...\n"); runDepthFirst(start, end, INT_MAX); printf("\nRunning Iterative Deepening Search...\n"); runIterDeepening(start, end); printf("\nRunning Breadth First Search...\n"); runBreadthFirst(start, end, 0); printf("\nRunning Uniform Cost Search...\n"); runUniformCost(start, end, (int (*)(void *, void *))basicComp); printf("\nRunning Best First Search with straightLineDistance...\n"); runBestFirst(start, end, (int (*)(void *, void *))basicComp, (int (*)(void *))straightLineDistance); printf("\nRunning Best First Search with nonEuclideanDistance...\n"); runBestFirst(start, end, (int (*)(void *, void *))basicComp, (int (*)(void *))nonEuclideanDistance); printf("\nRunning A* Search with straightLineDistance...\n"); runAStar(start, end, (int (*)(void *, void *))basicComp, (int (*)(void *))straightLineDistance, INT_MAX); printf("\nRunning A* Search with nonEuclideanDistance...\n"); runAStar(start, end, (int (*)(void *, void *))basicComp, (int (*)(void *))nonEuclideanDistance, INT_MAX); printf("\nRunning IDA* Search with straightLineDistance...\n"); runIDAStar(start, end, (int (*)(void *, void *))basicComp, (int (*)(void *))straightLineDistance, 0); printf("\nRunning IDA* Search with nonEuclideanDistance...\n"); runIDAStar(start, end, (int (*)(void *, void *))basicComp, (int (*)(void *))nonEuclideanDistance, 0); } return 0; }