本文整理汇总了C++中Generator类的典型用法代码示例。如果您正苦于以下问题:C++ Generator类的具体用法?C++ Generator怎么用?C++ Generator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Generator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: propagate_photons
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;
}
示例2: catch
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;
}
示例3: genFiles
// 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);
}
示例4: switch
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;
}
示例5:
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;
}
示例6: coupling_efficiency
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;
}
示例7: mxAppMain
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;
}
示例8: main
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;
}
示例9:
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;
}
示例10: SetDefaults
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);
}
示例11:
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;
}
示例12: Generator
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();
}
}
示例13: interfejs
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";
}
示例14: TEST
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());
}
示例15: main
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;
}