-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallapotgep.cpp
158 lines (136 loc) · 3.57 KB
/
allapotgep.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/**
* \file allapotgep.cpp
*
* Ebben a fájlban kell megvalósítania az Allapotgep osztály
* metódusait, valamint mindazon további osztályokat, melyek szükségesek
* a feladat megvalósításához.
*
* Ezt a fájlt be kell adni (fel kell tölteni) a megoldással.
*/
#include <iostream>
#include <fstream>
#include "allapotgep.h"
#include "memtrace.h"
Matrix::Matrix(int szel, int mag){
sz = szel * 4;
m = mag;
tomb = new int [sz * m];
for (int i = 0; i < sz * m; i++){
tomb[i] = 0;
}
}
Matrix& Matrix::operator=(Matrix const& other){
if (this != &other){
delete[] tomb;
sz = other.sz;
m = other.m;
tomb = new int [sz * m];
for (int i = 0; i < sz * m; i++){
tomb[i] = other.tomb[i];
}
}
return *this;
}
int& Matrix::operator()(int i, int j){
return tomb[i * sz + j];
}
int const& Matrix::operator()(int i, int j) const{
return tomb[i * sz + j];
}
Matrix::~Matrix(){
delete[] tomb;
}
void Allapot::setAllapot(char t, char* allapot){
if (t == 'I')
x = true;
else
x = false;
state = new char [21];
strcpy(state,allapot);
}
char* Allapot::getAllapot(){ return state; }
bool Allapot::getBool(){ return x; }
Allapot::~Allapot(){
delete[] state;
}
void Allapotgep::konfigural(const char* fajlnev){
if (current != nullptr){
delete[] current;
}
std::ifstream file(fajlnev);
if (!file){
throw "X079FB";
}
char temp1;
char temp2[21];
char temp3[5];
file >> alap;
current = new Allapot [alap];
for (int i = 0; i < alap; i++){
file >> temp1;
file >> temp2;
current[i].setAllapot(temp1, temp2);
}
Matrix a(alap, alap);
konfig = a;
allapotszam = 0;
for (int i = 0; i < alap; i++){
for (int j = 0; j < 4*alap; j+=4){
bool ciklus = true;
int f = 0;
file >> temp3;
while (ciklus){
switch(temp3[f]){
case 'A': konfig(i,j) = konfig(i,j) + 1; f++; break;
case 'C': konfig(i,j+1) = konfig(i,j+1) + 2; f++; break;
case 'G': konfig(i,j+2) = konfig(i,j+2) + 3; f++; break;
case 'T': konfig(i,j+3) = konfig(i,j+3) + 4; f++; break;
default: ciklus = false; break;
}
}
}
}
file.close();
}
const char* Allapotgep::aktualisallapot(){
return current[allapotszam].getAllapot();
}
bool Allapotgep::elfogad(){
return current[allapotszam].getBool();
}
void Allapotgep::atmenet(Bazis b){
char bazis = cast(b);
int bazisnum = 0;
switch(bazis){
case 'A': bazisnum += 0; break;
case 'C': bazisnum += 1; break;
case 'G': bazisnum += 2; break;
case 'T': bazisnum += 3; break;
default: break;
}
if (konfig(allapotszam, (allapotszam * 4) + bazisnum) == 0){
int ertek = bazisnum;
if ((allapotszam * 4) + ertek >= 4*alap){
ertek = -(allapotszam * 4);
}
while ((bazisnum+1) != konfig(allapotszam, (allapotszam * 4) + ertek)){
ertek++;
if ((allapotszam * 4) + ertek >= 4*alap){
ertek = -(allapotszam * 4);
}
}
allapotszam += (ertek-bazisnum) / 4;
}
}
bool Allapotgep::feldolgoz(const Bazis *b, int n){
for (int i = 0; i < n; i++){
Allapotgep::atmenet(b[i]);
}
return Allapotgep::elfogad();
}
void Allapotgep::alaphelyzet(){
allapotszam = 0;
}
Allapotgep::~Allapotgep(){
delete[] current;
}