Exemple #1
0
mat propagate_photons(Generator &gen, size_t N, double r1, double z0, double theta_0){
	vec x = zeros<vec>(N);
	vec y = zeros<vec>(N);
	double cos_theta_0 = std::cos(theta_0);
	for(size_t i=0; i<N; i++){
		double xs = 2.0*gen.uniform()-1.0;
		double ys = 2.0*gen.uniform()-1.0;
		//double xs = gen.gaussian();
		//double ys = gen.gaussian();
		while((xs*xs+ys*ys) > 1.0){
			xs = 2.0*gen.uniform()-1.0;
			ys = 2.0*gen.uniform()-1.0;
			//xs = gen.gaussian();
			//ys = gen.gaussian();
		}
		xs = r1*xs;
		ys = r1*ys;
		double psi = 2.0*M_PI*gen.uniform();
//		double theta = gen.uniform()*theta_0;
//		double theta = std::acos(2.0*gen.uniform() - 1.0);
		double theta = std::acos((1.0-cos_theta_0)*gen.uniform() + cos_theta_0);
		double cos_phi = std::cos(psi);
		double sin_phi = std::sin(psi);
		double tan_theta = std::tan(theta);
		x(i) = xs + z0*cos_phi*tan_theta;
		y(i) = ys + z0*sin_phi*tan_theta;
	}
	mat positions = zeros<mat>(N,2);
	positions.col(0) = x;
	positions.col(1) = y;
	return positions;
}	
Exemple #2
0
int
Test_Objref_Struct::init_parameters (Param_Test_ptr objref)
{
  try
    {
      Generator *gen = GENERATOR::instance (); // value generator

      // Set the long member.
      this->in_.x = gen->gen_long ();

      this->in_.y = objref->make_coffee ();

      Coffee::Desc d;
      d.name = gen->gen_string ();

      this->in_.y->description (d);

            this->inout_->x = 0;

            this->inout_->y = Coffee::_nil ();

      Coffee::Desc dd;
            dd.name = CORBA::string_dup ("");

      return 0;
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Test_Objref_Struct::init_parameters\n");

    }
  return -1;
}
// supporting function implementation ***************************************
void genFiles(){

  // make directory
  const int dir_err = system("mkdir sample_data");
  if (dir_err == -1){
      printf("Error creating directory!n");
      exit(1);
  }

  Generator generator;

  // default filenames
  std::string filename1 = "sample_data/output1";
  std::string filename2 = "sample_data/output2";
  std::string filename3 = "sample_data/output3";

  // remove file if exists
  std::remove(filename1.c_str());
  std::remove(filename2.c_str());
  std::remove(filename3.c_str());

  // Prob1: generate samples for class1 and class 2
  generator.generateSample(1.0, sqrt(2.0), 10000, filename1);
  generator.generateSample(6.0, sqrt(2.0), 10000, filename2);

  // Prob2: generate samples for class 2
  generator.generateSample(6.0, 6.0, sqrt(4.0), sqrt(8.0), 10000, filename3);
}
Exemple #4
0
int
Test_Small_Union::reset_parameters (void)
{
  Generator *gen = GENERATOR::instance (); // value generator
  CORBA::ULong index = (counter++ % 2);

  switch (index)
    {
    case 0:
      {
        CORBA::Long l = gen->gen_long ();
        this->in_.the_long (l);
        this->inout_.the_long (l);
      }
      break;
    default:
    case 1:
      {
        CORBA::Short s = gen->gen_short ();
        this->in_.the_short (s);
        this->inout_.the_short (s);
      }
      break;
    }
  this->out_ = new Param_Test::Small_Union (this->in_);
  this->ret_ = new Param_Test::Small_Union (this->in_);
  return 0;
}
Exemple #5
0
int
Test_Bounded_Array_Sequence::init_parameters (Param_Test_ptr)
{
  Generator *gen = GENERATOR::instance (); // value generator

  // set the length of the sequence
  this->in_.length (MAX_ARRAYSEQ_LEN);
  // different from in_.
  this->inout_->length (1);

  // now set each individual element
  Param_Test::Fixed_Array tmp;

  for (CORBA::ULong j = 0; j < Param_Test::DIM1; j++)
    {
      tmp[j] = gen->gen_long ();
    }

  Param_Test::Fixed_Array_copy (this->inout_[0], tmp);

  for (CORBA::ULong i = 0; i < this->in_.length (); i++)
    {
      // Generate some arbitrary array to be filled into the ith
      // location in the sequence.
      for (CORBA::ULong j = 0; j < Param_Test::DIM1; j++)
        {
          tmp[j] = gen->gen_long ();
        }

      Param_Test::Fixed_Array_copy (this->in_[i], tmp);
    }

  return 0;
}
Exemple #6
0
double coupling_efficiency(Generator &gen, size_t seed, size_t N, double r1, double z0, double theta_0, double r2, double theta_a, double offset){
	double r2_square = r2*r2;
	double cos_theta_0 = std::cos(theta_0);
	size_t count = 0;
	for(size_t i=0; i<N; i++){
		double xs = 2.0*gen.uniform()-1.0;
		double ys = 2.0*gen.uniform()-1.0;
		while((xs*xs+ys*ys) > 1.0){
			xs = 2.0*gen.uniform()-1.0;
			ys = 2.0*gen.uniform()-1.0;
		}
		xs = r1*xs;
		ys = r1*ys;
		double psi = 2.0*M_PI*gen.uniform();
//		double theta = gen.uniform()*theta_0;
//		double theta = std::acos(2.0*gen.uniform() - 1.0);
		double theta = std::acos((1.0-cos_theta_0)*gen.uniform() + cos_theta_0);
		double cos_phi = std::cos(psi);
		double sin_phi = std::sin(psi);
		double tan_theta = std::tan(theta);
		double x = xs + z0*cos_phi*tan_theta;
		double y = ys + z0*sin_phi*tan_theta;
		if((x*x+(y-offset)*(y-offset))<r2_square){
			if(theta <= theta_a){
				count++;
			}
		}
	}
	double c = ((double) count)/((double) N);
	return c;
}
Exemple #7
0
int mxAppMain()
{
	//FileLogUtil		fileLog;

	Options	config;

	{
		config.srcFiles.Add(OSPathName(INPUT_FILE_0));
		config.srcFiles.Add(OSPathName(INPUT_FILE_1));
	}

	config.outputFolderHLSL = OUTPUT_FOLDER;
	config.outputFolderCPP = OUTPUT_FOLDER;

	config.bDebugMode = true;


	Generator* p = Generator::Create( config );

	p->GenerateShaderLib();

	Generator::Destroy( p );

	return 0;
}
int main(int argc, char** argv)
{

	srand(time(NULL));

	int util,tasksNumber;
	char* outFile;

	//
	//Parsing the arguments
	//
	for(int i=1;i<argc-1;i+=2) {
		if((string)argv[i] == "-u") {
			util = atoi(((string)argv[i+1]).c_str());
		}
		else if((string)argv[i] == "-n") {
			tasksNumber = atoi(((string)argv[i+1]).c_str());
		}
		else if((string)argv[i] == "-o") {
			outFile = argv[i+1];
		}
		else {
			cout << "Problem with the arguments" << endl;
			exit(0);
		}
	}
	int tasks[tasksNumber][4];
	Generator* gen = new Generator(util,tasksNumber);
	gen->generateTasks(tasks);
	gen->tasksToFile(outFile,tasks);
	return 0;
}
Exemple #9
0
int
Test_Nested_Struct::init_parameters (Param_Test_ptr)
{
  Generator *gen = GENERATOR::instance (); // value generator

  // get some sequence length (not more than 10)
  CORBA::ULong len = (CORBA::ULong) (gen->gen_long () % 10) + 1;

  this->in_.vs.dbl = 0.0;
  this->in_.vs.dummy1 = CORBA::string_dup ("");
  this->in_.vs.boole = 0;
  this->in_.vs.dummy2 = CORBA::string_dup ("");
  this->in_.vs.shrt = 0;
  // set the length of the sequence
  this->in_.vs.seq.length (len);
  // now set each individual element
  for (CORBA::ULong i = 0; i < len; ++i)
    {
      // generate some arbitrary string to be filled into the ith location in
      // the sequence
      char *str = gen->gen_string ();
      this->in_.vs.seq[i] = str;
    }

  this->inout_->vs.dbl = 0.0;
  this->inout_->vs.dummy1 = CORBA::string_dup ("");
  this->inout_->vs.boole = 0;
  this->inout_->vs.dummy2 = CORBA::string_dup ("");
  this->inout_->vs.shrt = 0;
  // set the length of the sequence
  this->inout_->vs.seq.length (0);

  return 0;
}
Exemple #10
0
void GuiManager::SetDefaults()
{
	m_LayerManager.RemoveAllLayers();
	std::string path = UserPromptUtil::GetExecutablePath();
	path.append(DEFAULT_FILENAME);
	if(FileExists(path.c_str()))
	{
		//try to get XML - if success, get outa here
		if(LoadFromXmlWithErrors(path) == XML_SUCCESS)
			return;
	}

	//we failed.
	m_LayerManager.RemoveAllLayers();
	Generator* newlayer = RenderableFactory::CreateGenerator(4);
	SubGenerator* noise1 = RenderableFactory::CreateLayer2d(0);
	SubGenerator* noise2 = RenderableFactory::CreateLayer2d(0);

	noise1->Scale(0.01f, 0.01f);
	noise2->Scale(-5, -5);

	newlayer->AssignLayerToVariable(0, noise1);
	newlayer->AssignLayerToVariable(1, noise2);

	m_World.SetWindowSize(14);

	m_World.ResetCameras();
	m_World.SetVisualMode(VISUAL_TOPDOWN);

	AddLayer(newlayer);
}
Exemple #11
0
int
Test_Recursive_Struct::reset_parameters (void)
{
  // Since these are _vars, we do this the first call and
  // every call thereafter (if any).
  this->inout_ = new Param_Test::Recursive_Struct;
  this->out_ = new Param_Test::Recursive_Struct;
  this->ret_ = new Param_Test::Recursive_Struct;

   // value generator
  Generator *gen = GENERATOR::instance ();

  // Set the depth of recursion.
  CORBA::ULong depth = (CORBA::ULong) (gen->gen_long () % MAX_DEPTH) + 1;

  // No recursion for inout_ until after the call.
  this->inout_->children.length (0);

  // Keeps Purify happy.
  this->inout_->x = 0;

  // Call the recursive helper function.
  this->deep_init (this->in_,
                   gen,
                   depth);

  return 0;
}
void AbelianEquationsSolver::makeSystem()
{
  for( int i = 0 ; i < rawSystem.length() ; i++ )
    {
      for( int j = 0 ; j < rawSystem[i].length() ; j++ )
	{
	  Generator g = rawSystem[i][j];
	  
	  if( abs( g.hash() ) > numberOfVariables )
	    {
	      Generator newg;
	      if( g.hash() > 0 )
		newg = Generator( g.hash() - numberOfVariables );
	      else
		newg = Generator( g.hash() + numberOfVariables );
	      
	      b[i] *= inv(newg);
	    }
	  else
	    system[i] *= g;
	}
      
      system[i] = system[i].freelyReduce();
      b[i] = b[i].freelyReduce();
    }
}
Exemple #13
0
void interfejs(Generator &generator, int nPrzestojow)
{
	cout << "\n======== GENERATOR ========\n\n";
	int liczba_zadan = generator.liczbaZadan;
	int x,y,z;

	//generujemy zadania
	y=1;
	z=50;
	int gotowosc=0;
	for(int i = 0; i < generator.liczbaZadan; ++i){				//generowanie zadañ
		generator.generujZadanie(y,z,gotowosc,i);
		//generator.generujZadanie(5,5,2,i);			//TESTOWE
		gotowosc+=10;
	}

	//generujemy przestoje dla 3 maszyn
	x=nPrzestojow;
	int czasPrzestojow=100;

	generator.generujMaszyne(x,x,czasPrzestojow);
	//generator.generujMaszyne(2,2,2);			//TESTOWE
	
	//wyswietlZadania(generator);
	cout <<"\n===========================\n\n";
	cout <<"DLUGOSC INSTANCJI: " << generator.dlugoscInstancji <<endl<<endl;
	//wyswietlMaszyny(generator);

	cout <<"\n===========================\n\n";
}
Exemple #14
0
TEST(Generator, addCommand)
{
	std::vector<const char*> cmd1;
	cmd1.push_back("this");
	cmd1.push_back("is");
	cmd1.push_back("a");
	cmd1.push_back("test");

	std::vector<const char*> cmd2;
	cmd2.push_back("this");
	cmd2.push_back("is");
	cmd2.push_back("a");
	cmd2.push_back("second");
	cmd2.push_back("test");

	Generator g;
	g.addCommand(cmd1);

	EXPECT_EQ(1, g.cmds.size());
	EXPECT_EQ(4, g.cmds[0].size());

	g.addCommand(cmd2);
	EXPECT_EQ(2, g.cmds.size());
	EXPECT_EQ(4, g.cmds[0].size());
	EXPECT_EQ(5, g.cmds[1].size());

	g.addCommand(cmd1);
	EXPECT_EQ(3, g.cmds.size());
	EXPECT_EQ(4, g.cmds[0].size());
	EXPECT_EQ(5, g.cmds[1].size());
	EXPECT_EQ(4, g.cmds[2].size());
}
int main(int argc, char *argv[])
{
  /* avoid compile warnings */
  argc = argc;
  argv = argv;
  
  Generator *gen = new Generator(std::string("example-tcpLargeTransfer"));
  
  /* Add the Pc equipement. */
  gen->AddNode("Pc");
  gen->AddNode("Pc"); 

  /* Add the NetworkHardware (csma) */
  gen->AddNetworkHardware("Hub"); 
  /* Add equipement to te link */
  gen->GetNetworkHardware(0)->Install(gen->GetNode(0)->GetNodeName());
  gen->GetNetworkHardware(0)->Install(gen->GetNode(1)->GetNodeName());
  
  /* Enable trace... */
  gen->GetNetworkHardware(0)->SetTrace(true);

  /* Add Tcp large transfer application from pc to pc on PORT 6666 */
  gen->AddApplication("TcpLargeTransfer", gen->GetNode(0)->GetNodeName(), gen->GetNode(1)->GetNodeName(), 0, 5, 6666);// 0 start time - 5 end time
                                                                                                                             
  gen->GenerateCodeCpp();
  
  delete gen;
}
Exemple #16
0
String HHVM_METHOD(Generator, getOrigFuncName) {
  Generator* gen = Native::data<Generator>(this_);
  const Func* origFunc = gen->actRec()->func();
  auto const origName = origFunc->isClosureBody() ? s__closure_.get()
                                                  : origFunc->name();
  assert(origName->isStatic());
  return String(const_cast<StringData*>(origName));
}
Exemple #17
0
void BasicDelay_::setInput(Generator input) {
    Effect_::setInput(input);
    setIsStereoInput(input.isStereoOutput());
    setIsStereoOutput(input.isStereoOutput());

    // can safely resize as TonicFrames subclass - calling functions account for channel offset
    delayLine_.resize(delayLine_.frames(), input.isStereoOutput() ? 2 : 1, 0);
}
Exemple #18
0
        void visit(FilterNotMatchingFilter* filter) override
        {
            Generator generator;
            const QString internal_condition = generator.parse( {filter->filter} );

            //http://stackoverflow.com/questions/367863/sql-find-records-from-one-table-which-dont-exist-in-another
            m_filterResult.conditions.append( QString("photos.id NOT IN (%1)").arg(internal_condition) );
        }
/*!\func
 *
 * \param no
 * \return no
 */
void EnterInputs::on_actionGeneration_triggered()
{
    LOG(LOG_DEBUG, QString(__FUNCTION__) + " <" + QString::number(__LINE__) + ">");
    static Generator generator(graphBody->getParentNode(), ms_wizard_path);
    generator.setModal(true);
    generator.show();
    generator.checkValidate();
}
Exemple #20
0
void ModelBuilder :: BuildGenerator( Model * model,
										const ALib::XMLElement * e ) {
	Generator * g = TagDictionary::Instance()->CreateGen( e );

	if ( (! ALib::IsEmpty( g->Name() )) &&  model->FindGen( g->Name() )) {
		throw XMLError( "duplicate name " + ALib::SQuote( g->Name() ), e );
	}
	model->AddGen( g );
}
Exemple #21
0
Generator * Model :: FindGen( const std::string & name ) const {
	for ( unsigned int i = 0; i < EntryCount() ; i++ ) {
		Generator * gp = GenAt( i );
		if ( gp && gp->Name() == name ) {
			return gp;
		}
	}
	return 0;
}
Exemple #22
0
int
Test_ULongLong::init_parameters (Param_Test_ptr)
{
  Generator *gen = GENERATOR::instance (); // value generator

  this->in_ = gen->gen_long ();
  this->inout_ =  0;
  return 0;
}
Exemple #23
0
int main()
{
	{
		asd::FontRasterizer rasterizer;

		auto fp = fopen("C:\\Windows\\Fonts\\meiryo.ttc", "rb");
		fseek(fp, 0, SEEK_END);
		auto size = ftell(fp);
		fseek(fp, 0, SEEK_SET);
		std::vector<uint8_t> data;
		data.resize(size);
		fread(data.data(), 1, size, fp);
		fclose(fp);

		if (rasterizer.Initialize(data.data(), data.size(), 14, 0, asd::Color(100, 0, 0, 255), asd::Color(0, 100, 0, 255), 1024))
		{
			rasterizer.AddGlyph(asd::ToAString("a").c_str()[0]);
			rasterizer.AddGlyph(asd::ToAString("b").c_str()[0]);
			rasterizer.AddGlyph(asd::ToAString("c").c_str()[0]);
			rasterizer.AddGlyph(asd::ToAString("d").c_str()[0]);

			SavePNGImage(L"result.png", 1024, 1024, rasterizer.GetImages()[0]->Buffer.data(), false);
		}
		
		return 0;
	}
	
	//Test();
	//return 0;

	Generator gen;

	try
	{
		SettingForRendering setting;
		setting.SetFontSize(32);
		setting.SetFontColor(Color(255, 128, 0, 255));
		setting.SetBorder(make_shared<BorderSetting>(1, Color(0, 0, 0, 255), 1));
		
		gen.SetSetting(setting);
		gen.SetSheetName(L"result/Nac1220_1");

		gen.GenerateFontFile(
			L"C:/Windows/Fonts/FlopDesignFONT.otf",
			//L"C:/Windows/Fonts/KozGoPr6N-Regular.otf",
			//L"C:/Windows/Fonts/meiryo.ttc",
			L"test.txt");
	}
	catch (const char* err)
	{
		std::cout << err << std::endl;
	}


	system("pause");
	return 0;
}
Exemple #24
0
TEST(Generator, addDescription)
{
	const char *d = "This is the description.";
	Generator g;
	g.addDescription(d);

	EXPECT_STREQ(d, g.desc);
	EXPECT_NE(d, g.desc) << "Description was not coppied.";
}
Exemple #25
0
int main(int argc, char *argv[])
{
    Generator generator;
    int index;
    std::string input = "";
    std::string plate = "xy";

    while ((index = getopt(argc, argv, "yze:o:f:Z:O:r:a:n")) != -1) {
        switch (index) {
            case 'n':
                generator.circleDetection = false;
                break;
            case 'r': {
                          auto parts = split(std::string(optarg), ':');
                          if (parts.size() == 3) {
                              generator.setRepeat(parts[0], atoi(parts[1].c_str()), atof(parts[2].c_str()));
                          }
                      }
                      break;
            case 'a':
                      generator.setAreaTreshold(atof(optarg));
                      break;
            case 'O':
                      generator.setPOffset(atof(optarg));
                      break;
            case 'f':
                      generator.setOutputFormat(std::string(optarg));
                      break;
            case 'z':
                      plate = "xz";
                      break;
            case 'y':
                      plate = "yz";
                      break;
            case 'e': {
                          auto parts = split(std::string(optarg), ':');
                          if (parts.size() != 2) usage();
                          generator.addEngravure(atof(parts[0].c_str()), parts[1]);
                      }
                      break;
            case 'o':
                      generator.setOutput(std::string(optarg));
                      break;
            case 'Z':
                      generator.setZExtra(atof(optarg));
                      break;
        }
    }

    if (optind != argc) {
        generator.openSTL(std::string(argv[optind]), plate);
    } else {
        usage();
    }

    generator.run();
}
void CommentHandler::handleComment(Annotator &A, Generator& generator, clang::Sema &Sema,
                                   const char *bufferStart, int commentStart, int len,
                                   clang::SourceLocation searchLocBegin, clang::SourceLocation searchLocEnd,
                                   clang::SourceLocation commentLoc)
{
    llvm::StringRef rawString(bufferStart+commentStart, len);
    std::string attributes;
    std::string DeclRef;


    if ((rawString.ltrim().startswith("/**") && !rawString.ltrim().startswith("/***"))
            || rawString.ltrim().startswith("/*!") || rawString.ltrim().startswith("//!")
            || (rawString.ltrim().startswith("///") && !rawString.ltrim().startswith("////")))
#if CLANG_VERSION_MAJOR==3 && CLANG_VERSION_MINOR<=4
        if (rawString.find("deprecated") == rawString.npos) // workaround crash in comments::Sema::checkDeprecatedCommand
#endif
    {
        attributes = "class=\"doc\"";

        clang::Preprocessor &PP = Sema.getPreprocessor();
        clang::comments::CommandTraits traits(PP.getPreprocessorAllocator(), clang::CommentOptions());
#if CLANG_VERSION_MAJOR==3 && CLANG_VERSION_MINOR<=4
        traits.registerBlockCommand("deprecated"); // avoid typo correction leading to crash.
#endif
        clang::comments::Lexer lexer(PP.getPreprocessorAllocator(), PP.getDiagnostics(), traits,
                                     clang::SourceLocation::getFromRawEncoding(commentStart), bufferStart + commentStart, bufferStart + commentStart + len);
        clang::comments::Sema sema(PP.getPreprocessorAllocator(), PP.getSourceManager(), PP.getDiagnostics(), traits, &PP);
        clang::comments::Parser parser(lexer, sema, PP.getPreprocessorAllocator(), PP.getSourceManager(),
                                       PP.getDiagnostics(), traits);
        auto fullComment = parser.parseFullComment();
        CommentVisitor visitor{A, generator, traits, Sema};
        visitor.visit(fullComment);
        DeclRef = visitor.DeclRef;
    }

    if (!DeclRef.empty()) {
        docs.insert({std::move(DeclRef), { rawString.str() , commentLoc }});
        generator.addTag("i", attributes, commentStart, len);
        return;
    }

    // Try to find a matching declaration
    const auto &dof = decl_offsets;
    //is there one and one single decl in that range.
    auto it_before = dof.lower_bound(searchLocBegin);
    auto it_after = dof.upper_bound(searchLocEnd);
    if (it_before != dof.end() && it_after != dof.begin() && it_before == (--it_after)) {
        if (it_before->second.second) {
            docs.insert({it_before->second.first, { rawString.str() , commentLoc }});
        } else {
            attributes %= " data-doc=\"" % it_before->second.first % "\"";
        }
    }

    generator.addTag("i", attributes, commentStart, len);
}
Exemple #27
0
int
Test_Unbounded_String::init_parameters (Alt_Mapping_ptr)
{
  Generator *gen = GENERATOR::instance (); // value generator

  this->in_ = gen->gen_string ();
  this->inout_ = this->in_.c_str ();

  return 0;
}
/** Converts a Generator object to a rational vector
 */
math::rational_vector convert_to_rational_vector(
		const Generator& g) {
	math::rational_vector p=
			math::rational_vector(g.space_dimension());
//	mpq_class q(0);
	for (unsigned int i=0; i<g.space_dimension(); ++i) {
		p[i]=Rational(g.coefficient(Variable(i)), g.divisor());
	}
	return p;
}
math::double_vector convert_to_double_vector(const Generator& g) {
	math::double_vector p=
			math::double_vector(g.space_dimension());
	Rational temp;

	for (unsigned int i=0; i<g.space_dimension(); ++i) {
		temp = Rational(g.coefficient(Variable(i)), g.divisor());
		p[i] = temp.get_double();
	}
	return p;
}
Exemple #30
0
int main()
{
    Generator gen; //creating an object 
    while (gen.toRepeat())
    {
        gen.generatePassword();
        gen.show();
        
    }
    gen.saveToFile();
    return 0;
}