-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparserbin.h
More file actions
275 lines (240 loc) · 7.83 KB
/
parserbin.h
File metadata and controls
275 lines (240 loc) · 7.83 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
Pcuda: Simulating P systems with active membranes on the GPU
This simulator is published on:
J.M. Cecilia, J.M. García, G.D. Guerrero, M.A. Martínez-del-Amor, I. Pérez-Hurtado,
M.J. Pérez-Jiménez. Simulation of P systems with active membranes on CUDA,
Briefings in Bioinformatics, 11, 3 (2010), 313-322
Pcuda is a subproject of PMCGPU (Parallel simulators for Membrane
Computing on the GPU)
Copyright (c) 2009 Miguel Á. Martínez-del-Amor (RGNC, University of Seville)
Ginés D. Guerrero (GACOP, University of Murcia)
Chema Cecilia (GACOP, University of Murcia)
Ignacio Pérez-Hurtado (RGNC, University of Seville)
This file is part of Pcuda.
Pcuda is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Pcuda is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Pcuda. If not, see <http://www.gnu.org/licenses/>. */
/**
parserbin.h: Read the binary input file and convert it into structures
for being used on the simulator
Define a class for the parser and the class for configurations of P systems
*/
#ifndef PARSERBIN_H_
#define PARSERBIN_H_
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include "binvalues.h"
#include "multiset.h"
#include "ruleset.h"
#include "membrane.h"
using namespace std;
/******************************************************************/
/* Classes: Configuration, Parserbin */
class Configuration;
/*-----------------------------------------------------------------
* PARSERBIN: Read a binary file and returns a Configuration object
* that stores all the information inside the file
*/
class Parserbin {
private:
Configuration * cfg;
int object_id_size,label_id_size,mmbr_id_size;
bool short_object_mode,short_label_mode,short_mmbr_mode;
/**
read_head: Reads the header, and returns the last 2 Bytes
*/
unsigned int read_header(ifstream& is);
/**
read_alphabet: Reads the alphabet, and returns the number of objects
*/
int read_alphabet(ifstream& is);
/**
read_label_set: Reads the label set, and returns the number of labels
*/
int read_label_set(ifstream& is);
/**
read_membrane_set: Reads the membrane set, and returns the number of membranes
*/
int read_membrane_set(ifstream& is);
/**
read_initial_multiset: Reads the multisets, and returns the number of them
*/
int read_initial_multiset(ifstream& is,uint number_membranes);
/**
read_multiset: Reads a multiset, and returns the number of objects
*/
int read_multiset(ifstream& is, Multiset& multiset, unsigned int alphabet_size);
/**
read_rules: Reads rules depending on the variant, and returns the number them
*/
int read_rules (ifstream& is, int variant, LabelID number_of_labels);
/**
read_evolution_rule: Reads evolution rules, and returns the number them
*/
int read_evolution_rule(ifstream& is);
/**
read_send-in_rule: Reads send-in rules, and returns the number them
*/
int read_sendin_rule(ifstream& is);
/**
read_send-out_rule: Reads send-out rules, and returns the number them
*/
int read_sendout_rule(ifstream& is);
/**
read_disolution_rule: Reads disolution rules, and returns the number them
*/
int read_disolution_rule(ifstream& is);
/**
read_division_rule: Reads division rules, and returns the number them
*/
int read_division_rule(ifstream& is);
public:
Configuration * readfile (const char * file);
};
/*--------------------------------------------------------
* CONFIGURATION: store the configuration of the P system
* specified in the binary file
*/
class Configuration {
friend class Parserbin;
/* Internal data*/
private:
int configuration_number;
unsigned int alphabet_size;
unsigned int label_set_size;
char** alphabet; /* Alphabet of the objects (i.e. a,b,c,...) */
char** label_set; /* All the labels available (i.e. h0,h1,h2,...) */
Multiset* environment;
unsigned int membrane_set_size;
Membrane* skin; /* A pointer to the skin membrane (the head of the tree) */
/* Handle new membrane ids */
MembraneID _next_membrane_id;
/* Auxiliary membrane set */
struct __membrane_slot {
int mother, first_child, next_sister, next_childs_sister;
Membrane * mmbr;
};
typedef struct __membrane_slot Membrane_slot;
Membrane_slot* mmbr_set;
Ruleset *rule_set;
Selectedrulelist *rule_selection;
protected:
Configuration(){
configuration_number=0;
membrane_set_size=0;
_next_membrane_id=0;
skin=NULL;
alphabet=NULL;
label_set=NULL;
rule_set=NULL;
rule_selection=NULL;
environment=NULL;
}
public:
~Configuration () {
/*TODO: delete all the nodes of the membrane tree */
if (skin != NULL)
delete skin;
if (alphabet !=NULL)
delete alphabet;
if (label_set != NULL)
delete label_set;
if (rule_set != NULL)
delete rule_set;
if (rule_selection != NULL)
delete rule_selection;
if (environment != NULL)
delete environment;
}
/* Get values of the configuration */
char** get_alphabet() {
return alphabet;
}
int get_alphabet_size () {
return this->alphabet_size;
}
char** get_labels() {
return label_set;
}
int get_label_set_size() {
return this->label_set_size;
}
Membrane* get_skin() {
return skin;
}
Ruleset* get_rules() {
return rule_set;
}
/************************************/
/* Sets and handle a selection set of rules */
void new_selection() {
if (rule_selection == NULL)
delete rule_selection;
rule_selection=new Selectedrulelist();
}
Selectedrulelist* get_selection() {
return rule_selection;
}
void delete_selection() {
if (rule_selection != NULL)
delete rule_selection;
rule_selection=NULL;
}
/********************************************/
/* Administration of the environment of the configuration */
void new_environment() {
if (environment == NULL)
delete environment;
environment = new Multiset();
}
Multiset * get_environment() {
return environment;
}
void delete_environment() {
if (environment!=NULL)
delete environment;
environment=NULL;
}
/***********************************************/
/* Administration of the membrane ids */
void ini_membrane_id() {
_next_membrane_id=SKIN_ID;
}
MembraneID get_new_membrane_id () {
/*TODO: reuse membrane ids of deleted membranes */
return _next_membrane_id++;
}
int get_number_membranes () {
return membrane_set_size;
}
int increment_number_membranes() {
return ++membrane_set_size;
}
int decrement_number_membranes() {
return --membrane_set_size;
}
/***************************/
/* Administration of the configuration number */
void set_configuration_number (int new_configuration_number) {
configuration_number=new_configuration_number;
}
int get_configuration_number () {
return configuration_number;
}
void increment_configuration_number () {
configuration_number++;
}
/*********************************************/
};
#endif /* PARSERBIN_H_ */