19 #include "../utility/LogHelper.hpp" 25 int maxNeighbourCount)
26 : mAllObjectRelationsPerPattern(allObjectRelationsPerPattern)
27 , mMaxNeighbourCount(maxNeighbourCount)
29 std::map<std::string, unsigned int> numObjectsPerPattern;
35 unsigned int numRelations = it->second.size();
36 unsigned int numObjects = ((std::sqrt(8 * numRelations + 1) - 1) / 2) + 1;
39 numObjectsPerPattern[it->first] = numObjects;
48 std::vector<std::vector<bool>> filteredNeighours =
filterBitvectors(neighbours, pattern);
49 std::vector<std::vector<bool>> selectedNeighbours =
selectNeighbours(filteredNeighours);
50 std::vector<TopologyPtr> topologies =
convertBitvectors(selectedNeighbours, pattern);
56 std::vector<std::vector<bool>> starBitVectors;
59 unsigned int numObjects = ((std::sqrt(8 * numAllRelations + 1) - 1) / 2) + 1;
61 for (
unsigned int i = 0; i < numObjects; ++i)
63 std::vector<bool> star(numAllRelations, 0);
65 for (
unsigned int j = 0; j < i; ++j) {
66 star[pos + i - (j + 1)] = 1;
67 pos += numObjects - (j + 1);
69 for (
unsigned int k = pos; k < pos + numObjects - 1 - i; ++k) {
72 starBitVectors.push_back(star);
81 std::vector<bool> fullyMeshed(numRelations,
true);
90 std::random_device rd;
91 std::mt19937 eng(rd());
92 std::uniform_int_distribution<unsigned int> dist(0, 1);
94 std::vector<bool> relations(numAllRelations, 0);
97 for (
unsigned int i = 0; i < numAllRelations; i++)
99 relations[i] = dist(eng);
110 if (mMaxNeighbourCount < 0 || mMaxNeighbourCount >= (
int) from.size())
115 bool operator() (
const std::vector<bool> & first,
const std::vector<bool> & second) {
116 return first.size() > second.size();
120 std::sort(from.begin(), from.end(), compare());
122 std::random_device rd;
123 std::mt19937 eng(rd());
124 std::normal_distribution<double> dist(0, from.size() / 2);
126 std::vector<std::vector<bool>> selectedNeighbours;
130 unsigned int randIndex;
132 randIndex = std::abs(dist(eng));
133 }
while (randIndex >= from.size());
135 selectedNeighbours.push_back(from[randIndex]);
136 from.erase(from.begin() + randIndex);
140 return selectedNeighbours;
144 const std::string& pattern)
148 std::ostringstream oss;
149 std::vector<unsigned int> relationIndices;
151 for (
unsigned int i = 0; i < bitvector.size(); ++i)
155 relationIndices.push_back(i);
160 oss <<
"[" << relationIndices[0];
161 for (
unsigned int i = 1; i < relationIndices.size(); ++i)
163 oss <<
", " << relationIndices[i];
168 topology->objectRelations = objectRelations;
169 topology->identifier = oss.str();
174 const std::string& pattern)
177 std::vector<bool> bitvector(numAllRelations, 0);
179 for (ObjectRelations::iterator it = objectRelations.begin(); it != objectRelations.end(); ++it)
181 bitvector[it->first] = 1;
189 const std::string& pattern)
191 std::vector<std::vector<bool>> result;
192 for (
unsigned int i = 0; i < bitvectors.size(); ++i)
196 result.push_back(bitvectors[i]);
204 const std::string& pattern)
206 std::vector<TopologyPtr> result;
207 for (
unsigned int i = 0; i < bitvectors.size(); ++i)
218 std::ostringstream oss;
220 if (neighbours.size() == 0)
222 oss << from->objectRelations <<
"does not have any neighbours" 223 << std::endl << std::endl;
225 oss <<
"Generated " << totalNumber <<
" neighbour topologies of topology\n\n" << from->objectRelations
226 <<
"and selected the following " << neighbours.size() <<
" topologies of those neighbours:\n\n";
228 for (
unsigned int i = 0; i < neighbours.size(); ++i)
230 oss <<
"\t- Topology " << neighbours[i]->identifier << std::endl;
std::vector< TopologyPtr > generateStarTopologies(const std::string &pattern)
std::vector< TopologyPtr > generateNeighbours(const std::string &pattern, TopologyPtr from)
virtual std::vector< std::vector< bool > > calculateNeighbours(const std::string &pattern, std::vector< bool > from)=0
TopologyPtr convertBitvectorToTopology(const std::vector< bool > &bitvector, const std::string &pattern)
static void logLine(LogLevel logLevel=LOG_INFO)
std::vector< std::vector< bool > > selectNeighbours(std::vector< std::vector< bool >> &neighbours)
boost::shared_ptr< ConnectivityChecker > ConnectivityCheckerPtr
std::vector< std::vector< bool > > filterBitvectors(std::vector< std::vector< bool >> bitvectors, const std::string &pattern)
std::map< std::string, unsigned int > mNumRelationsPerPattern
boost::shared_ptr< Topology > TopologyPtr
std::vector< bool > convertTopologyToBitvector(TopologyPtr topology, const std::string &pattern)
static void logMessage(const std::string &message, LogLevel logLevel=LOG_INFO, const char *logColor=LOG_COLOR_DEFAULT)
std::vector< TopologyPtr > convertBitvectors(std::vector< std::vector< bool >> bitvectors, const std::string &pattern)
std::map< std::string, ISM::ObjectRelations > mAllObjectRelationsPerPattern
std::map< unsigned int, ISM::ObjectRelationPtr, std::less< unsigned > > ObjectRelations
ConnectivityCheckerPtr mConnectivityChecker
TopologyPtr generateRandomTopology(const std::string &pattern)
TopologyGenerator(const std::map< std::string, ISM::ObjectRelations > allObjectRelationsPerPattern, int maxNeighbourCount)
void logNeighbourGeneration(const std::vector< TopologyPtr > &neighbours, TopologyPtr from, const unsigned int totalNumber)
TopologyPtr generateFullyMeshedTopology(const std::string &pattern)
this namespace contains all generally usable classes.