friend inline value_type get(const global_index_map& gim, const key_type& x) { using boost::get; return (*gim.starting_index)[get(gim.global, x).first] + get(gim.index_map, x); }
void update(MoveableValueRef v) #endif { using boost::get; size_type index = get(index_in_heap, v); assert(index <= data.size()); preserve_heap_property_up(GRAEHL_D_ARY_FORWARD_REF(v), index, get(distance, v)); verify_heap(); }
void push_or_update(Value const& v) #endif { using boost::get; size_type index = get(index_in_heap, v); if (contains(v, index)) preserve_heap_property_up(GRAEHL_D_ARY_FORWARD_REF(v), index, get(distance, v)); else push(GRAEHL_D_ARY_FORWARD_REF(v)); }
distance_type second_best(distance_type null = 0) const { if (data.size() < 2) return null; int m = std::min(data.size(), Arity + 1); distance_type b = get(distance, data[1]); for (int i = 2; i < m; ++i) { distance_type d = get(distance, data[i]); if (better(d, b)) b = d; } return b; }
inline void swap(ArrayBinaryTreeNode x, ExternalData& edata ) { using boost::get; value_type tmp = x.value(); /*swap external data*/ edata[ get(id, tmp) ] = i; edata[ get(id, value()) ] = x.i; x.value() = value(); value() = tmp; i = x.i; }
virtual boost::any get(const any& key) { #if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 95) return boost::get(property_map, any_cast<key_type>(key)); #else using boost::get; return get(property_map, any_cast<key_type>(key)); #endif }
void tree_edge(Edge e, const Graph& g) { using boost::get; m_decreased = relax(e, g, m_weight, m_predecessor, m_distance, m_combine, m_compare); if(m_decreased) { m_vis.edge_relaxed(e, g); put(m_cost, target(e, g), m_combine(get(m_distance, target(e, g)), m_h(target(e, g)))); } else m_vis.edge_not_relaxed(e, g); }
virtual std::string get_string(const any& key) { #if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 95) std::ostringstream out; out << boost::get(property_map, any_cast<key_type>(key)); return out.str(); #else using boost::get; std::ostringstream out; out << get(property_map, any_cast<key_type>(key)); return out.str(); #endif }
void black_target(Edge e, const Graph& g) { using boost::get; m_decreased = relax(e, g, m_weight, m_predecessor, m_distance, m_combine, m_compare); if(m_decreased) { m_vis.edge_relaxed(e, g); put(m_cost, target(e, g), m_combine(get(m_distance, target(e, g)), m_h(target(e, g)))); m_Q.push(target(e, g)); put(m_color, target(e, g), Color::gray()); m_vis.black_target(e, g); } else m_vis.edge_not_relaxed(e, g); }
void push(MoveableValueRef v) #endif { size_type index = data.size(); if (index) { #if GRAEHL_CPP11 data.emplace_back(); #else data.push_back(Value()); // (hoping default construct is cheap, construct-copy inline) #endif preserve_heap_property_up(GRAEHL_D_ARY_FORWARD_REF(v), index, get(distance, v)); // we don't have to recopy v, or init index_in_heap verify_heap(); } else { put(index_in_heap, v, 0); #if GRAEHL_CPP11 data.emplace_back(GRAEHL_D_ARY_FORWARD_REF(v)); #else data.push_back(v); // (hoping default construct is cheap, construct-copy inline) #endif } }
int test_main(int,char**) { // build property maps using associative_property_map std::map<std::string, int> string2int; std::map<double,std::string> double2string; boost::associative_property_map< std::map<std::string, int> > int_map(string2int); boost::associative_property_map< std::map<double, std::string> > dbl_map(double2string); // add key-value information string2int["one"] = 1; string2int["five"] = 5; double2string[5.3] = "five point three"; double2string[3.14] = "pi"; // build and populate dynamic interface boost::dynamic_properties properties; properties.property("int",int_map); properties.property("double",dbl_map); using boost::get; using boost::put; using boost::type; // Get tests { BOOST_CHECK(get("int",properties,std::string("one")) == "1"); #ifndef BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS BOOST_CHECK(boost::get<int>("int",properties,std::string("one")) == 1); #endif BOOST_CHECK(get("int",properties,std::string("one"), type<int>()) == 1); BOOST_CHECK(get("double",properties,5.3) == "five point three"); } // Put tests { put("int",properties,std::string("five"),6); BOOST_CHECK(get("int",properties,std::string("five")) == "6"); put("int",properties,std::string("five"),std::string("5")); #ifndef BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS BOOST_CHECK(get<int>("int",properties,std::string("five")) == 5); #endif BOOST_CHECK(get("int",properties,std::string("five"),type<int>()) == 5); put("double",properties,3.14,std::string("3.14159")); BOOST_CHECK(get("double",properties,3.14) == "3.14159"); put("double",properties,3.14,std::string("pi")); #ifndef BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS BOOST_CHECK(get<std::string>("double",properties,3.14) == "pi"); #endif BOOST_CHECK(get("double",properties,3.14,type<std::string>()) == "pi"); } // Nonexistent property { try { get("nope",properties,3.14); BOOST_ERROR("No exception thrown."); } catch (boost::dynamic_get_failure&) { } try { put("nada",properties,3.14,std::string("3.14159")); BOOST_ERROR("No exception thrown."); } catch (boost::property_not_found&) { } } // Nonexistent property gets generated { boost::dynamic_properties props(&string2string_gen); put("nada",props,std::string("3.14"),std::string("pi")); BOOST_CHECK(get("nada",props,std::string("3.14")) == "pi"); } return boost::exit_success; }
bool colored_edges_test() { std::cout << "colored_edges_test()" << std::endl; typedef boost::property<alps::edge_type_t,unsigned int> edge_props; typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, boost::no_property, edge_props> graph_type; typedef boost::graph_traits<graph_type>::edge_descriptor edge_descriptor; typedef boost::property_map<graph_type,alps::edge_type_t>::type edge_color_map_type; graph_type g(4); { edge_color_map_type edge_color = get(alps::edge_type_t(),g); edge_descriptor e; e = add_edge(0, 1, g).first; edge_color[e] = 0; e = add_edge(1, 2, g).first; edge_color[e] = 0; e = add_edge(2, 3, g).first; edge_color[e] = 0; e = add_edge(0, 3, g).first; edge_color[e] = 0; } graph_type h(g); { edge_descriptor e = edge(2,3,h).first; get(alps::edge_type_t(),h)[e] = 1; } graph_type i(g); { edge_descriptor e = edge(2,3,i).first; get(alps::edge_type_t(),i)[e] = 2; } graph_type j(h); { edge_descriptor e = edge(2,3,j).first; get(alps::edge_type_t(),j)[e] = 1; } graph_type k(g); { edge_color_map_type edge_color = get(alps::edge_type_t(),k); edge_descriptor e; e = edge( 0, 1, k).first; edge_color[e] = 1; e = edge( 1, 2, k).first; edge_color[e] = 1; e = edge( 2, 3, k).first; edge_color[e] = 1; e = edge( 0, 3, k).first; edge_color[e] = 1; } alps::graph::graph_label<graph_type>::type label_g(get<1>(canonical_properties(g))); alps::graph::graph_label<graph_type>::type label_h(get<1>(canonical_properties(h))); alps::graph::graph_label<graph_type>::type label_i(get<1>(canonical_properties(i))); alps::graph::graph_label<graph_type>::type label_j(get<1>(canonical_properties(j))); alps::graph::graph_label<graph_type>::type label_k(get<1>(canonical_properties(k))); std::cout<<label_g<<std::endl; std::cout<<label_h<<std::endl; std::cout<<label_i<<std::endl; std::cout<<label_j<<std::endl; std::cout<<label_k<<std::endl; std::cout<<std::boolalpha<<(label_g == label_h)<<std::endl; std::cout<<std::boolalpha<<(label_h == label_i)<<std::endl; std::cout<<std::boolalpha<<(label_h == label_j)<<std::endl; std::cout<<std::boolalpha<<(label_g == label_k)<<std::endl; return true; }
void examine_edge(Edge e, const Graph& g) { if (m_compare(get(m_weight, e), m_zero)) BOOST_THROW_EXCEPTION(negative_edge()); m_vis.examine_edge(e, g); }
int main() { using boost::get; using boost::put; using alps::graph::canonical_properties; typedef unsigned int lc_type; typedef boost::property<alps::edge_type_t,alps::type_type> edge_props; typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,boost::no_property,edge_props> graph_type; typedef alps::graph_helper<>::vertex_iterator vertex_iterator; typedef alps::graph_helper<>::edge_iterator edge_iterator; alps::Parameters parm; unsigned int side_length = 40; std::ifstream in("../../lib/xml/lattices.xml"); parm["LATTICE"] = "coupled ladders"; parm["L"] = side_length; parm["L"] = side_length; alps::graph_helper<> lattice(in,parm); graph_type lattice_graph(num_vertices(lattice.graph())); boost::graph_traits<alps::graph_helper<>::graph_type>::edge_iterator it, et; for(boost::tie(it, et) = edges(lattice.graph()); it != et; ++it) { boost::graph_traits<graph_type>::edge_descriptor e = add_edge(source(*it, lattice.graph()), target(*it, lattice.graph()), lattice_graph).first; if(get(alps::edge_type_t(),lattice.graph(),*it) == 1) put(alps::edge_type_t(), lattice_graph, e, 1); else put(alps::edge_type_t(), lattice_graph, e, 0); } std::vector<std::pair<graph_type,lc_type> > g; boost::graph_traits<graph_type>::edge_descriptor e; // edge color 0 ... // edge color 1 ___ // 0...1 g.push_back(std::make_pair(graph_type(), 3)); e = add_edge(0, 1, g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); // 0___1 g.push_back(std::make_pair(graph_type(), 1)); e = add_edge(0, 1, g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); // 0...1 // | | // 2...3 // g.push_back(std::make_pair(graph_type(), 1)); e = add_edge(0, 1, g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(1, 3, g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); e = add_edge(3, 2, g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(2, 0, g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); // // 0...1 // : : // 2...3 // g.push_back(std::make_pair(graph_type(), 1)); e = add_edge(0, 1, g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(1, 3, g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(3, 2, g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(2, 0, g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); // // 0...1 // . | // 2___3 // g.push_back(std::make_pair(graph_type(), 0)); e = add_edge(0, 1, g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(1, 3, g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); e = add_edge(3, 2, g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); e = add_edge(2, 0, g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); // // 1...0...2 // g.push_back(std::make_pair(graph_type(),6)); e = add_edge(0, 1,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(0, 2,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); // // 1...0___2 // g.push_back(std::make_pair(graph_type(),6)); e = add_edge(0, 1,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(0, 2,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); // // 1___0___2 // g.push_back(std::make_pair(graph_type(),0)); e = add_edge(0, 1,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); e = add_edge(0, 2,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); // // 1___0___2...3 // g.push_back(std::make_pair(graph_type(),0)); e = add_edge(0, 1,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); e = add_edge(0, 2,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); e = add_edge(2, 3,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); // // 3___1...0___2 // g.push_back(std::make_pair(graph_type(),3)); e = add_edge(0, 1,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(0, 2,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); e = add_edge(1, 3,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); // // 3...1___0...2 // g.push_back(std::make_pair(graph_type(),9)); e = add_edge(0, 1,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); e = add_edge(0, 2,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(1, 3,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); // // 3...1...0___2 // g.push_back(std::make_pair(graph_type(),12)); e = add_edge(0, 1,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(0, 2,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); e = add_edge(1, 3,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); // 4 // : // 3___1...0___2 // g.push_back(std::make_pair(graph_type(),12)); e = add_edge(0, 1,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(0, 2,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); e = add_edge(1, 3,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); e = add_edge(0, 4,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); // 4 // : // 3...1...0___2 // g.push_back(std::make_pair(graph_type(),24)); e = add_edge(0, 1,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(0, 2,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); e = add_edge(1, 3,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(0, 4,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); // 4 // : // 3...1...0___2 // g.push_back(std::make_pair(graph_type(),6)); e = add_edge(0, 1,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(0, 2,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); e = add_edge(1, 3,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(1, 4,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); // // 3...1...0___2...4 // g.push_back(std::make_pair(graph_type(),36)); e = add_edge(0, 1,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(0, 2,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); e = add_edge(1, 3,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(2, 4,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); // // 3___1...0...2...4 // g.push_back(std::make_pair(graph_type(),24)); e = add_edge(0, 1,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(0, 2,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(1, 3,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); e = add_edge(2, 4,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); // // 3___1...0___2...4 // g.push_back(std::make_pair(graph_type(),14)); e = add_edge(0, 1,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); e = add_edge(0, 2,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); e = add_edge(1, 3,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 1); e = add_edge(2, 4,g.back().first).first; put(alps::edge_type_t(), g.back().first, e, 0); int success = 0; for(std::vector<std::pair<graph_type, lc_type> >::iterator it= g.begin(); it != g.end(); ++it) { lc_type lc = alps::graph::lattice_constant( it->first , lattice_graph , lattice.lattice() , alps::cell(std::vector<int>(2,side_length/2),lattice.lattice()) //side_length * side_length / 2 + side_length / 2 - 1 ); if ( lc != it->second) { std::cerr<<"ERROR: lattice constant does not match!"<<std::endl; std::cerr<<"Graph:"<<std::distance(g.begin(),it)<<" Calculated: "<<lc<<"\tReference: "<<it->second<<std::endl<<std::endl; success = -1; } } return success; }
distance_type best(distance_type null = 0) const { return empty() ? null : get(distance, data[0]); }
// for debugging, please size_type loc(Value const& v) const { return get(index_in_heap, v); }
typename boost::property_traits<PMap>::reference get_wrapper_xxx(const PMap& pmap, const Key& key) { using boost::get; return get(pmap, key); }
bool contains(Value const& v) const { using boost::get; return contains(v, get(index_in_heap, v)); }