Exemplo n.º 1
0
	std::string toString<stringmap>(const stringmap &v)
	{
		std::ostringstream oss;
		oss << "std::map( ";
		for (stringmap::const_iterator it = v.begin(); it != v.end(); ++it) {
			oss << it->first << " = " << it->second;

			stringmap::const_iterator jt(it);
			if (++jt != v.end()) oss << ", ";
		}
		oss << " )";
		return oss.str();
	}
Exemplo n.º 2
0
 std::vector<std::string> extract_keys_from_string_map
     (stringmap const& keyword_dictionary
     )
 {
     std::vector<std::string> keywords;
     stringmap_iterator i_keyword_dictionary = keyword_dictionary.begin();
     for
         (
         ;i_keyword_dictionary != keyword_dictionary.end()
         ;++i_keyword_dictionary
         )
         {
         keywords.push_back((*i_keyword_dictionary).first);
         }
     return keywords;
 }
// second version - reverse
bool takeRoute_2(string start, vector<string> & modesList, d_stringmap & UniqueRoutes, int modeIndex, stringmap & result, string end) {
  if (modesList[modeIndex] == "stop") 
  {
    if (result.count(start) == 0)
    {
      result.insert({start,0}) ;
    }
    return true ;
  }
  if (allCitiesPossible(UniqueRoutes,result))
  {
    return true ;
  }
  
  int modeID = getModeID(modesList[modeIndex]) ;

}
Exemplo n.º 4
0
void insert_element(stringmap &map, const Node &node, pthread_rwlock_t *lock, ofstream &fout){
  bool to_write = false;
  string key;

  try{
    string name = node["package"].as<string>();
    string version = node["version"].as<string>();
    key = name + version;
  }catch(...){
    return;
  }

  pthread_rwlock_rdlock(lock);
    if(map.find(key) == map.end()){
      to_write = true;
    }
  pthread_rwlock_unlock(lock);


  if(to_write){
    string name = node["package"].as<string>();
    string version = node["version"].as<string>();
    string key = name + version;

    pthread_rwlock_wrlock(lock);

    map.insert(make_pair(key, ""));

    Emitter out;
    out << BeginSeq;
    out << node;
    out << EndSeq;
    fout << out.c_str() << endl;


    if(node["status"].as<string>() != "ok"){
      broken++;
    }

    total++;

    pthread_rwlock_unlock(lock);
  }
}
Exemplo n.º 5
0
void
show
(
   const std::string & tag,
   const stringmap<VALUETYPE> & container
)
{
   fprintf
   (
      stdout,
      "- xpc::stringmap '%s':\n"
      "-    Name:                    '%s'\n"
      "-    Size:                     %d\n"
      ,
      tag.c_str(),
      container.name().c_str(),
      int(container.size())
   );
   std::for_each(container.begin(), container.end(), show_pair<VALUETYPE>);
}
bool allCitiesPossible(d_stringmap & UniqueRoutes, stringmap & result) {

    bool notFound = false ;
    for (d_stringmap::iterator kt = UniqueRoutes.begin(); kt != UniqueRoutes.end(); ++kt)
    {
        if (result.count(kt->first) == 0)
        {
            return false ;
            //cout << "ALL CITIES NOT POSSIBLE!" << endl ;
        }
    }

    //cout << "ALL CITIES POSSIBLE!!!" << endl ;
    return true ;
}
stringmap merge(stringmap a, stringmap b)
{
	stringmap tmp(a);
	tmp.insert(b.begin(),b.end());
	return tmp;
}
Exemplo n.º 8
0
void insert_element(stringmap &map, const Node &node, pthread_rwlock_t *lock, ofstream &fout, string date){
  bool to_write = false;
  string key;

  try{
    string name = node["package"].as<string>();
    string version = node["version"].as<string>();
    key = name + version;
  }catch(...){
    return;
  }

  pthread_rwlock_rdlock(lock);
    if(map.find(key) == map.end()){
      to_write = true;
    }
  pthread_rwlock_unlock(lock);


  if(to_write){
    string name = node["package"].as<string>();
    string version = node["version"].as<string>();
    string number = node["number"].as<string>();
    string key = name + version;
    string status = node["status"].as<string>();

    string set;

    if(status == "ok"){

      ostringstream out_set;
      out_set << "[";

      auto install =  node["installationset"];

      for(size_t i = 0; i < install.size(); i++){
        out_set << "{";
        out_set << "\"" << install[i]["package"] << "\"" << ":" << "\"" << install[i]["version"] << "\"";
        out_set << "}";

        if(i + 1 != install.size()){
          out_set << ",";
        }
      }

      out_set << "]";

      set = out_set.str();
    }else{

      ostringstream out_set;
      auto reasons = node["reasons"];
      out_set << "[";

      for(size_t i = 0; i < reasons.size(); i++){
        out_set << "{";

        auto missing = reasons[i]["missing"];
        auto pkg = missing["pkg"];
          //YAML::Emitter out;
          //out << node["reasons"];
          //cout << out.c_str() << endl;
          //exit(-1);
        //}
        auto depchains = missing["depchains"];

        string unsat = pkg["unsat-dependency"].as<string>();
        string version_unsat = pkg["version"].as<string>();

        out_set << "\"unsat\": \"" << unsat << "\", ";
        out_set << "\"version\": \"" << version_unsat << "\"";
        out_set << "}";

        if(i + 1 != reasons.size()){
          out_set << ",";
        }
      }
      out_set << "]";
      set = out_set.str();
    }



//- reasons:
    //- missing:
        //pkg:
          //unsat-dependency: system.collections.generic (>= 1)
          //version: 2
          //package: windows.applicationmodel.datatransfer
        //depchains:
          //- depchain:
              //- version: 1
                //depends: windows.graphics.printing (>= 1)
                //package: windows.graphics.printing.optiondetails
              //- depends: windows.applicationmodel.datatransfer (>= 1)
                //version: 2
                //package: windows.graphics.printing

  //reasons:
    //- missing:
        //pkg:
          //version: 18
          //unsat-dependency: node-authorizenet (>= 1)
          //package: 42-cent




    string str_status;
    
    if(status == "ok"){
      str_status = "true";
    }else{
      str_status = "false";
    }

    ostringstream out;
    out << "{\"name\": " << "\"" << name << "\"";
    out << ", \"version\": " << "\"" << version << "\"";
    out << ", \"number\": " << "\"" << number << "\"";
    out << ", \"status\": " << "\"" << str_status << "\"";
    out << ", \"date\": " << "{ $date: \"" << date << "T00:00:00Z" << "\"}";
    out << ", \"set\": " << set << "}";


    pthread_rwlock_wrlock(lock);

    fout << out.str() << endl;

    if(status != "ok"){
      broken++;
    }

    total++;
    map.insert(make_pair(key, ""));

    pthread_rwlock_unlock(lock);
  }
}
Exemplo n.º 9
0
///' Calculate the intermediate network properties in the discovery dataset
///' 
///' These properties are need at every permutation: so they will be computed 
///' once.
///' 
///' @details
///' \subsection{Input expectations:}{
///'   Note that this function expects all inputs to be sensible, as checked by
///'   the R function 'checkUserInput' and processed by 'modulePreservation'. 
///'   
///'   These requirements are:
///'   \itemize{
///'   \item{The ordering of node names across 'dData', 'dCorr', and 'dNet' is
///'         consistent.}
///'   \item{The columns of 'dData' are the nodes.}
///'   \item{'dData' has been scaled by 'Scale'.}
///'   \item{'dCorr' and 'dNet'  are square matrices, and their rownames are 
///'         identical to their column names.}
///'   \item{'moduleAssigments' is a named character vector, where the names
///'         represent node labels found in the discovery dataset (e.g. 'dNet').}
///'   }
///' }
///' 
///' @param dData scaled data matrix from the \emph{discovery} dataset.
///' @param dCorr matrix of correlation coefficients between all pairs of 
///'   variables/nodes in the \emph{discovery} dataset.
///' @param dNet adjacency matrix of network edge weights between all pairs of 
///'   nodes in the \emph{discovery} dataset.
///' @param tNodeNames a character vector of node names in the test dataset
///' @param moduleAssignments a named character vector containing the module 
///'   each node belongs to in the discovery dataset. 
///' @param modules a character vector of modules for which to calculate the 
///'   module preservation statistics.
///' 
///' @return a list containing three lists: a list of weighted degree vectors,
///'   a list of correlation coefficient vectors, and a list of node 
///'   contribution vectors. There is one vector for each module in each list.
///' 
///' @keywords internal
// [[Rcpp::export]]
Rcpp::List IntermediateProperties (
    Rcpp::NumericMatrix dData, Rcpp::NumericMatrix dCorr, Rcpp::NumericMatrix dNet,
    Rcpp::CharacterVector tNodeNames, Rcpp::CharacterVector moduleAssignments, 
    Rcpp::CharacterVector modules
) {
  // First, scale the matrix data
  unsigned int nSamples = dData.nrow();
  unsigned int nNodes = dData.ncol();

  R_CheckUserInterrupt(); 
  
  // convert the colnames / rownames to C++ equivalents
  const std::vector<std::string> dNames (Rcpp::as<std::vector<std::string>>(colnames(dNet)));
  const std::vector<std::string> tNames (Rcpp::as<std::vector<std::string>>(tNodeNames));
  
  /* Next, we need to create three mappings:
  *  - From node IDs to indices in the discovery dataset.
  *  - From modules to all node IDs.
  *  - From modules to just node IDs present in the test dataset.
  */
  const namemap dIdxMap = MakeIdxMap(dNames);
  const stringmap modNodeMap = MakeModMap(moduleAssignments);
  const namemap tIdxMap = MakeIdxMap(tNames);
  const stringmap modNodePresentMap = MakeModMap(moduleAssignments, tIdxMap);
  
  // What modules do we actually want to analyse?
  const std::vector<std::string> mods (Rcpp::as<std::vector<std::string>>(modules));
  
  // We only need to iterate through modules which have nodes in the test 
  // dataset
  std::vector<std::string> modsPresent;
  for (auto it = mods.begin(); it != mods.end(); ++it) {
    if (modNodePresentMap.count(*it) > 0) {
      modsPresent.push_back(*it);
    }
  }
  
  R_CheckUserInterrupt(); 
  
  Rcpp::List degree;
  Rcpp::List corr;
  Rcpp::List contribution;
  
  // Calculate the network properties in the discovery dataset.
  std::string mod;
  unsigned int mNodes;
  arma::uvec dIdx, dRank;
  arma::vec dSP, dWD, dCV, dNC; 
  for (auto mi = modsPresent.begin(); mi != modsPresent.end(); ++mi) {
    // Get the node indices in the discovery dataset for this module
    mod = *mi;
    dIdx = GetNodeIdx(mod, modNodePresentMap, dIdxMap);
    mNodes = dIdx.n_elem;
    R_CheckUserInterrupt(); 
    
    // Calculate the network properties and insert into their storage containers
    dCV = CorrVector(dCorr.begin(), nNodes, dIdx.memptr(), mNodes);
    R_CheckUserInterrupt(); 
    
    // Sort node indices for sequential memory access
    dRank = SortNodes(dIdx.memptr(), mNodes); 
    
    dWD = WeightedDegree(dNet.begin(), nNodes, dIdx.memptr(), mNodes);
    dWD = dWD(dRank); // reorder
    R_CheckUserInterrupt(); 
    
    dSP = SummaryProfile(dData.begin(), nSamples, nNodes, dIdx.memptr(), mNodes);
    R_CheckUserInterrupt(); 
    
    dNC = NodeContribution(dData.begin(), nSamples, nNodes, 
                           dIdx.memptr(), mNodes, dSP.memptr());
    dNC = dNC(dRank); // reorder results
    R_CheckUserInterrupt(); 
    
    // Cast to R-vectors and add to results lists
    corr.push_back(Rcpp::NumericVector(dCV.begin(), dCV.end()));
    degree.push_back(Rcpp::NumericVector(dWD.begin(), dWD.end()));
    contribution.push_back(Rcpp::NumericVector(dNC.begin(), dNC.end()));
  }
  degree.names() = modsPresent;
  corr.names() = modsPresent;
  contribution.names() = modsPresent;
  
  return Rcpp::List::create(
    Rcpp::Named("degree") = degree,
    Rcpp::Named("corr") = corr,
    Rcpp::Named("contribution") = contribution
  );
}
bool takeRoute(string start, vector<string> & modesList, d_stringmap & UniqueRoutes, int modeIndex, stringmap & result) {
    //cout << "TEST NO takeRoute" << endl ; // TESTDEBUG
     //cout << "At " << start << " travelled " << modeIndex << " modes by " << modesList[modeIndex] << endl;
    // at the final stop we...
    if (modesList[modeIndex] == "stop") 
    {
        if (result.count(start) == 0)
        {
          result.insert({start,0}) ;
        }
        // cout << " found!" << endl ;
        return true ;
    }
    if (allCitiesPossible(UniqueRoutes,result))
    {
      return true ;
    }
    // Part 1
    //cout << "Part 1" << endl ; // testing
    bool notImpossible = false ;
    int modeID = getModeID(modesList[modeIndex]) ;
    //cout << "Part 1.5" << endl ; // testing
    string nextStart ;
    //cout << "Part 2" << endl ; //testing
    //cout << endl << "Possible Routes at " << start << " mode " << modesList[modeIndex] << " are "; // testing
    //cout << UniqueRoutes[start][modeID].size() << endl ; // testing
    //cout << "They are: " << endl ; // testing

    if (UniqueRoutes[start][modeID].size() == 0) 
    {
        //cout << "No route found from " << start << " for " << modesList[modeIndex] << endl;
        return false;
    }
    
    // for testing, printing out all possible routes,
    // for (int i = 0; i < UniqueRoutes[start][modeID].size(); ++i)
    // {
    //   cout << UniqueRoutes[start][modeID][i] << ", " ;
    // }
    // cout << endl << endl ; // testing

    for (int i = 0; i < UniqueRoutes[start][modeID].size(); ++i)
    {
        // cout << "In this loop " << i << endl ;
        nextStart = UniqueRoutes[start][modeID][i];
        //cout << "After nextStart " << nextStart << " with modeIndex " << modeIndex << endl ;
        if (takeRoute(nextStart, modesList, UniqueRoutes, modeIndex+1, result))
        {
            notImpossible = true ;

            //cout << notImpossible << "Setting notImpossible to true at " << start << endl ;
        }
        // cout << "Back from " << nextStart << " route. " << notImpossible << endl ;
    }

    if (notImpossible == true)
    {
        //cout << "Not Impossible, returning true." << endl ;
        return true ;
    }

    // cout << "Failed, returning false at " << start << endl ;
    return false;
}