| 221 | } |
| 222 | |
| 223 | void BuildDistributionTree(TDistributionTreesData* res, |
| 224 | const TArray2D<TVector<float>>& delayMatrixData) { |
| 225 | Y_ASSERT(delayMatrixData.GetXSize() == delayMatrixData.GetYSize()); |
| 226 | int searcherCount = delayMatrixData.GetXSize(); |
| 227 | |
| 228 | // write median to the delay matrix |
| 229 | TArray2D<float> delayMatrix; |
| 230 | delayMatrix.SetSizes(searcherCount, searcherCount); |
| 231 | delayMatrix.FillZero(); |
| 232 | for (int srcHostId = 0; srcHostId < searcherCount; ++srcHostId) { |
| 233 | for (int dstHostId = 0; dstHostId < searcherCount; ++dstHostId) { |
| 234 | TVector<float> delays = delayMatrixData[srcHostId][dstHostId]; |
| 235 | if (delays.empty()) { |
| 236 | // out of luck, no delay data |
| 237 | delayMatrix[srcHostId][dstHostId] = 0; |
| 238 | continue; |
| 239 | } |
| 240 | std::sort(delays.begin(), delays.end()); |
| 241 | delayMatrix[srcHostId][dstHostId] = delays[delays.ysize() / 2]; |
| 242 | } |
| 243 | } |
| 244 | TVector<TTreeConnectorCost> links; |
| 245 | links.reserve(searcherCount * searcherCount / 2); |
| 246 | for (int srcHostId = 0; srcHostId < searcherCount; ++srcHostId) { |
| 247 | for (int dstHostId = srcHostId + 1; dstHostId < searcherCount; ++dstHostId) { |
| 248 | float delay12 = delayMatrix[srcHostId][dstHostId]; |
| 249 | float delay21 = delayMatrix[dstHostId][srcHostId]; |
| 250 | if (delay12 == 0) |
| 251 | delay12 = delay21; |
| 252 | if (delay21 == 0) |
| 253 | delay21 = delay12; |
| 254 | TTreeConnectorCost tc; |
| 255 | tc.Cost = delay12 + delay21; |
| 256 | tc.Vec1 = srcHostId; |
| 257 | tc.Vec2 = dstHostId; |
| 258 | if (tc.Cost == 0) |
| 259 | tc.Cost = 1e20f; |
| 260 | links.push_back(tc); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | std::sort(links.begin(), links.end(), TTreeConnectorCostCmp()); |
| 265 | |
| 266 | TDistrTree tree100K, tree1M, tree10M, treeBranch6; |
| 267 | ConstructTree(&tree100K, links, searcherCount, 0.001f); // 1ms, 100K packets |
| 268 | ConstructTree(&tree1M, links, searcherCount, 0.01f); |
| 269 | ConstructTree(&tree10M, links, searcherCount, 0.1f); |
| 270 | ConstructTreeLimitBranching(&treeBranch6, links, searcherCount, 6); |
| 271 | EncodeTree(tree100K, &res->Tree100K); |
| 272 | EncodeTree(tree1M, &res->Tree1M); |
| 273 | EncodeTree(tree10M, &res->Tree10M); |
| 274 | EncodeTree(treeBranch6, &res->TreeBranch6); |
| 275 | //TOFStream f("c:/111mptest/tree.txt"); |
| 276 | //PrintTree(f, treeBranch6, 0, hostNames); |
| 277 | } |
| 278 | |
| 279 | void GenerateSubtasks(const TVector<ui16>& src, TVector<TVector<ui16>>* subTasks) { |
| 280 | for (int i = 0; i < src.ysize(); ++i) { |
no test coverage detected