AntiGenAbstract.java :  » 6.0-JDK-Modules » Java-Advanced-Imaging » jaimoves » immun » Java Open Source

Java Open Source » 6.0 JDK Modules » Java Advanced Imaging 
Java Advanced Imaging » jaimoves » immun » AntiGenAbstract.java
/*
 * AntiGenAbstract.java
 *
 * Created on 30 kwiecie 2007, 12:33
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package jaimoves.immun;

/**
 *
 * @author Sirius.pl
 */
public class AntiGenAbstract {
    
    /** Creates a new instance of AntiGenAbstract */
    public AntiGenAbstract() {
    }
    
    private double getDigit(AntiBody antibody,int start, int length, boolean sign) {
        int translate = 0;
        for(int i = start; i < start+length-1; i++) {
            if (antibody.getKod().get(i))
                translate += (int) Math.pow((double) 2,(double) i - start);
        }
        if(antibody.getKod().get(start+length-1) && sign) translate = -translate; // odwrocenie
        return (double)translate;
    }
    
//    protected double[] parserAntiBody(AntiBody antibody, double range, int problemSize){
    public double[] parserAntiBody(AntiBody antibody, double range, int problemSize){
        int A[] = new int[problemSize];
        double B[] = new double[problemSize];
        int h = 0;
        int translate = 0;
        int power_lev = 0;
        for (int i = 0; i < antibody.getKod().size(); i++) {
            if (antibody.getKod().get(i)) translate += (int) Math.pow((double) 2,(double) power_lev);
//            System.out.println("TLUMACZENIE " + translate);
            A[h] = translate - (int) Math.pow((double) 2,(double) problemSize-1);
            B[h] = A[h] * range;
            //          System.out.println("TLUMACZENIE do B" + B[h]);
            power_lev++;
            //                int divide = (int)java.lang.Math.floor((antibody.getKod().length()) / A.length);
            int divide = (int)((antibody.getKod().size()) / A.length);
            if(i > divide * (h+1)) {
                h++; translate =0;power_lev = 0;}
        }
        return B;
    }
    
    public double[] patternParserAntiBody(AntiBody antibody, int pattern[],boolean signs){
        double B[] = new double[pattern.length];
        int start = 0;
        for(int i = 0; i < pattern.length; i++) {
            B[i] = getDigit(antibody,start, pattern[i], signs);
            start += pattern[i];
        }
        return B;
    }
    
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.