From 1a6ec4e8b4b71ef36cf81bea6e42abbc8610f1ac Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 9 Mar 2012 06:06:17 -0600 Subject: Fixed the way adjacency_list was being used --- src/history.h | 90 +++-------------------------------------------------------- 1 file changed, 4 insertions(+), 86 deletions(-) (limited to 'src/history.h') diff --git a/src/history.h b/src/history.h index 63550ff5..920feec6 100644 --- a/src/history.h +++ b/src/history.h @@ -60,79 +60,12 @@ namespace ledger { typedef std::map price_map_t; -template -class recent_edge_weight -{ -public: - EdgeWeightMap weight; - PricePointMap price_point; - PriceRatioMap ratios; - - datetime_t reftime; - optional oldest; - - recent_edge_weight() { } - recent_edge_weight(EdgeWeightMap _weight, - PricePointMap _price_point, - PriceRatioMap _ratios, - datetime_t _reftime, - const optional& _oldest = none) - : weight(_weight), price_point(_price_point), ratios(_ratios), - reftime(_reftime), oldest(_oldest) { } - - template - bool operator()(const Edge& e) const - { -#if defined(DEBUG_ON) - DEBUG("history.find", " reftime = " << reftime); - if (oldest) { - DEBUG("history.find", " oldest = " << *oldest); - } -#endif - - const price_map_t& prices(get(ratios, e)); - if (prices.empty()) { - DEBUG("history.find", " prices map is empty for this edge"); - put(weight, e, std::numeric_limits::max()); - return false; - } - - price_map_t::const_iterator low = prices.upper_bound(reftime); - if (low != prices.end() && low == prices.begin()) { - DEBUG("history.find", " don't use this edge"); - put(weight, e, std::numeric_limits::max()); - return false; - } else { - --low; - assert(((*low).first <= reftime)); - - if (oldest && (*low).first < *oldest) { - DEBUG("history.find", " edge is out of range"); - put(weight, e, std::numeric_limits::max()); - return false; - } - - long secs = (reftime - (*low).first).total_seconds(); - assert(secs >= 0); - - put(weight, e, secs); - put(price_point, e, price_point_t((*low).first, (*low).second)); - - DEBUG("history.find", " using edge at price point " - << (*low).first << " " << (*low).second); - return true; - } - } -}; - class commodity_history_t : public noncopyable { public: typedef adjacency_list - ::vertex_descriptor vertex_descriptor; typedef graph_traits::edge_descriptor edge_descriptor; - typedef property_map::type NameMap; - typedef property_map::type IndexMap; - + typedef property_map::type NameMap; typedef property_map::type EdgeWeightMap; typedef property_map::type PricePointMap; typedef property_map::type PriceRatioMap; - IndexMap indexmap; PricePointMap pricemap; PriceRatioMap ratiomap; - typedef filtered_graph > FGraph; - - typedef property_map::type FNameMap; - typedef property_map::type FIndexMap; - typedef iterator_property_map FPredecessorMap; - typedef iterator_property_map FDistanceMap; - commodity_history_t() - : indexmap(get(vertex_index, price_graph)), - pricemap(get(edge_price_point, price_graph)), + : pricemap(get(edge_price_point, price_graph)), ratiomap(get(edge_price_ratio, price_graph)) {} void add_commodity(commodity_t& comm); -- cgit v1.2.3