source: cpp/frams/model/similarity/measure-greedy.h @ 1139

Last change on this file since 1139 was 1048, checked in by Maciej Komosinski, 4 years ago

SimilMeasure? -> SimilMeasureBase?; introduced a new class (SimilMeasure?) that allows scripts to access all similarity measures; a number of minor fixes and improvements

File size: 4.2 KB
RevLine 
[1044]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
4
5#ifndef _GREEDY_MEASURE_H
6#define _GREEDY_MEASURE_H
7
8#include "measure-mds-based.h"
9#include "frams/genetics/geno.h"
10#include "frams/model/model.h"
11#include "simil-match.h"
12
13#define TDN_SIZE 5
14
15
16enum TDNELEMS2
17{
18        ORG_IND = 0,
19        DEG = 1,
20        NEUR_CONNS = 2,
21        NEUROS = 3,
22        FUZ_DEG = 4
23};
24
25class SimilMeasureGreedy : public SimilMeasureMDSBased
26{
27public:
28        SimilMeasureGreedy();
29        ~SimilMeasureGreedy(){};
30
31        static int compareDegrees(const void *pElem1, const void *pElem2);
32        static int compareFuzzyDegrees(const void *pElem1, const void *pElem2);
33        static int compareConnsNo(const void *pElem1, const void *pElem2);
34        static int getNOFactors();
35        int setParams(std::vector<double> params);
36        /// Interface to local parameters
37        Param localpar;
38        /// Table of weights for weighted distance function.
39        /// Weights are for factors in the following order:
40        /// [0]: m_iDV (difference in the number of vertices)
41        /// [1]: m_iDD (difference in degrees over matching)
42        /// [2]: m_iDN (difference in neurons over matching)
43        /// [3]: m_dDG (difference in geometry over matching)
44        /// @sa EvaluateDistance
45        double m_adFactors[4];
46
47        //Controls the depth of fuzzy neighbourhood
48        int fuzzyDepth;
49        bool isFuzzy;
50
51protected:
52        double distanceForTransformation();
53        double distanceWithoutAlignment();
54        void prepareData();
55        void beforeTransformation();
56        void computeMatching();
57        void copyMatching();
58        void cleanData();
59
60        int sortPartInfoTables();
61        int countPartNeurons();
62        int countPartDegrees();
63        int countPartsDistance();
64
65        void countFuzzyNeighb();
66        void sortFuzzyNeighb();
67        void getNeighbIndexes(int mod, int partInd, std::vector<int> &indexes);
68        void fuzzyOrder();
69        int createPartInfoTables();
70       
71        void _PrintArray(int *array, int base, int size);
72        void _PrintArrayDouble(double *array, int base, int size);
73        void _PrintDegrees(int i);
74        void _PrintNeighbourhood(int i);
75        void _PrintFuzzyNeighbourhood(int i);
76        void _PrintSeamnessTable(std::vector<int> *pVector, int iCount);
77        void _PrintPartsMatching();
78        void saveIntermediateFiles();
79
80        /// Number of parts of two creatures (index the same as for m_Mod).
81        int m_aiPartCount[2];
82
83        /// Difference between number of parts in organisms
84        int m_iDV;
85
86        /// Sum of absolute values of differences between matched part degrees
87        int m_iDD;
88
89        /// Sum of absolute values of differences between matched part
90        /// in neurons number.
91        int m_iDN;
92        //2 matrices of neighbourhood of parts - one for each genotype
93
94        /// Sum of Euclidean distances between matched parts
95        /// Unmatched Parts have the distance measured to (0,0,0) (the middle of
96        /// an organism)
97        double m_dDG;
98
99        /// Object that holds the matching of Parts.
100        SimilMatching *m_pMatching;
101        /// Object that holds temporary matching of Parts.
102        SimilMatching *tempMatching;
103
104        /// Type of 4 ints - describing one Part of the creature in
105        /// its sorted table of degrees
106        /// TDN[0] - original index of creature's Part (that is "i" from GetPart(i))
107        /// TDN[1] - degree (number of adjacent joints) of one Part
108        /// TDN[2] - number of NeuroConnections and Neurons belonging to one Part
109        /// TDN[3] - number of Neurons of the Part
110        /// TDN[4] - fuzzy degree
111        typedef int TDN[5];
112
113        /** 2 arrays holding information about compared organisms (one for each
114        creature) of degree and neuro info for Parts.
115        Index corresponds to the one in m_Mod
116        m_aDegrees[i][j] is a TDN of the j-th Part of the i-th creature in m_Mod
117        */
118        TDN *m_aDegrees[2];
119
120        //std::pair<TDN, double> *m_aDegrees[2];
121        /// Holds information on all on-joint neurons. Only TDN[3] and TDN[4]
122        /// are important (original index and degree are not important).
123        TDN m_aOnJoint[2];
124
125        /// Holds information on all neurons that are not placed neither on
126        /// a joint nor on a part. Only TDN[3] and TDN[4]
127        /// are important (original index and degree are not important).
128        TDN m_aAnywhere[2];
129
130        //array of parts neighbourhood
131        int **m_Neighbours[2];
132        //array of "fuzzy neigbourhood" for each of organisms. Dimensions: parts_num x fuzzyDepth
133        float **m_fuzzyNeighb[2];
134
135        /// Number of weights in the function which evaluates distance.
136        static const int iNOFactors;
137};
138
139#endif /* GREEDY_MEASURE_H */
140
Note: See TracBrowser for help on using the repository browser.