Added option to maintain lazy RU-decomposition during transpositions. Plus minor fixes.
authorDmitriy Morozov <morozov@cs.duke.edu>
Mon, 01 Jan 2007 11:45:28 -0500
changeset 11 a0736dd3c671
parent 10 475c019ac1e4
child 12 0239c3f0a598
Added option to maintain lazy RU-decomposition during transpositions. Plus minor fixes.
examples/grid/combustion-vineyard.cpp
include/counter.h
include/filtration.h
include/filtration.hpp
include/lowerstarfiltration.hpp
include/orderlist.hpp
--- a/examples/grid/combustion-vineyard.cpp	Fri Dec 29 18:20:50 2006 -0500
+++ b/examples/grid/combustion-vineyard.cpp	Mon Jan 01 11:45:28 2007 -0500
@@ -3,6 +3,9 @@
  * Department of Computer Science, Duke University, 2005
  */
 
+#include <sys.h>
+#include <debug.h>
+
 #include <iostream>
 #include <fstream>
 #include <algorithm>
--- a/include/counter.h	Fri Dec 29 18:20:50 2006 -0500
+++ b/include/counter.h	Mon Jan 01 11:45:28 2007 -0500
@@ -56,7 +56,7 @@
 		CounterType lookup(const KeyType& key, int num = 0) const
 		{
 #ifdef COUNTERS
-			return ctrs[key][num];
+			return const_cast<KeyMap&>(ctrs)[key][num];
 #endif // COUNTERS
 		}
 };
--- a/include/filtration.h	Fri Dec 29 18:20:50 2006 -0500
+++ b/include/filtration.h	Mon Jan 01 11:45:28 2007 -0500
@@ -62,7 +62,7 @@
 		/// Computes RU decomposition of the simplices in [bg, end) range, assuming that everything before bg has been paired 
 		void 							pair_simplices(Index bg, Index end);
 		void 							pair_simplices()							{ pair_simplices(begin(), end()); }
-		bool							transpose(Index i);
+		bool							transpose(Index i, bool maintain_lazy = true);
 		bool							is_paired() const;
 		Index							append(const Simplex& s);					///< Appends s to the filtration
 		Index							insert(Index prior, const Simplex& s);		///< Inserts s after prior
@@ -80,7 +80,7 @@
 	
 	protected:
 		using 							Parent::swap;
-		bool 							transpose_simplices(Index i);				
+		bool 							transpose_simplices(Index i, bool maintain_lazy);				
 
 	public:
 		/// \name Container Operations
--- a/include/filtration.hpp	Fri Dec 29 18:20:50 2006 -0500
+++ b/include/filtration.hpp	Mon Jan 01 11:45:28 2007 -0500
@@ -1,5 +1,6 @@
 #include "counter.h"
 #include "types.h"
+#include <algorithm>
 
 #include <boost/utility.hpp>
 #include <boost/serialization/vector.hpp>
@@ -74,14 +75,14 @@
 template<class S, class FS, class V>
 bool
 Filtration<S,FS,V>::
-transpose(Index i)
+transpose(Index i, bool maintain_lazy)
 {
 	AssertMsg(vineyard() != 0, "We must have a vineyard for transpositions");
 	
 	Index i_orig = i++;
 	
 	AssertMsg(i_orig->pair() != i, "Transposing simplices must not be paired");
-	bool result = transpose_simplices(i_orig);
+	bool result = transpose_simplices(i_orig, maintain_lazy);
 	AssertMsg(i_orig == boost::next(i), "Wrong indices after transposition");
 	
 	if (result) vineyard()->switched(i, i_orig);
@@ -163,7 +164,7 @@
 template<class S, class FS, class V>
 bool 
 Filtration<S,FS,V>::
-transpose_simplices(Index i)
+transpose_simplices(Index i, bool maintain_lazy)
 {
 	AssertMsg(is_paired(), "Pairing must be computed before transpositions");
 	counters.inc("SimplexTransposition");
@@ -184,11 +185,11 @@
 		Dout(dc::transpositions, "Trail prev: " << i_prev->trail());
 
 		// Case 1
-		TrailIterator i_prev_second = i_prev->trail().get_second(Filtration::get_trails_cmp());
-		if (*i_prev_second == i)
+		TrailIterator i_in_i_prev = std::find(i_prev->trail().begin(), i_prev->trail().end(), i);
+		if (i_in_i_prev != i_prev->trail().end())
 		{
 			Dout(dc::transpositions, "Case 1, U[i,i+1] = 1");
-			i_prev->trail().erase(i_prev_second);
+			i_prev->trail().erase(i_in_i_prev);
 		}
 
 		Index k = i_prev->pair();
@@ -204,7 +205,7 @@
 			return false;
 		} else if (k == i_prev)
 		{
-			if (*(l->cycle().get_second(Filtration::get_cycles_cmp())) != i_prev)
+			if (std::find(l->cycle().begin(), l->cycle().end(), i_prev) == l->cycle().end())
 			{
 				// Case 1.2
 				swap(i_prev, i);
@@ -225,9 +226,18 @@
 		}
 		
 		Dout(dc::transpositions, "l cycle: " << l->cycle());
-		if (*(l->cycle().get_second(Filtration::get_cycles_cmp())) != i_prev)
+		if (std::find(l->cycle().begin(), l->cycle().end(), i_prev) == l->cycle().end())
 		{
 			// Case 1.2
+			if (maintain_lazy)
+			{
+				TrailIterator k_in_l = std::find(l->trail().begin(), l->trail().end(), k);
+				if (k_in_l != l->trail().end())
+				{
+					l->trail().add(k->trail(), Filtration::get_consistency_cmp());		// Add row k to l
+					k->cycle().add(l->cycle(), Filtration::get_consistency_cmp());		// Add column l to k
+				}
+			}
 			swap(i_prev, i);
 			Dout(dc::transpositions, "Case 1.2");
 			counters.inc("Case 1.2");
@@ -259,7 +269,7 @@
 	} else if (!si && !sii)
 	{
 		// Case 2
-		if (*(i_prev->trail().get_second(Filtration::get_trails_cmp())) != i)
+		if (std::find(i_prev->trail().begin(), i_prev->trail().end(), i) == i_prev->trail().end())
 		{
 			// Case 2.2
 			swap(i_prev, i);
@@ -293,9 +303,8 @@
 	} else if (!si && sii)
 	{
 		// Case 3
-		if (*(i_prev->trail().get_second(Filtration::get_trails_cmp())) != i)
+		if (std::find(i_prev->trail().begin(), i_prev->trail().end(), i) == i_prev->trail().end())
 		{
-			//AssertMsg(pair(i)->cycle_get_second(cycles_cmp) != i, dc::transpositions, "Problem in Case 3");
 			// Case 3.2
 			swap(i_prev, i);
 			Dout(dc::transpositions, "Case 3.2");
@@ -317,11 +326,11 @@
 	} else if (si && !sii)
 	{
 		// Case 4
-		TrailIterator i_prev_second = i_prev->trail().get_second(Filtration::get_trails_cmp());
-		if (*i_prev_second == i)
+		TrailIterator i_in_i_prev = std::find(i_prev->trail().begin(), i_prev->trail().end(), i);
+		if (i_in_i_prev != i_prev->trail().end())
 		{
 			Dout(dc::transpositions, "Case 4, U[i,i+1] = 1");
-			i_prev->trail().erase(i_prev_second);
+			i_prev->trail().erase(i_in_i_prev);
 		}
 		swap(i_prev, i);
 		Dout(dc::transpositions, "Case 4");
--- a/include/lowerstarfiltration.hpp	Fri Dec 29 18:20:50 2006 -0500
+++ b/include/lowerstarfiltration.hpp	Mon Jan 01 11:45:28 2007 -0500
@@ -137,7 +137,7 @@
 	assert_pairing(i);
 	assert_pairing(j);
 
-	bool res = Parent::transpose(i);
+	bool res = Parent::transpose(i, false);
 	Dout(dc::lsfiltration, "    " << *j << ": " << *(j->pair()) << ", " << *i << ": " << *(i->pair()));
 
 	assert_pairing(j);
--- a/include/orderlist.hpp	Fri Dec 29 18:20:50 2006 -0500
+++ b/include/orderlist.hpp	Mon Jan 01 11:45:28 2007 -0500
@@ -23,7 +23,7 @@
 {
 	Parent::sort(OrderListNodeComparison<T, BinaryPredicate>(cmp));
 	OrderType cur_order = 0;
-	for (typename Parent::iterator cur = begin(); cur != end(); ++cur)
+	for (typename Parent::iterator cur = Parent::begin(); cur != Parent::end(); ++cur)
 		cur->tag = cur_order++;
 }