Exemple #1
0
static bool rhh_compare_alignments(read_hit_heap_e * a, read_hit_heap_e * b) {
	assert(a->rh[0]!=NULL);
	assert(b->rh[0]!=NULL);
	int result = compare_read_hit(a->rh[0],b->rh[0]);
	if (result==1) { 
		return true;
	} else if (result==-1) {
		return false;
	} else if (a->rh[1]!=NULL && b->rh[1]!=NULL) {
		result = compare_read_hit(a->rh[1],b->rh[1]);
		if (result==1) {
			return true;
		} else if (result==-1) {
			return false;
		} else {
			return compare_scores(a,b)==1 ? true : false;
		}
	}
	return false;
}
Exemple #2
0
static bool rhh_compare_scores(read_hit_heap_e * a, read_hit_heap_e * b) {
	return compare_scores(a,b)==1 ? true  : false;
}
static bool
test_replay(const Contest olc_type,
            const ContestResult &official_score)
{
  Directory::Create(_T("output/results"));
  std::ofstream f("output/results/res-sample.txt");

  GlidePolar glide_polar(fixed(2));

  Error error;
  FileLineReaderA *reader = new FileLineReaderA(replay_file.c_str(), error);
  if (reader->error()) {
    delete reader;
    fprintf(stderr, "%s\n", error.GetMessage());
    return false;
  }

  ReplayLoggerSim sim(reader);

  ComputerSettings settings_computer;
  settings_computer.SetDefaults();
  settings_computer.contest.enable = true;
  load_scores(settings_computer.contest.handicap);

  if (verbose) {
    switch (olc_type) {
    case Contest::OLC_LEAGUE:
      std::cout << "# OLC-League\n";
      break;
    case Contest::OLC_SPRINT:
      std::cout << "# OLC-Sprint\n";
      break;
    case Contest::OLC_FAI:
      std::cout << "# OLC-FAI\n";
      break;
    case Contest::OLC_CLASSIC:
      std::cout << "# OLC-Classic\n";
      break;
    case Contest::OLC_PLUS:
      std::cout << "# OLC-Plus\n";
      break;
    default:
      std::cout << "# Unknown!\n";
      break;
    }
  }

  bool do_print = verbose;
  unsigned print_counter=0;

  MoreData basic;
  basic.Reset();

  FlyingComputer flying_computer;
  flying_computer.Reset();

  FlyingState flying_state;
  flying_state.Reset();

  TraceComputer trace_computer;

  ContestManager contest_manager(olc_type,
                                 trace_computer.GetFull(),
                                 trace_computer.GetFull(),
                                 trace_computer.GetSprint());
  contest_manager.SetHandicap(settings_computer.contest.handicap);

  DerivedInfo calculated;

  while (sim.Update(basic)) {
    n_samples++;

    flying_computer.Compute(glide_polar.GetVTakeoff(),
			    basic, calculated,
			    flying_state);

    calculated.flight.flying = true;
    
    trace_computer.Update(settings_computer, basic, calculated);
    
    contest_manager.UpdateIdle();
  
    if (verbose>1) {
      sim.print(f, basic);
      f.flush();
    }
    if (do_print) {
      PrintHelper::trace_print(trace_computer.GetFull(), basic.location);
    }
    do_print = (++print_counter % output_skip ==0) && verbose;
  };

  contest_manager.SolveExhaustive();

  if (verbose) {
    PrintDistanceCounts();
  }
  return compare_scores(official_score, 
                        contest_manager.GetStats().GetResult(0));
}
Exemple #4
0
static bool
test_replay(const Contests olc_type, 
            const ContestResult &official_score)
{
  std::ofstream f("results/res-sample.txt");

  GlidePolar glide_polar(fixed_two);
  Waypoints waypoints;
  AIRCRAFT_STATE state_last;

  TaskBehaviour task_behaviour;

  TaskEventsPrint default_events(verbose);
  TaskManager task_manager(default_events,
                           waypoints);

  task_manager.set_glide_polar(glide_polar);

  task_manager.set_contest(olc_type);
  task_manager.get_task_behaviour().enable_olc = true;

  ReplayLoggerSim sim;
  TCHAR szFilename[MAX_PATH];
  ConvertCToT(szFilename, replay_file.c_str());
  sim.SetFilename(szFilename);

  load_scores(task_manager.get_task_behaviour().contest_handicap);

  if (verbose) {
    switch (olc_type) {
    case OLC_League:
      std::cout << "# OLC-League\n";
      break;
    case OLC_Sprint:
      std::cout << "# OLC-Sprint\n";
      break;
    case OLC_FAI:
      std::cout << "# OLC-FAI\n";
      break;
    case OLC_Classic:
      std::cout << "# OLC-Classic\n";
      break;
    case OLC_Plus:
      std::cout << "# OLC-Plus\n";
      break;
    default:
      std::cout << "# Unknown!\n";
      break;
    }
  }

  sim.Start();

  bool do_print = verbose;
  unsigned print_counter=0;

  while (sim.Update() && !sim.started) {
  }
  state_last = sim.state;

  fixed time_last = sim.state.Time;

  while (sim.Update()) {
    if (sim.state.Time>time_last) {

      n_samples++;

      if (sim.state.Speed> glide_polar.get_Vtakeoff()) {
        sim.state.flying_state_moving(sim.state.Time);
      } else {
        sim.state.flying_state_stationary(sim.state.Time);
      }

      task_manager.update(sim.state, state_last);
      task_manager.update_idle(sim.state);
  
      state_last = sim.state;

      if (verbose>1) {
        sim.print(f);
        f.flush();
      }
      if (do_print) {
        PrintHelper::taskmanager_print(task_manager, sim.state);
      }
      do_print = (++print_counter % output_skip ==0) && verbose;
    }
    time_last = sim.state.Time;
  };
  sim.Stop();

  task_manager.score_exhaustive();

  if (verbose) {
    distance_counts();
  }
  return compare_scores(official_score, 
                        task_manager.get_contest_stats().get_contest_result(0));
}
Exemple #5
0
static bool
test_replay(const Contests olc_type, 
            const ContestResult &official_score)
{
  std::ofstream f("results/res-sample.txt");

  GlidePolar glide_polar(fixed_two);
  AircraftState state_last;

  FileLineReaderA *reader = new FileLineReaderA(replay_file.c_str());
  if (reader->error()) {
    delete reader;
    return false;
  }

  ReplayLoggerSim sim(reader);

  ComputerSettings settings_computer;
  settings_computer.SetDefaults();
  settings_computer.task.enable_olc = true;
  load_scores(settings_computer.task.contest_handicap);

  if (verbose) {
    switch (olc_type) {
    case OLC_League:
      std::cout << "# OLC-League\n";
      break;
    case OLC_Sprint:
      std::cout << "# OLC-Sprint\n";
      break;
    case OLC_FAI:
      std::cout << "# OLC-FAI\n";
      break;
    case OLC_Classic:
      std::cout << "# OLC-Classic\n";
      break;
    case OLC_Plus:
      std::cout << "# OLC-Plus\n";
      break;
    default:
      std::cout << "# Unknown!\n";
      break;
    }
  }

  bool do_print = verbose;
  unsigned print_counter=0;

  MoreData basic;
  basic.Reset();

  while (sim.Update(basic, fixed_one) && !sim.started) {
  }
  state_last = sim.state;

  fixed time_last = sim.state.time;

  FlyingComputer flying_computer;
  flying_computer.Reset();

  FlyingState flying_state;
  flying_state.Reset();

  TraceComputer trace_computer;

  ContestManager contest_manager(olc_type,
                                 trace_computer.GetFull(),
                                 trace_computer.GetSprint());
  contest_manager.SetHandicap(settings_computer.task.contest_handicap);

  DerivedInfo calculated;

  while (sim.Update(basic, fixed_one)) {
    if (sim.state.time>time_last) {

      n_samples++;

      flying_computer.Compute(glide_polar.GetVTakeoff(),
                              sim.state, flying_state);

      calculated.flight.flying = flying_state.flying;

      trace_computer.Update(settings_computer, basic, calculated);

      contest_manager.UpdateIdle();
  
      state_last = sim.state;

      if (verbose>1) {
        sim.print(f);
        f.flush();
      }
      if (do_print) {
        PrintHelper::trace_print(trace_computer.GetFull(), sim.state.location);
      }
      do_print = (++print_counter % output_skip ==0) && verbose;
    }
    time_last = sim.state.time;
  };

  contest_manager.SolveExhaustive();

  if (verbose) {
    PrintDistanceCounts();
  }
  return compare_scores(official_score, 
                        contest_manager.GetStats().GetResult(0));
}