// 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]) ;

}
示例#2
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);
  }
}
示例#3
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);
  }
}
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;
}