void SMO::reconstructGradient() { // reconstruct inactive elements of G from G_bar and free variables if (activeSet.size() == data->size()) return; int i; for(IndexSetItr itr=activeSet.begin(); itr!=activeSet.end(); ++itr) { i = (*itr); G[i] = Gbar[i] + 1.0; /// 1 instead of b[i]; } for(IndexSetItr itr=activeSet.begin(); itr!=activeSet.end(); ++itr) { i = *itr; if (isFree(i)) { vector<float> &irow = cache.getRow(i); double alpha_i = alpha[i]; for (int j = 0; j < size(); j++) { //if (activeSet.find(j) != activeSet.end()) // continue; /// there is some waste here since we don't need all the entries; /// does not matter yet since we are not doing shrinking... G[j] += alpha_i * Y[i] * Y[j] * irow[j]; } } } }
uint32_t RegAlloc::countFree() { int cnt = 0; for(Register i=FirstReg; i <= LastReg; i = nextreg(i)) cnt += isFree(i) ? 1 : 0; return cnt; }
int tacticControl::findBestPlayerForPass() { int index = -1; double min = 10000; QList<int> ourAgents = wm->kn->ActiveAgents(); QList<int> freeAgents; while( !ourAgents.isEmpty() ) { int index = ourAgents.takeFirst(); if(isFree(index)) freeAgents.append(index); } while ( !freeAgents.isEmpty() ) { int i = freeAgents.takeFirst(); if(wm->ourRobot[i].isValid && this->id != i) { if( (wm->ball.pos.loc-wm->ourRobot[i].pos.loc).length() < min) { min = (wm->ball.pos.loc-wm->ourRobot[i].pos.loc).length(); index = i; } } } return index; }
void Streckenblock::mainSensorFree() { DEBUG(id); DEBUG(": MainSensor Free\n"); if (isFree()) { trackFree(); }; }
bool Board::placePiece(PiecePtr p, Square s) { if(!isFree(s)) //if the square is not free return false; //else m_board[s.y][s.x] = p; return true; }
bool Board::movePiece(Square pos, Square dest) { if(isFree(dest)) { m_board[dest.y][dest.x] = m_board[pos.y][pos.x]; m_board[pos.y][pos.x] = nullptr; return true; } return false; }
bool Board::checkDeath(Square s) { if(!isTrap(s) || isFree(s)) //if it is not a trap, or no piece is on the trap return false; Color color = getPiece(s)->getColor(); Square adjSquare; for(int i = 0; i < 4; ++i) //checks the 4 directions { adjSquare = s + m_cardinals[i]; if(isValid(adjSquare) && !isFree(adjSquare)) { if(getPiece(adjSquare)->getColor() == color) //an ally is around : the piece can't die return false; } } removePiece(s); return true; }
void Streckenblock::actExitSignalRequestedState() { if ((after == NULL) && frontSensorWasOccupied && !isFree()) { // Track is occupied, react. if (exitSignalRequestedState == SWITCH_RED) { requestSwitchRed(); } else { requestSwitchGreen(); } } }
bool Board::isFrozen(Square s) const { if(isFree(s)) return true; //a blank square is considered frozen Color color = getPiece(s)->getColor(); Square adjSquare; bool frozen = false; for(int i = 0; i < 4; ++i) //checks the 4 directions { adjSquare = s + m_cardinals[i]; if(isValid(adjSquare) && !isFree(adjSquare)) { if(getPiece(adjSquare)->getColor() == color) //an ally is around : the piece can't be frozen return false; else //an ennemy is around : frozen if weaker or if already frozen frozen |= (*getPiece(s) < *getPiece(adjSquare)); } } return frozen; }
// EUR/CHF grid trader main function int run() { BarPeriod = 60; Hedge = 5; // activate virtual hedging var Grid = 20*PIP; // set grid distance to 20 pips var Close = priceClose(); // place pending trades at 5 grid lines above and below the Close int i; for(i = Close/Grid - 4; i < Close/Grid + 4; i++) { var Price = i*Grid; // place short trades with profit target below the current price if(Price < Close && isFree(Price,Grid,true)) enterShort(10,Price,0,Grid); // place long trades with profit target above the current price else if(Price > Close && isFree(Price,Grid,false)) enterLong(10,Price,0,Grid); } }
bool RectPlacement::addAtEmptySpot(Rectangle &r) { // Find a valid spot among available anchors. bool bFound = false; CPosArray::iterator it; for (it = m_vPositions.begin(); !bFound && it != m_vPositions.end(); ++it) { Rectangle rect(it->x(), it->y(), r.width(), r.height(), true); if (isFree(rect)) { r = rect; bFound = true; break; // Don't let the loop increase the iterator. } } if (bFound) { // Remove the used anchor point m_vPositions.erase(it); // Sometimes, anchors end up displaced from the optimal position // due to irregular sizes of the subrects. // So, try to adjut it up & left as much as possible. int x,y; for (x = 1; x <= r.x(); x++) if (!isFree(Rectangle(r.x() - x, r.y(), r.width(), r.height(), true))) break; for (y = 1; y <= r.y(); y++) if (!isFree(Rectangle(r.x(), r.y() - y, r.width(), r.height(), true))) break; if (y > x) r.y1 -= y-1; else r.x1 -= x-1; addRect(r); } return bFound; }
STBase* STObject::getPField (SField const& field, bool createOkay) { int index = getFieldIndex (field); if (index == -1) { if (createOkay && isFree ()) return getPIndex(emplace_back(detail::defaultObject, field)); return nullptr; } return getPIndex (index); }
void rgbCellsFree () { int freeCells; char tempStr[256]; freeCells = cellsFree(); if (isFree (thePixel)) { sprintf (tempStr, "%d cells free including %ld",freeCells,thePixel); enableInput(); } else { sprintf (tempStr, "%d cells free but not %ld", freeCells, thePixel); disableInput(); } setLabel (freeLabel, tempStr); }
SerializedType* STObject::getPField (SField::ref field, bool createOkay) { int index = getFieldIndex (field); if (index == -1) { if (createOkay && isFree ()) return getPIndex (giveObject (makeDefaultObject (field))); return NULL; } return getPIndex (index); }
//o--------------------------------------------------------------------------o //| Function - bool Save( ofstream &outStream ) //| Date - 28th July, 2000 //| Programmer - Abaddon //| Modified - //o--------------------------------------------------------------------------o //| Purpose - Saves a multi out to disk //| outStream is the file to write to //o--------------------------------------------------------------------------o bool CMultiObj::Save( std::ofstream &outStream ) { bool rvalue = false; if( !isFree() ) { rvalue = true; MapData_st& mMap = Map->GetMapData( worldNumber ); if( GetCont() != NULL || ( GetX() > 0 && GetX() < mMap.xBlock && GetY() < mMap.yBlock ) ) { DumpHeader( outStream ); DumpBody( outStream ); DumpFooter( outStream ); } } return rvalue; }
void STObject::set (std::unique_ptr<STBase> v) { auto const i = getFieldIndex(v->getFName()); if (i != -1) { v_[i] = std::move(*v); } else { if (! isFree()) throw std::runtime_error( "missing field in templated STObject"); v_.emplace_back(std::move(*v)); } }
void Ghost::move() { if(isInsideGhostHouse()) { if(isFree()) { if(!isCaught()) { release(); } } } else if(isOnTheMove()) localMove(); else if(isCaught()) goHome(); else if(areGhostsScared()) escape(); else if(isScattering()) scatter(); else chase(); }
bool Map::movePlayer (Player* player, char step) { int x; int y; getXY(step, x, y); debug(LOG_SERVER, String::format("move player %i:%i (current: %i:%i)", x, y, player->getCol(), player->getRow())); // move player and move touching packages const int targetCol = player->getCol() + x; const int targetRow = player->getRow() + y; MapTile* package = getPackage(targetCol, targetRow); if (package != nullptr) { const int pCol = targetCol + x; const int pRow = targetRow + y; if (!isFree(pCol, pRow)) { debug(LOG_SERVER, "can't move here - can't move package. target field is blocked"); return false; } if (!package->setPos(pCol, pRow)) { debug(LOG_SERVER, "failed to move the package - thus can't move the player"); return false; } debug(LOG_SERVER, String::format("moved package %i", package->getID())); increasePushes(); rebuildField(); if (isTarget(pCol, pRow)) { package->setState(CavePackerEntityStates::DELIVERED); debug(LOG_SERVER, String::format("mark package as delivered %i", package->getID())); } else if (package->getState() == CavePackerEntityStates::DELIVERED) { debug(LOG_SERVER, String::format("reset package state %i", package->getID())); package->setState(CavePackerEntityStates::NONE); } // sokoban standard - if a package was moved, the move char is uppercase step = toupper(step); } if (!player->setPos(targetCol, targetRow)) { debug(LOG_SERVER, "failed to move the player"); return false; } player->storeStep(step); increaseMoves(); return true; }
SerializedType* STObject::makeFieldPresent (SField::ref field) { int index = getFieldIndex (field); if (index == -1) { if (!isFree ()) throw std::runtime_error ("Field not found"); return getPIndex (giveObject (makeNonPresentObject (field))); } SerializedType* f = getPIndex (index); if (f->getSType () != STI_NOTPRESENT) return f; mData.replace (index, makeDefaultObject (f->getFName ()).release ()); return getPIndex (index); }
STBase* STObject::makeFieldPresent (SField const& field) { int index = getFieldIndex (field); if (index == -1) { if (!isFree ()) throw std::runtime_error ("Field not found"); return getPIndex (emplace_back(detail::nonPresentObject, field)); } STBase* f = getPIndex (index); if (f->getSType () != STI_NOTPRESENT) return f; v_[index] = detail::STVar( detail::defaultObject, f->getFName()); return getPIndex (index); }
void RegAlloc::formatRegisters(char* s, Fragment *frag) { if (!frag || !frag->lirbuf) return; LirNameMap *names = frag->lirbuf->names; for (Register r = FirstReg; r <= LastReg; r = nextreg(r)) { LIns *ins = getActive(r); if (!ins) continue; NanoAssertMsg(!isFree(r), "Coding error; register is both free and active! " ); if (ins->isop(LIR_param) && ins->paramKind()==1 && r == Assembler::savedRegs[ins->paramArg()]) { // dont print callee-saved regs that arent used continue; } s += VMPI_strlen(s); const char* rname = ins->isQuad() ? fpn(r) : gpn(r); VMPI_sprintf(s, " %s(%s)", rname, names->formatRef(ins)); } }
BTModel &BTModel::operator=(const BTModel &o) { if(this == &o) return *this; if(!isFree()) cleanup(); if(!o.isFree()) { mOwnerAgent = o.mOwnerAgent; mBlackBoardModelId = o.mBlackBoardModelId; mLevel = o.mLevel; mStateStream = o.mStateStream; mCurrentStateIndex = o.mCurrentStateIndex; mStatesStack = o.mStatesStack; mPaused = o.mPaused; mKilled = o.mKilled; } return *this; }
// in use (not unused or deleted) static bool isInUse(key_type const & v) { return !isFree(v); }
bool isInUse(key_type const & v) const { return !isFree(v); }
/* BEGIN TEMPLATE */ void solve() { /* BEGIN SOLUTION */ /* cruft to search for an instance exercising all transformations */ int doneA=0; int doneB=0; int doneC=0; int doneD=0; int doneE=0; int doneF=0; int doneG=0; int doneH=0; int* origSizes = (int*)malloc(sizeof(int)*getStackSize()); int i; for (i=0;i<getStackSize();i++) origSizes[i] = getPancakeRadius(i); /* end of this cruft */ int stackSize = getStackSize(); if (debug>0) { printf("{\n"); int rank; for (rank=0; rank < stackSize; rank++){ printf("%d\n",getPancakeRadius(rank)); } printf("}\n"); } while (1) { int tRadius = getPancakeRadius(0); int posTPlus = getRankOf(tRadius+1); // returns -99 if non-existent, that is then ignored int posTMinus = getRankOf(tRadius-1); int posT = 0; if (debug>1) { printf("t Radius: %d\n",tRadius); int rank; for (rank=0; rank < stackSize; rank++) { printf("[%d]=%d; ",rank,getPancakeRadius(rank)); if (isFree(rank)) printf("free;"); else printf("NON-free;"); if (isFirst(rank)) printf("first; "); else printf("NON-first; "); if (isLast(rank)) printf("last; "); else printf("NON-last; "); if (rank == posTPlus) printf("t+1; "); if (rank == posTMinus) printf("t-1; "); if (rank == posT) printf("t;" ); printf("\n"); } } if (isFree(posT)) { if (isFree(posTPlus)) { /* CASE A: t and t+o free */ if (debug>0) printf("Case A+\n"); flip(posTPlus); doneA = 1; } else if (isFree(posTMinus)) { /* CASE A: t and t-o free */ if (debug>0) printf("Case A-\n"); flip(posTMinus); doneA = 1; } else if (isFirst(posTPlus)) { /* CASE B: t free, t+o first element */ if (debug>0) printf("Case B+\n"); flip(posTPlus); doneB = 1; } else if (isFirst(posTMinus)) { /* CASE B: t free, t-o first element */ if (debug>0) printf("Case B-\n"); flip(posTMinus); doneB = 1; } else if (min(posTPlus,posTMinus) != -99) { /* CASE C: t free, but both t+o and t-o are last elements */ if (debug>0) printf("Case C\n"); flip(min(posTPlus,posTMinus) ); flip(min(posTPlus,posTMinus) - 1); flip(max(posTPlus,posTMinus) + 1); flip(min(posTPlus,posTMinus) - 1); doneC = 1; } else { if (debug>0) printf("Case Cbis\n"); flip(max(posTPlus,posTMinus) + 1); flip(max(posTPlus,posTMinus) ); doneC = 1; } } else { // t is in a block if (blockLength() == stackSize) { // Done! if (tRadius != 1) // all reverse flip(stackSize); if (doneA && doneB && doneC && doneD && doneE && doneF && doneG && doneH && wasRandom()) { printf("BINGO! This instance is VERY interesting as it experiences every cases of the algorithm.\nPLEASE REPORT IT. PLEASE DONT LOSE IT.\n"); printf("{\n"); int rank; for (rank=0; rank < stackSize; rank++) printf("%d, ",origSizes[rank]); printf("}\n"); } free(origSizes); return; } if (isFree(posTPlus)) { /* CASE D: t in a block, t+1 free */ if (debug>0) printf("Case D+\n"); flip(posTPlus); doneD = 1; } else if (isFree(posTMinus)) { /* CASE D: t in a block, t-1 free */ if (debug>0) printf("Case D-\n"); flip(posTMinus); doneD = 1; } else if (isFirst(posTPlus)) { /* CASE E: t in a block, t+1 first element */ if (debug>0) printf("Case E+\n"); flip(posTPlus); doneE = 1; } else if (isFirst(posTMinus)) { /* CASE E: t in a block, t-1 first element */ if (debug>0) printf("Case E-\n"); flip(posTMinus); doneE = 1; } else if (isLast(posTPlus) && posTPlus != 1) { /* CASE F+: t in a block, t+1 last element */ doneF = 1; if (debug>0) printf("Case F+\n"); flip(blockLength()); flip(posTPlus + 1); int newPos = getRankOf(tRadius); if (newPos>0) flip(newPos); } else if (isLast(posTMinus) && posTMinus != 1) { /* CASE F-: t in a block, t-1 last element */ doneF = 1; if (debug>0) printf("Case F-\n"); flip(blockLength()); flip(posTMinus + 1); int newPos = getRankOf(tRadius); if (newPos>0) flip(newPos); } else { int k = blockLength()-1; int o = getPancakeRadius(1) - tRadius; int pos = getRankOf(tRadius+(k+1)*o); if (isFree(pos) || isFirst(pos)) { doneG = 1; if (debug>0) printf("Case G\n"); flip(k+1); flip(pos); } else { doneH = 1; if (debug>0) printf("Case H\n"); flip(pos+1); flip(getRankOf(tRadius+k*o)); } } } } free(origSizes); /* END SOLUTION */ }
bool CollisionGeometry::isUncertain() const { return !isOccupied() && !isFree(); }
void RegAlloc::removeFree(Register r) { NanoAssert(isFree(r)); free &= ~rmask(r); }
void RegAlloc::addFree(Register r) { NanoAssert(!isFree(r)); free |= rmask(r); }
bool RegAlloc::isConsistent(Register r, LIns* i) { NanoAssert(r != UnknownReg); return (isFree(r) && !getActive(r) && !i) || (!isFree(r) && getActive(r)== i && i ); }
/******************************************************************************* * @author : Rohan Jyoti * @name : malloc * @param : size_t * @return : void * to allocated block * @purpose : allocate/return space on the heap ******************************************************************************/ void *malloc(size_t size) { if(size==0) return NULL; if(mBlock == NULL) { fprintf(stderr, "Custom malloc engine initiated rev 98\n"); //sbrk a new mBlock buffer where buffSize = mBlock_t + space for fList + space for mList int listMaxBound = LIST_MAX + 1; int buffSize = sizeof(mBlock_t)+(sizeof(fListNode*)*listMaxBound)+sizeof(int)*listMaxBound; mBlock=sbrk(buffSize); init_Lists(mBlock); } void *ptr1 = NULL; int index1, index2, listIndex; //reusable F_COMP = (int)(2*M_POW(2,9)); if(mBlock->fListCount > 0) { for(index1 = 0; index1 < LIST_THRESHOLD; index1++) { listIndex = soMD * (int)(M_POW(2,index1)); if(listIndex >= (int)size) { if(isFree(index1)) return fListRemove(index1); else break; } } if(index1 >= LIST_THRESHOLD) { size_t ptr_size; for(; index1 <= LIST_MAX; index1++) { fListNode *prev = NULL; fListNode *fLN_at_index =(mBlock->fList)[index1]; while(fLN_at_index) { ptr1 = fLN_at_index; ptr_size = getSize(fLN_at_index); if(size <= ptr_size) { if(size == ptr_size) { if(!prev) mBlock->fList[index1]=fLN_at_index->nextNode; else prev->nextNode=fLN_at_index->nextNode; mBlock->fListCount--; return ptr1; } else { //meaning size < ptr_size float t1 = ERR_COMP + (100.0/size); int t2 = (int)(size * t1); if((int)ptr_size < t2) { if(!prev) mBlock->fList[index1]=fLN_at_index->nextNode; else prev->nextNode=fLN_at_index->nextNode; mBlock->fListCount--; return ptr1; } } } prev=fLN_at_index; fLN_at_index=fLN_at_index->nextNode; } } } } //we reach here indicating that there is no free memory block that can accomodate size or there is no free memory for(index1 = 0; index1 < LIST_THRESHOLD; index1++) { listIndex = soMD * (int)(M_POW(2,index1)); if(listIndex >= (int)size) { int soMD_index1 = soMD * (int)(M_POW(2,index1)); int soMD_index1_minus_1 = soMD * (int)(M_POW(2,index1-1)); int buffSize = (sizeof(int)+soMD_index1) * (1<<(mBlock->mList)[index1]) + (sizeof(int)+soMD_index1_minus_1); ptr1=sbrk(buffSize); if(ptr1 == (int*)-1) return NULL; //meaning we have run out of memory else { for(index2 = 0; index2 < (1<<(mBlock->mList)[index1])-1; index2++) { ptr1 = setSize(ptr1, listIndex, AT_HEAD); fListAdd(ptr1, index1, listIndex); char *tempy = (char*)ptr1; tempy+=listIndex; ptr1=tempy; } if(index1!=0) { ptr1 = setSize(ptr1, soMD_index1_minus_1, AT_HEAD); fListAdd(ptr1, index1-1, soMD_index1_minus_1); char *tempy = (char*)ptr1; tempy+=soMD_index1_minus_1; ptr1=tempy; } ptr1 = setSize(ptr1, listIndex, AT_HEAD); (mBlock->mList)[index1]++; int shiftMax = 8; int reduce_val = 4; if((mBlock->mList)[index1]>shiftMax) (mBlock->mList)[index1]=reduce_val; return ptr1; } } } for(; index1 < LIST_MAX; index1++) { int soMD_LT = soMD * (int)(M_POW(2,LIST_THRESHOLD)); listIndex = soMD_LT + (index1 * F_COMP); if(listIndex >= (int)size) { int size_to_alloc = sizeof(int) + size; ptr1=sbrk(size_to_alloc); ptr1 = setSize(ptr1, size, AT_HEAD); return ptr1; } } if(index1 == LIST_MAX) { int size_to_alloc = sizeof(int) + size; ptr1=sbrk(size_to_alloc); if(ptr1 == (int*)-1) return NULL; //meaning we have run out of memory ptr1 = setSize(ptr1, size, AT_HEAD); return ptr1; } return ptr1; }