/*! * Two house numbers are considered to be equal if * * country, city, postcode, suburb, street, housenumber, name, and shop equal * * or housenumber, street, name, and shop equal, and country, city, and postcode do not differ (ignoring empty values), * and lat/lon difference is less than DISTANCE_THRESHOLD */ bool HouseNumber::isSameAddress(HouseNumber const& rhs) const { if(getName().toLower()!=rhs.getName().toLower() || getShop().toLower()!=rhs.getShop().toLower() || getNumber().toLower()!=rhs.getNumber().toLower() || getStreet().toLower()!=rhs.getStreet().toLower() || getNumber()=="" || getStreet()=="") { return false; } if(getPostcode().toLower()==rhs.getPostcode().toLower() && getPostcode()!="" && getCity().toLower()==rhs.getCity().toLower() && getCity()!="" && getSuburb().toLower()==rhs.getSuburb().toLower() && getCountry().toLower()==rhs.getCountry().toLower() && getCountry()!="") { return true; } // consider two house numbers with similar address information and little distance to each other to be equal if(myAbs(getLat()-rhs.getLat())>DISTANCE_THRESHOLD || myAbs(getLon()-rhs.getLon())>DISTANCE_THRESHOLD) return false; if(getPostcode()!="" && rhs.getPostcode()!="" && getPostcode().toLower()!=rhs.getPostcode().toLower()) return false; if(getCity()!="" && rhs.getCity()!="" && getCity().toLower()!=rhs.getCity().toLower()) return false; if(getSuburb()!="" && rhs.getSuburb()!="" && getSuburb()!=rhs.getSuburb()) return false; if(getCountry()!="" && rhs.getCountry()!="" && getCountry().toLower()!=rhs.getCountry().toLower()) return false; return true; }
QVariant TimezoneListModel::data(const QModelIndex &index, int role) const { if (!index.isValid() || index.row() > itemsDisplay.count()) return QVariant(); if (role == Title) return itemsDisplay[index.row()]->name(); if (role == City) return getCity(itemsDisplay[index.row()]->name()); if (role == GMTOffset) return itemsDisplay[index.row()]->currentOffset(Qt::UTC)/3600; if (role == Latitude) return itemsDisplay[index.row()]->latitude(); if (role == Longitude) return itemsDisplay[index.row()]->longitude(); if (role == CountryCode) return itemsDisplay[index.row()]->countryCode(); if (role == Index) return index.row(); return QVariant(); }
/*! * compares QString("%1%2%3%4%5%6%7") * .arg(number_).arg(street_).arg(postcode_).arg(city_).arg(suburb_).arg(country_).arg(name_).arg(shop_).toLower() * thus, the house numbers are sorted by address (used for treeHousenumbers) * @note the address information must be complete */ bool HouseNumber::isLessThanAddress(HouseNumber const& rhs) const { if(getNumber().toLower()!=rhs.getNumber().toLower()) return getNumber().toLower()<rhs.getNumber().toLower(); if(getStreet().toLower()!=rhs.getStreet().toLower()) return getStreet().toLower()<rhs.getStreet().toLower(); if(getPostcode().toLower()!=rhs.getPostcode().toLower()) return getPostcode().toLower()<rhs.getPostcode().toLower(); if(getCity().toLower()!=rhs.getCity().toLower()) return getCity().toLower()<rhs.getCity().toLower(); if(getSuburb().toLower()!=rhs.getSuburb().toLower()) return getSuburb().toLower()<rhs.getSuburb().toLower(); if(getCountry().toLower()!=rhs.getCountry().toLower()) return getCountry().toLower()<rhs.getCountry().toLower(); if(getName().toLower()!=rhs.getName().toLower()) return getName().toLower()<rhs.getName().toLower(); return getShop().toLower()<rhs.getShop().toLower(); }
void BusinessInfo::print() const { cout << "Name: " << getName() << endl; cout << "Address: " << getAddress() << endl; cout << "City: " << getCity() << endl; cout << "State: " << getState() << endl; cout << "Zip Code: " << getZipCode() << endl; cout << "Sales Tax: " << getSalesTax() << "%" << endl; }
// Save current info to BusinessInfo.txt void BusinessInfo::saveBusinessInfo() { string delimiter = ","; fstream outfile; outfile.open("BusinessInfo.txt", ios::out); outfile << getName() << delimiter << getAddress() << delimiter << getCity() << delimiter << getState() << delimiter << getZipCode() << delimiter << getSalesTax() << delimiter; outfile.close(); }
void modifyClient(Client *pClients) { unsigned long id; int pos, modifyOpt, addressOpt; bool valId = false; do { printf(MSG_ID); scanf("%lu", &id); if(id > ID_MINIMUM && id < ID_MAXIMUM){ valId = true; } else { printf(MSG_ID_ERROR, NEWLINE); } } while(valId == false); pos = verifyClientToModify(pClients, id); if(pos != EOF) { ModifyMenu(); limparBufferEntradaDados(); scanf("%d", &modifyOpt); if(modifyOpt == 1){ getName(pClients, pos); } else if(modifyOpt == 2) { AddressModifyMenu(); scanf("%d", &addressOpt); limparBufferEntradaDados(); if(addressOpt == 1) { getStreet(pClients, pos); } else if(addressOpt == 2) { getNumber(pClients, pos); } else if(addressOpt == 3) { getPostalCode(pClients, pos); } else if(addressOpt == 4) { getCity(pClients, pos); } else { printf(MSG_MENU_ERROR, NEWLINE); } } else if(modifyOpt == 3) { getPhone(pClients, pos); } else if(modifyOpt == 4) { getBirthday(pClients, pos); } else if(modifyOpt == 5) { getSignupDate(pClients, pos); } else { printf(MSG_MENU_ERROR, NEWLINE); } saveClientFile(pClients); } else { printf(MSG_ID_DOESNT_EXIST_ERROR, NEWLINE); } }
int main(void) { int cases; char temp[100]; scanf("%d", &cases); for(int c=1;c<=cases;c++) { scanf("%d %s", &numRoads, temp); numCities = 0; for(int i=0;i<numRoads;i++) { scanf("%s %s %d", roads[i].city1, roads[i].city2, &roads[i].time); roads[i].id1 = getCity(roads[i].city1); roads[i].id2 = getCity(roads[i].city2); roads[i].prob = 0; } calculateMinDistances(); calculateRoutes(); calculateProbability(getCity(temp)); printf("Case #%d:", c); for(int i=0;i<numRoads;i++) printf(" %.7f", roads[i].prob); printf("\n"); } }
/*! * * @return */ QString Address::toString() const{ ostringstream oss; oss << getStreetAddress().toStdString() << endl << getCity().toStdString(); if(getState() != "DC" && getState() != "D.C."){ oss << ", " << getState().toStdString() << " "; } else{ oss << " "; } oss << getZip().toStdString(); return QString::fromStdString(oss.str()); }
void addClient(Client *pClients) { int pos; pos = verifyIfPosEmpty(pClients); if(pos == EOF) { printf(MSG_CLIENTS_FULL_ERROR); } else { getId(pClients, pos); getName(pClients, pos); getStreet(pClients, pos); getNumber(pClients, pos); getPostalCode(pClients, pos); getCity(pClients, pos); getPhone(pClients, pos); getBirthday(pClients, pos); getSignupDate(pClients, pos); // TODO: SORT CLIENTS IN ORDER printf(MSG_CLIENT_ADDED); } }
Employee modifyEmployee(Employee employee, int modOpt) { if(modOpt == 1) { employee.general = getName(employee.general); } else if(modOpt == 2) { employee.general.address = getStreetName(employee.general.address); } else if(modOpt == 3) { employee.general.address = getNumber(employee.general.address); } else if(modOpt == 4) { employee.general.address = getPostalCode(employee.general.address); } else if(modOpt == 5) { employee.general.address = getCity(employee.general.address); } else if(modOpt == 6) { employee.general = getPhone(employee.general); } else if(modOpt == 7) { employee.general = getLevel(employee.general); } return employee; }
// Indicate the plots we might want to move to that the enemy can attack void CvTacticalAnalysisMap::MarkCellsNearEnemy() { for(unsigned int iUnitIndex = 0; iUnitIndex < m_EnemyUnits.size(); iUnitIndex++) { CvUnit* pUnit = getUnit(m_EnemyUnits[iUnitIndex]); //for ranged every plot we can enter with movement left is a base for attack int iMinMovesLeft = pUnit->IsCanAttackRanged() ? 1 : 0; //be a bit conservative here, use ZOC - if one of our units is killed, this is not correct anymore //therefore we later do a dilation filter on the cells ReachablePlots tiles = pUnit->GetAllPlotsInReachThisTurn(false,true,false,iMinMovesLeft); for (ReachablePlots::iterator moveTile=tiles.begin(); moveTile!=tiles.end(); ++moveTile) { CvPlot* pMoveTile = GC.getMap().plotByIndexUnchecked(moveTile->iPlotIndex); int iPlotIndex = GC.getMap().plotNum(pMoveTile->getX(),pMoveTile->getY()); if (pUnit->IsCanAttackRanged()) { std::set<int> rangedPlots; //this generates some overlap, but preventing that is about as bad as ignoring it TacticalAIHelpers::GetPlotsUnderRangedAttackFrom(pUnit,pMoveTile,rangedPlots,false,false); for (std::set<int>::iterator attackTile=rangedPlots.begin(); attackTile!=rangedPlots.end(); ++attackTile) { m_pCells[*attackTile].SetSubjectToAttack(true); } } else { //for melee every tile he can move into can be attacked m_pCells[iPlotIndex].SetSubjectToAttack(true); } } } //do the dilation std::vector<int> vCellsToMark; for (int iPlotLoop = 0; iPlotLoop < GC.getMap().numPlots(); iPlotLoop++) { //nothing to do if (m_pCells[iPlotLoop].IsSubjectToAttack()) continue; CvPlot* pPlot = GC.getMap().plotByIndexUnchecked(iPlotLoop); //danger plots are calculated without ZOC if (GET_PLAYER(m_ePlayer).GetPossibleAttackers(*pPlot).size()>0) { //check whether neighbors are subject to attack with ZOC CvPlot** aPlotsToCheck = GC.getMap().getNeighborsUnchecked(pPlot); for (int iI = 0; iI < NUM_DIRECTION_TYPES; iI++) { CvPlot* pAdjacentPlot = aPlotsToCheck[iI]; if (pAdjacentPlot) { if (m_pCells[pAdjacentPlot->GetPlotIndex()].IsSubjectToAttack()) { vCellsToMark.push_back(iPlotLoop); break; } } } } } //this should give a nice compromise for (size_t iI = 0; iI < vCellsToMark.size(); iI++) m_pCells[vCellsToMark[iI]].SetSubjectToAttack(true); // Look at every cell on the map for(int iI = 0; iI < GC.getMap().numPlots(); iI++) { CvPlot* pPlot = GC.getMap().plotByIndexUnchecked(iI); if(m_pCells[iI].IsRevealed() && !m_pCells[iI].IsImpassableTerrain() && !m_pCells[iI].IsImpassableTerritory()) { // Friendly cities always safe if(!m_pCells[iI].IsFriendlyCity()) { if(!pPlot->isVisibleToEnemy(m_ePlayer)) { m_pCells[iI].SetNotVisibleToEnemy(true); } else { // Check adjacent plots for enemy citadels if(!m_pCells[iI].IsSubjectToAttack()) { if ( pPlot->IsNearEnemyCitadel( m_ePlayer ) ) m_pCells[iI].SetSubjectToAttack(true); for(unsigned int iCityIndex = 0; iCityIndex < m_EnemyCities.size(); iCityIndex++) { CvCity* pCity = getCity( m_EnemyCities[iCityIndex] ); if (pCity->canRangeStrikeAt( pPlot->getX(), pPlot->getY() )) m_pCells[iI].SetSubjectToAttack(true); } } } } } } }
void MSNet::updateWeather() { OptionsCont &oc = OptionsCont::getOptions(); std::string currentTimeString, initialTimeString = MyHandler2::getInitialTimeString(); MSNet *net = MSNet::getInstance(); if(oc.getAnyVerbosity()>1) std::cout<<"----> void MSNet::updateWeather()"<<std::endl; if(oc.getAnyVerbosity()>2) std::cout<<"initialTimeString{"<<initialTimeString<<"}"<<std::endl; int tempTendingTo; if(oc.getSafeBool("rlwc")) { // Update time string to catch night or day becoming currentTimeString = net->makeTimeString(net->getCurrentTimeStep()); if(getCity()=="cambiano") { // Real Life simulation envtemp update // Month depending analysis if(extractMonth(initialTimeString) < 3 || extractMonth(initialTimeString) > 11) { // December, January or February if(net->isNight(currentTimeString)) tempTendingTo = 0; else tempTendingTo = 5; } else if(extractMonth(initialTimeString)<6) { // March, April or May if(net->isNight(currentTimeString)) tempTendingTo = 10; else tempTendingTo = 15; } else if(extractMonth(initialTimeString)<9) { // June, July or August if(net->isNight(currentTimeString)) tempTendingTo = 15; else tempTendingTo = 20; } else { // September, October or November if(net->isNight(currentTimeString)) tempTendingTo = 5; else tempTendingTo = 10; } // Real Life simulation envhum update if(rand()%10==0) { rand()%2==0? setCurrentEnvHum(getCurrentEnvHum() + ((float)rand()) / RAND_MAX) : setCurrentEnvHum(getCurrentEnvHum() - ((float)rand()) / RAND_MAX); } } else if(getCity()=="munchen") { // Real Life simulation envtemp update // Month depending analysis if((extractMonth(initialTimeString)<3)|| extractMonth(initialTimeString)>11) { // December, January or February if(net->isNight(currentTimeString)) tempTendingTo = 0; else tempTendingTo = 5; } else if(extractMonth(initialTimeString)<6) { // March, April or May if(net->isNight(currentTimeString)) tempTendingTo = 10; else tempTendingTo = 15; } else if(extractMonth(initialTimeString)<9) { // June, July or August if(net->isNight(currentTimeString)) tempTendingTo = 15; else tempTendingTo = 20; } else { // September, October or November if(net->isNight(currentTimeString)) tempTendingTo = 5; else tempTendingTo = 10; } // Real Life simulation envhum update if(rand() % 10 == 0) { (rand() % 2 == 0) ? setCurrentEnvHum(getCurrentEnvHum() + ((float)rand()) / RAND_MAX) : setCurrentEnvHum(getCurrentEnvHum() - ((float)rand()) / RAND_MAX); } } // Envtemp update if(rand() % 10 == 0) { if(rand() % 2 == 0) { // Adding if(getCurrentEnvTemp() > tempTendingTo) { rand() % 3 == 0 ? setCurrentEnvTemp(getCurrentEnvTemp() + ((float)rand()) / RAND_MAX) : setCurrentEnvTemp(getCurrentEnvTemp() - ((float)rand()) / RAND_MAX); } else { rand() % 2 == 0 ? setCurrentEnvTemp(getCurrentEnvTemp() + ((float)rand()) / RAND_MAX) : setCurrentEnvTemp(getCurrentEnvTemp() - ((float)rand()) / RAND_MAX); } } else { // Substracting if(getCurrentEnvTemp() > tempTendingTo) { rand() % 2 == 0 ? setCurrentEnvTemp(getCurrentEnvTemp() + ((float)rand()) / RAND_MAX) : setCurrentEnvTemp(getCurrentEnvTemp() - ((float)rand()) / RAND_MAX); } else { rand() % 3 == 0 ? setCurrentEnvTemp(getCurrentEnvTemp() - ((float)rand()) / RAND_MAX) : setCurrentEnvTemp(getCurrentEnvTemp() + ((float)rand()) / RAND_MAX); } } } } else if((oc.getSafeBool("rwc") || (oc.getSafeBool("rlwc") && (getCity() == "unknown")))) { tag: // Random envtemp update if(rand() % 10 == 0) { (rand() % 2 == 0) ? setCurrentEnvTemp(getCurrentEnvTemp() + ((float)rand())/RAND_MAX) : setCurrentEnvTemp(getCurrentEnvTemp() - ((float)rand())/RAND_MAX); } // Random envhum update if(rand()%10==0) { (rand()%2==0)? setCurrentEnvHum(getCurrentEnvHum()+((float)rand())/RAND_MAX) : setCurrentEnvHum(getCurrentEnvHum()-((float)rand())/RAND_MAX); } } // else weather is constant }
CyCity* cyGetCity(IDInfo city) { return new CyCity(getCity(city)); }
CvCity* CvArea::getTargetCity(PlayerTypes eIndex) const { FAssertMsg(eIndex >= 0, "eIndex is expected to be >= 0"); FAssertMsg(eIndex < MAX_PLAYERS, "eIndex is expected to be < MAX_PLAYERS"); return getCity(m_aTargetCities[eIndex]); }
ResearchTech getResearchTech(const PlayerTactics& playerTactics, TechTypes ignoreTechType) { TechSelectionData selectionData(playerTactics); // pure tech tactics ('first to tech' items, open borders, etc...) for (PlayerTactics::TechTacticsMap::const_iterator ci = playerTactics.techTacticsMap_.begin(), ciEnd = playerTactics.techTacticsMap_.end(); ci != ciEnd; ++ci) { if (ci->second) { ci->second->apply(selectionData.tacticSelectionDataMap[DependencyItem(ResearchTechDependency::ID, ci->first)]); } } // buildings for (PlayerTactics::CityBuildingTacticsMap::const_iterator ci = playerTactics.cityBuildingTacticsMap_.begin(), ciEnd = playerTactics.cityBuildingTacticsMap_.end(); ci != ciEnd; ++ci) { const CvCity* pCity = getCity(ci->first); const City& city = gGlobals.getGame().getAltAI()->getPlayer(pCity->getOwner())->getCity(pCity); for (PlayerTactics::CityBuildingTacticsList::const_iterator li(ci->second.begin()), liEnd(ci->second.end()); li != liEnd; ++li) { li->second->update(playerTactics.player, city.getCityData()); li->second->apply(selectionData.tacticSelectionDataMap, IDependentTactic::Ignore_Techs); } } // units for (PlayerTactics::UnitTacticsMap::const_iterator iter(playerTactics.unitTacticsMap_.begin()), endIter(playerTactics.unitTacticsMap_.end()); iter != endIter; ++iter) { if (iter->second) { iter->second->update(playerTactics.player); iter->second->apply(selectionData.tacticSelectionDataMap, IDependentTactic::Ignore_Techs); } } // city improvements for (PlayerTactics::CityImprovementTacticsMap::const_iterator ci(playerTactics.cityImprovementTacticsMap_.begin()), ciEnd(playerTactics.cityImprovementTacticsMap_.end()); ci != ciEnd; ++ci) { const CvCity* pCity = getCity(ci->first); if (pCity) { const City& city = playerTactics.player.getCity(pCity); TotalOutput base = city.getCurrentOutputProjection().getOutput(); for (PlayerTactics::CityImprovementTacticsList::const_iterator li(ci->second.begin()), liEnd(ci->second.end()); li != liEnd; ++li) { (*li)->update(playerTactics.player, city.getCityData()); const std::vector<ResearchTechDependencyPtr> techs = (*li)->getTechDependencies(); for (size_t i = 0, count = techs.size(); i < count; ++i) { selectionData.tacticSelectionDataMap[techs[i]->getDependencyItem()].cityImprovementsDelta += (*li)->getProjection().getOutput() - base; } } } } // processes for (PlayerTactics::ProcessTacticsMap::const_iterator ci(playerTactics.processTacticsMap_.begin()), ciEnd(playerTactics.processTacticsMap_.end()); ci != ciEnd; ++ci) { if (ci->second->areDependenciesSatisfied(playerTactics.player, IDependentTactic::Ignore_Techs)) { CityIter iter(*playerTactics.player.getCvPlayer()); TotalOutput processOutput; while (CvCity* pCity = iter()) { ProjectionLadder projection = ci->second->getProjection(pCity->getIDInfo()); processOutput += projection.getProcessOutput(); } const std::vector<ResearchTechDependencyPtr>& techs = ci->second->getTechDependencies(); for (size_t i = 0, count = techs.size(); i < count; ++i) { selectionData.tacticSelectionDataMap[techs[i]->getDependencyItem()]. processOutputsMap[ci->second->getProcessType()] += processOutput; } } } selectionData.processTechs(); if (ignoreTechType != NO_TECH) { //selectionData.removeTech(ignoreTechType); } selectionData.scoreTechs(); selectionData.debug(); return selectionData.getSelection(); }