source: cpp/f8-to-f1/conv_f8tof1.h @ 11

Last change on this file since 11 was 1, checked in by Maciej Komosinski, 15 years ago

added f8 (L-systems) representation and converter f8->f1

File size: 4.1 KB
Line 
1/*
2 *  conv_f8tof1.h
3 *  L-systemToF1
4 *
5 *  Created by Maciej Wajcht on 08-03-21.
6 *  Copyright 2008 __MyCompanyName__. All rights reserved.
7 *
8 */
9
10#ifndef _CONV_F8_TO_F1_H
11#define _CONV_F8_TO_F1_H
12
13#include <map>
14#include <vector>
15#include <string>
16#include <list>
17#include <iostream>
18#include "genoconv.h"
19#include "model.h"
20
21using std::ostream;
22using std::vector;
23using std::list;
24using std::string;
25using std::map;
26
27enum RelationType {
28        r_greater,
29        r_greaterEqual,
30        r_less,
31        r_lessEqual,
32        r_equal,
33        r_different
34};
35
36class Condition {
37public:
38        RelationType relation;
39        SString parameter;
40        double value;
41       
42        friend ostream& operator<<(ostream& os, const Condition& c);
43};
44
45class ActionP;
46
47class Action {
48public:
49        SString name;
50        bool ignoreParams;
51        virtual const SString getF1Genotype(vector<double> params) = 0;
52        virtual const list<ActionP> getActionList(const vector<double> params) = 0;
53        virtual const SString getF8Representation() = 0;
54        virtual ~Action() {}
55};
56
57class ActionStrP {
58public:
59        Action *action;
60        vector<SString> params;
61};
62
63class ActionP {
64public:
65        Action *action;
66        vector<double> params;
67};
68
69class SubProduction {
70public:
71        vector<Condition> conditions;
72        vector<ActionStrP> actions;
73};
74
75class PrimitiveProduction : public Action {
76public:
77        PrimitiveProduction(const SString command);
78        const SString getF1Genotype(const vector<double> params);
79        const list<ActionP> getActionList(const vector<double> params);
80        const SString getF8Representation();
81protected:
82        SString f1command;
83        SString f8command;
84};
85
86class ParamProduction : public Action {
87public:
88        ParamProduction(const SString paramName);
89        const SString getF1Genotype(const vector<double> params);
90        const list<ActionP> getActionList(const vector<double> params);
91        const SString getF8Representation();
92protected:
93        SString paramName;
94};
95
96class NeuronProduction : public Action {
97public:
98        NeuronProduction(SString body);
99        const SString getF1Genotype(const vector<double> params);
100        const list<ActionP> getActionList(const vector<double> params);
101        const SString getF8Representation();
102protected:
103        SString body;
104};
105
106/**
107 * Pozycje liczone od 1 a nie od 0!
108 */
109class ParameterCollection {
110public:
111        const double getValue(int position);
112        const double getValue(SString name);
113        const SString getParameterName(int position);
114        const int getParameterPosition(SString name); //zwróci index liczony od 1!
115        void setValue(int position, double value);
116        void setValue(SString name, double value);
117        void addParameter(SString name, int position = -1, double value = 0.0);
118        const int size();
119        void removeParameter(int position);
120        void removeParameter(SString name);
121        bool paramExist(SString name);
122protected:
123        vector<string> parameters;
124        map<string, double> paramValues;
125};
126
127class Production : public Action {
128public:
129        ParameterCollection parameters;
130        vector<SubProduction> subproductions;
131       
132        Production();
133        ~Production() {};
134        const SString getF1Genotype(const vector<double> params);
135        const list<ActionP> getActionList(const vector<double> params);
136        const SString getF8Representation();
137};
138
139class Lsystem {
140public:
141        int iterations;
142        map<string, double> startParams;
143        map<string, Production*> productions;
144        vector<NeuronProduction*> neuronProductions;
145        string firstProductionName;
146       
147        Lsystem();
148        ~Lsystem();
149        PrimitiveProduction* getPrimitiveProduction(SString name);
150        ParamProduction* getParamProduction(SString name);
151        SString toString();
152        vector<Action*> getAllActions(bool normal, bool primitives, bool params, bool neurons);
153protected:
154        map<string, PrimitiveProduction*> primitiveProductions;
155        map<string, ParamProduction*> paramProductions;
156       
157        void removeEmptySubproductionsAndProductions();
158};
159
160class GenoConv_F8ToF1 : public GenoConverter {
161public:
162        GenoConv_F8ToF1() {
163                name = "f8 to f1 converter";
164                in_format = '8';
165                out_format = '1';
166                mapsupport = 0;
167                info = "ble";
168        }
169       
170        ~GenoConv_F8ToF1() {}
171       
172        SString convert(SString &in, MultiMap *map);
173        bool checkSyntax(const char *geno);
174        vector<SString> readProductionNames(const SString &in);
175        //Lsystem* createLsystem(const SString &in);
176        Lsystem* createLsystem(SString in);
177protected:
178        bool parseInput(const char* src, Lsystem* lsys);
179};
180
181#endif
Note: See TracBrowser for help on using the repository browser.