Open GoogleCodeExporter opened 9 years ago
Thanks for your report. We have fixed this problem and are ready to push the
change very shortly. Right now, I will paste the update code in below:
int backtrace(const vector<int> &F, int idx) {
while (F[idx] != idx) {
idx = F[idx];
}
return idx;
}
/*
* A and B encode pairwise equivalences on a cardinality N set whose elements
* are indexed by 0, 1, 2, ..., N-1.
*
* For example A[i] = 6 and B[i] = 0 indicates that the 6 and 0 are to be
* grouped into the same equivalence class.
*
* We return the weakest equivalence relation implied by A and B in an array
* F of length N; F[i] holds the smallest index of all the elements that
* i is equivalent to.
*/
vector<int> compute_equival_classes(const int &n, const vector<int> &A,
const vector<int> &B) {
// Each element maps to itself
vector<int> F(n);
iota(F.begin(), F.end(), 0);
for (int i = 0; i < A.size(); ++i) {
int a = backtrace(F, A[i]), b = backtrace(F, B[i]);
a < b ? F[b] = a : F[a] = b;
}
// Generate the weakest equivalence relation
for (int &f : F) {
while (f != F[f]) {
f = F[f];
}
}
return F;
}
If you have any problem or comments, please feel free to contact us.
Tsung-Hsien
Original comment by TsungHsi...@gmail.com
on 9 Apr 2013 at 6:14
in the for loop you are still assuming that B.size() = A.size() aren't you?
for (int i = 0; i < A.size(); ++i) { // here why A.size() ?
int a = backtrace(F, A[i]), b = backtrace(F, B[i]);
a < b ? F[b] = a : F[a] = b;
}
Original comment by tplee...@gmail.com
on 21 Apr 2013 at 8:55
we are assuming that B.size() = A.size() because these arrays encode pairs of
elements that are taken to be equivalent.
you can take a look at the new wording of the problem which may help (it's
attached as a PNG)
thank you for your taking the trouble to write to us, we appreciate your
feedback. please write to us (directly or via google code) whenever you need
clarifications or have suggestions (like the one above)
cheers,
adnan
Original comment by adnan.a...@gmail.com
on 22 Apr 2013 at 4:34
Attachments:
Original issue reported on code.google.com by
fuban...@gmail.com
on 9 Apr 2013 at 6:05