Changed PolynomialKernel to FunctionKernel ar
authorDmitriy Morozov <morozov@cs.duke.edu>
Thu, 21 Feb 2008 04:50:09 -0500
branchar
changeset 63 ef9470ed5441
parent 62 0e7554fd0d51
child 64 948be30f1d58
Changed PolynomialKernel to FunctionKernel
include/geometry/kinetic-sort.h
include/geometry/kinetic-sort.hpp
include/geometry/polynomial.h
include/geometry/simulator.h
include/geometry/simulator.hpp
--- a/include/geometry/kinetic-sort.h	Tue Feb 19 09:10:51 2008 -0500
+++ b/include/geometry/kinetic-sort.h	Thu Feb 21 04:50:09 2008 -0500
@@ -11,8 +11,8 @@
  * trajectories given by TrajectoryExtractor_.
  *
  *  \arg ElementIterator_     iterator over the underlying data structure that's kept in sorted order
- *  \arg TrajectoryExtractor_ applied to the iterator into SortDS_ should return a rational 
- *                            function describing the 
+ *  \arg TrajectoryExtractor_ applied to the iterator into SortDS_ should return a function 
+ *                            (of type Simulator_::FunctionKernel::Function) describing the trajectory of the element
  *  \arg Simulator_           the Simulator type, e.g. Simulator. Note that KineticSort does not store 
  *                            a pointer to the Simulator (so a pointer is passed in each relevant operation)
  *  \arg Swap_                is called with an ElementIterator_ when a swap needs to be performed
@@ -25,7 +25,7 @@
 {
 	public:
 		typedef						Simulator_									Simulator;
-		typedef						typename Simulator::PolynomialKernel		PolynomialKernel;
+		typedef						typename Simulator::FunctionKernel		    FunctionKernel;
 		typedef						ElementIterator_							ElementIterator;
 		typedef						Swap_										Swap;
 		typedef						TrajectoryExtractor_						TrajectoryExtractor;
--- a/include/geometry/kinetic-sort.hpp	Tue Feb 19 09:10:51 2008 -0500
+++ b/include/geometry/kinetic-sort.hpp	Thu Feb 21 04:50:09 2008 -0500
@@ -123,7 +123,7 @@
 KineticSort<ElementIterator_, TrajectoryExtractor_, Simulator_, Swap_>::
 audit(Simulator* simulator) const
 {
-	typedef 		typename Simulator::RationalFunction		RationalFunction;
+	typedef 		typename Simulator::Function		        Function;
 	typedef 		typename Simulator::Time					Time;
 	
 	Time t = simulator->audit_time();
@@ -133,18 +133,18 @@
 	
 	typename NodeList::const_iterator next = list_.begin();
 	typename NodeList::const_iterator cur = next++;
-	RationalFunction cur_trajectory = te(cur->element);
+	Function cur_trajectory = te(cur->element);
 	while (next != list_.end())
 	{
 		rLog(rlKineticSortAudit, "  %s", intostring(**(cur->swap_event_key)).c_str());
 
-		RationalFunction next_trajectory = te(next->element);
+		Function next_trajectory = te(next->element);
 		rLog(rlKineticSortAudit, "  Auditing:   %s, %s", tostring(cur_trajectory).c_str(),
                                                          tostring(next_trajectory).c_str());
 		rLog(rlKineticSortAudit, "  Difference: %s", tostring(next_trajectory - cur_trajectory).c_str());
 		rLog(rlKineticSortAudit, "  Sign at:    %s, %s", tostring(t).c_str(),
-                                                         tostring(PolynomialKernel::sign_at(next_trajectory - cur_trajectory, t)).c_str());
-		if (PolynomialKernel::sign_at(next_trajectory - cur_trajectory, t) == -1)
+                                                         tostring(FunctionKernel::sign_at(next_trajectory - cur_trajectory, t)).c_str());
+		if (FunctionKernel::sign_at(next_trajectory - cur_trajectory, t) == -1)
 		{
 			rError("Audit failed at %s, %s", tostring(*cur->element).c_str(), 
                                              tostring(*next->element).c_str());
@@ -164,16 +164,16 @@
 KineticSort<ElementIterator_, TrajectoryExtractor_, Simulator_, Swap_>::
 schedule_swaps(iterator b, iterator e, Simulator* simulator)
 {
-	typedef 		typename Simulator::RationalFunction		RationalFunction;
+	typedef 		typename Simulator::Function		        Function;
 	
 	TrajectoryExtractor	te;
 	
 	iterator next = b; 
 	iterator cur = next++;
-	RationalFunction cur_trajectory = te(cur->element);
+	Function cur_trajectory = te(cur->element);
 	while (next != e)
 	{
-		RationalFunction next_trajectory = te(next->element);
+		Function next_trajectory = te(next->element);
 		rLog(rlKineticSortSchedule, "Next trajectory: %s", tostring(next_trajectory).c_str());
 		// TODO: add assertion that (next_trajectory - cur_trajectory)(s->curren_time()) > 0
 		cur->swap_event_key = simulator->add(next_trajectory - cur_trajectory, SwapEvent(this, cur));
@@ -188,7 +188,7 @@
 KineticSort<ElementIterator_, TrajectoryExtractor_, Simulator_, Swap_>::
 schedule_swaps(iterator i, Simulator* simulator)
 {
-	typedef 		typename Simulator::RationalFunction		RationalFunction;
+	typedef 		typename Simulator::Function		        Function;
 	
 	if (i == list_.end()) return;
 	if (boost::next(i) == list_.end())
@@ -200,8 +200,8 @@
 	TrajectoryExtractor	te;
 	
 	iterator next = boost::next(i); 
-	RationalFunction i_trajectory = te(i->element);
-	RationalFunction next_trajectory = te(next->element);
+	Function i_trajectory = te(i->element);
+	Function next_trajectory = te(next->element);
 	
 	//std::cout << "Updating swaps for: " << i_trajectory << ", " << next_trajectory << std::endl;
 	//std::cout << "Difference:         " << next_trajectory - i_trajectory << std::endl;
--- a/include/geometry/polynomial.h	Tue Feb 19 09:10:51 2008 -0500
+++ b/include/geometry/polynomial.h	Thu Feb 21 04:50:09 2008 -0500
@@ -22,6 +22,7 @@
 	public:
 		typedef						typename SynapsTraits<T>::Polynomial				Polynomial;
 		typedef						RationalFunction<Polynomial>						RationalFunction;
+        typedef                     RationalFunction                                    Function;
 
 		typedef						typename SynapsTraits<T>::Solver					Solver;
 		typedef						typename SynapsTraits<T>::RootType					RootType;
--- a/include/geometry/simulator.h	Tue Feb 19 09:10:51 2008 -0500
+++ b/include/geometry/simulator.h	Thu Feb 21 04:50:09 2008 -0500
@@ -10,20 +10,19 @@
  * Simulator class. Keeps a queue of events. Infinity is reached if the Event 
  * at the front of the queue has an empty root stack. Keeps track of current time, 
  * Event addition, and processes events one by one. Degeneracies are handled by 
- * assuming that the RationalFunction responsible for the event must be positive
- * before the Event occurs.
+ * assuming that the FunctionKernel::Function responsible for the event must be 
+ * positive before the Event occurs.
  *
  * \ingroup kinetic
  */
-template<class PolyKernel_, template<class Event> class EventComparison_ = std::less>
+template<class FuncKernel_, template<class Event> class EventComparison_ = std::less>
 class Simulator
 {
 	public:
-		typedef						PolyKernel_									PolynomialKernel;
-		typedef						typename PolynomialKernel::Polynomial		Polynomial;
-		typedef						typename PolynomialKernel::RationalFunction	RationalFunction;
-		typedef						typename PolynomialKernel::RootStack		RootStack;
-		typedef						typename PolynomialKernel::RootType			RootType;
+		typedef						FuncKernel_								    FunctionKernel;
+		typedef						typename FunctionKernel::Function	        Function;
+		typedef						typename FunctionKernel::RootStack		    RootStack;
+		typedef						typename FunctionKernel::RootType			RootType;
 		typedef						RootType									Time;
 
 		class Event;
@@ -34,7 +33,7 @@
 		typedef						typename EventQueue::const_iterator			const_Key;
 
 
-									Simulator(Time start = PolynomialKernel::root(0)):
+									Simulator(Time start = FunctionKernel::root(0)):
 										current_(start), 
 										reached_infinity_(false)				{}
 
@@ -42,9 +41,9 @@
 		template<class Event_> 
 		Key							add(const Event_& e);
 		template<class Event_> 
-		Key							add(const RationalFunction& f, const Event_& e);
+		Key							add(const Function& f, const Event_& e);
 		void						process();
-		void						update(Key k, const RationalFunction& f);
+		void						update(Key k, const Function& f);
 		
 		void						remove(Key k)								{ queue_.remove(k); }
 		Key							null_key() 									{ return queue_.end(); }
@@ -70,15 +69,17 @@
  * Event with an empty root stack compares greater than any other Event, 
  * pushing those events to the end of the queue.
  */
-template<class PolyKernel_, template<class Event> class EventComparison_>
-class Simulator<PolyKernel_, EventComparison_>::Event
+template<class FuncKernel_, template<class Event> class EventComparison_>
+class Simulator<FuncKernel_, EventComparison_>::Event
 {
 	public:
-		typedef						PolyKernel_									PolynomialKernel;
-		typedef						typename PolynomialKernel::RootStack		RootStack;
+		typedef						FuncKernel_									FunctionKernel;
+		typedef						typename FunctionKernel::RootStack		    RootStack;
 
+        /// process() is called when the event is at the top of the queue 
+        /// in the simulator.
 		/// Returns true if the event needs to remain in the Simulator 
-		/// (top of the root_stack() will be used for new time)
+		/// (top of the root_stack() will be used for new time).
 		virtual	bool				process(Simulator* s) const					=0;
 		
 		RootStack&					root_stack()								{ return root_stack_; }
@@ -94,7 +95,9 @@
 				return root_stack().top() < e.root_stack().top();
 		}
 
-		virtual std::ostream&		operator<<(std::ostream& out) const				{ return out << "Event with " << root_stack_.size() << " roots"; }
+		virtual std::ostream&		operator<<(std::ostream& out) const			{ return out << "Event with " 
+                                                                                             << root_stack_.size() 
+                                                                                             << " roots"; }
 
 	private:
 		RootStack					root_stack_;
--- a/include/geometry/simulator.hpp	Tue Feb 19 09:10:51 2008 -0500
+++ b/include/geometry/simulator.hpp	Thu Feb 21 04:50:09 2008 -0500
@@ -11,26 +11,26 @@
 #endif // COUNTERS
 
 
-template<class PolyKernel_, template<class Event> class EventComparison_>
+template<class FuncKernel_, template<class Event> class EventComparison_>
 template<class Event_>
-typename Simulator<PolyKernel_, EventComparison_>::Key
-Simulator<PolyKernel_, EventComparison_>::
+typename Simulator<FuncKernel_, EventComparison_>::Key
+Simulator<FuncKernel_, EventComparison_>::
 add(const Event_& e)
 {
 	Event* ee = new Event_(e);
 	return queue_.push(ee);
 }
 
-template<class PolyKernel_, template<class Event> class EventComparison_>
+template<class FuncKernel_, template<class Event> class EventComparison_>
 template<class Event_>
-typename Simulator<PolyKernel_, EventComparison_>::Key
-Simulator<PolyKernel_, EventComparison_>::
-add(const RationalFunction& f, const Event_& e)
+typename Simulator<FuncKernel_, EventComparison_>::Key
+Simulator<FuncKernel_, EventComparison_>::
+add(const Function& f, const Event_& e)
 {
 	Event* ee = new Event_(e);
 	rLog(rlSimulator, "Solving: %s", tostring(f).c_str());
-	PolynomialKernel::solve(f, ee->root_stack());
-	bool sign = PolynomialKernel::sign_at_negative_infinity(f);
+	FunctionKernel::solve(f, ee->root_stack());
+	bool sign = FunctionKernel::sign_at_negative_infinity(f);
 	while (!ee->root_stack().empty() && ee->root_stack().top() < current_time())
 	{
 		ee->root_stack().pop();
@@ -41,22 +41,22 @@
 	return queue_.push(ee);
 }
 		
-template<class PolyKernel_, template<class Event> class EventComparison_>
+template<class FuncKernel_, template<class Event> class EventComparison_>
 void
-Simulator<PolyKernel_, EventComparison_>::
-update(Key k, const RationalFunction& f)
+Simulator<FuncKernel_, EventComparison_>::
+update(Key k, const Function& f)
 {
 	Event* ee = *k;
 	ee->root_stack() = RootStack();								// no clear() in std::stack
-	PolynomialKernel::solve(f, ee->root_stack());
+	FunctionKernel::solve(f, ee->root_stack());
 	while (!ee->root_stack().empty() && ee->root_stack().top() < current_time())
 		ee->root_stack().pop();
 	update(k);
 }
 
-template<class PolyKernel_, template<class Event> class EventComparison_>
+template<class FuncKernel_, template<class Event> class EventComparison_>
 void
-Simulator<PolyKernel_, EventComparison_>::
+Simulator<FuncKernel_, EventComparison_>::
 process()
 {
     Count(cSimulatorProcess);
@@ -71,45 +71,45 @@
 	else								{ queue_.pop(); delete e; }
 }
 
-template<class PolyKernel_, template<class Event> class EventComparison_>
+template<class FuncKernel_, template<class Event> class EventComparison_>
 void
-Simulator<PolyKernel_, EventComparison_>::
+Simulator<FuncKernel_, EventComparison_>::
 update(Key i)
 {
 	queue_.update(i);
 }
 		
-template<class PolyKernel_, template<class Event> class EventComparison_>
-typename Simulator<PolyKernel_, EventComparison_>::Time
-Simulator<PolyKernel_, EventComparison_>::
+template<class FuncKernel_, template<class Event> class EventComparison_>
+typename Simulator<FuncKernel_, EventComparison_>::Time
+Simulator<FuncKernel_, EventComparison_>::
 audit_time() const
 {
 	const_Key top = queue_.top();
 	Event* e = *top;
 
 	if (e->root_stack().empty()) return current_ + 1;
-	else return PolynomialKernel::between(e->root_stack().top(), current_);
+	else return FunctionKernel::between(e->root_stack().top(), current_);
 }
 		
-template<class PolyKernel_, template<class Event> class EventComparison_>
+template<class FuncKernel_, template<class Event> class EventComparison_>
 std::ostream&
-Simulator<PolyKernel_, EventComparison_>::
+Simulator<FuncKernel_, EventComparison_>::
 operator<<(std::ostream& out) const
 {
 	out << "Simulator: " << std::endl;
 	return queue_.print(out, "  ");
 }
 
-template<class PolyKernel_, template<class Event> class EventComparison_>
+template<class FuncKernel_, template<class Event> class EventComparison_>
 std::ostream&
-operator<<(std::ostream& out, const Simulator<PolyKernel_, EventComparison_>& s)
+operator<<(std::ostream& out, const Simulator<FuncKernel_, EventComparison_>& s)
 {
     return s.operator<<(out);
 }
 
-template<class PolyKernel_, template<class Event> class EventComparison_>
+template<class FuncKernel_, template<class Event> class EventComparison_>
 std::ostream&
-operator<<(std::ostream& out, const typename Simulator<PolyKernel_, EventComparison_>::Event& e)
+operator<<(std::ostream& out, const typename Simulator<FuncKernel_, EventComparison_>::Event& e)
 {
     return e.operator<<(out);
 }