Example #1
0
 DiffSeq
 mutationDiff()
   {
     return snapshot({after(Ref::ATTRIBS)      // fast forward to the first child
                    , find(CHILD_T)
                    , pick(CHILD_A)
                    , skip(CHILD_T)
                    , del(CHILD_T)
                    , pick(Ref::CHILD)         // pick a child anonymously
                    , mut(Ref::THIS)           // mutate the current element (the one just picked)
                      , ins(ATTRIB3)
                      , ins(ATTRIB_NODE)       // attributes can also be nested objects
                      , find(CHILD_A)
                      , del(CHILD_B)
                      , ins(CHILD_NODE)
                      , ins(CHILD_T)
                      , skip(CHILD_A)
                      , mut(CHILD_NODE)
                        , ins(TYPE_Y)
                        , ins(ATTRIB2)
                      , emu(CHILD_NODE)
                      , mut(ATTRIB_NODE)       // mutation can be out-of order, target found by ID
                        , ins(CHILD_A)
                        , ins(CHILD_A)
                        , ins(CHILD_A)
                      , emu(ATTRIB_NODE)
                    , emu(Ref::THIS)
                    });
   }
Example #2
0
void emulator_wrapper(double ombh2, double ommh2, double ns, double H0, double w,
                      double sigma8, double z, int use_cmbh, double *ystar) {

    int type=2;
    double xstar[7], stuff[4], xstarcmb[6];
    int cmbh=use_cmbh;

    // the cosmo params
    xstar[0] = ombh2;
    xstar[1] = ommh2;
    xstar[2] = ns;
    if (cmbh == 0) xstar[3] = H0;
    xstar[4] = w;
    xstar[5] = sigma8;
    xstar[6] = z;

    if(cmbh == 1) {
        xstarcmb[0] = xstar[0];
        xstarcmb[1] = xstar[1];
        xstarcmb[2] = xstar[2];
        xstarcmb[3] = xstar[4];
        xstarcmb[4] = xstar[5];
        xstarcmb[5] = xstar[6];
        emu_noh(xstarcmb, ystar, &type);
        getH0fromCMB(xstarcmb, stuff);
        xstar[3] = 100.*stuff[3];
    } else {
        emu(xstar, ystar, &type);
    }
}
Example #3
0
void Nes_Mapper::set_prg_bank( nes_addr_t addr, bank_size_t bs, int bank )
{
	require( addr >= 0x2000 ); // can't remap low-memory
	
	int bank_size = 1 << bs;
	require( addr % bank_size == 0 ); // must be aligned
	
	int bank_count = cart_->prg_size() >> bs;
	if ( bank < 0 )
		bank += bank_count;
	
	if ( bank >= bank_count )
	{
		check( !(cart_->prg_size() & (cart_->prg_size() - 1)) ); // ensure PRG size is power of 2
		bank %= bank_count;
	}
	
	emu().map_code( addr, bank_size, cart_->prg() + (bank << bs) );
	
	if ( unsigned (addr - 0x6000) < 0x2000 )
		emu().enable_prg_6000();
}
Example #4
0
int main(int argc, char *argv[])
{
  bool	retval = true;

  // Set path to source directory
  srcdir = getenv("srcdir");
  if(!srcdir) srcdir = ".";

  {
    CEmuopl emu(8000, true, false);
    retval = check_emu_output(&emu);
  }

  return retval ? EXIT_SUCCESS : EXIT_FAILURE;
}
Example #5
0
File: main.c Project: nullsub/mproc
int main ( int argc, char *argv[] ) {
	if ( argc != 2 ) {       
		printf( "usage: %s filename\n", argv[0] );
		return -1;
	}

	FILE *file = fopen( argv[1], "r" );
	if (file == 0) {
		printf( "Could not open file\n" );
		return -1;
	} 
	emu(file);
	fclose(file);
	return 0;
}
Example #6
0
 DiffSeq
 populationDiff()
   {
     return snapshot({ins(TYPE_X)
                    , ins(ATTRIB1)
                    , ins(ATTRIB2)
                    , ins(ATTRIB3)
                    , ins(CHILD_A)
                    , ins(CHILD_T)
                    , ins(CHILD_T)
                    , ins(SUB_NODE)
                    , mut(SUB_NODE)
                      , ins(CHILD_B)
                      , ins(CHILD_A)
                    , emu(SUB_NODE)
                    });
   }
Example #7
0
main(int argc, char **argv) {
    int i,j,type=1, writeout=0;
    double xstar[6], ystar[2*1995], stuff[4];
    FILE *fp;

    char fname[256];

    // xstar contains the 5 emulator parameters plus the red shift.

    // M000 
    /*h_CMB
    if ((fp = fopen("xstar.dat","r"))==NULL) {
        printf("Cannot find inputs.\n");
        exit(1);
    }
    for(j=0; j<5; j++) {
        fscanf(fp, "%lf", &xstar[j]);
    }
    fclose(fp);
    */


    xstar[0] = 1.344000e-01;
    xstar[1] = 2.246000e-02;
    xstar[2] = 9.610000e-01;
    xstar[3] = 8.070000e-01;
    xstar[4] = -1.000;
    xstar[5] = 0.0;

  sprintf(fname,"pdelta_11");

//     printf("Enter filename for output: ");
//     scanf("%s",fname);
//     printf("output will be written to: %s\n",fname);
// 
//     printf("Enter (Omega_m)*h^2: ");
//     scanf("%lf",&xstar[0]);
//     printf("%g\n",xstar[0]);
//     printf("Enter (Omega_b)*h^2: ");
//     scanf("%lf",&xstar[1]);
//     printf("%g\n",xstar[1]);
//     printf("Enter n_s: ");
//     scanf("%lf",&xstar[2]);
//     printf("%g\n",xstar[2]);
//     printf("Enter sigma_8: ");
//     scanf("%lf",&xstar[3]);
//     printf("%g\n",xstar[3]);
//     printf("Enter w: ");
//     scanf("%lf",&xstar[4]);
//     printf("%g\n",xstar[4]);
//     printf("Enter z: ");
//     scanf("%lf",&xstar[5]);
//     printf("%g\n",xstar[5]);
//     
//     printf("Enter output type (0: Delta^2/k^1.5; 1: Delta^2; 2: P(k)): ");
//     scanf("%li",&type);
//     printf("%i\n", type);
//     
type=1;
    getH0fromCMB(xstar, stuff);
    emu(xstar, ystar, &type);

    if ((fp = fopen(fname,"w"))==NULL) {
        printf("cannot open %s \n",fname);
        exit(1);
    }
    
    fprintf(fp, "# Parameters:\n");
    fprintf(fp, "# (Omega_m)*h^2 = %f, (Omega_b)*h^2 = %f, n_s = %f, sigma_8 = %f, w = %f\n", xstar[0], xstar[1], xstar[2], xstar[3], xstar[4]);
    fprintf(fp, "# z = %f\n", xstar[5]);
    fprintf(fp, "#\n");
    fprintf(fp, "# sound horizon: %g Mpc\n", stuff[0]);
    fprintf(fp, "# z_lss: %g\n", stuff[1]);
    fprintf(fp, "# d_lss from CMB: %g Mpc\n", stuff[2]);
    fprintf(fp, "# dimensionless Hubble parameter derived from CMB constraint: %1.3f\n",stuff[3]);
        
    switch(type) {
        default:
            fprintf(fp, "#\n# k[1/Mpc] Delta^2 / k^1.5:\n");
            break;
        case 1:
            fprintf(fp, "#\n# k[1/Mpc] Delta^2:\n");
            break;
        case 2:
            fprintf(fp, "#\n# k[1/Mpc] P(k):\n");
            break;
    }
    for(j=0; j<1995; j++) {
        for(i=0; i<=1; i++) {
            fprintf(fp, "%f ", ystar[i*1995+j]);
        }
        fprintf(fp,"\n");
    }
    fclose(fp);
}
Example #8
0
int Nes_Mapper::handle_bus_conflict( nes_addr_t addr, int data )
{
	if ( emu().Nes_Cpu::get_code( addr ) [0] != data )
		dprintf( "Mapper write had bus conflict\n" );
	return data;
}
Example #9
0
void Nes_Mapper::mirror_manual( int page0, int page1, int page2, int page3 )
{
	emu().ppu.render_bg_until( emu().clock() ); 
	emu().ppu.set_nt_banks( page0, page1, page2, page3 );
}
Example #10
0
void Nes_Mapper::set_chr_bank( nes_addr_t addr, bank_size_t bs, int bank )
{
	emu().ppu.render_until( emu().clock() ); 
	emu().ppu.set_chr_bank( addr, 1 << bs, bank << bs );
}
Example #11
0
bool Nes_Mapper::ppu_enabled() const { return emu().ppu.w2001 & 0x08; }
Example #12
0
int main(int argc, char**argv)
{

  double newparams[nparams]; 
  char inputs[256]; 
  char paramnames[5][20]; 
  double outputredshift; 

  if (argc < 3)
    {
      fprintf(stderr, "Some input files are missing.\n The correct arguments are ./emu.out params.ini output.txt\n"); 
      exit(1); 
    }

  sprintf(paramnames[0], "M_cut"); 
  sprintf(paramnames[1], "M1"); 
  sprintf(paramnames[2], "sigma"); 
  sprintf(paramnames[3], "kappa"); 
  sprintf(paramnames[4], "alpha"); 


  //read .ini file
  sprintf(inputs, "%s", argv[1]); 
  FILE *fpinputs = fopen(inputs,"r");
  if (fpinputs==NULL)
    {
      fprintf(stderr, "I can't find this parameter file: %s.\nExiting now. \n", argv[1]); 
      exit(1);
    }
  float buf; 
  char line[1000];
  int n=0;
  int c; 
  while (fgets(line, sizeof(line), fpinputs) || n < 6) {
    if (*line == '#') continue; // ignore comment line 
    if (sscanf(line, "%f", &buf) != 1) 
      {
	// one parameter per line only! 
	if (strlen(line)!=1) // ignore blank lines
	  {
	    fprintf(stderr, "I don't know how to read your file format.\nPlease modify it to contain one parameter per line only.\nFor comments, please use a '#' symbol at the start of the line.\n"); 
	    exit(1); 
	  }

      }
    else 
      {
	if (n==5)
	  outputredshift = buf; 
	else 
	  newparams[n] = buf; 
	n++; 
      }
  }

  if (n < 6)
    {
      fprintf(stderr, "I didn't read enough input parameters. \nSome lines may be missing from your input file.\n");  
      exit(1);
    }

  fclose(fpinputs);

  // check if parameters are within emulation range: 
  for (n = 0; n < 5; n++)
    {
      if (newparams[n] < min_design[n] || newparams[n] > max_design[n])
  	{
	  /* if (n == 3) */
	  /*   fprintf(stderr, "%s = %lf is outside of the emulation range: %f -- %f. \nPlease adjust your parameters accordingly.\n", paramnames[n], newparams[n], min_design[n], max_design[n]); */
	  /* else */
	    fprintf(stderr, "%s = %lf is outside of the emulation range: %f -- %f. \nPlease adjust your parameters accordingly.\n", paramnames[n], newparams[n], min_design[n], max_design[n]);
  	  fflush;
  	  exit(1);
  	}
      //      fprintf(stderr, "%s = %lf\n", paramnames[n], newparams[n]); 
    }
  if (outputredshift > 1 || outputredshift < 0)
    {
      fprintf(stderr, "%s = %f is outside of the emulation range: %f -- %f. \nPlease adjust your parameters accordingly.\n", paramnames[n], newparams[n], min_design[n], max_design[n]);
      fflush;
      exit(1);
    }
  

  char outputfile[256]; 
  sprintf(outputfile, "%s", argv[2]); 
  FILE *fp = fopen(outputfile,"w");
  if (fp==NULL)
    {
      fprintf(stderr, "I can't open this file for writing: %s.\nExiting now. \n", argv[2]); 
      exit(1);
    }
  else
      fprintf(fp, "# P_gal(k) at z = %.2f for: \n", outputredshift); 

  double *output_pk = malloc(nk*sizeof(double)); // this must be at least of length nk elements
  double h; 

  //write parameters to output file as a record of used parameters
  for (n = 0; n < 5; n++)
    fprintf(fp, "# %s = %f\n", paramnames[n], newparams[n]);

  // Now do the emulation! 
  emu(newparams, outputredshift, output_pk); 

  //  Convert back to P(k) from \Delta = k^1.5*P(k)/(4pi^2)

  double *k_unlogged = malloc(nk*sizeof(double)); 

  for (n = 0; n < nk; n++)
    {
      k_unlogged[n] = pow(10.,logk[n]);
      output_pk[n] = pow(10.,output_pk[n])/pow(k_unlogged[n], 1.5)*4*M_PI*M_PI;	  
      fprintf(fp,"%f %f\n", k_unlogged[n], output_pk[n]);  
    }

  fclose(fp);


  free(k_unlogged); 
  free(output_pk); 
  return(0);
}
Example #13
0
int main(int argc, char* argv[])
{
    // スコープ長いけれど……
    std::string const output_filename = "report_movement";

    if(argc != 2 || argc != 4)\
    if(argc != 2 && argc != 4)
    {
        std::cout << "Usage: " << argv[0] << " 試行回数 [分割数タテ 分割数ヨコ]" << std::endl;
        //std::quick_exit(-1);
        return -1;
    }

    bool const is_fixed  = argc == 4;
    int  const try_num   = std::atoi(argv[1]);
    auto const split_num = is_fixed ? std::make_pair(std::atoi(argv[3]), std::atoi(argv[2])) : std::make_pair(-1, -1);

    std::mt19937 mt;
    std::uniform_int_distribution<int> select_dist(1, 20); // 選択可能回数生成器
    std::uniform_int_distribution<int> size_dist  (2, 16); // サイズ生成器
    std::uniform_int_distribution<int> cost_dist  (1, 50); // コスト生成器

    for(int n=0; n<try_num; ++n)
    {
        int const problem_id = 0; // 仮
        std::string const player_id = "0"; //仮
        std::pair<int,int> const size = is_fixed ? split_num : std::make_pair(size_dist(mt), size_dist(mt));
        int const selectable = select_dist(mt);
        int const cost_select = cost_dist(mt);
        int const cost_change = cost_dist(mt);

        std::vector<std::vector<point_type>> block(
            size.second,
            std::vector<point_type>(size.first, {-1, -1})
            );

        std::uniform_int_distribution<int> x_dist(0, size.first  - 1);
        std::uniform_int_distribution<int> y_dist(0, size.second - 1);
        for(int i=0; i<size.second; ++i)
        {
            for(int j=0; j<size.first; ++j)
            {
                int x, y;
                do
                {
                    x = x_dist(mt);
                    y = y_dist(mt);
                }
                while(!(block[y][x] == point_type{-1, -1}));

                block[y][x] = point_type{j, i};
            }
        }

        // テストデータ発行
        question_data question{
            problem_id,
            player_id,
            size,
            selectable,
            cost_select,
            cost_change,
            block
            };

        // 実行から評価まで
        algorithm algo;
        algo.reset(question);     // テストデータのセット

        // エミュレータ起動
        test_tool::emulator emu(question);

        // 評価保存先ファイルを開き,問題データを書き込む
        std::ofstream ofs(output_filename + std::to_string(n) + ".csv");
        ofs << "[Question]\n";
        for(auto const& line : block)
        {
            for(auto const& elem : line)
            {
                ofs << R"(")" << elem.x << "," << elem.y << R"(", )";
            }
            ofs << "\n";
        }
        ofs << "\n";

        ofs << "[Answer]\n";
        ofs << "回数,間違い位置数,コスト\n";

        int counter = 0;
        while(auto first_result = algo.get())  // 解答が受け取れる間ループ
        {
            // 評価
            auto const evaluate = emu.start(first_result.get());

            // 書出
            ofs << counter+1 << "," <<evaluate.wrong << "," << evaluate.cost << "\n";

            ++counter; // テストなので解答回数をカウントする必要あるかなと
        }
    }

    return 0;
}