01: /*
02: * AntiGenAbstract.java
03: *
04: * Created on 30 kwiecie 2007, 12:33
05: *
06: * To change this template, choose Tools | Template Manager
07: * and open the template in the editor.
08: */
09:
10: package jaimoves.immun;
11:
12: /**
13: *
14: * @author Sirius.pl
15: */
16: public class AntiGenAbstract {
17:
18: /** Creates a new instance of AntiGenAbstract */
19: public AntiGenAbstract() {
20: }
21:
22: private double getDigit(AntiBody antibody, int start, int length,
23: boolean sign) {
24: int translate = 0;
25: for (int i = start; i < start + length - 1; i++) {
26: if (antibody.getKod().get(i))
27: translate += (int) Math.pow((double) 2, (double) i
28: - start);
29: }
30: if (antibody.getKod().get(start + length - 1) && sign)
31: translate = -translate; // odwrocenie
32: return (double) translate;
33: }
34:
35: // protected double[] parserAntiBody(AntiBody antibody, double range, int problemSize){
36: public double[] parserAntiBody(AntiBody antibody, double range,
37: int problemSize) {
38: int A[] = new int[problemSize];
39: double B[] = new double[problemSize];
40: int h = 0;
41: int translate = 0;
42: int power_lev = 0;
43: for (int i = 0; i < antibody.getKod().size(); i++) {
44: if (antibody.getKod().get(i))
45: translate += (int) Math.pow((double) 2,
46: (double) power_lev);
47: // System.out.println("TLUMACZENIE " + translate);
48: A[h] = translate
49: - (int) Math.pow((double) 2,
50: (double) problemSize - 1);
51: B[h] = A[h] * range;
52: // System.out.println("TLUMACZENIE do B" + B[h]);
53: power_lev++;
54: // int divide = (int)java.lang.Math.floor((antibody.getKod().length()) / A.length);
55: int divide = (int) ((antibody.getKod().size()) / A.length);
56: if (i > divide * (h + 1)) {
57: h++;
58: translate = 0;
59: power_lev = 0;
60: }
61: }
62: return B;
63: }
64:
65: public double[] patternParserAntiBody(AntiBody antibody,
66: int pattern[], boolean signs) {
67: double B[] = new double[pattern.length];
68: int start = 0;
69: for (int i = 0; i < pattern.length; i++) {
70: B[i] = getDigit(antibody, start, pattern[i], signs);
71: start += pattern[i];
72: }
73: return B;
74: }
75:
76: }
|