Fixed Simulator not processing events correctly
Event that is being processed needed to be removed from the queue while its own
process() method ran.
--- a/include/geometry/kinetic-sort.hpp Fri Feb 22 13:06:40 2008 -0500
+++ b/include/geometry/kinetic-sort.hpp Fri Feb 22 18:29:43 2008 -0500
@@ -247,6 +247,6 @@
KineticSort<ElementIterator_, TrajectoryExtractor_, Simulator_, Swap_>::SwapEvent::
operator<<(std::ostream& out) const
{
- Parent::operator<<(out) << ", SwapEvent at " << TrajectoryExtractor_()(position()->element);
+ Parent::operator<<(out) << "SwapEvent at " << TrajectoryExtractor_()(position()->element);
return out;
}
--- a/include/geometry/simulator.h Fri Feb 22 13:06:40 2008 -0500
+++ b/include/geometry/simulator.h Fri Feb 22 18:29:43 2008 -0500
@@ -95,9 +95,13 @@
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
+ {
+ out << "Event with " << root_stack_.size() << " roots";
+ if (!root_stack_.empty()) out << "; top root: " << root_stack_.top();
+ out << ", ";
+ return out;
+ }
private:
RootStack root_stack_;
--- a/include/geometry/simulator.hpp Fri Feb 22 13:06:40 2008 -0500
+++ b/include/geometry/simulator.hpp Fri Feb 22 18:29:43 2008 -0500
@@ -70,8 +70,11 @@
if (e->root_stack().empty()) { reached_infinity_ = true; return; }
else { current_ = e->root_stack().top(); e->root_stack().pop(); }
- if (e->process(this)) update(top);
- else { queue_.pop(); delete e; }
+ // Get the top element out of the queue, put it back depending on what process() says
+ EventQueue tmp; tmp.prepend(top, queue_);
+
+ if (e->process(this)) { queue_.prepend(top, tmp); update(top); }
+ else { delete e; }
}
template<class FuncKernel_, template<class Event> class EventComparison_>
--- a/include/utilities/eventqueue.h Fri Feb 22 13:06:40 2008 -0500
+++ b/include/utilities/eventqueue.h Fri Feb 22 18:29:43 2008 -0500
@@ -34,6 +34,9 @@
void pop() { assert(!empty()); queue_.erase(queue_.begin()); }
void remove(iterator i) { queue_.erase(i); }
void update(iterator i);
+ void prepend(iterator i,
+ EventQueue& other) { queue_.splice(queue_.begin(), other.queue_, i); }
+ ///< intended for temporary storage of elements from other queues
iterator end() { return queue_.end(); }
const_iterator end() const { return queue_.end(); }
--- a/tests/geometry/test-kinetic-sort.cpp Fri Feb 22 13:06:40 2008 -0500
+++ b/tests/geometry/test-kinetic-sort.cpp Fri Feb 22 18:29:43 2008 -0500
@@ -44,7 +44,8 @@
#ifdef LOGGING
rlog::RLogInit(argc, argv);
- //stdoutLog.subscribeTo( RLOG_CHANNEL("geometry/simulator") );
+ stderrLog.subscribeTo( RLOG_CHANNEL("error") );
+ stdoutLog.subscribeTo( RLOG_CHANNEL("geometry/simulator") );
stdoutLog.subscribeTo( RLOG_CHANNEL("geometry/kinetic-sort") );
#endif
@@ -68,12 +69,21 @@
// Setup kinetic sort
KineticSortDS ks(list.begin(), list.end(), boost::bind(swap, &list, _1, _2), &simulator);
- while(!simulator.reached_infinity() && simulator.current_time() < 4)
+ std::cout << "Examining " << simulator;
+
+ while(!simulator.reached_infinity() && simulator.current_time() < 5)
{
std::cout << "Current time before: " << simulator.current_time() << std::endl;
- if (!ks.audit(&simulator)) return 1;
+ //if (!ks.audit(&simulator)) return 1;
+ ks.audit(&simulator);
std::cout << "Examining " << simulator;
simulator.process();
std::cout << "Current time after: " << simulator.current_time() << std::endl;
}
+ ks.audit(&simulator);
+ std::cout << "Examining " << simulator;
+
+ std::cout << "Done at " << simulator.current_time() << std::endl;
+ for (SortDS::const_iterator cur = list.begin(); cur != list.end(); ++cur)
+ std::cout << " " << *cur << std::endl;
}