void Population::Evolve(size_t elitism_count) {
	std::vector<Individual> evolved_pop(pop_.size());
	std::vector<size_t> elites = Elitism(elitism_count);
	
	/* Choosing elite individuals uses raw fitness */
	for (size_t j = 0; j < elitism_count; ++j) {
		evolved_pop[j] = pop_[elites[j]];
	}

	for (size_t j = elitism_count; j < pop_.size(); ++j) {
		size_t p1 = SelectIndividual();
		size_t p2;
		do {
			p2 = SelectIndividual();
		} while (p2 == p1);

		Individual parent1(pop_[p1]);
		Individual parent2(pop_[p2]);
		Crossover(&parent1, &parent2);

		evolved_pop[j] = parent1;
		evolved_pop[j].Mutate(mutation_rate_);
	}
	this->pop_ = evolved_pop;
	CalculateFitness();
}
Пример #2
0
int main ()
{
  printf ("Results of node_bind3_test:\n");
  
  Node::Pointer node (Node::Create ()), parent1 (Node::Create ()), parent2 (Node::Create ());

  node->SetPosition    (1, 2, 3);
  node->SetOrientation (degree (90.0f), 1, 0, 0);
  node->SetScale       (-1, 2, 3);
  
  parent1->SetPosition    (-1, -5, 2);
  parent1->SetOrientation (degree (90.0f), 0, 1, 0);
  parent1->SetScale       (-1, -2, 1);  
  
  parent1->SetPosition    (8, 2, 3);
  parent1->SetOrientation (degree (90.0f), 0, 0, 1);
  parent1->SetScale       (2, 3, 1);
  
  node->BindToParent (*parent1);
  
  printf           ("before\n  position:    ");
  dump_position    (*node);
  printf           ("\n  orientation: ");
  dump_orientation (*node);
  printf           ("\n  scale:       ");
  dump_scale       (*node);  
  printf           ("\n");  
  
  node->BindToParent (*parent2, NodeBindMode_AddRef, NodeTransformSpace_World);
  
  printf           ("after rebind\n  position:    ");
  dump_position    (*node);
  printf           ("\n  orientation: ");  
  dump_orientation (*node);
  printf           ("\n  scale:       ");  
  dump_scale       (*node);  
  printf           ("\n");  
  
  node->Unbind (NodeTransformSpace_World);
  
  printf           ("after unbind\n  position:    ");
  dump_position    (*node);
  printf           ("\n  orientation: ");  
  dump_orientation (*node);
  printf           ("\n  scale:       ");  
  dump_scale       (*node);  
  printf           ("\n");    

  return 0;
}
Пример #3
0
EdenMount::EdenMount(
    std::unique_ptr<ClientConfig> config,
    std::shared_ptr<ObjectStore> objectStore,
    std::shared_ptr<ServerState> serverState)
    : config_{std::move(config)},
      serverState_{std::move(serverState)},
      objectStore_{std::move(objectStore)},
      straceLogger_{kEdenStracePrefix.str() + config_->getMountPath().value()},
      dispatcher_{this},
      fsChannel_{config_->getMountPath(), this},
      mountGeneration_{generateLuid()} {
  auto parents = std::make_shared<ParentCommits>(config_->getParentCommits());

  XLOGF(
      INFO,
      "Creating eden mount {} Parent Commit {}",
      getPath(),
      parents->parent1().toString());
  parentInfo_.wlock()->parents.setParents(*parents);
}
Пример #4
0
int loginS1() // Run the login program in serial port 1
{
  stdin = open("/dev/ttyS1", 0);    // Open serial port 1 as stdin for READ  
  stdout = open("/dev/ttyS1", 1);   // Open serial port 1 as stdout for WRITE   
  stderr = open("/dev/ttyS1", 1);   
  //printf("Entered loginS1() to fork login task to serial port 1\n"); 
  
  s1 = fork(); 

  if(s1)
  {
    //printf("fork() failed to create new process to execute login task in serial port 1\n"); 
    parent1(); 
  } 
  else
  {
    //printf("forked() child P%d to execute login task in serial port 1\n", getpid()); 
    exec("login /dev/ttyS1"); 
  }
    
}
Пример #5
0
int main(int argc, char **argv){

mpi::environment env(argc, argv);
mpi::communicator world;
std::srand(135+2*world.rank()); 

int nodecount, max_i, max_j, max_k;
if(world.rank()==0) {
  std::cout << "usage:  ./individual_test.exe testfilename\n";
  FILE* nodefile = fopen(argv[1], "r"); 
  if (nodefile==NULL) {
    std::cout << "error opening file "<<argv[1] << "\n"; 
    return 1; 
  }

  char oneline[100];
  int line_count=0;
  while( fgets(oneline,100,nodefile)!=NULL){
    if(oneline[0]=='#' || oneline[0]=='\n'){
      std::cout << oneline; 
      continue;
    }else{
      line_count+=1;
      if(line_count==1){ 
        sscanf(oneline,"%d%d%d%d",&nodecount,&max_i,&max_j,&max_k); 
      }else{
        gampi_nodelist.push_back((nodeid) atoi(oneline));
      } 
    }
  } 
}

broadcast(world, max_i, 0);
broadcast(world, max_j, 0);
broadcast(world, max_k, 0);
broadcast(world, gampi_nodelist, 0);

gampi_domain=Domain(max_i, max_j, max_k); 

Individual a;
if(world.rank()==0) a.show(); 

Individual b(true); 
if(world.rank()==0) b.show(); 
if(world.rank()==0) b.mutate(); 
if(world.rank()==0) b.show(); 
broadcast(world, b, 0); 

char s[16];
sprintf(s,"bcst %d",world.rank()); 
b.show(s); 

Individual c(b, true); 
sprintf(s,"mutt %d",world.rank()); 
c.show(s); 

if(world.rank()==0) {
std::cout << "Begin crossover test \n"; 

Individual parent1(true); 
parent1.show((char*) "parent1"); 

Individual parent2(true); 
parent2.show((char*) "parent2"); 

Individual pt2mind=parent2; 
pt2mind.mindiff(parent1); 
pt2mind.show((char*) "pt2mind"); 

Individual child1, child2;
Individual::crossover(parent1, parent2, child1, child2); 
child1.show((char*) "child1 "); 
child2.show((char*) "child2 "); 
}

} // end main
int main(int argc, char* argv[])
{
    typedef double DecisionVariable_t;
    typedef std::mt19937 RNG_t;
    unsigned int seed = 1;
    double eta = 10;
    double crossover_probability = 1.0;
    double eps = 0.00001;
    double proportion_crossed = 1.0;
    RNG_t rng(seed);
    
    DebsSBXCrossover<RNG_t> crossover_tester(rng, eta, crossover_probability, eps, proportion_crossed);
    
    int number_dvs = 1; //number of decision variables
    double min_value = -1.0;
    double max_value = 8.0;
    std::vector<double> lower_bounds(number_dvs, min_value);
    std::vector<double> upper_bounds(number_dvs, max_value);
    std::vector<int> lower_bounds_i;
    std::vector<int> upper_bounds_i;
    std::vector<MinOrMaxType> min_or_max(1, MINIMISATION);
    
//    std::vector<DecisionVariable_t> parent1_dv_values {2};
//    std::vector<DecisionVariable_t> parent2_dv_values {5};
    ProblemDefinitions defs(lower_bounds, upper_bounds,lower_bounds_i, upper_bounds_i, min_or_max, 0);
    Individual parent1(defs);
    Individual parent2(defs);
    
    std::vector<double> results;
    
    int num_samples = 1000000;
    for (int i = 0; i < num_samples; ++i)
    {
        Individual child1(parent1);
        Individual child2(parent2);
        crossover_tester.crossover_implementation(child1, child2);
        results.push_back(child1.getRealDV(0));
        results.push_back(child2.getRealDV(0));
//        std::cout << child1[0] << std::endl;
//        std::cout << child2[0] << std::endl;
    }
    
#ifdef WITH_VTK
    // plot results.
    // Set up a 2D scene, add an XY chart to it
    VTK_CREATE(vtkContextView, view);
    view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
    view->GetRenderWindow()->SetSize(400, 300);
    VTK_CREATE(vtkChartXY, chart);
    view->GetScene()->AddItem(chart);
    
    // Create a table with some points in it...
    VTK_CREATE(vtkTable, table);
    
    VTK_CREATE(vtkIntArray, arrBin);
    arrBin->SetName("decision variable value");
    table->AddColumn(arrBin);
    
    VTK_CREATE(vtkIntArray, arrFrequency);
    arrFrequency->SetName("Frequency");
    table->AddColumn(arrFrequency);
    
    int num_bins = 50;
    table->SetNumberOfRows(num_bins);
    
    std::vector<int> frequency_count(num_bins);
//    std::vector<std::string> bin_names(num_bins);
    std::vector<int> bin_names(num_bins);
    
    for (int i = 0; i < num_samples; ++i)
    {
        frequency_count[int((results[i] - min_value) / (max_value - min_value) * num_bins)]++;
    }
    
    for (int i = 0; i < num_bins; ++i)
    {
//        bin_names[i] = std::to_string((double(i) / double(num_bins)) * (max_value-min_value) + min_value);
        bin_names[i] = i;
    }
    
    for (int i = 0; i < num_bins; i++)
    {
        table->SetValue(i,0,bin_names[i]);
        table->SetValue(i,1,frequency_count[i]);
    }
    
    // Add multiple line plots, setting the colors etc
    vtkPlot *line = 0;
    
    line = chart->AddPlot(vtkChart::BAR);
#if VTK_MAJOR_VERSION <= 5
    line->SetInput(table, 0, 1);
#else
    line->SetInputData(table, 0, 1);
#endif
    line->SetColor(0, 255, 0, 255);
    
    //Finally render the scene and compare the image to a reference image
    view->GetRenderWindow()->SetMultiSamples(0);
    view->GetInteractor()->Initialize();
    view->GetInteractor()->Start();
#endif
    
}
Пример #7
0
/**
@SYMTestCaseID		GRAPHICS-WSERV-0462

@SYMDEF  			PDEF114190

@SYMTestCaseDesc    Test sprite list cleanup when a window is deleted in low memory conditions

@SYMTestPriority    High

@SYMTestStatus      Implemented

@SYMTestActions     Have a loop which increases the number of allocations in the server thread before failure;
					Within the loop:
					1) Create a parent window and a child window of the parent;
					2) Create a sprite on the child window; 
					3) Delete the parent window only, but not the child window; 
					4) Create a testWindow and do redraw on this window; 
					5) Do redraw on the testWindow. This testWindow's redraw will force checking the sprite list. 
					This would panic the client thread due to this defect because the sprite on the orphaned 
					window (which is the previous child window) is still in the sprite list;
					6) Delete all the windows involved.

@SYMTestExpectedResults The sprite should be disabled when a window is deleted;
						The client thread should not be panic'd.
						The test should pass.
*/
void CTTSprite::SpriteOnWindowOrphanedTestsL()
	{
	TInt handles = 344;
	TInt loop = 0;
	TInt allocFailRate = 0;
	TInt err = KErrNone;

	CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
	CleanupStack::PushL(bitmap);
	User::LeaveIfError(bitmap->Create(TSize(500, 500), EColor16MU));
	TSpriteMember spritemember;
	spritemember.iBitmap = bitmap;
	spritemember.iMaskBitmap = NULL;	
	
	RWindowGroup group(TheClient->iWs);
	RWindow parent1(TheClient->iWs);
	RWindow child1(TheClient->iWs);
	RWindow testWindow(TheClient->iWs);
	RWsSprite sprite(TheClient->iWs);
	
	while (loop < 5)
		{
		TRect mainRect(TPoint(0,0), TSize(500,500));
		err = group.Construct(++handles, EFalse);	
		if (err == KErrNone)
			{
			TheClient->iWs.HeapSetFail(RHeap::EDeterministic, allocFailRate);

			//Create parent 1
			err = parent1.Construct(group,++handles);
			if (err == KErrNone)
				{
				parent1.SetExtent(mainRect.iTl, mainRect.Size());
				parent1.EnableRedrawStore(ETrue);
				parent1.Activate();
				}			
			}
		
		//Create child 1
		if (err == KErrNone)
			{
			TRect childRect(TPoint (10, 10), TSize (200, 150));
			err = child1.Construct(parent1,++handles);
			if (err == KErrNone)
				{
				child1.SetExtent(childRect.iTl, childRect.Size());
				child1.SetBackgroundColor(TRgb(128,100,255,20));
				child1.Activate();
				}
			}
		
		//Add sprite to child 1
		if (err == KErrNone) 
			{
			err = sprite.Construct(child1,TPoint(10,10), 0);
			if (err == KErrNone)
				{
				err = sprite.AppendMember(spritemember);
				if (err == KErrNone)
					err = sprite.Activate();	
				}
			}

		//Only delete parent 1, but not child 1	
		parent1.Close();		

		if (err == KErrNone) 
			{
			TRect testRect(TPoint(10, 30), TSize(200, 150));
			//Create testWindow
			err = testWindow.Construct(group,++handles);
			if (err == KErrNone)
				{
				testWindow.SetExtent(testRect.iTl, testRect.Size());
				testWindow.SetBackgroundColor(TRgb(128,100,255,20));
				testWindow.EnableRedrawStore(ETrue);
				testWindow.Activate();
				testWindow.BeginRedraw();
				testWindow.EndRedraw();	
				TheClient->Flush();			
				}
			}
		TheClient->iWs.HeapSetFail(RAllocator::ENone, 0);

		sprite.Close();
		child1.Close();
		testWindow.Close();
		group.Close();		
		++allocFailRate;
		loop = (err == KErrNone) ? loop + 1 : 0;
		}
	CleanupStack::PopAndDestroy(bitmap);
	}