/// This also updates next bound inline double changeInCost(int iRow, double alpha, double &rhs) { int sequence=model_->pivotVariable()[iRow]; double returnValue = 0.0; unsigned char iStatus = status_[sequence]; int iWhere = currentStatus(iStatus); if (iWhere == CLP_SAME) iWhere = originalStatus(iStatus); // rhs always increases if (iWhere == CLP_FEASIBLE) { if (alpha > 0.0) { // going below iWhere = CLP_BELOW_LOWER; rhs = COIN_DBL_MAX; } else { // going above iWhere = CLP_ABOVE_UPPER; rhs = COIN_DBL_MAX; } } else if (iWhere == CLP_BELOW_LOWER) { assert (alpha < 0); // going feasible iWhere = CLP_FEASIBLE; rhs += bound_[sequence] - model_->upperRegion()[sequence]; } else { assert (iWhere == CLP_ABOVE_UPPER); // going feasible iWhere = CLP_FEASIBLE; rhs += model_->lowerRegion()[sequence] - bound_[sequence]; } setCurrentStatus(status_[sequence], iWhere); returnValue = fabs(alpha) * infeasibilityWeight_; return returnValue; }
// ----------------------------------------------------------------------------- // CHWRMExtendedLightStatusObserver::CurrentStatus // Return Light status // ----------------------------------------------------------------------------- // CHWRMExtendedLight::TLightStatus CHWRMExtendedLightStatusObserver::CurrentStatus(TInt aTarget) const { COMPONENT_TRACE2(_L( "HWRM ExtendedLightClient - CHWRMExtendedLightStatusObserver::CurrentStatus(0x%x)" ), aTarget ); CHWRMExtendedLight::TLightStatus status( CHWRMExtendedLight::ELightStatusUnknown ); RLightStatusArray currentStatus( KHWRMLightMaxTargets ); TInt err = InitializeStatusArray( currentStatus ); if ( err == KErrNone ) { TInt arraySize = sizeof( THWRMStatusInfo ) * KHWRMLightMaxTargets; TPtr8 arrayPtr( ( TUint8* )¤tStatus[0], arraySize, arraySize ); err = RProperty::Get( KPSUidHWResourceNotification, KHWRMLightStatus, arrayPtr ); if( err == KErrNone ) { TInt index = currentStatus.FindInOrder( aTarget, FindByTarget ); if( index >= 0 && index < KHWRMLightMaxTargets ) { status = static_cast<CHWRMExtendedLight::TLightStatus>( currentStatus[index].iStatus ); } } } // Clean up currentStatus.Close(); COMPONENT_TRACE2(_L( "HWRM ExtendedLightClient - CHWRMExtendedLightStatusObserver::CurrentStatus - return 0x%x" ), status ); return status; }
/// This also updates next bound inline double changeInCost(int sequence, double alpha, double &rhs) { double returnValue = 0.0; #ifdef NONLIN_DEBUG double saveRhs = rhs; #endif if (CLP_METHOD1) { int iRange = whichRange_[sequence] + offset_[sequence]; if (alpha > 0.0) { assert(iRange - 1 >= start_[sequence]); offset_[sequence]--; rhs += lower_[iRange] - lower_[iRange-1]; returnValue = alpha * (cost_[iRange] - cost_[iRange-1]); } else { assert(iRange + 1 < start_[sequence+1] - 1); offset_[sequence]++; rhs += lower_[iRange+2] - lower_[iRange+1]; returnValue = alpha * (cost_[iRange] - cost_[iRange+1]); } } if (CLP_METHOD2) { #ifdef NONLIN_DEBUG double saveRhs1 = rhs; rhs = saveRhs; #endif unsigned char iStatus = status_[sequence]; int iWhere = currentStatus(iStatus); if (iWhere == CLP_SAME) iWhere = originalStatus(iStatus); // rhs always increases if (iWhere == CLP_FEASIBLE) { if (alpha > 0.0) { // going below iWhere = CLP_BELOW_LOWER; rhs = COIN_DBL_MAX; } else { // going above iWhere = CLP_ABOVE_UPPER; rhs = COIN_DBL_MAX; } } else if (iWhere == CLP_BELOW_LOWER) { assert (alpha < 0); // going feasible iWhere = CLP_FEASIBLE; rhs += bound_[sequence] - model_->upperRegion()[sequence]; } else { assert (iWhere == CLP_ABOVE_UPPER); // going feasible iWhere = CLP_FEASIBLE; rhs += model_->lowerRegion()[sequence] - bound_[sequence]; } setCurrentStatus(status_[sequence], iWhere); #ifdef NONLIN_DEBUG assert(saveRhs1 == rhs); #endif returnValue = fabs(alpha) * infeasibilityWeight_; } return returnValue; }
OtrIsLoggedInService::IsLoggedInStatus OtrIsLoggedInService::isLoggedIn(const Account &account, const QString &contactId) { auto contact = m_contactManager->byId(account, contactId, ActionReturnNull); if (!contact) return NotSure; if (contact.currentStatus().isDisconnected()) return NotLoggedIn; else return LoggedIn; }
// If the returned queue is empty, it means there is no direct path between source and destination std::deque<unsigned int> Dijkstra::findShortest(unsigned int sourceNode, unsigned int destNode, const Graph& g) { //requires (1 <= sourceNode <= Nodes && 1 <= destNode <= Nodes) //ensures 1 <= \result.size() <= Nodes //ensures \result.at(0).NodeId == sourceNode && \result.at(\result.size()-1).NodeId == destNode PriorityQueue currentStatus(sourceNode,NODES); unsigned int currentNode,currNeighbor,newCost,oldCost; currentNode = sourceNode; map<unsigned int,Plan>::iterator it; while(currentStatus.indexMap[destNode-1] != -1) { for(it = g.nodeGraph[currentNode-1].begin(); it!= g.nodeGraph[currentNode-1].end();it++) { currNeighbor = it->first+1; //the Node ID of the node. Node ID is used as nodeID-1 for indexing later // If the current neighbor is already visited, skip if(currentStatus.indexMap[currNeighbor] != -1) { nodeMap N = g.nodeGraph; newCost = N[currentNode-1][currNeighbor-1].cost + currentStatus.at(currentNode).priority; oldCost = currentStatus.at(currNeighbor).priority; if( newCost < oldCost) { currentStatus.decreasepriority(currNeighbor,newCost);//change the current cost (priority) of the current neighbour to the new lower cost (priority) predecessor[currNeighbor]= currentNode; } } } currentStatus.extractMin(); //extract the current node which is at the root right now and has the minimum cost currentStatus.SetInd(currentNode,-1); //since the current node has been extracted from the priority queue, we mark it visited by making its index -1 currentNode = currentStatus.getRoot().nodeID; } // Reverse the order of queue unsigned int NodeIterator; deque<unsigned int> shortestPath; NodeIterator = destNode; while (NodeIterator!=sourceNode) { shortestPath.push_front(NodeIterator); NodeIterator = predecessor[NodeIterator]; } shortestPath.push_front(NodeIterator); return shortestPath; }
void GaduProtocol::socketContactStatusChanged( UinType uin, unsigned int ggStatusId, const QString &description, unsigned int maxImageSize) { auto newStatus = Status{}; newStatus.setType(GaduProtocolHelper::statusTypeFromGaduStatus(ggStatusId)); newStatus.setDescription(description); if (uin == GaduLoginParams.uin) { if ((!m_lastRemoteStatusRequest.isValid() || m_lastRemoteStatusRequest.elapsed() > 10) && newStatus != m_lastSentStatus) { emit remoteStatusChangeRequest(account(), newStatus); if (m_lastRemoteStatusRequest.isValid()) m_lastRemoteStatusRequest.restart(); else m_lastRemoteStatusRequest.start(); } return; } auto contact = contactManager()->byId(account(), QString::number(uin), ActionReturnNull); contact.setMaximumImageSize(maxImageSize); auto oldStatus = contact.currentStatus(); contact.setCurrentStatus(newStatus); contact.setBlocking(GaduProtocolHelper::isBlockingStatus(ggStatusId)); if (contact.isAnonymous()) { if (contact.ownerBuddy()) emit userStatusChangeIgnored(contact.ownerBuddy()); rosterService()->removeContact(contact); return; } // see issue #2159 - we need a way to ignore first status of given contact if (contact.ignoreNextStatusChange()) contact.setIgnoreNextStatusChange(false); else emit contactStatusChanged(contact, oldStatus); }
void CSleepModeListenerPrivate::RunL() { sleepModeState.Subscribe(iStatus); SetActive(); CHWRMLight::TLightStatus status(CHWRMLight::ELightStatusUnknown); RLightStatusArray currentStatus(KHWRMLightMaxTargets); TInt err = InitializeStatusArray(currentStatus); if (err == KErrNone) { TInt arraySize = sizeof(THWRMStatusInfo) * KHWRMLightMaxTargets; TPtr8 arrayPtr((TUint8 *)¤tStatus[0], arraySize, arraySize); err = sleepModeState.Get(arrayPtr); if (err == KErrNone) { TInt index = currentStatus.FindInOrder(KHWRMLightFirstTarget, FindByTarget); if (index >= 0 && index < KHWRMLightMaxTargets) { status = static_cast<CHWRMLight::TLightStatus>(currentStatus[index].iStatus); if (!lastStatusValid || lastStatus != status) { lastStatusValid = true; lastStatus = status; RProcess process; // If process is something else than themeserver if (process.SecureId().iId != KHbPsHardwareCoarseOrientationCategoryUid.iUid) { QList<HbMainWindow *> mainWindowList = hbInstance->allMainWindows(); for (int i = 0; i < mainWindowList.count(); ++i) { if (status == CHWRMLight::ELightOff) { mainWindowList[i]->broadcastEvent(HbEvent::SleepModeEnter); } else { mainWindowList[i]->broadcastEvent(HbEvent::SleepModeExit); } } } else { HbEvent event(status == CHWRMLight::ELightOff ? HbEvent::SleepModeEnter : HbEvent::SleepModeExit); QCoreApplication::sendEvent(qApp, &event); } } } } } // Clean up currentStatus.Close(); }
// If the returned queue is empty, it means there is no direct path between source and destination std::deque<size_t> Dijkstra::findShortest(size_t sourceNode, size_t destNode) { // DON"T QUANTIFY VARIABLES THAT ARE ALREADY IN SCOPE! //requires forall size_t sourceNode, destNode:: 1 <= sourceNode <= Nodes && 1 <= destNode <= Nodes // by shortestpath, I assume you mean \result //ensures forall size_t sourceNode, destNode:: 1 <= shortestPath.size() <= Nodes // you also need that the result is a path //ensures forall sizet sourceNode, destNode:: shortestPath.at(0).NodeId == sourceNode && shortestPath.at(shortestPath.size()-1).NodeId == destNode routeMap routes; // For Initializing RouteMap for(size_t i=1;i<NODES;i++) { std::deque<size_t> defaultQueue; std::pair <size_t,size_t> routePair; routePair = std::make_pair (i,i); //1,2,3,.... to 1,2,3..... routes.insert(routePair); } // Assigning every node's tentative distance to infinity and 0 for source node PriorityQueue currentStatus(sourceNode); // For Source Node shortest path is node itself //routes[sourceNode-1].push_back(sourceNode); size_t currentNode,currNeighbor,newCost,oldCost; currentNode = sourceNode; map<size_t,Plan>::iterator it; while(currentStatus.indexMap[destNode-1] != -1) { for(it = nodeGraph[currentNode-1].begin(); it!= nodeGraph[currentNode-1].end();it++) { //invariant forall size_t n: 1 <= n <= i && currentStatus[n-1] != -2: // (currentStatus[currentNode-1])+ p[currentNode-1][n-1].cost <= /old(currentStatus[n-1]) ? currentStatus[n-1] == currNeighbor = it->first+1; // If the current neighbor is already visited, skip if(currentStatus.indexMap[currNeighbor-1] != -1) { newCost = nodeGraph[currentNode-1][currNeighbor-1].cost + currentStatus.at(currentNode).cost; oldCost = currentStatus.at(currNeighbor).cost; if( newCost < oldCost) { currentStatus.decreaseCost(currNeighbor,newCost); //currentStatus[i-1] = p[currentNode-1][i-1].cost + currentStatus[currentNode-1]; // Copying Elements of routes[CurrentNode-1] to routes[currNeighbor-1] - it will overwrite /* queueSize = routes[currentNode-1].size(); for(size_t j=1; j <= queueSize;j++) { //invariant routes[currentNode-1].size() == queueSize //invariant routes[i-1].size() == j-1 //invariant forall size_t a: 0 <= a < j <= queueSize: routes[currentNodes-1].at(queueSize - a - 1) == routes[i-1].at(j-a-1) temp = routes[currentNode-1].at(0); routes[currentNode-1].pop_front(); routes[currNeighbor-1].push_back(temp); routes[currentNode-1].push_back(temp); }*/ routes[currNeighbor]= currentNode; }//end if } } // for ends here currentStatus.extractMin(); currentStatus.indexMap[currentNode-1] = -1; currentNode = currentStatus.node[1].nodeID; }//while ends here size_t myNode; myNode = destNode; deque<size_t> myPath; // for (map<size_t,size_t>::iterator it=routes.begin(); it!=routes.end(); it++) // pc.printf("\n\rnode-> %d predecessor-> %d\r\n", it->first, it->second ); while (myNode!=sourceNode) { myPath.push_front(myNode); myNode = routes[myNode]; } myPath.push_front(myNode); return myPath; }
/* Calls relevant functions to play the game and allows user to guess letter after letter * and checks if the user has won or lost after each guess.*/ void userLoop(){ createLists(); // This reads the dictionary and generates an array of all lists of all word lengths char guess; // This is the variable where the current letter being guessed is kept int next=0; // Prevents duplication of code on first pass. int won=0; // Keeps track of whether the game has been won or lost int hard= difficulty(); //User chosen difficulty level int numberOfLetter=numberOfLetters(); //number of wrong guesses left before game is over int guessNumber=numberOfGuesses(); printf("To play, type in a single letter as a guess.\n"); printf("You have %i guesses remaining.\n", guessNumber); // game plays while the user still has some guesses left and has not won guess = obtainGuess(); //Gets first guess from user insertInList(&head, guess );//Puts guessed letter in list of guessed letters //All word families of user defined length are created generateDescriptions(&lists[numberOfLetter],numberOfLetter,guess); currentStatus(); // The status of game is shown to the user getNewList(hard); /*Finds the biggest members list from current *families and makes it the new main list of possible words*/ //This is the loop that allows the game to proceed. The first part of the loop is similar to above. while ((guessNumber)>0 && won==0) { if (next==1) {// prevents and initial duplication printf("You have %i guesses remaining.", guessNumber); // prints the status of the uncovered letters guess = obtainGuess(); //Gets first guess from user insertInList(&head, guess ); //Adds the guessed letter to the list containing all guessed letters currentFamily=NULL; //Resets list of current families //All word families of user defined length are created generateDescriptions(¤tWordList,numberOfLetter,guess); //All word families of user defined length are created /*Finds the biggest members list from current *families and makes it the new main list*/ getNewList(hard); currentStatus(); } // Allows the first part of the loop to be run on all subsequent guesses. next=1; // Lets the use know if they uncovered a letter. if (checkIfFound(guess,numberOfLetter)) { printf("\n \n \n Wrong!\n"); } else { printf("\n \n \n Correct.\n"); } // The number of guesses remaining decreases after each guess guessNumber--; // Checks to see if the user has uncovered all letters if (checkWin(numberOfLetter)) { printf("You Win!!"); won=1; } } printf("Game over. You uncovered:"); //Shows final game state currentStatus(); //Shows user a word that fits the currently visible letter pattern. printf("The word was: %s\n",currentFamily->members->word); }