Search in sources :

Example 6 with Entry

use of javax.cache.Cache.Entry in project ignite by apache.

the class GAGrid method selectGeneByChromsomeCriteria.

/**
 * method assumes ChromosomeCriteria is set.
 *
 * @param k Gene index in Chromosome
 * @return Primary key of respective Gene
 */
private long selectGeneByChromsomeCriteria(int k) {
    List<Gene> genes = new ArrayList();
    StringBuffer sbSqlClause = new StringBuffer("_val like '");
    sbSqlClause.append("%");
    sbSqlClause.append(config.getChromosomeCriteria().getCriteria().get(k));
    sbSqlClause.append("%'");
    IgniteCache<Long, Gene> cache = ignite.cache(GAGridConstants.GENE_CACHE);
    SqlQuery sql = new SqlQuery(Gene.class, sbSqlClause.toString());
    try (QueryCursor<Entry<Long, Gene>> cursor = cache.query(sql)) {
        for (Entry<Long, Gene> e : cursor) genes.add(e.getValue());
    }
    int idx = selectRandomIndex(genes.size());
    Gene gene = genes.get(idx);
    return gene.id();
}
Also used : Entry(javax.cache.Cache.Entry) SqlQuery(org.apache.ignite.cache.query.SqlQuery) ArrayList(java.util.ArrayList)

Example 7 with Entry

use of javax.cache.Cache.Entry in project ignite by apache.

the class GAGridUtils method getGenesInOrderForChromosome.

/**
 * Retrieve genes in order
 *
 * @param ignite Ignite
 * @param chromosome Chromosome
 * @return List of Genes
 */
public static List<Gene> getGenesInOrderForChromosome(Ignite ignite, Chromosome chromosome) {
    List<Gene> genes = new ArrayList();
    IgniteCache<Long, Gene> cache = ignite.cache(GAGridConstants.GENE_CACHE);
    long[] primaryKeys = chromosome.getGenes();
    for (int k = 0; k < primaryKeys.length; k++) {
        StringBuffer sbSqlClause = new StringBuffer();
        sbSqlClause.append("_key IN ");
        sbSqlClause.append("(");
        sbSqlClause.append(primaryKeys[k]);
        sbSqlClause.append(")");
        SqlQuery sql = new SqlQuery(Gene.class, sbSqlClause.toString());
        try (QueryCursor<Entry<Long, Gene>> cursor = cache.query(sql)) {
            for (Entry<Long, Gene> e : cursor) genes.add(e.getValue());
        }
    }
    return genes;
}
Also used : Entry(javax.cache.Cache.Entry) SqlQuery(org.apache.ignite.cache.query.SqlQuery) Gene(org.apache.ignite.ml.genetic.Gene) ArrayList(java.util.ArrayList)

Aggregations

Entry (javax.cache.Cache.Entry)7 SqlQuery (org.apache.ignite.cache.query.SqlQuery)6 ArrayList (java.util.ArrayList)5 Gene (org.apache.ignite.ml.genetic.Gene)2 HashSet (java.util.HashSet)1 List (java.util.List)1 ScanQuery (org.apache.ignite.cache.query.ScanQuery)1 Chromosome (org.apache.ignite.ml.genetic.Chromosome)1 Test (org.junit.Test)1