예제 #1
0
double get_lunar_transit_time( const int year, const int month,
   const int day, const double latitude, const double longitude,
   const int time_zone, const int dst, const int real_transit)
{
   const long jd0 = dmy_to_day( day, month, year, 0);
   const long day_of_year = jd0 - dmy_to_day( 1, 1, year, 0);
   double jd = (double)jd0;
   static char *vsop_data = NULL;
   int dst_hours = (dst ? is_dst( 720, (int)day_of_year, year) : 0);

   if( !vsop_data)
      vsop_data = load_file_into_memory( "vsop.bin", NULL);
   if( !vsop_data)
      return( -2.);
   jd -= (double)time_zone / 24.;      /* convert local to UT */
   jd -= dst_hours / 24.;

   jd = look_for_transit_time( 10, jd,
            latitude * pi / 180., longitude * pi / 180.,
            vsop_data, real_transit);
   jd += (double)time_zone / 24.;      /* convert UT back to local */
   jd += dst_hours / 24.;
   return( jd - (double)jd0 + .5);
}
예제 #2
0
  std::vector<std::pair<int, int>> solve_astar(std::vector<std::vector<int>>& G,
                   int ys, int xs, int yd, int xd) {
    m_G = G;
    m_h = G.size();
    m_w = G[0].size();
    m_ys = ys;
    m_xs = xs;
    m_yd = yd;
    m_xd = xd;

    // open set, close set
    std::set<std::pair<double, std::pair<int, int>>> st_open;
    std::set<std::pair<int, int>> st_close;

    // cell
    m_C.resize(m_h, std::vector<cell>(m_w));
    for (int y = 0; y < m_h; ++y) {
      for (int x = 0; x < m_w; ++x) {
        cell& C = m_C[y][x];
        if (y == ys && x == xs) {
          C.m_f = 0.0;
          C.m_g = 0.0;
          C.m_h = 0.0;
          C.m_p_y = y;
          C.m_p_x = x;
          st_open.insert({C.m_f, {y, x}});
        } else {
          C.m_f = std::numeric_limits<double>::max();
          C.m_g = std::numeric_limits<double>::max();
          C.m_h = std::numeric_limits<double>::max();
          C.m_p_y = -1;
          C.m_p_x = -1;
        }
      }
    }

    int dy[8] = {-1, 1, 0, 1, 1,  1,  0, -1};
    int dx[8] = { 0, 1, 1, 1, 0, -1, -1, -1};
    
    while (!st_open.empty()) {
      // get node which has small f
      auto it = st_open.begin();
      int y = (*it).second.first;
      int x = (*it).second.second;
      st_open.erase(it);
      st_close.insert({y, x});

      if (is_dst(y, x)) {
        // printf("st_open.count: %d, st_close.count: %d\n",
        //        st_open.size(), st_close.size());
        return get_path();
      }
      
      for (int d = 0; d < 8; ++d) {
        // get node to visit
        int yn = y + dy[d];
        int xn = x + dx[d];

        // printf("  %d, %d\n", yn, xn);
        
        if (!is_valid(yn, xn) ||
            st_close.count({yn, xn}) > 0 ||
            !is_placeable(yn, xn))
          continue;
        
        cell& C = m_C[yn][xn];
        double gn = C.m_g + 1.0;
        double hn = get_h(yn, xn);
        double fn = gn + hn;
        if (C.m_f == std::numeric_limits<double>::max() ||
            C.m_f > fn) {
          st_open.insert({fn, {yn, xn}});
          C.m_f = fn;
          C.m_g = gn;
          C.m_h = hn;
          C.m_p_y = y;
          C.m_p_x = x;
          // printf("(%d, %d) -> (%d, %d)\n", y, x, yn, xn);          
        }
      }
    }

    return {};
  }