Exemplo n.º 1
0
void texpedite::merit(twindow& window)
{
	std::vector<unit*>& reside_troops = city_.reside_troops();
	unit& temp = *reside_troops[troop_index_];

	tunit_merit merit(gui_, temp);
	merit.show(gui_.video());
}
Exemplo n.º 2
0
double
merit_u (unsigned int t, mpf_t v, mpz_t m)
{
  mpf_t rop;
  double res;

  mpf_init (rop);
  merit (rop, t, v, m);
  res = mpf_get_d (rop);
  mpf_clear (rop);
  return res;
}
Exemplo n.º 3
0
void ttroop_detail::merit(twindow& window)
{
	const unit& temp = *(partial_troops_[troop_index_]);
	tunit_merit merit(gui_, temp);
	merit.show(gui_.video());
}
Exemplo n.º 4
0
int
main (int argc, char *argv[])
{
  const char usage[] = "usage: findlc [-dv] m2exp [low_merit [high_merit]]\n";
  int f;
  int v_lose, m_lose, v_best, m_best;
  int c;
  int debug = 1;
  int cnt_high_merit;
  mpz_t m;
  unsigned long int m2exp;
#define DIMS 6			/* dimensions run in spectral test */
  mpf_t v[DIMS-1];		/* spectral test result (there's no v
                                   for 1st dimension */
  mpf_t f_merit, low_merit, high_merit;
  mpz_t acc, minus8;
  mpz_t min, max;
  mpz_t s;


  mpz_init (m);
  mpz_init (a);
  for (f = 0; f < DIMS-1; f++)
    mpf_init (v[f]);
  mpf_init (f_merit);
  mpf_init_set_d (low_merit, .1);
  mpf_init_set_d (high_merit, .1);

  while ((c = getopt (argc, argv, "a:di:hv")) != -1)
    switch (c)
      {
      case 'd':			/* debug */
	g_debug++;
	break;

      case 'v':			/* print version */
	puts (rcsid[1]);
	exit (0);

      case 'h':
      case '?':
      default:
	fputs (usage, stderr);
	exit (1);
      }

  argc -= optind;
  argv += optind;

  if (argc < 1)
    {
      fputs (usage, stderr);
      exit (1);
    }

  /* Install signal handler. */
  if (SIG_ERR == signal (SIGSEGV, sh_status))
    {
      perror ("signal (SIGSEGV)");
      exit (1);
    }
  if (SIG_ERR == signal (SIGHUP, sh_status))
    {
      perror ("signal (SIGHUP)");
      exit (1);
    }

  printf ("findlc: version: %s\n", rcsid[1]);
  m2exp = atol (argv[0]);
  mpz_init_set_ui (m, 1);
  mpz_mul_2exp (m, m, m2exp);
  printf ("m = 0x");
  mpz_out_str (stdout, 16, m);
  puts ("");

  if (argc > 1)			/* have low_merit */
    mpf_set_str (low_merit, argv[1], 0);
  if (argc > 2)			/* have high_merit */
    mpf_set_str (high_merit, argv[2], 0);

  if (debug)
    {
      fprintf (stderr, "low_merit = ");
      mpf_out_str (stderr, 10, 2, low_merit);
      fprintf (stderr, "; high_merit = ");
      mpf_out_str (stderr, 10, 2, high_merit);
      fputs ("\n", stderr);
    }

  mpz_init (minus8);
  mpz_set_si (minus8, -8L);
  mpz_init_set_ui (acc, 0);
  mpz_init (s);
  mpz_init_set_d (min, 0.01 * pow (2.0, (double) m2exp));
  mpz_init_set_d (max, 0.99 * pow (2.0, (double) m2exp));

  mpz_true_random (s, m2exp);	/* Start.  */
  mpz_setbit (s, 0);		/* Make it odd.  */

  v_best = m_best = 2*(DIMS-1);
  for (;;) 
    {
      mpz_add (acc, acc, s);
      mpz_mod_2exp (acc, acc, m2exp);
#if later
      mpz_and_si (a, acc, -8L);
#else
      mpz_and (a, acc, minus8);
#endif
      mpz_add_ui (a, a, 5);
      if (mpz_cmp (a, min) <= 0 || mpz_cmp (a, max) >= 0)
	continue;

      spectral_test (v, DIMS, a, m);
      for (f = 0, v_lose = m_lose = 0, cnt_high_merit = DIMS-1;
	   f < DIMS-1; f++)
	{
	  merit (f_merit, f + 2, v[f], m);

	  if (mpf_cmp_ui (v[f], 1 << (30 / (f + 2) + (f == 2))) < 0)
	    v_lose++;
	    
	  if (mpf_cmp (f_merit, low_merit) < 0)
	    m_lose++;

	  if (mpf_cmp (f_merit, high_merit) >= 0)
	    cnt_high_merit--;
	}

      if (0 == v_lose && 0 == m_lose)
	{
	  mpz_out_str (stdout, 10, a); puts (""); fflush (stdout);
	  if (0 == cnt_high_merit)
	    break;		/* leave loop */
	}
      if (v_lose < v_best)
	{
	  v_best = v_lose;
	  printf ("best (v_lose=%d; m_lose=%d): ", v_lose, m_lose);
	  mpz_out_str (stdout, 10, a); puts (""); fflush (stdout);
	}
      if (m_lose < m_best)
	{
	  m_best = m_lose;
	  printf ("best (v_lose=%d; m_lose=%d): ", v_lose, m_lose);
	  mpz_out_str (stdout, 10, a); puts (""); fflush (stdout);
	}
    }

  mpz_clear (m);
  mpz_clear (a);
  for (f = 0; f < DIMS-1; f++)
    mpf_clear (v[f]);
  mpf_clear (f_merit);
  mpf_clear (low_merit);
  mpf_clear (high_merit);

  printf ("done.\n");
  return 0;
}
Exemplo n.º 5
0
int
main (int argc, char *argv[])
{
  const char usage[] = "usage: spect [-d] a m n\n";
  int c;
  unsigned int n;
  mpz_t a, m;
  mpf_t res[GMP_SPECT_MAXT], res_min[GMP_SPECT_MAXT], f_tmp;
  register int f;


  mpz_init (a);
  mpz_init (m);
  for (f = 0; f < GMP_SPECT_MAXT; f++)
    {
      mpf_init (res[f]);
      mpf_init (res_min[f]);
    }
  mpf_init (f_tmp);
  mpf_set_ui (res_min[0], 32768); /* 2^15 */
  mpf_set_ui (res_min[1], 1024); /* 2^10 */
  mpf_set_ui (res_min[2], 256); /* 2^8 */
  mpf_set_ui (res_min[3], 64); /* 2^6 */
  mpf_set_ui (res_min[4], 32); /* 2^5 */

  while ((c = getopt (argc, argv, "dh")) != -1)
    switch (c)
      {
      case 'd':			/* debug */
	g_debug++;
	break;
      case 'h':
      default:
	fputs (usage, stderr);
	exit (1);
      }
  argc -= optind;
  argv += optind;

  if (argc < 3)
    {
      fputs (usage, stderr);
      exit (1);
    }

  mpz_set_str (a, argv[0], 0);
  mpz_set_str (m, argv[1], 0);
  n = (unsigned int) atoi (argv[2]);
  if (n + 1 > GMP_SPECT_MAXT)
    n = GMP_SPECT_MAXT + 1;

  spectral_test (res, n, a, m);

  for (f = 0; f < n - 1; f++)
    {
      /* print v */
      printf ("%d: v = ", f + 2);
      mpf_out_str (stdout, 10, 4, res[f]);

#ifdef PRINT_RAISED_BY_TWO_AS_WELL
      printf (" (^2 = ");
      mpf_mul (f_tmp, res[f], res[f]);
      mpf_out_str (stdout, 10, 4, f_tmp);
      printf (")");
#endif /* PRINT_RAISED_BY_TWO_AS_WELL */

      /* print merit */
      printf (" m = ");
      merit (f_tmp, f + 2, res[f], m);
      mpf_out_str (stdout, 10, 4, f_tmp);

      if (mpf_cmp (res[f], res_min[f]) < 0)
	printf ("\t*** v too low ***");
      if (mpf_get_d (f_tmp) < .1)
	printf ("\t*** merit too low ***");

      puts ("");
    }

  mpz_clear (a);
  mpz_clear (m);
  for (f = 0; f < GMP_SPECT_MAXT; f++)
    {
      mpf_clear (res[f]);
      mpf_clear (res_min[f]);
    }
  mpf_clear (f_tmp);

  return 0;
}