当前位置: 首页>>代码示例>>Java>>正文


Java Configuration类代码示例

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


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

示例1: useGeneticOperators

import org.jgap.Configuration; //导入依赖的package包/类
/**
 * Applies all GeneticOperators registered with the Configuration. The
 * chromosomes created by the operators are collected in a new Population
 * instance, which is returned.
 * 
 * @param a_config
 *            the configuration to use
 * @param a_pop
 *            the population to use as input
 * @return a new Population instance containing the new Chromosomes
 * 
 * @author Klaus Meffert
 * @author Tamas Mahr
 * @since 3.2
 */
@SuppressWarnings("rawtypes")
protected Population useGeneticOperators(Configuration a_config, Population a_pop) {
	try {
		Population newGeneration = new Population(a_config, a_pop.size());

		List geneticOperators = a_config.getGeneticOperators();
		Iterator operatorIterator = geneticOperators.iterator();
		while (operatorIterator.hasNext()) {
			GeneticOperator operator = (GeneticOperator) operatorIterator.next();
			/**@todo utilize jobs: integrate job into GeneticOperator*/
			operator.operate(a_pop, newGeneration.getChromosomes());
		}

		return newGeneration;
	} catch (InvalidConfigurationException e){
		// should never happen
		throw new IllegalStateException(e);
	}
}
 
开发者ID:crisis-economics,项目名称:CRISIS,代码行数:35,代码来源:DashboardBreeder.java

示例2: MyCrossoverOperator

import org.jgap.Configuration; //导入依赖的package包/类
/**
 * Constructs a new instance of this CrossoverOperator with the given
 * crossover rate.
 *
 * @param a_configuration the configuration to use
 * @param a_desiredCrossoverRate the desired rate of crossover
 * @param a_allowFullCrossOver true: x-over before AND after x-over point,
 * false: only x-over after x-over point
 * @throws InvalidConfigurationException
 * @param a_xoverNewAge true: also x-over chromosomes with age of zero (newly
 * created chromosomes)
 *
 * @author Klaus Meffert
 * @since 3.3.2
 */
public MyCrossoverOperator(final Configuration a_configuration,
                         final int a_desiredCrossoverRate,
                         final boolean a_allowFullCrossOver,
                         final boolean a_xoverNewAge)
    throws InvalidConfigurationException {
  super(a_configuration);
  if (a_desiredCrossoverRate < 1) {
    throw new IllegalArgumentException("Crossover rate must be greater zero");
  }
  m_crossoverRate = a_desiredCrossoverRate;
  m_crossoverRatePercent = -1;
  setCrossoverRateCalc(null);
  setAllowFullCrossOver(a_allowFullCrossOver);
  setXoverNewAge(a_xoverNewAge);
}
 
开发者ID:ecarlini,项目名称:smartfed,代码行数:31,代码来源:MyCrossoverOperator.java

示例3: main

import org.jgap.Configuration; //导入依赖的package包/类
/**
 * @param args
 * @throws Exception
 */
public static void main( String[] args ) throws Exception {
	System.out.println( Copyright.STRING );
	if ( args.length < 2 )
		System.err
				.println( "usage: <cmd> <properties-file> <chromosome1-id> [<chromosome2-id> <chromosome3-id> ...]" );

	Properties props = new Properties( args[ 0 ] );
	IdentifyImageFitnessFunction iiff = new IdentifyImageFitnessFunction();
	iiff.init( props );
	FilePersistence db = new FilePersistence();
	db.init( props );

	Configuration config = new DummyConfiguration();
	ArrayList chroms = new ArrayList();
	for ( int i = 1; i < args.length; ++i ) {
		Chromosome chrom = db.loadChromosome( args[ i ], config );
		chroms.add( chrom );
	}
	int fitness = ( chroms.size() > 1 ) ? iiff.evaluateEnsemble( chroms ) : iiff
			.evaluate( (Chromosome) chroms.get( 0 ) );
	System.out
			.println( "fitness = " + fitness + " / " + IdentifyImageFitnessFunction.MAX_FITNESS );
}
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:28,代码来源:EvaluateImageIdentifier.java

示例4: genotypeFromRunXml

import org.jgap.Configuration; //导入依赖的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

示例5: reproduce

import org.jgap.Configuration; //导入依赖的package包/类
/**
 * Crossover according to <a
 * href="http://nn.cs.utexas.edu/downloads/papers/stanley.ec02.pdf">NEAT </a> crossover
 * methodology.
 * 
 * @param config
 * @param dominantChrom dominant parent
 * @param recessiveChrom recessive parent
 * @return ChromosomeMaterial offspring
 */
protected ChromosomeMaterial reproduce( Configuration config, Chromosome dominantChrom,
		Chromosome recessiveChrom ) {
	ChromosomeMaterial child = dominantChrom.cloneMaterial();
	child.setSecondaryParentId( recessiveChrom.getId() );

	Iterator iter = child.getAlleles().iterator();
	while ( iter.hasNext() ) {
		Allele allele = (Allele) iter.next();
		if ( allele instanceof ConnectionAllele ) {
			ConnectionAllele dominantConnectionAllele = (ConnectionAllele) allele;
			ConnectionAllele recessiveConnectionAllele = (ConnectionAllele) recessiveChrom
					.findMatchingGene( dominantConnectionAllele );
			if ( recessiveConnectionAllele != null ) {
				// TODO blending?
				if ( config.getRandomGenerator().nextBoolean() )
					dominantConnectionAllele.setWeight( recessiveConnectionAllele.getWeight() );
			}
		}
	}

	return child;
}
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:33,代码来源:NeatCrossoverReproductionOperator.java

示例6: mutate

import org.jgap.Configuration; //导入依赖的package包/类
/**
 * Removes, in ascending order of weight magnitude, those connections whose weight magnitude is
 * less than the maximum weight to be removed. Maximum number of connections that can be removed
 * is determined by mutation rate.
 * 
 * @param jgapConfig must be <code>NeatConfiguration</code>
 * @param target chromosome material to mutate
 * @param allelesToAdd <code>Set</code> contains <code>Allele</code> objects
 * @param allelesToRemove <code>Set</code> contains <code>Allele</code> objects
 * @see org.jgap.MutationOperator#mutate(org.jgap.Configuration, org.jgap.ChromosomeMaterial,
 * java.util.Set, java.util.Set)
 */
protected void mutate( Configuration jgapConfig, final ChromosomeMaterial target,
		Set allelesToAdd, Set allelesToRemove ) {
	if ( ( jgapConfig instanceof NeatConfiguration ) == false )
		throw new AnjiRequiredException( "com.anji.neat.NeatConfiguration" );
	NeatConfiguration config = (NeatConfiguration) jgapConfig;
	List allConns = NeatChromosomeUtility.getConnectionList( target.getAlleles() );

	if ( Strategy.SMALL.equals( strategy ) )
		mutateSmall( config, allConns, allelesToRemove );
	else if ( Strategy.ALL.equals( strategy ) )
		mutateAll( config, allConns, allelesToRemove );
	else if ( Strategy.SKEWED.equals( strategy ) )
		mutateSkewed( config, allConns, allelesToRemove );
	else
		throw new IllegalStateException( "invalid remove connection operator strategy: " + strategy );
}
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:29,代码来源:RemoveConnectionMutationOperator.java

示例7: mutate

import org.jgap.Configuration; //导入依赖的package包/类
/**
 * Adds connections according to <a
 * href="http://nn.cs.utexas.edu/downloads/papers/stanley.ec02.pdf">NEAT </a> add connection
 * mutation.
 * 
 * @param jgapConfig
 * @param target chromosome material to mutate
 * @param allelesToAdd <code>Set</code> contains <code>Allele</code> objects
 * @param allelesToRemove <code>Set</code> contains <code>Allele</code> objects
 * @see org.jgap.MutationOperator#mutate(org.jgap.Configuration, org.jgap.ChromosomeMaterial,
 * java.util.Set, java.util.Set)
 */
protected void mutate( Configuration jgapConfig, final ChromosomeMaterial target,
		Set allelesToAdd, Set allelesToRemove ) {
	if ( ( jgapConfig instanceof NeatConfiguration ) == false )
		throw new AnjiRequiredException( "com.anji.neat.NeatConfiguration" );
	NeatConfiguration config = (NeatConfiguration) jgapConfig;

	// connection can mutate between any 2 neurons, excluding those neurons already removed
	List neuronList = NeatChromosomeUtility.getNeuronList( target.getAlleles() );
	SortedMap conns = NeatChromosomeUtility.getConnectionMap( target.getAlleles() );

	// Determine # neurons to add and iterate randomly through alleles ...
	int maxConnectionsToAdd = ( neuronList.size() * neuronList.size() ) - conns.size();
	int numConnectionsToAdd = numMutations( config.getRandomGenerator(), maxConnectionsToAdd );

	addConnections( numConnectionsToAdd, config, neuronList, conns, allelesToAdd );
}
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:29,代码来源:AddConnectionMutationOperator.java

示例8: mutate

import org.jgap.Configuration; //导入依赖的package包/类
/**
 * Adds connections according to <a
 * href="http://nn.cs.utexas.edu/downloads/papers/stanley.ec02.pdf">NEAT </a> add node mutation.
 * @see org.jgap.MutationOperator#mutate(org.jgap.Configuration, org.jgap.ChromosomeMaterial,
 * java.util.Set, java.util.Set)
 */
protected void mutate( Configuration jgapConfig, final ChromosomeMaterial target,
		Set allelesToAdd, Set allelesToRemove ) {
	if ( ( jgapConfig instanceof NeatConfiguration ) == false )
		throw new AnjiRequiredException( "com.anji.neat.NeatConfiguration" );
	NeatConfiguration config = (NeatConfiguration) jgapConfig;

	Map neurons = NeatChromosomeUtility.getNeuronMap( target.getAlleles() );

	// neuron can be mutated on any connection
	List connList = NeatChromosomeUtility.getConnectionList( target.getAlleles() );
	Collections.shuffle( connList, config.getRandomGenerator() );

	int numConnections = numMutations( config.getRandomGenerator(), connList.size() );
	Iterator iter = connList.iterator();
	int count = 0;
	while ( iter.hasNext() && ( count++ < numConnections ) ) {
		ConnectionAllele oldConnectAllele = (ConnectionAllele) iter.next();
		addNeuronAtConnection( config, neurons, oldConnectAllele, allelesToAdd, allelesToRemove );
	}
}
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:27,代码来源:AddNeuronMutationOperator.java

示例9: apply

import org.jgap.Configuration; //导入依赖的package包/类
public IChromosome apply (IChromosome firstMate, IChromosome secondMate, RandomGenerator generator, Configuration config) throws InvalidConfigurationException
{
	Gene[] rgGenes = new Gene[m_nElementPerOperand];
	for (int i = 0; i < m_nElementPerOperand; i++)
		rgGenes[i] = new IntegerGene (config, 0, 2 * m_nElementPerOperand - 1);
	
	int[] rgOpConfig = new int[m_mapSelectors.size ()];

	int nIdx = 0;
	for (int nID : m_listIDs)
	{
		List<Selector> list = m_mapSelectors.get (nID);
		rgOpConfig[nIdx] = generator.nextInt (list.get (0).getArgsCount ());
		for (Selector s : list)
			rgGenes[s.getIndex ()].setAllele (s.getResult (firstMate, secondMate, rgOpConfig[nIdx], m_nElementPerOperand));
		nIdx++;
	}
	
	List<Operand> listParent = new ArrayList<> (2);
	listParent.add ((Operand) firstMate.getApplicationData ());
	if (m_nOperandsCount >= 2)
		listParent.add ((Operand) secondMate.getApplicationData ());

	IChromosome c = new Chromosome (config, rgGenes);
	c.setApplicationData (new Operand (null, null, listParent, this, rgOpConfig));
	return c;
}
 
开发者ID:matthias-christen,项目名称:patus,代码行数:28,代码来源:PermutatorGenetic.java

示例10: getSelector

import org.jgap.Configuration; //导入依赖的package包/类
public NaturalSelector getSelector(final Configuration config) throws InvalidConfigurationException {
	final BestChromosomesSelector selector = new BestChromosomesSelector(config,model.getValue() / 100.0);
	selector.setDoubletteChromosomesAllowed(false);
	//selector.setDoubletteChromosomesAllowed(doubletteCheckBox.isSelected());
	
	return selector;
}
 
开发者ID:crisis-economics,项目名称:CRISIS,代码行数:8,代码来源:BestChromosomeSelectorConfigurator.java

示例11: IdentifiableLongGene

import org.jgap.Configuration; //导入依赖的package包/类
public IdentifiableLongGene(final String id, final Configuration a_config, final long lowerBound, final long upperBound) throws InvalidConfigurationException {
	super(a_config);
	Preconditions.checkNotNull(id);
	this.id = id;
	this.lowerBound = lowerBound;
	this.upperBound = upperBound;
}
 
开发者ID:crisis-economics,项目名称:CRISIS,代码行数:8,代码来源:IdentifiableLongGene.java

示例12: getSelector

import org.jgap.Configuration; //导入依赖的package包/类
public NaturalSelector getSelector(final Configuration config) throws InvalidConfigurationException {
		final int size = (Integer) tournamentSizeModel.getValue();
		final double probability = selectionProbabilityModel.getValue() / 100.0;
		final TournamentSelector selector = new TournamentSelector(config,size,probability);
//		selector.setDoubletteChromosomesAllowed(doubletteCheckBox.isSelected());
		
		return selector;
	}
 
开发者ID:crisis-economics,项目名称:CRISIS,代码行数:9,代码来源:TournamentSelectorConfigurator.java

示例13: EliteTournamentCrossoverer

import org.jgap.Configuration; //导入依赖的package包/类
public EliteTournamentCrossoverer( Configuration aConfig, float elitismRate, int tournamentSize )
		throws InvalidConfigurationException {
	super( aConfig );
	m_chromosomes = new Vector<IChromosome>();
	m_needsSorting = false;
	m_fitnessValueComparator = new FitnessValueComparator();
	random = getConfiguration().getRandomGenerator();
	this.elitismRate = elitismRate;
	this.tournamentSize = tournamentSize;
}
 
开发者ID:adamchainz,项目名称:sound-resynthesis,代码行数:11,代码来源:EliteTournamentCrossoverer.java

示例14: IntegerAllele

import org.jgap.Configuration; //导入依赖的package包/类
/**
 * Constructs a new IntegerGene with the given active configuration and the specified lower and
 * upper bounds for values represented by this Gene.
 * 
 * @param a_activeConfiguration The current active configuration.
 * @param a_lowerBounds The lowest value that this Gene may represent, inclusive.
 * @param a_upperBounds The highest value that this Gene may represent, inclusive.
 */
public IntegerAllele( Configuration a_activeConfiguration, int a_lowerBounds, int a_upperBounds ) {
	super( new Gene( ( a_activeConfiguration == null ) ? new Long( 0 ) : a_activeConfiguration
			.nextInnovationId() ) );
	m_activeConfiguration = a_activeConfiguration;
	m_lowerBounds = a_lowerBounds;
	m_upperBounds = a_upperBounds;
	calculateBoundsUnitsToIntegerUnitsRatio();
}
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:17,代码来源:IntegerAllele.java

示例15: select

import org.jgap.Configuration; //导入依赖的package包/类
/**
 * Returns the <code>a_howManyToSelect</code> chromosomes with highest speciated fitness.
 * @param a_activeConfiguration
 * @param a_howManyToSelect
 * @return <code>List</code> contains <code>Chromosome</code> objects
 */
protected List select( Configuration a_activeConfiguration, int a_howManyToSelect ) {
	Collections.sort( chromosomes, 
		new ChromosomeFitnessComparator( false /* asc */, true /* speciated fitness*/ ) );
	List result = new ArrayList( a_howManyToSelect );
	Iterator it = chromosomes.iterator();
	while ( it.hasNext() && ( result.size() < a_howManyToSelect ) )
		result.add( it.next() );
	return result;
}
 
开发者ID:nezbo,项目名称:neat4speed2,代码行数:16,代码来源:SimpleSelector.java


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