void ComponentSplitterLayout::call(GraphAttributes &GA)
{
	// Only do preparations and call if layout is valid
	if (m_secondaryLayout.valid())
	{
		//first we split the graph into its components
		const Graph& G = GA.constGraph();

		NodeArray<int> componentNumber(G);
		m_numberOfComponents = connectedComponents(G, componentNumber);
		if (m_numberOfComponents == 0) {
			return;
		}

		//std::vector< std::vector<node> > componentArray;
		//componentArray.resize(numComponents);
		//Array<GraphAttributes *> components(numComponents);
		//

		// intialize the array of lists of nodes contained in a CC
		nodesInCC.init(m_numberOfComponents);

		node v;
		forall_nodes(v,G)
			nodesInCC[componentNumber[v]].pushBack(v);

		 // Create copies of the connected components and corresponding
		 // GraphAttributes
		 GraphCopy GC;
		 GC.createEmpty(G);

		 EdgeArray<edge> auxCopy(G);

		 for (int i = 0; i < m_numberOfComponents; i++)
		 {
			 GC.initByNodes(nodesInCC[i],auxCopy);
			 GraphAttributes cGA(GC);
			 //copy information into copy GA
			 forall_nodes(v, GC)
			 {
				cGA.width(v) = GA.width(GC.original(v));
				cGA.height(v) = GA.height(GC.original(v));
				cGA.x(v) = GA.x(GC.original(v));
				cGA.y(v) = GA.y(GC.original(v));
			 }
			 m_secondaryLayout.get().call(cGA);

			 //copy layout information back into GA
			 forall_nodes(v, GC)
			 {
				 node w = GC.original(v);
				 if (w != 0)
					 GA.x(w) = cGA.x(v);
				 GA.y(w) = cGA.y(v);
			 }
		 }
int main() {
   CMPGA cGA(CRange<Real>(-10.0,10.0),            // Allele range
             GENOME_SIZE,                         // Genome size
             5,                                   // Population size
             0.05,                                // Mutation probability
             5,                                   // Number of trials
             100,                                 // Number of generations
             false,                               // Minimize score
             "experiments/mpga.argos",            // .argos conf file
             &ScoreAggregator,                    // The score aggregator
             12345                                // Random seed
      );
   cGA.Evaluate();
   argos::LOG << "Generation #" << cGA.GetGeneration() << "...";
   argos::LOG << " scores:";
   for(UInt32 i = 0; i < cGA.GetPopulation().size(); ++i) {
      argos::LOG << " " << cGA.GetPopulation()[i]->Score;
   }
   LOG << std::endl;
   LOG.Flush();
   while(!cGA.Done()) {
      cGA.NextGen();
      cGA.Evaluate();
      argos::LOG << "Generation #" << cGA.GetGeneration() << "...";
      argos::LOG << " scores:";
      for(UInt32 i = 0; i < cGA.GetPopulation().size(); ++i) {
         argos::LOG << " " << cGA.GetPopulation()[i]->Score;
      }
      if(cGA.GetGeneration() % 5 == 0) {
         argos::LOG << " [Flushing genome... ";
         /* Flush scores of best individual */
         FlushIndividual(*cGA.GetPopulation()[0],
                         cGA.GetGeneration());
         argos::LOG << "done.]";
      }
      LOG << std::endl;
      LOG.Flush();
   }
   return 0;
}
Example #3
0
int main(int argc, char** argv) {
   /*
    * Initialize GALIB
    */
   /* Create an allele whose values can be in the range [-10,10] */
   GAAlleleSet<float> cAlleleSet(-10.0f, 10.0f);
   /* Create a genome with 10 genes, using LaunchARGoS() to evaluate it */
   GARealGenome cGenome(GENOME_SIZE, cAlleleSet, LaunchARGoS);
   /* Create and configure a basic genetic algorithm using the genome */
   GASimpleGA cGA(cGenome);
   cGA.minimize();                     // the objective function must be minimized
   cGA.populationSize(5);              // population size for each generation
   cGA.nGenerations(500);              // number of generations
   cGA.pMutation(0.05f);               // prob of gene mutation
   cGA.pCrossover(0.15f);              // prob of gene crossover
   cGA.scoreFilename("evolution.dat"); // filename for the result log
   cGA.flushFrequency(1);              // log the results every generation

   /*
    * Initialize ARGoS
    */
   /* The CSimulator class of ARGoS is a singleton. Therefore, to
    * manipulate an ARGoS experiment, it is enough to get its instance */
   argos::CSimulator& cSimulator = argos::CSimulator::GetInstance();
   /* Set the .argos configuration file
    * This is a relative path which assumed that you launch the executable
    * from argos3-examples (as said also in the README) */
   cSimulator.SetExperimentFileName("experiments/evolution.argos");
   /* Load it to configure ARGoS */
   cSimulator.LoadExperiment();

   /*
    * Launch the evolution, setting the random seed
    */
   cGA.initialize(12345);
   do {
      argos::LOG << "Generation #" << cGA.generation() << "...";
      cGA.step();
      argos::LOG << "done.";
      if(cGA.generation() % cGA.flushFrequency() == 0) {
         argos::LOG << "   Flushing...";
         /* Flush scores */
         cGA.flushScores();
         /* Flush best individual */
         FlushBest(dynamic_cast<const GARealGenome&>(cGA.statistics().bestIndividual()),
                   cGA.generation());
         argos::LOG << "done.";
      }
      LOG << std::endl;
      LOG.Flush();
   }
   while(! cGA.done());

   /*
    * Dispose of ARGoS stuff
    */
   cSimulator.Destroy();

   /* All is OK */
   return 0;
}
Example #4
0
void ComponentSplitterLayout::call(GraphAttributes &GA)
{
	// Only do preparations and call if layout is valid
	if (m_secondaryLayout.valid())
	{
		//first we split the graph into its components
		const Graph& G = GA.constGraph();

		NodeArray<int> componentNumber(G);
		int numberOfComponents = connectedComponents(G, componentNumber);
		if (numberOfComponents == 0) {
			return;
		}

		// intialize the array of lists of nodes contained in a CC
		Array<List<node> > nodesInCC(numberOfComponents);

		for(node v : G.nodes)
			nodesInCC[componentNumber[v]].pushBack(v);

		// Create copies of the connected components and corresponding
		// GraphAttributes
		GraphCopy GC;
		GC.createEmpty(G);

		EdgeArray<edge> auxCopy(G);

		for (int i = 0; i < numberOfComponents; i++)
		{
			GC.initByNodes(nodesInCC[i],auxCopy);
			GraphAttributes cGA(GC, GA.attributes());
			//copy information into copy GA
			for(node v : GC.nodes)
			{
				cGA.width(v) = GA.width(GC.original(v));
				cGA.height(v) = GA.height(GC.original(v));
				cGA.x(v) = GA.x(GC.original(v));
				cGA.y(v) = GA.y(GC.original(v));
			}
			// copy information on edges
			if (GA.attributes() & GraphAttributes::edgeDoubleWeight) {
				for (edge e : GC.edges) {
					cGA.doubleWeight(e) = GA.doubleWeight(GC.original(e));
				}
			}
			m_secondaryLayout.get().call(cGA);

			//copy layout information back into GA
			for(node v : GC.nodes)
			{
				node w = GC.original(v);
				if (w != nullptr)
				{
					GA.x(w) = cGA.x(v);
					GA.y(w) = cGA.y(v);
					if (GA.attributes() & GraphAttributes::threeD) {
						GA.z(w) = cGA.z(v);
					}
				}
			}
		}

		// rotate component drawings and call the packer
		reassembleDrawings(GA, nodesInCC);

	}//if valid
}