Exemple #1
0
void TdbDatabase::getCatalogs(const string& database_path, vector<string>& result) {
    const bf::path p(database_path);

    if (bf::is_directory(p)) {

        typedef bf::directory_iterator dirIter;

        for (dirIter iter = dirIter(p); iter != dirIter(); ++iter) {
            bf::path cand(*iter);
            if (cand.extension() == ".tdb" && bf::is_regular_file(cand)) {
                result.push_back(cand.stem().string());
            }
        }
    }
}
Exemple #2
0
QString SystemInfo::lsbRelease(const QStringList  &args)
{
	QStringList path = QString(qgetenv("PATH")).split(':');
	QString found;

	foreach (const QString &dirname, path)
	{
		QDir dir(dirname);
		QFileInfo cand(dir.filePath("lsb_release"));
		if (cand.isExecutable())
		{
			found = cand.absoluteFilePath();
			break;
		}
	}
void predict(int u, vector< pair<int,float> > & ret){
     set<int> rated(ui[u].begin(), ui[u].end());
     vector<float> cand(ITEM_NUM, 0);
     for(int i = 0; i < ui[u].size(); ++i){
          int ii = ui[u][i];
          for(int j = 0; j < w[ii].size(); ++j){
               int jj = w[ii][j].first;
               if(rated.find(jj) != rated.end()) continue;
               cand[jj] += w[ii][j].second;
          }
     }
     for(int i = 0; i < cand.size(); ++i)
          if(cand[i] > 0)
               ret.push_back(make_pair<int,float>(i, cand[i]));
     sort(ret.begin(), ret.end(), GreaterSecond<int,float>);
}
Exemple #4
0
int main(int argc, char **argv) {
	int i = 0, j = 0, k = 0;

	alloc_puzzle();
	read_in();
	printf("\n\nPuzzle as read in:\n");
	print_puzzle();
	alloc_cand();

	while (!solved()) {
		if (i == 2) {
			printf("\nno luck after 20 iterations...\nis the puzzle solvable?\nexiting...\n");
			free_mem();
			exit(EXIT_SUCCESS);
		}
		i++;
		cand();
		printf("\nPuzzle after iteration #%d\n", i);
		print_puzzle();
		/*
		if (i == 50) {
			printf("num candidates\n");
			for (j = 0; j < N; j++) 
				for (k = 0; k < N; k++) 
					printf("%d_%d: %d\n", j, k, puz_can[j][k][0]);
		}
		*/
		reset();
	}

	/*
	cand();
	printf("\nPuzzle after one candidacy:\n");
	print_puzzle();
	reset();
	cand();
	printf("\nPuzzle after two candidacies:\n");
	print_puzzle();
	reset();
	cand();
	printf("\nPuzzle after three candidacies:\n");
	print_puzzle();
	*/

	return EXIT_SUCCESS;
}
Exemple #5
0
void population_mis::get_one_individuum_tournament(MISConfig & config, individuum_mis & ind) {

    // Create random candidates
    std::vector<unsigned int> cand(population_size);
    random_functions::permutate_vector_good(cand, true);

    unsigned int winner_id = 0;
    unsigned int winner_size = 0;
    for (unsigned int i = 0; i < config.tournament_size; ++i) {
        unsigned int ind_id = cand[i];
        if (internal_population[ind_id].solution_size > winner_size) {
            winner_id = ind_id;
            winner_size = internal_population[ind_id].solution_size;
        }
    }
    ind = internal_population[winner_id];
}
//https://leetcode.com/problems/remove-duplicate-letters/
string removeDuplicateLetters(string s)
{
    vector<int> cand(256, 0);
    vector<bool> visited(256, false);
for (char c : s)
        cand[c]++;
    string result = "0";
for (char c : s)
    {
        cand[c]--;
        if (visited[c]) continue;
        while (c < result.back() && cand[result.back()])
        {
            visited[result.back()] = false;
            result.pop_back();
        }
        result += c;
        visited[c] = true;
    }
    return result.substr(1);
}
 vector<vector<int> > combinationSum(vector<int> &candidates, int target) {
     // Start typing your C/C++ solution below
     // DO NOT write int main() function
     vector<vector<vector<int>>> table(target + 1);
     table.clear();
     int len = candidates.size();
     for (int n = 0; n < len; n ++){
         int cand_num = candidates[n];
         vector<int> cand;
         cand.push_back(cand_num);
         if (cand_num <= target){
             table[cand_num].push_back(cand);
         }
     }
     
     for (int i = 0; i <= target; i ++){
         int size = table[i].size();
         if (size == 0){
             continue;
         }
         for (int j = 0; j < size; j ++){
             vector<int> cand(table[i][j]);
             for (int k = 0; k < len; k ++){
                 int tmp = candidates[k];
                 if(tmp < cand[cand.size() - 1]){
                     continue;
                 }
                 vector<int> cand_new (cand);
                 cand_new.push_back(tmp);
                 int sum = i + tmp;
                 if (sum <= target){
                     table[sum].push_back(cand_new);
                 }
             }
         }
     }
     return table[target];
 }
Exemple #8
0
 /**
 Query function item (FunctionDbItem) by query key of device and engine
 (Regex can be used).
 */
 typename Item::function_t query(const string &backend, const string &engine) {
   std::regex re_backend(backend);
   std::regex re_engine(engine);
   vector<shared_ptr<Item>> cand(items_);
   cand.erase(std::remove_if(
                  cand.begin(), cand.end(),
                  [&](shared_ptr<Item> item) {
                    if (!std::regex_match(item->backend.begin(),
                                          item->backend.end(), re_backend)) {
                      return true;
                    }
                    if (!std::regex_match(item->engine.begin(),
                                          item->engine.end(), re_engine)) {
                      return true;
                    }
                    return false;
                  }),
              cand.end());
   NBLA_CHECK(cand.size() > 0, error_code::unclassified,
              "('%s', '%s') could not be found in %s", backend.c_str(),
              engine.c_str(), print_function_items<Item>(items_).c_str());
   // Use one that has highest priority
   return cand[cand.size() - 1]->function;
 }
Exemple #9
0
Status
hbitsCreate(std::string &result, std::string &addressOut)
{
    while (true)
    {
        libbitcoin::data_chunk cand(21);
        ABC_CHECK(randomData(cand, cand.size()));
        std::string minikey = libbitcoin::encode_base58(cand);
        minikey.insert(0, "a");
        if (30 == minikey.size() &&
                0x00 == bc::sha256_hash(bc::to_data_chunk(minikey + "!"))[0])
        {
            bc::ec_secret secret;
            hbitsDecode(secret, minikey);
            bc::ec_point pubkey = bc::secret_to_public_key(secret, true);
            bc::payment_address address;
            address.set(pubkeyVersion(), bc::bitcoin_short_hash(pubkey));

            result = minikey;
            addressOut = address.encoded();
            return Status();
        }
    }
}
void NuboNoseDetectorImpl::onNose (gchar *message)
{

  /*the String received will be like this ( the ; is the seperation among noses): 
    x:int,y:int,width:int,height:int;x:int,y:int,width:int,height:int;*/
  std::string del1 = ";";
  std::string del2 = ",";
  std::string del3 = ":";
  std::vector<std::string> *noses = new std::vector<std::string>;
  std::vector<std::string> *fields = new std::vector<std::string>;
  std::vector<std::string> *all = new std::vector<std::string>;
  std::vector<std::shared_ptr<NoseInfo>> test;
  int x,y,height,width;
  std::string t; 
  
  bool register_completed=true;
  int i=0;

  try {
    
    split_message(message,del1,noses);
    for( i=0; (int)(noses->size())>i; i++) 
      split_message(noses->at(i),del2,fields);
    
    for( i=0; (int)(fields->size())>i; i++)
      split_message(fields->at(i),del3,all);
    
    NoseInfo *fi;
    
    for(int i=0; (int)(all->size())>i; i=i+2)
      {
	
	if (register_completed)
	  {
	    t="nose";
	    x=0;y=0;width=0;height=0;
	    register_completed=false;
	  }
	if (0==all->at(i).compare("x")) 	
	  {
	    if ((i+1)< (int)(all->size()))	      
	      x=std::stoi(all->at(i+1));
	  }
	else if (0==all->at(i).compare("y")) 
	  {
	    if ((i+1)< (int)(all->size()))
	      y=std::stoi(all->at(i+1));
	  }
	
	else if (0==all->at(i).compare("width"))     
	  {
	    if ((i+1)< (int)(all->size()))
	      width=std::stoi(all->at(i+1));
	  }
	else if (0==all->at(i).compare("height"))     
	  {
	    if ((i+1)< (int)(all->size()))
	      {
		height=std::stoi(all->at(i+1));
		std::shared_ptr <NoseInfo> cand ( new NoseInfo(t,x,y,width,height));
		test.push_back(cand);
		register_completed=true;
	      }
	  }
      }
   
    if (test.size()>0)
      {
	OnNose event (shared_from_this(), OnNose::getName(), test);
	signalOnNose (event);
      }
  } catch (std::bad_weak_ptr &e) {
  }
}
Exemple #11
0
MemoryMapNode *MemoryMap::addChild(
        const Instance &origInst, const InstanceList &candidates,
        MemoryMapNode *parent, int threadIndex, quint64 addrInParent,
        bool addToQueue)
{
    MemoryMapNode *child = 0;
    // Only proceed if we don't have more than one instance to process
    if (candidates.size() > 1 || (!origInst.isValid() && candidates.isEmpty()))
        return 0;

    Instance i(origInst);

    // Do we have a candidate?
    if (!candidates.isEmpty()) {
        float o_prob, c_prob;
        Instance cand(candidates.first());
        // Does one instance embed the other?
        ObjectRelation orel = BaseType::embeds(
                cand.type(), cand.address(),
                origInst.type(), origInst.address());

        switch(orel) {
        case orSecondEmbedsFirst:
            // Use the original type
            break;

        // Use the candidate type
        case orFirstEmbedsSecond:
        // Use the candidate type (it might hold properties from the
        // JavaScript rule evaluation
        case orEqual:
            i = cand;
            break;

        case orCover:
        case orOverlap:
        case orNoOverlap:
            // Calculate probability for both
            o_prob = calculateNodeProbability(origInst, 1.0);
            c_prob = calculateNodeProbability(cand, 1.0);
            // If probs are significantly different (> 0.1), and add the one
            // with higher prob., otherwise add both
            if (qAbs(c_prob - o_prob) > 0.1) {
                if (c_prob > o_prob)
                    i = cand;
            }
            else {
                addChild(cand, InstanceList(), parent, threadIndex,
                         addrInParent, addToQueue);
            }
            break;
        }
    }

    // Dereference, if required
    if (i.type() && (i.type()->type() & BaseType::trLexical))
        i = i.dereference(BaseType::trLexical);

    if (!i.isNull() && i.type() && (i.type()->type() & interestingTypes)) {
        // Don't add nodes if the probability is below the threshold
        float prob = calculateNodeProbability(i, parent ? parent->probability() : 1.0);
        if (prob <= _shared->minProbability)
            return 0;

        // Is any other thread currently searching for the same address?
        _shared->currAddressesLock.lockForWrite();
        _shared->currAddresses[threadIndex] = 0;
        int idx = 0;
        while (idx < _shared->threadCount) {
            if (_shared->currAddresses[idx] == i.address()) {
                // Another thread searches for the same address, so release the
                // currAddressesLock and wait for it to finish
                _shared->currAddressesLock.unlock();
                _shared->perThreadLock[idx].lock();
                // We are blocked until the other thread has finished its node
                _shared->perThreadLock[idx].unlock();
                _shared->currAddressesLock.lockForWrite();
                idx = 0;
            }
            else
                ++idx;
        }

        // No conflicts anymore, so we lock our current address
        _shared->currAddresses[threadIndex] = i.address();
        QMutexLocker threadLock(&_shared->perThreadLock[threadIndex]);

        _shared->currAddressesLock.unlock();

        // Check if object conflicts previously given objects
        if (objectIsSane(i) && parent) {

            try {
                MemoryMapNodeSV* parent_sv = _buildType == btSibi ?
                            dynamic_cast<MemoryMapNodeSV*>(parent) : 0;
                if (parent_sv)
                    child = parent_sv->addChild(i, addrInParent);
                else
                    child = parent->addChild(i);
            }
            catch(GenericException& ge) {
                // The address of the instance is invalid

                // Release locks and return
                _shared->currAddressesLock.lockForWrite();
                _shared->currAddresses[threadIndex] = 0;
                _shared->currAddressesLock.unlock();

                return child;
            }

            addNodeToHashes(child);

            // Insert the new node into the queue
            if (addToQueue && shouldEnqueue(i, child)) {
                _shared->queueLock.lock();
                _shared->queue.insert(child->probability(), child);
                _shared->queueLock.unlock();
            }
        }

        // Done, release our current address (no need to hold currAddressesLock)
        _shared->currAddressesLock.lockForWrite();
        _shared->currAddresses[threadIndex] = 0;
        _shared->currAddressesLock.unlock();
//        // Wake up a waiting thread (if it exists)
//        _shared->threadDone[threadIndex].wakeOne();

    }

    return child;
}