WeightedFace(shared_ptr<Face> face_, const milliseconds& delay = milliseconds(0)) : face(face_) , lastDelay(delay) { calculateWeight(); }
uint32_t GraphData::getOutgoingBandwidth( const uint32_t & ip, std::stringstream &connections ) { uint32_t outgoing = 0; std::map< uint32_t, GraphInfo* >::iterator itr; graphMapMutex_.lock( ); connections << "<Outgoing>" << std::endl; for( itr = graphMap_[ip].begin(); itr != graphMap_[ip].end(); ++itr ) { outgoing += calculateWeight( itr->second->weights, itr->second->lastAccess ); std::vector< Connections >::iterator citr; for( citr = itr->second->connections.begin(); citr != itr->second->connections.end(); ++citr ) { connections << "<Connection>" << std::endl; connections << "<Protocol>" << citr->protocol << "</Protocol>" << std::endl; connections << "<Source>" << std::endl; connections << "<IP>" << inet_ntoa( *((struct in_addr*)&ip)) << "</IP>" << std::endl; connections << "<Port>" << citr->sport << "</Port>" << std::endl; connections << "</Source>" << std::endl; connections << "<Destination>" << std::endl; connections << "<IP>" << inet_ntoa( *((struct in_addr*)&(itr->first))) << "</IP>" << std::endl; connections << "<Port>" << citr->dport << "</Port>" << std::endl; connections << "</Destination>" << std::endl; connections << "</Connection>" << std::endl; } } connections << "</Outgoing>" << std::endl; graphMapMutex_.unlock( ); return outgoing; }
bool UInventoryComponent::removeItem(UItemBase* Item, int32 ammount) { if (!Item) return false; if (ammount > 0) { UItemBase* place = items[Item->type].map[Item]; if (place) { if (ammount > place->ammount) ammount = place->ammount; currentWeight -= place->weight * ammount; place->ammount -= ammount; if (place->ammount > 0) return false; //fallthrough to past if nothing is left of the thing } else { return false; } } items[Item->type].map.Remove(Item); equipment->unequipItemByPointer(Item);//used only when character needs to be equipped while looting refresh(); calculateWeight(); return true; }
void Inventory::updateStats() { calculateWeight(getAllItems()); calculateRsAndBe(); // flag setzen: Werte sind up to Date mValuesUpToDate = true; }
void UInventoryComponent::dropItem(UItemBase* Item) { if (!Item) return; items[Item->type].map.Remove(Item); if(Item->ammount > 0) GetWorld()->SpawnActor<AItemBaseActor>(itemBaseTemplate, GetOwner()->GetActorLocation(), GetOwner()->GetActorRotation())->spawn(Item); if (requiresUI) Item->widget->RemoveFromParent(); calculateWeight(); }
bool UInventoryComponent::addItem(UItemBase* Item,bool forceNew) { if (!Item) return true; if (items.Find(Item->type) == NULL) return false; if (items[Item->type].map.Find(Item) != NULL) { return true; } if (forceNew) { addItemCreate(Item); } else { for (auto& x : items[Item->type].map) { if (x.Key->name == Item->name) { int32 ammountPossibleToAdd = x.Key->maxAmmount - x.Key->ammount; if (ammountPossibleToAdd < Item->ammount ) { x.Key->ammount += ammountPossibleToAdd; Item->ammount -= ammountPossibleToAdd; } else { x.Key->ammount += Item->ammount; Item->ammount = 0; } if (requiresUI) if(x.Key->widget) x.Key->widget->loadVisuals(); } } if (Item->ammount > 0) { addItemCreate(Item); } } if (requiresUI) if (Item->widget) Item->widget->loadVisuals(); calculateWeight(); refresh(); return true; }
T* UInventoryComponent::createItem(FString ID) { static const FString ContextString(TEXT("GENERAL")); FItemTable* row = standardItemTable->FindRow<FItemTable>(FName(*ID), ContextString); if (!row) { UE_LOG(LogTemp, Warning, TEXT("ItemRowNotFound")); return NULL; } calculateWeight(); T* x = Cast<T>(NewObject<UItemBase>(this, row->base)); Cast<UItemBase>(x)->initialize(GetOwner()->GetWorld()); return x; }
ClassifyDocum::ClassifyDocum(string nameclass ,string namedirclass) // конструктор , сразу нормализует документы { countAllWords = 0; nameClass=nameclass; nameDirClass = namedirclass; normalize = new NormalizeDocum(nameDirClass); normalize->scanListFiles(); normalize->normalizeFiles(); listFiles = normalize->getListFiles(); countAllFiles = listFiles.size(); calculateWords(); calculateWeight(); cout<<listFiles.size()<<endl; }
std::string GraphData::makeGraphPacket() { std::string data; std::string datastream; graphMapMutex_.lock( ); std::cerr << "mutex locked" << std::endl; std::map< uint32_t, std::map< uint32_t, GraphInfo*> >::iterator ritr; std::map< uint32_t, GraphInfo* >::iterator citr; std::map< uint32_t, GraphInfo* >::iterator tmp; uint32_t edges = 0; edgeLifeMutex_.lock( ); for( ritr = graphMap_.begin(); ritr != graphMap_.end(); ++ritr ) { for( citr = ritr->second.begin(); citr != ritr->second.end(); ) { tmp = citr; //Needed to be able to delete the current element in all cases. ++citr; //edge exist //recalculate weight time_t currentTime = time( NULL ); if( (currentTime - tmp->second->lastAccess) >= edgeLife_ ) { //edge past life expectancy - time to die Edge edge; edge.ipA = ritr->first; edge.ipB = tmp->first; deadNodesMutex_.lock( ); deadNodes_.push_back( edge ); deadNodesMutex_.unlock(); delete tmp->second; (ritr->second).erase( tmp->first ); continue; } ++edges; data += numToString( ritr->first ); data += numToString( tmp->first ); data += numToString( htonl(calculateWeight((tmp->second)->weights, tmp->second->lastAccess)) ); } } edgeLifeMutex_.unlock( ); graphMapMutex_.unlock( ); std::cout << "Number of Edges: " << edges << std::endl; datastream += numToString( htonl(edges) ); datastream += data; return datastream; }
void MultiColvarBase::performTask( const unsigned& task_index, const unsigned& current, MultiValue& myvals ) const { AtomValuePack myatoms( myvals, this ); // Retrieve the atom list if( !setupCurrentAtomList( current, myatoms ) ) return; // Do a quick check on the size of this contribution calculateWeight( myatoms ); if( myatoms.getValue(0)<getTolerance() ){ updateActiveAtoms( myatoms ); return; } // Compute everything double vv=doCalculation( task_index, myatoms ); myatoms.setValue( 1, vv ); return; }
void ActiveGroup::finish() { const int nsel = vertices->size(); if(nsel < 1) return; average(vertices); if(nsel > 1) { meanPosition *= 1.f / (float)nsel; meanPosition = incidentRay.closetPointOnRay(meanPosition); meanNormal.normalize(); } //std::cout<<"\n n sel "<<nsel //<<"\n mean p "<<meanPosition<<" depth "<<depthMin; calculateWeight(vertices); }
STImage *FieldMorph(STImage *image, const std::vector<Feature> &sourceFeatures, const std::vector<Feature> &targetFeatures, float t, float a, float b, float p) { int width = image->GetWidth(); int height = image->GetHeight(); STImage *result = new STImage(width, height, STColor4ub(255,255,255,255)); std::vector<Feature> interpolatedFeatures = interpolateFeatures(sourceFeatures, targetFeatures, t); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { STVector2 dispSum = STVector2(0, 0); float weightsum = 0; STPoint2 X = STPoint2(x, y); int numFeatures = sourceFeatures.size(); for (int i = 0; i < numFeatures; i++) { STPoint2 Pp = sourceFeatures[i].P; STPoint2 Qp = sourceFeatures[i].Q; STPoint2 P = interpolatedFeatures[i].P; STPoint2 Q = interpolatedFeatures[i].Q; float u = calculateU(X, P, Q); float v = calculateV(X, P, Q); STPoint2 Xp = calculateXp(Pp, Qp, u, v); STVector2 displacement = STVector2(Xp) - STVector2(X); float dist = calculateDistance(X, P, Q, u, v); float weight = calculateWeight(Q, P, a, b, p, dist); dispSum += displacement * weight; weightsum += weight; } STPoint2 Xprime = X + dispSum/weightsum; result->SetPixel(x, y, interpolatedColor(Xprime, image)); } } return result; }
uint32_t GraphData::getIncommingBandwidth( const uint32_t & ip, std::stringstream &connections ) { uint32_t incomming = 0; std::map< uint32_t, std::map< uint32_t, GraphInfo* > >::iterator ritr; std::map< uint32_t, GraphInfo* >::iterator citr; graphMapMutex_.lock( ); connections << "<Incoming>" << std::endl; for( ritr = graphMap_.begin( ); ritr != graphMap_.end(); ++ritr ) { for( citr = ritr->second.begin(); citr != ritr->second.end(); ++citr ) { if( citr->first == ip ) { //incomming incomming += calculateWeight( citr->second->weights, citr->second->lastAccess ); std::vector< Connections >::iterator itr; for( itr = citr->second->connections.begin(); itr != citr->second->connections.end(); ++itr ) { connections << "<Connection>" << std::endl; connections << "<Protocol>" << itr->protocol << "</Protocol>" << std::endl; connections << "<Source>" << std::endl; connections << "<IP>" << inet_ntoa( *((struct in_addr*)&(citr->first)) ) << "</IP>" << std::endl; connections << "<Port>" << itr->dport << "</Port>" << std::endl; connections << "</Source>" << std::endl; connections << "<Destination>" << std::endl; connections << "<IP>" << inet_ntoa( *((struct in_addr*)&(ritr->first)) ) << "</IP>" << std::endl; connections << "<Port>" << itr->sport << "</Port>" << std::endl; connections << "</Destination>" << std::endl; connections << "</Connection>" << std::endl; } } else { //next continue; } } } connections << "</Incoming>" << std::endl; graphMapMutex_.unlock( ); return incomming; }
void MultiColvarBase::performTask(){ // Currently no atoms have derivatives so deactivate those that are active atoms_with_derivatives.deactivateAll(); // Currently no central atoms have derivatives so deactive them all atomsWithCatomDer.deactivateAll(); // Retrieve the atom list if( !setupCurrentAtomList( getCurrentTask() ) ) return; // Do a quick check on the size of this contribution calculateWeight(); // printf("HELLO WEIGHT %f \n",getElementValue(1) ); if( getElementValue(1)<getTolerance() ){ updateActiveAtoms(); return; } // Compute everything double vv=doCalculation(); // Set the value of this element in ActionWithVessel setElementValue( 0, vv ); return; }
MStatus BCIViz::compute( const MPlug& plug, MDataBlock& block ) { if( plug == outValue ) { MStatus status; MDagPath path; MDagPath::getAPathTo(thisMObject(), path); MMatrix worldInverseSpace = path.inclusiveMatrixInverse(); MDataHandle inputdata = block.inputValue(ainput, &status); if(status) { const MMatrix drvSpace = inputdata.asMatrix(); fDriverPos.x = drvSpace(3, 0); fDriverPos.y = drvSpace(3, 1); fDriverPos.z = drvSpace(3, 2); fDriverPos *= worldInverseSpace; } fTargetPositions.clear(); MArrayDataHandle htarget = block.inputArrayValue( atargets ); unsigned numTarget = htarget.elementCount(); fTargetPositions.setLength(numTarget); for(unsigned i = 0; i<numTarget; i++) { MDataHandle tgtdata = htarget.inputValue(&status); if(status) { const MMatrix tgtSpace = tgtdata.asMatrix(); MPoint tgtPos(tgtSpace(3,0), tgtSpace(3,1), tgtSpace(3,2)); tgtPos *= worldInverseSpace; MVector disp = tgtPos; disp.normalize(); tgtPos = disp; fTargetPositions[i] = tgtPos; } htarget.next(); } m_hitTriangle = 0; neighbourId[0] = 0; neighbourId[1] = 1; neighbourId[2] = 2; if(!checkTarget()) { MGlobal::displayWarning("convex hull must have no less than 4 targes."); return MS::kSuccess; } if(!checkFirstFour(fTargetPositions)) { MGlobal::displayWarning("first 4 targes cannot sit on the same plane."); return MS::kSuccess; } if(!constructHull()) { MGlobal::displayWarning("convex hull failed on construction."); return MS::kSuccess; } findNeighbours(); calculateWeight(); MArrayDataHandle outputHandle = block.outputArrayValue( outValue ); int numWeight = fTargetPositions.length(); m_resultWeights.setLength(numWeight); for(int i=0; i < numWeight; i++) m_resultWeights[i] = 0.0; m_resultWeights[neighbourId[0]] = fAlpha; m_resultWeights[neighbourId[1]] = fBeta; m_resultWeights[neighbourId[2]] = fGamma; MArrayDataBuilder builder(outValue, numWeight, &status); for(int i=0; i < numWeight; i++) { MDataHandle outWeightHandle = builder.addElement(i); outWeightHandle.set( m_resultWeights[i] ); //MGlobal::displayInfo(MString("wei ") + i + " " + weights[i]); } outputHandle.set(builder); outputHandle.setAllClean(); } return MS::kSuccess; }
float UInventoryComponent::getWeight() { calculateWeight(); return currentWeight; }
/*任务类要执行的任务 */ void Task::process() { map<string,double> query; //存储查询词权重 calculateWeight(query); //计算查询词权重 if(query.size()==0) { cout<<"查询词为空"<<endl; return; } map<string,double>::iterator it = query.begin(); map<int,double> ret; ret = index_.search(it->first); //调用InvertIndex中的search()函数,返回对应单词的倒排列表 map<int,double>::iterator pos = ret.begin(); //用于遍历ret的迭代器 map<int,map<string,double> > common; //存储交集容器 while(pos!=ret.end()) //遍历map<int,double> ret 生成第一个交集 { pair<int,map<string,double> > pr1; //element of common pr1.first = pos->first; //docid pair<string,double> pr2; //element of pr1.second pr2.first = it->first; //string pr2.second = pos->second; //weight pr1.second.insert(pr2); common.insert(pr1); ++pos; } it++; //取交集值 while(it!=query.end()) { string word(it->first); ret = index_.search(word);//查找下一个查询词 map<int,double>::iterator invalid = ret.begin(); if(-1==(invalid->first)) { query.erase(it); it++; continue; } if(0==(invalid->first)) ret.erase(invalid); map<int,map<string,double> >::iterator beg1 = common.begin(); map<int,map<string,double> >::iterator last1 = common.end(); map<int,double>::iterator beg2 = ret.begin(); map<int,double>::iterator last2 = ret.end(); common = intersection(&beg1,&last1,&beg2,&last2,word);//交集 it++; } //求余弦值 if(common.size()==0) { cout<<"交集为空"<<endl; return; } map<int,map<string,double> >::iterator iter = common.begin(); map<string,double>::iterator iter1 = query.begin(); Document doc; while(iter!=common.end()) { double fenzi=0,fenmu=0,part1=0,part2=0; double cos; while(iter1!=query.end()) { fenzi = fenzi +(iter1->second)*(query[iter1->first]);//分子 = 分子 + part1 = part1 +(iter1->second)*(iter1->second); part2 = part2 +(query[iter1->first])*(query[iter1->first]); ++iter1; } fenmu = sqrt(part1)*sqrt(part2); cos = fenzi/fenmu; memset(&doc,0,sizeof(doc)); if(iter->first==0) { ++iter; continue; } doc.docid = iter->first; doc.cosValue = cos; pq_.push(doc); ++iter; } }