-
Notifications
You must be signed in to change notification settings - Fork 0
/
createIntervals.cpp
53 lines (39 loc) · 1.32 KB
/
createIntervals.cpp
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
#include "dummyinterval.h"
#include "createIntervals.h"
#include <iostream>
// for random
#include <cstdlib>
#include <ctime>
#include <cmath>
createIntervals::createIntervals(int size){
this->size = size;
}
void createIntervals::getIntervals(dummyInterval *intervalArray){
int rand = 0;
std::srand((unsigned int) std::time(NULL));
int counter = 0;
int base = 0;
double overlap_ratio = 0.1; // for high overlap make this close to 0.
for (int i = 0; i < this->size; i ++) {
base = this->size*counter*overlap_ratio;
rand = std::rand() % (this->size + 1);
int r = rand + base;
rand = std::rand() % (this->size + 1);
int l = rand + base;
// swap values to always have (l < r) for each interval
if (l > r) {
int temp = l;
l = r;
r = temp;
}
intervalArray[i] = dummyInterval(l, r);
intervalArray[i].setNameLabel("i"+std::to_string(r));
counter ++;
}
for (int i = 0; i < this->size; i ++) {
std::cout << intervalArray[i].nameLabel() << " ["
<< std::to_string(intervalArray[i].left()) << ", "
<< std::to_string(intervalArray[i].right()) << "]"
<< std::endl;
}
}