Skip to content

Commit 071a819

Browse files
committed
Added function for first descendant
1 parent 9f7beea commit 071a819

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

highs/ipm/hipo/auxiliary/Auxiliary.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,22 @@ double getDiagStart(Int n, Int k, Int nb, Int n_blocks, std::vector<Int>& start,
265265
return result;
266266
}
267267

268+
void firstDescendant(const std::vector<Int>& parent, std::vector<Int>& first) {
269+
// Given an elimination tree, find the first descendant of each node, i.e.
270+
// given a node j, first[j] is the descendant of j with smallest number.
271+
272+
const Int n = parent.size();
273+
first.assign(n, -1);
274+
275+
for (Int i = 0; i < n; ++i) {
276+
Int j = i;
277+
while (j != -1 && first[j] == -1) {
278+
first[j] = i;
279+
j = parent[j];
280+
}
281+
}
282+
}
283+
268284
Clock::Clock() { start(); }
269285
void Clock::start() { t0 = std::chrono::high_resolution_clock::now(); }
270286
double Clock::stop() const {

highs/ipm/hipo/auxiliary/Auxiliary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void processEdge(Int j, Int i, const std::vector<Int>& first,
3737
std::vector<Int>& prevleaf, std::vector<Int>& ancestor);
3838
double getDiagStart(Int n, Int k, Int nb, Int n_blocks, std::vector<Int>& start,
3939
bool triang = false);
40+
void firstDescendant(const std::vector<Int>& parent, std::vector<Int>& first);
4041

4142
template <typename T>
4243
void permuteVector(std::vector<T>& v, const std::vector<Int>& perm) {

0 commit comments

Comments
 (0)