25 mAllObjectTypes(pAllObjectTypes), mMaxNeighbourCount(pMaxNeighbourCount), mRemoveRelations(pRemoveRelations), mSwapRelations(pSwapRelations)
35 std::cout <<
"-----------------------------------------------------------" << std::endl;
36 std::cout <<
"Generating neighbours (c indicates connectedness): ";
40 std::vector<std::vector<bool>> selectedNeighbours;
42 for (std::vector<bool> i: neighbours)
46 if (bit) std::cout <<
"1";
47 else std::cout <<
"0";
52 selectedNeighbours.push_back(i);
56 std::cout << std::endl;
60 std::cout <<
"Found " << selectedNeighbours.size() <<
" neighbours, maximum is " <<
mMaxNeighbourCount <<
". Selecting random neighbours." << std::endl;
63 throw std::runtime_error(
"In TopologyCreator: number of randomly selected neighbours (" + boost::lexical_cast<std::string>(selectedNeighbours.size()) +
") was not equal to maximum.");
65 std::vector<boost::shared_ptr<Topology>> result;
66 std::cout <<
"Selected neighbours: ";
67 for (std::vector<bool> i: selectedNeighbours)
71 if (bit) std::cout <<
"1";
72 else std::cout <<
"0";
77 std::cout << std::endl;
78 std::cout <<
"-----------------------------------------------------------" << std::endl;
85 std::vector<boost::shared_ptr<Topology>> result;
87 std::vector<std::vector<bool>> starBitVectors;
89 unsigned int numAllRelations = (numObjects - 1) * numObjects / 2;
91 for (
unsigned int i = 0; i < numObjects; ++i)
93 std::vector<bool> star(numAllRelations, 0);
95 for (
unsigned int j = 0; j < i; ++j) {
96 star[pos + i - (j + 1)] = 1;
97 pos += numObjects - (j + 1);
99 for (
unsigned int k = pos; k < pos + numObjects - 1 - i; ++k) {
102 starBitVectors.push_back(star);
105 for (std::vector<bool> starBitVector: starBitVectors)
114 std::vector<bool> bitvector((numObjects - 1) * numObjects / 2,
true);
122 unsigned int numAllRelations = (numAllObjects - 1) * numAllObjects / 2;
124 std::random_device rd;
125 std::mt19937 eng(rd());
126 std::uniform_int_distribution<unsigned int> dist(0, 1);
128 std::vector<bool> relations(numAllRelations, 0);
131 for (
unsigned int i = 0; i < numAllRelations; i++) relations[i] = dist(eng);
140 std::vector<boost::shared_ptr<Topology>> result;
142 result.push_back(fullyMeshed);
143 std::cout <<
"Trying to reach all possible topologies from the fully meshed one." << std::endl;
144 std::vector<boost::shared_ptr<SceneModel::Topology>> neighboursToVisit;
145 neighboursToVisit.push_back(fullyMeshed);
146 std::vector<std::string> seenNeighbourIDs;
147 seenNeighbourIDs.push_back(fullyMeshed->mIdentifier);
148 unsigned int visitedCounter = 0;
149 while(!neighboursToVisit.empty())
152 neighboursToVisit.erase(neighboursToVisit.begin());
154 std::cout <<
"Generating neighbours of topology " << from->mIdentifier <<
":";
155 std::vector<boost::shared_ptr<SceneModel::Topology>> newNeighbours =
generateNeighbours(from);
156 unsigned int uniqueCounter = 0;
159 std::cout <<
" " << newNeighbour->mIdentifier;
160 if (std::find(seenNeighbourIDs.begin(), seenNeighbourIDs.end(), newNeighbour->mIdentifier) == seenNeighbourIDs.end())
163 neighboursToVisit.push_back(newNeighbour);
164 seenNeighbourIDs.push_back(newNeighbour->mIdentifier);
165 result.push_back(newNeighbour);
169 std::cout << std::endl << newNeighbours.size() <<
" neighbours found. " << uniqueCounter <<
" not yet visited." << std::endl;
170 std::cout <<
"===================================================" << std::endl;
173 std::cout <<
"Done." << std::endl;
174 std::cout <<
"Visited " << visitedCounter <<
" topologies in total." << std::endl;
175 std::cout <<
"===================================================" << std::endl;
185 bool operator() (
const std::vector<bool> & first,
const std::vector<bool> & second) {
186 return first.size() > second.size();
190 std::sort(pNeighbours.begin(), pNeighbours.end(), compare());
192 std::random_device rd;
193 std::mt19937 eng(rd());
194 std::normal_distribution<double> dist(0, pNeighbours.size() / 2);
196 std::vector<std::vector<bool>> selectedNeighbours;
200 unsigned int randIndex;
202 randIndex = std::abs(dist(eng));
203 }
while (randIndex >= pNeighbours.size());
205 selectedNeighbours.push_back(pNeighbours[randIndex]);
206 pNeighbours.erase(pNeighbours.begin() + randIndex);
210 return selectedNeighbours;
216 std::vector<boost::shared_ptr<Relation>> relations;
217 unsigned int bitvectorindex = 0;
218 for (
unsigned int i = 0; i < numObjectTypes - 1; i++)
221 for (
unsigned int j = i + 1; j < numObjectTypes; j++)
224 if (pBitvector[bitvectorindex])
227 relations.push_back(newRelation);
233 result->mRelations = relations;
235 std::string identifier =
"";
236 for (
bool bit: pBitvector)
238 if (bit) identifier +=
"1";
239 else identifier +=
"0";
241 result->mIdentifier = identifier;
248 unsigned int numAllRelations = (numObjectTypes - 1) * numObjectTypes / 2;
249 std::vector<bool> result = std::vector<bool>(numAllRelations,
false);
250 std::map<std::string, unsigned int> indicesByTypes;
251 for (
unsigned int i = 0; i < numObjectTypes; i++)
254 std::vector<boost::shared_ptr<Relation>> relations = pTopology->mRelations;
257 std::string typeA = relation->getObjectTypeA();
258 std::string typeB = relation->getObjectTypeB();
259 unsigned int indexA = indicesByTypes[typeA];
260 unsigned int indexB = indicesByTypes[typeB];
261 unsigned int indexMin = std::min(indexA, indexB);
262 unsigned int indexMax = std::max(indexA, indexB);
263 unsigned int bitvectorindex = indexMin * numObjectTypes - indexMin * (indexMin + 1) / 2 + (indexMax - indexMin) - 1;
264 result[bitvectorindex] =
true;
272 std::vector<std::vector<bool>> neighbours;
273 std::vector<unsigned int> ones;
274 std::vector<unsigned int> zeros;
276 for (
unsigned int i = 0; i < pFrom.size(); ++i)
286 std::vector<bool> neighbour;
290 for (
unsigned int i = 0; i < ones.size(); ++i)
293 neighbour[ones[i]] = 0;
294 neighbours.push_back(neighbour);
298 for (
unsigned int i = 0; i < zeros.size(); ++i)
302 neighbour[zeros[i]] = 1;
303 neighbours.push_back(neighbour);
308 for (
unsigned int j = 0; j < ones.size(); ++j)
311 neighbour[zeros[i]] = 1;
312 neighbour[ones[j]] = 0;
313 neighbours.push_back(neighbour);
boost::shared_ptr< Topology > generateFullyMeshedTopology()
boost::shared_ptr< Topology > generateRandomTopology()
boost::shared_ptr< Topology > convertBitvectorToTopology(const std::vector< bool > &pBitvector)
std::vector< boost::shared_ptr< Topology > > generateNeighbours(boost::shared_ptr< Topology > pFrom)
std::vector< std::vector< bool > > calculateNeighbours(std::vector< bool > pFrom)
std::vector< bool > convertTopologyToBitvector(boost::shared_ptr< Topology > pTopology)
unsigned int mMaxNeighbourCount
std::vector< std::string > mAllObjectTypes
boost::shared_ptr< ConnectivityChecker > mConnectivityChecker
TopologyCreator(const std::vector< std::string > &pAllObjectTypes, unsigned int pMaxNeighbourCount, bool pRemoveRelations, bool pSwapRelations)
std::vector< boost::shared_ptr< Topology > > generateStarTopologies()
std::vector< std::vector< bool > > selectRandomNeighbours(std::vector< std::vector< bool >> &pNeighbours)
std::vector< boost::shared_ptr< Topology > > generateAllConnectedTopologies()