[286] | 1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
| 2 | // Copyright (C) 1999-2015 Maciej Komosinski and Szymon Ulatowski. |
---|
| 3 | // See LICENSE.txt for details. |
---|
[109] | 4 | |
---|
| 5 | #ifndef _MULTIMAP_H_ |
---|
| 6 | #define _MULTIMAP_H_ |
---|
| 7 | |
---|
| 8 | #include "multirange.h" |
---|
| 9 | |
---|
| 10 | class SingleMapping |
---|
| 11 | { |
---|
[733] | 12 | public: |
---|
| 13 | SingleMapping(int b, const MultiRange& t) :begin(b), to(t) {} |
---|
| 14 | SingleMapping(int b) :begin(b) {} |
---|
| 15 | SingleMapping(const SingleMapping& sm) :begin(sm.begin), to(sm.to) {} |
---|
| 16 | int begin; |
---|
| 17 | MultiRange to; |
---|
[109] | 18 | }; |
---|
| 19 | |
---|
| 20 | /** MultiMap - used for conversion mapping. |
---|
[733] | 21 | Read about how mappings work: http://www.framsticks.com/files/common/GeneticMappingsInArtificialGenomes.pdf |
---|
| 22 | see @ref convmap |
---|
| 23 | */ |
---|
[109] | 24 | class MultiMap |
---|
| 25 | { |
---|
[733] | 26 | /** list of (SingleMapping*) */ |
---|
| 27 | SList data; |
---|
[109] | 28 | |
---|
[733] | 29 | SingleMapping* getData(int i) const { return (SingleMapping*)data(i); } |
---|
| 30 | void addData(int i, SingleMapping* mapping) { data.insert(i, (void*)mapping); } |
---|
| 31 | void removeData(int i) { data.remove(i); } |
---|
| 32 | int findData(int x) const; |
---|
| 33 | int getBegin(int i) const { return getData(i)->begin; } |
---|
[109] | 34 | |
---|
[733] | 35 | // addRangeXXX return the shift for range numbers > r |
---|
| 36 | int addRange(int &r, const MultiRange& mr); |
---|
| 37 | // value of 'r' is adjusted according to its range number change |
---|
| 38 | int addRangeBeginEnd(int &r, int begin, int end, const MultiRange& mr); |
---|
[109] | 39 | |
---|
[733] | 40 | public: |
---|
| 41 | MultiMap() {} |
---|
| 42 | MultiMap(const MultiMap& mm) { operator=(mm); } |
---|
| 43 | ~MultiMap(); |
---|
| 44 | void operator=(const MultiMap& mm); |
---|
[109] | 45 | |
---|
[733] | 46 | void clear(); |
---|
| 47 | int isEmpty() const { return data.size() == 0; } |
---|
| 48 | int mappingCount() const { return data.size(); } |
---|
| 49 | SingleMapping* getMapping(int i) const { return (SingleMapping*)getData(i); } |
---|
| 50 | int findMappingId(int x) const { return findData(x); } |
---|
| 51 | int rangeCount() const { return isEmpty() ? 0 : data.size() - 1; } |
---|
| 52 | IRange getRange(int i) const; |
---|
[109] | 53 | |
---|
[733] | 54 | int getBegin() const; |
---|
| 55 | int getEnd() const; |
---|
[109] | 56 | |
---|
[733] | 57 | void add(const IRange& from, const IRange& to) { add(from.begin, from.end, MultiRange(to)); } |
---|
| 58 | void add(const IRange& from, const MultiRange& to) { add(from.begin, from.end, to); } |
---|
| 59 | void add(int from1, int from2, int to1, int to2) { add(from1, from2, MultiRange(to1, to2)); } |
---|
| 60 | void add(int from1, int from2, const MultiRange& to); |
---|
| 61 | void add(const MultiRange& from, const MultiRange& to); |
---|
| 62 | void add(const MultiMap& mm); |
---|
| 63 | void addCombined(const MultiMap& m1, const MultiMap& m2); |
---|
| 64 | void addReversed(const MultiMap& mm); |
---|
[109] | 65 | |
---|
[733] | 66 | const MultiRange& map(int x) const; |
---|
| 67 | MultiRange map(int begin, int end) const; |
---|
| 68 | MultiRange map(const IRange& range) const { return map(range.begin, range.end); } |
---|
| 69 | MultiRange map(const MultiRange& ranges) const; |
---|
[109] | 70 | |
---|
[733] | 71 | void print() const; |
---|
| 72 | void print2() const; |
---|
[109] | 73 | }; |
---|
| 74 | |
---|
| 75 | #endif |
---|