• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Genotype类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jgap.Genotype的典型用法代码示例。如果您正苦于以下问题:Java Genotype类的具体用法?Java Genotype怎么用?Java Genotype使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Genotype类属于org.jgap包,在下文中一共展示了Genotype类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: genotypeFromRunXml

import org.jgap.Genotype; //导入依赖的package包/类
/**
 * Construct new <code>Genotype</code> object from population in specified run XML data.
 * 
 * @param runXml XML data from which to construct initial population
 * @return new <code>Genotype</code>
 * @throws Exception
 */
private Genotype genotypeFromRunXml( InputStream runXml, Configuration config )
		throws Exception {
	DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
	Document doc = builder.parse( runXml, baseDir.getAbsolutePath() );
	Node runNode = doc.getFirstChild();
	if ( XmlPersistableRun.RUN_TAG.equals( runNode.getNodeName() ) == false )
		throw new IllegalArgumentException( "node name not " + XmlPersistableRun.RUN_TAG );

	// loop through list to find last generation
	Node generationNode = null;
	for ( int i = 0; i < runNode.getChildNodes().getLength(); ++i ) {
		Node nextNode = runNode.getChildNodes().item( i );
		if ( Generation.GENERATION_TAG.equals( nextNode.getNodeName() ) )
			generationNode = nextNode;
	}

	return genotypeFromXml( generationNode, config, this );
}
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:26,代码来源:FilePersistence.java


示例2: geneticEventFired

import org.jgap.Genotype; //导入依赖的package包/类
/**
 * @param event <code>GeneticEvent.GENOTYPE_EVALUATED_EVENT</code> writes chromosomes and
 * updates run; <code>GeneticEvent.GENOTYPE_START_GENETIC_OPERATORS_EVENT</code> loads config;
 * <code>GeneticEvent.GENOTYPE_FINISH_GENETIC_OPERATORS_EVEN</code> stores config
 */
public void geneticEventFired( GeneticEvent event ) {
	Genotype genotype = (Genotype) event.getSource();
	if ( GeneticEvent.GENOTYPE_START_GENETIC_OPERATORS_EVENT.equals( event.getEventName() ) ) {
		genotypeStartGeneticOperatorsEvent();
	}
	if ( GeneticEvent.GENOTYPE_FINISH_GENETIC_OPERATORS_EVENT.equals( event.getEventName() ) ) {
		genotypeFinishGeneticOperatorsEvent();
	}
	else if ( GeneticEvent.GENOTYPE_EVALUATED_EVENT.equals( event.getEventName() ) ) {
		genotypeEvaluatedEvent( genotype );
	}
}
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:18,代码来源:PersistenceEventListener.java


示例3: geneticEventFired

import org.jgap.Genotype; //导入依赖的package包/类
/**
 * @param event <code>GeneticEvent.GENOTYPE_EVOLVED_EVENT</code> is the
 * only event handled; writes species count and stats of fittest chromosome.
 */
public void geneticEventFired(GeneticEvent event) {
	if ( GeneticEvent.GENOTYPE_EVOLVED_EVENT.equals( event.getEventName() ) ) {
		Genotype genotype = (Genotype) event.getSource();
		Chromosome fittest = genotype.getFittestChromosome();
		double maxFitnessValue = (config.getBulkFitnessFunction() != null) ?
			config.getBulkFitnessFunction().getMaxFitnessValue() :
			config.getFitnessFunction().getMaxFitnessValue();
		double fitness = (maxFitnessValue == 0) ? fittest.getFitnessValue() :
			(fittest.getFitnessValue() / maxFitnessValue);
		out.println( "species count: " + genotype.getSpecies().size() );
		out.println( "fittest chromosome: " + fittest.getId() + ", score == " + fitness + " and # genes == " + fittest.size() );	
	}
}
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:18,代码来源:ConsoleLogEventListener.java


示例4: geneticEventFired

import org.jgap.Genotype; //导入依赖的package包/类
/**
 * @param event <code>GeneticEvent.GENOTYPE_EVOLVED_EVENT</code> is the only event handled;
 * writes species count and stats of all fittest chromosomes.
 */
public void geneticEventFired( GeneticEvent event ) {
	if ( GeneticEvent.GENOTYPE_EVOLVED_EVENT.equals( event.getEventName() ) ) {
		Genotype genotype = (Genotype) event.getSource();
		Chromosome fittest = genotype.getFittestChromosome();
		double maxFitnessValue = ( config.getBulkFitnessFunction() != null ) ? config
				.getBulkFitnessFunction().getMaxFitnessValue() : config.getFitnessFunction()
				.getMaxFitnessValue();
		double fitness = ( maxFitnessValue == 0 ) ? fittest.getFitnessValue() : ( fittest
				.getFitnessValue() / maxFitnessValue );
		logger.info( "species count: " + genotype.getSpecies().size() );
		List chroms = genotype.getChromosomes();
		Iterator iter = chroms.iterator();
		int maxFitnessCount = 0;
		while ( iter.hasNext() ) {
			Chromosome c = (Chromosome) iter.next();
			if ( c.getFitnessValue() == maxFitnessValue ) {
				logger.info( "max: id=" + c.getId() + " score=" + fitness + " size=" + c.size() );
				++maxFitnessCount;
			}
		}
// TODO		if ( maxFitnessCount > 0 )
			logger.info( "# chromosomes with max fitness: " + maxFitnessCount );
		logger.info( "champ: id=" + fittest.getId() + " score=" + fitness + " size="
				+ fittest.size() );
	}
}
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:31,代码来源:LogEventListener.java


示例5: optimize

import org.jgap.Genotype; //导入依赖的package包/类
@Override
public void optimize (final IRunExecutable run)
{
	Configuration config = new DefaultConfiguration ();
	config.setPreservFittestIndividual (true);
	
	try
	{
		config.setFitnessFunction (new FitnessFunction ()
		{
			private static final long serialVersionUID = 1L;
			private Double m_fBias = null;

			@Override
			protected double evaluate (IChromosome chromosome)
			{
				StringBuilder sbResult = new StringBuilder ();					
				double fResult = run.execute (MetaHeuristicOptimizer.getParametersFromChromosome (chromosome), sbResult, checkBounds ());
				chromosome.setApplicationData (sbResult.toString ());

				// JGAP maximizes the fitness function, and only positive results are allowed
				
				//return Math.exp (-fResult / 1e8);
				
				//if (m_fBias == null)
				//	m_fBias = fResult * 10;
				//return m_fBias - fResult;
				
				if (m_fBias == null && fResult != Double.MAX_VALUE && fResult != 0)
					m_fBias = fResult;
				if (m_fBias == null)
					return Math.exp (-fResult);
				return Math.exp (-fResult / m_fBias);
			}
		});
		
		// create the chromosome
		Gene[] rgSampleGenes = new Gene[run.getParametersCount ()];
		for (int i = 0; i < run.getParametersCount (); i++)
			rgSampleGenes[i] = new IntegerGene (config, run.getParameterLowerBounds ()[i], run.getParameterUpperBounds ()[i]);
		config.setSampleChromosome (new Chromosome (config, rgSampleGenes));

		config.setPopulationSize (POPULATION_SIZE);
		
		// create population and evolve it
		Genotype population = Genotype.randomInitialGenotype (config);
		for (int i = 0; i < MAX_EVOLUTIONS; i++)
		{
			population.evolve ();
			LOGGER.info (population.getFittestChromosome ());
		}
		
		setResult (population.getFittestChromosome ());
	}
	catch (InvalidConfigurationException e)
	{
		e.printStackTrace ();
	}		
}
 
开发者ID:matthias-christen,项目名称:patus,代码行数:60,代码来源:MetaHeuristicOptimizer.java


示例6: findOneSequence

import org.jgap.Genotype; //导入依赖的package包/类
private Operand findOneSequence ()
{
	try
	{
		// create population and evolve it
		IChromosome[] rgChromosomes = new IChromosome[m_listInputOperands.size ()];
		int nIdx = 0;
		for (Operand op : m_listInputOperands)
		{
			Gene[] rgGenes = new Gene[m_nElementsCount];
			for (int i = 0; i < m_nElementsCount; i++)
			{
				rgGenes[i] = new IntegerGene (m_config, 0, 2 * m_nElementsCount - 1);
				rgGenes[i].setAllele (op.getElements ()[i]);
			}
			
			rgChromosomes[nIdx] = new Chromosome (m_config, rgGenes);
			rgChromosomes[nIdx].setApplicationData (op);
			nIdx++;
		}
		
		// evolve the population
		Population population = new Population (m_config, rgChromosomes);
		Genotype genotype = new Genotype (m_config, population);
		for (int i = 0; i < MAX_EVOLUTIONS; i++)
		{
			genotype.evolve ();
			//LOGGER.info (genotype.getFittestChromosome ());
		}
		
		IChromosome chromFittest = genotype.getFittestChromosome ();
		LOGGER.info (chromFittest);
		
		Operand opRes = (Operand) chromFittest.getApplicationData ();
		opRes.m_rgElements = new int[m_nElementsCount];
		for (int i = 0; i < m_nElementsCount; i++)
			opRes.m_rgElements[i] = (Integer) chromFittest.getGene (i).getAllele ();
		
		return opRes;
	}
	catch (InvalidConfigurationException e)
	{
		e.printStackTrace ();
	}

	return null;
}
 
开发者ID:matthias-christen,项目名称:patus,代码行数:48,代码来源:PermutatorGenetic.java


示例7: init

import org.jgap.Genotype; //导入依赖的package包/类
public void init() throws InvalidConfigurationException {
	genotype = Genotype.randomInitialGenotype( this );
}
 
开发者ID:adamchainz,项目名称:sound-resynthesis,代码行数:4,代码来源:GeneticSynth.java


示例8: Generation

import org.jgap.Genotype; //导入依赖的package包/类
/**
 * @param aGenotype chromosomes from this object make up generation.
 * @param anId of generation
 */
public Generation( Genotype aGenotype, long anId ) {
	genotype = aGenotype;
	id = new Long( anId );
	cacheXml();
}
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:10,代码来源:Generation.java


示例9: loadGenotype

import org.jgap.Genotype; //导入依赖的package包/类
/**
 * @see com.anji.persistence.Persistence#loadGenotype(org.jgap.Configuration)
 */
public Genotype loadGenotype( Configuration aConfig ) {
	return null;
}
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:7,代码来源:HibernatePersistence.java


示例10: genotypeFromXml

import org.jgap.Genotype; //导入依赖的package包/类
/**
 * Create a <code>Genotype</code> from XML.
 * 
 * @param generationNode XML
 * @param config
 * @param db persistence repository from which to read chromosomes
 * @return new genotype
 * @throws Exception
 */
private static Genotype genotypeFromXml( Node generationNode, Configuration config,
		Persistence db ) throws Exception {
	if ( Generation.GENERATION_TAG.equals( generationNode.getNodeName() ) == false )
		throw new IllegalArgumentException( "node name not " + Generation.GENERATION_TAG );

	// loop through list to find chromosomes
	ArrayList chroms = new ArrayList();
	for ( int generationChildIdx = 0; generationChildIdx < generationNode.getChildNodes()
			.getLength(); ++generationChildIdx ) {
		Node specieNode = generationNode.getChildNodes().item( generationChildIdx );
		if ( Specie.SPECIE_TAG.equals( specieNode.getNodeName() ) ) {
			// for each specie ...
			NamedNodeMap specieAttrs = specieNode.getAttributes();
			if ( specieAttrs == null )
				throw new IllegalArgumentException( "missing specie attributes" );

			// ... and loop through chromosomes
			for ( int specieChildIdx = 0; specieChildIdx < specieNode.getChildNodes().getLength(); ++specieChildIdx ) {
				Node chromNode = specieNode.getChildNodes().item( specieChildIdx );
				if ( Specie.CHROMOSOME_TAG.equals( chromNode.getNodeName() ) ) {
					NamedNodeMap chromAttrs = chromNode.getAttributes();
					if ( chromAttrs == null )
						throw new IllegalArgumentException( "missing chromosome attributes" );
					Node chromIdNode = chromAttrs.getNamedItem( Specie.ID_TAG );
					if ( chromIdNode == null )
						throw new IllegalArgumentException( "missing chromosome id" );

					// get id and load chromosome from persistence (skip if representative since its
					// already been added
					Long chromId = Long.valueOf( chromIdNode.getNodeValue() );
					Chromosome c = db.loadChromosome( chromId.toString(), config );
					if ( c != null )
						chroms.add( c );
					else
						logger.warn( "chromosome in run not found: " + chromId );
				}
			}
		}
	}

	// don't return empty genotype
	if ( chroms.size() <= 0 )
		return null;

	// sort in order of id so that they will be added in proper order (age)
	Collections.sort( chroms );
	return new Genotype( config, chroms );
}
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:58,代码来源:FilePersistence.java


示例11: init

import org.jgap.Genotype; //导入依赖的package包/类
/**
 * Construct new evolver with given properties. See <a href=" {@docRoot}/params.htm"
 * target="anji_params">Parameter Details </a> for specific property settings.
 * @see com.anji.util.Configurable#init(com.anji.util.Properties)
 */
public void init( Properties props ) throws Exception {
	boolean doReset = props.getBooleanProperty( RESET_KEY, false );
	if ( doReset ) {
		logger.warn( "Resetting previous run !!!" );
		Reset resetter = new Reset( props );
		resetter.setUserInteraction( false );
		resetter.reset();
	}

	config = new NeatConfiguration( props );

	// peristence
	db = (Persistence) props.singletonObjectProperty( Persistence.PERSISTENCE_CLASS_KEY );

	numEvolutions = props.getIntProperty( NUM_GENERATIONS_KEY );
	targetFitness = props.getDoubleProperty( FITNESS_TARGET_KEY, 1.0d );
	thresholdFitness = props.getDoubleProperty( FITNESS_THRESHOLD_KEY, targetFitness );

	//
	// event listeners
	//

	// run
	// TODO - hibernate
	Run run = (Run) props.singletonObjectProperty( Run.class );
	db.startRun( run.getName() );
	config.getEventManager().addEventListener( GeneticEvent.GENOTYPE_EVALUATED_EVENT, run );

	// logging
	LogEventListener logListener = new LogEventListener( config );
	config.getEventManager().addEventListener( GeneticEvent.GENOTYPE_EVOLVED_EVENT, logListener );
	config.getEventManager()
			.addEventListener( GeneticEvent.GENOTYPE_EVALUATED_EVENT, logListener );

	// persistence
	PersistenceEventListener dbListener = new PersistenceEventListener( config, run );
	dbListener.init( props );
	config.getEventManager().addEventListener(
			GeneticEvent.GENOTYPE_START_GENETIC_OPERATORS_EVENT, dbListener );
	config.getEventManager().addEventListener(
			GeneticEvent.GENOTYPE_FINISH_GENETIC_OPERATORS_EVENT, dbListener );
	config.getEventManager().addEventListener( GeneticEvent.GENOTYPE_EVALUATED_EVENT, dbListener );

	// presentation
	PresentationEventListener presListener = new PresentationEventListener( run );
	presListener.init( props );
	config.getEventManager().addEventListener( GeneticEvent.GENOTYPE_EVALUATED_EVENT,
			presListener );
	config.getEventManager().addEventListener( GeneticEvent.RUN_COMPLETED_EVENT, presListener );

	// fitness function
	BulkFitnessFunction fitnessFunc = (BulkFitnessFunction) props
			.singletonObjectProperty( FITNESS_FUNCTION_CLASS_KEY );
	config.setBulkFitnessFunction( fitnessFunc );
	maxFitness = fitnessFunc.getMaxFitnessValue();

	// load population, either from previous run or random
	genotype = db.loadGenotype( config );
	if ( genotype != null )
		logger.info( "genotype from previous run" );
	else {
		genotype = Genotype.randomInitialGenotype( config );
		logger.info( "random genotype" );
	}

}
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:72,代码来源:Evolver.java


示例12: geneticEventFired

import org.jgap.Genotype; //导入依赖的package包/类
/**
 * @see org.jgap.event.GeneticEventListener#geneticEventFired(org.jgap.event.GeneticEvent)
 */
public void geneticEventFired( GeneticEvent event ) {
	Genotype genotype = (Genotype) event.getSource();
	if ( GeneticEvent.GENOTYPE_EVALUATED_EVENT.equals( event.getEventName() ) )
		addGeneration( genotype );
}
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:9,代码来源:Run.java


示例13: StandardPostSelectorFixed

import org.jgap.Genotype; //导入依赖的package包/类
/**
 * Default constructor.<p>
 * Attention: The configuration used is the one set with the static method
 * Genotype.setConfiguration.
 *
 * @throws InvalidConfigurationException
 *
 * @author Klaus Meffert
 * @since 3.2
 */
public StandardPostSelectorFixed()
    throws InvalidConfigurationException {
  this(Genotype.getStaticConfiguration());
}
 
开发者ID:crisis-economics,项目名称:CRISIS,代码行数:15,代码来源:StandardPostSelectorFixed.java


示例14: MyMutationOperator

import org.jgap.Genotype; //导入依赖的package包/类
/**
 * Constructs a new instance of this MutationOperator without a specified
 * mutation rate, which results in dynamic mutation being turned on. This
 * means that the mutation rate will be automatically determined by this
 * operator based upon the number of genes present in the chromosomes.
 * <p>
 * Attention: The configuration used is the one set with the static method
 * Genotype.setConfiguration.
 *
 * @throws InvalidConfigurationException
 *
 * @author Neil Rotstan
 * @author Klaus Meffert
 * @since 1.0
 */
public MyMutationOperator()
    throws InvalidConfigurationException {
  this(Genotype.getStaticConfiguration());
}
 
开发者ID:ecarlini,项目名称:smartfed,代码行数:20,代码来源:MyMutationOperator.java


示例15: MyCrossoverOperator

import org.jgap.Genotype; //导入依赖的package包/类
/**
 * Constructs a new instance of this CrossoverOperator without a specified
 * crossover rate, this results in dynamic crossover rate being turned off.
 * This means that the crossover rate will be fixed at populationsize/2.<p>
 * Attention: The configuration used is the one set with the static method
 * Genotype.setConfiguration.
 *
 * @throws InvalidConfigurationException
 *
 * @author Chris Knowles
 * @since 2.0
 */
public MyCrossoverOperator()
    throws InvalidConfigurationException {
  super(Genotype.getStaticConfiguration());
  init();
}
 
开发者ID:ecarlini,项目名称:smartfed,代码行数:18,代码来源:MyCrossoverOperator.java


示例16: loadGenotype

import org.jgap.Genotype; //导入依赖的package包/类
/**
 * loads genotype as of latest generation in run
 * @param config
 * @return genotype; null if there is no previous run
 */
public Genotype loadGenotype( Configuration config );
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:7,代码来源:Persistence.java


示例17: addGeneration

import org.jgap.Genotype; //导入依赖的package包/类
/**
 * Add new generation to run.
 * 
 * @param genotype
 */
public void addGeneration( Genotype genotype ) {
	generations.add( new Generation( genotype, currentGenerationNumber++ ) );
}
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:9,代码来源:Run.java



注:本文中的org.jgap.Genotype类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CanScrollVerticallyDelegate类代码示例发布时间:2022-05-22
下一篇:
Java TokenUriInvalidException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap