Repository navigation
Expand file tree
/
Copy pathUtility.h
More file actions
64 lines (48 loc) · 1.47 KB
/
Copy pathUtility.h
File metadata and controls
64 lines (48 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// Created by Malysheva, Nadezhda on 10.07.20.
//
#ifndef ALGO_UTILITY_H
#define ALGO_UTILITY_H
#include <lemon/list_graph.h>
#include <random>
#include "ContactNetwork.h"
template <typename T> size_t binarySearch(std::vector<std::pair<double, T>> propCumSum,
size_t indL, size_t indR, double rStart, double rBound)
{
size_t result = size_t(-1);
if (indR == indL)
{
if (propCumSum.at(indR).first + rStart >= rBound)
{
result = indR;
}
return result;
}
else if (indR > indL)
{
size_t mid = indL + (indR - indL) / 2;
// If the element is present at the middle
// itself
if (propCumSum.at(mid).first + rStart < rBound)
{
return binarySearch(propCumSum, mid + 1, indR, rStart, rBound);
}
// If element is smaller than mid, then
// it can only be present in left subarray
else
{
return binarySearch(propCumSum, indL, mid, rStart, rBound);
}
// Else the element can only be present
// in right subarray
//return binarySearch(propCumSum, mid + 1, indR, rBound);
}
else
{
std::string msg = "BINARY SEARCH ERROR. Right index exceed left index";
throw std::domain_error(msg);
}
}
void printBenFile(std::string fileName, const std::vector<BenStructure> &benToFile);
double sampleRandUni(std::mt19937_64 &generator);
#endif //ALGO_UTILITY_H