Пример #1
0
  Lit heuristic::getSuggestion(){
  DREAL_LOG_INFO << "heuristic::getSuggestion()";
 
  if(!m_is_initialized)
    return lit_Undef;

  if (trail->size() > lastTrailEnd){
    pushTrailOnStack();
    //}

    //if (!m_is_initialized ||  backtracked){
    getSuggestions();
    backtracked = false;
  }
  if (!m_suggestions.empty()){
      std::pair<Enode *, bool> *s = m_suggestions.back();
      m_suggestions.pop_back();
      Enode *e = s->first;


    if ( e == NULL )
      return lit_Undef;



    DREAL_LOG_INFO << "heuristic::getSuggestion() " << e << " = " << s->second;
    if (theory_handler == NULL)
      DREAL_LOG_INFO << "heuristic::getSuggestion() NULL";
    Var v = theory_handler->enodeToVar(e);
    delete s;
    return Lit( v, !s->second );
    } else {
      return lit_Undef;
    }
  }
Пример #2
0
/*
 * Algorithm for automatically choosing songs from lastFM's service based
 * on previously choosen songs.
 */
bool lastFM::pickNewSong(std::vector<struct playlistitem> & list)
{
  //no items to use for suggestions
  if (list.size() == 0) return false;

  //find the last hand-picked item if possible
  size_t last_choice = list.size() - 1;
  for(size_t i=0; i<list.size(); i++)
  {
    if (list[i].reason == 0) last_choice = i;
  }

  int tries = 2;

  //limit the number of attempts to find a new song
  while (tries--)
  {
    //get some new suggestions if needed
    if (sugg_artist != list[last_choice].artist ||
        sugg_track  != list[last_choice].track)
    {
      //a different song has been manually picked

      if (!getSuggestions(list[last_choice].artist, list[last_choice].track))
        return false;

      sugg_artist = list[last_choice].artist;
      sugg_track  = list[last_choice].track;
      currentSuggestion = 0;
    }
    else if (suggestionList.size() <= currentSuggestion)
    {
      //there's no more suggestions for the last picked song

      if (suggestionList.size() == 0)
        return false;

      //get new suggestions from an item on the previous suggestion list
      if (!getSuggestions(suggestionList[0].artist, suggestionList[0].track))
        return false;

      sugg_artist = suggestionList[0].artist;
      sugg_track  = suggestionList[0].track;
      currentSuggestion = 0;
    }

    std::vector<std::string> artists = library->getArtists();

    //go through the suggestion list and check if there's any matches
    for (; currentSuggestion<suggestionList.size(); currentSuggestion++)
    {
      bool alreadyPlayed = false;
      //check if song was already played
      for(size_t i=0; i<list.size(); i++)
      {
        if (list[i].artist == suggestionList[currentSuggestion].artist ||
            list[i].track == suggestionList[currentSuggestion].track)
        {
          alreadyPlayed = true;
          break;
        }
      }
      if (alreadyPlayed) continue;

      //search for a matching song
      for (size_t i=0; i<artists.size(); i++)
      {
        //artist match?
        if (artists[i] == suggestionList[currentSuggestion].artist)
        {
          std::vector<std::string> tracks = library->getTracks(i + 1);
          for (size_t n=0; n<tracks.size(); n++)
          {
            //track match?
            if (tracks[n] == suggestionList[currentSuggestion].track)
            {
              //found a new track, add it to the playlist
              playlistitem newitem;
              newitem.artist = artists[i];
              newitem.track  = tracks[n];
              newitem.filename = library->getTrackFilename(i + 1, n + 1);
              newitem.reason = 3;
              list.push_back(newitem);

              currentSuggestion++;
              return true;
            }
          }
        }
      }
    }
  }

  return false;
}