-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreferencialPositionGraph.cpp
139 lines (114 loc) · 4.08 KB
/
referencialPositionGraph.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
// referencialPositionGraph.cpp
// DNASequenceAlignment
//
// Created by Zihan Qu on 7/7/21.
// Copyright © 2021 Zihan Qu. All rights reserved.
//
#include <stdio.h>
#include "Set.hpp"
using namespace std;
referencialPositionGraph::referencialPositionGraph(priority_queue<Query*, vector<Query*>, queryPrtComp> queryGroups) {
priority_queue<queryPqPtrCompHelper*, vector<queryPqPtrCompHelper*>, queryPqPtrComp> totalQueryGroupPq;
while (queryGroups.size() != 0) {
// Created a check matched pq with type Query*
priority_queue<Query*, vector<Query*>, queryPrtComp> findMatchPq = queryGroups;
findMatchPq.pop();
priority_queue<Query*, vector<Query*>, queryPrtComp> currQueryGroup;
Query *currFirstQuery = queryGroups.top();
while (findMatchPq.size() != 0) {
Query *find = findMatchPq.top();
// If find matched, then removed the corresponding query in the orginal
// priority queue
if (currFirstQuery->checkSameGroup(find) == true) {
// pushed the rest of query, such that A~bs, which is Bs
currQueryGroup.push(find);
queryGroups = remove(find, queryGroups);
}
findMatchPq.pop();
}
// push the first relative query, such that A~Bs, which is A
if (findMatchPq.size() == 0) {
currQueryGroup.push(currFirstQuery);
}
queryPqPtrCompHelper* currPushGroup = new queryPqPtrCompHelper(currQueryGroup);
totalQueryGroupPq.push(currPushGroup);
queryGroups.pop();
}
// Craft the graph
if (totalQueryGroupPq.size() != 0) {
priority_queue<Query*, vector<Query*>,queryPrtComp> topGroup
= totalQueryGroupPq.top()->getPq();
list<Query*> firstGroup;
// Dispose source
while (topGroup.size() != 0) {
firstGroup.push_back(topGroup.top());
topGroup.pop();
}
this->source = firstGroup;
this->mappingList.push_back(firstGroup);
totalQueryGroupPq.pop();
// Dispose middle rest
while (totalQueryGroupPq.size() > 1) {
priority_queue<Query*, vector<Query*>,queryPrtComp> currGroup
= totalQueryGroupPq.top()->getPq();
list<Query*> currList;
while (currGroup.size() != 0) {
currList.push_back(currGroup.top());
currGroup.pop();
}
this->mappingList.push_back(currList);
totalQueryGroupPq.pop();
}
// Dispose sink
priority_queue<Query*, vector<Query*>,queryPrtComp> bottomGroup
= totalQueryGroupPq.top()->getPq();
list<Query*> lastGroup;
while (bottomGroup.size() != 0) {
lastGroup.push_back(bottomGroup.top());
bottomGroup.pop();
}
this->sink = lastGroup;
this->mappingList.push_back(lastGroup);
totalQueryGroupPq.pop();
if (totalQueryGroupPq.size() == 0) {
cout << "Valid" << endl;
}
else {
cout << "Error" << ends;
}
}
}
referencialPositionGraph::~referencialPositionGraph() {
while (mappingList.size() != 0) {
while (mappingList.front().size() != 0) {
delete mappingList.front().front();
mappingList.front().pop_front();
}
}
}
list<list<Query*>> referencialPositionGraph::getMappingList() {
return this->mappingList;
}
list<Query*> referencialPositionGraph::getSource() {
return this->source;
}
list<Query*> referencialPositionGraph::getSink() {
return this->sink;
}
unsigned int referencialPositionGraph::getSourceStartPostion() {
if (this->source.size() != 0) {
return this->source.front()->getReferencePosition();
}
else {
return -1;
}
}
unsigned int referencialPositionGraph::getSinkEndPosition() {
if (this->sink.size() != 0) {
return this->sink.back()->getReferencePosition();
}
else {
return -1;
}
}