Blog

25 Dec 2012 . .
Alternative Boost Graph Construction based on defining edges independently Comments

So you may of seen previous posts on Boost Graph construction, here I present an easier way of constructing the graph but at a performance cost. This shouldn’t be used if can be avoided, but it may be useful if you want to adapt your edges on the fly.

So we start with the normal code:

1 typedef adjacency_list < listS, vecS, directedS, 2 no_property, property < edge_weight_t, float > > graph_t; 3 typedef graph_traits < graph_t >::vertex_descriptor vertex_descriptor; 4 typedef graph_traits < graph_t >::edge_descriptor edge_descriptor; 5 typedef std::pair<int, int> Edge; 6 7 const int num_nodes = 5; 8 enum nodes { A, B, C, D, E }; 9 char name[] = "ABCDE"; 10 Edge edge_array[] = { Edge(A, C), Edge(B, B), Edge(B, D), Edge(B, E), 11 Edge(C, B), Edge(C, D), Edge(D, E), Edge(E, A), Edge(E, B) 12 }; 13 float weights[] = { 1.5, 2.10, 1.4, 2.2, 7.6, 3.222, 1.125, 1.324, 1.983 }; 14 int num_arcs = sizeof(edge_array) / sizeof(Edge); 15 16 graph_t g(edge_array, edge_array + num_arcs, weights, num_nodes); 17 property_map<graph_t, edge_weight_t>::type weightmap = get(edge_weight, g); 18 19 std::vector<vertex_descriptor> p(num_vertices(g)); 20 std::vector<float> d(num_vertices(g)); 21 vertex_descriptor s = vertex(A, g); 22 23 24 dijkstra_shortest_paths_no_color_map(g, s, predecessor_map(&p[0]).distance_map(&d[0])); 25 26 std::vector<float> distances; 27 std::vector<float> node_index_ids; 28 29 int target = vertex(D, g); 30 do{ 31 node_index_ids.push_back(target); 32 distances.push_back(d[target]); 33 std::cout << "Target " << target << " dist " << d[target] << " Source " << s << std::endl; 34 target = p[target]; 35 }while(target != s);

So we start with a basic set of nodes, A->E with some connections between them. This is an example of a directed graph so “flow” can only go one direction.

The benefit of this is you define the construct of the graph and create the graph_t, object g.

An alternative way of constructing is to generate the nodes, then add in the weights as in:

1 graph_t g(num_nodes); 2 for (int i = 0 ; i < num_arcs ; ++i){ 3 boost::add_edge(edge_array[i].first,edge_array[i].second,weights[i],g); 4 }

This may seem easier but comes at a performance cost. In contrast even on this simple example there is a 0.001s time increase, scale this to a real solution you may suffer badly. As stated make sure your scenario makes sense.


Stuart James  


17 Nov 2012 . .
Boost Serialization for inherited objects Comments

Preface:

When chatting with a colleague yesterday, I referenced a blog post I never actually wrote. So to remedy that here we go, how to use boost in the case of inheritance.

How To:

Inheritance in C++ is very important, a long with classes and templates I would say the most important triplet (of course inheritance cant exist without classes). As I mentioned in a previous blog post I found a new love of boost serialization allowing me to easily be able to save out my objects in binary,text or xml, but there is a spanner in the works when it comes to inheritance, this is due to the serializer not being able to know it has a parent or even what that parent is.This is actually solved with a small amount additional of code but is critical to put in or your objects wont behave in the expected way.

1 class MyParent { 2 public: 3 MyParent() {}; 4 virtual ~MyParent() {}; 5 int getID(){ return ID; } ; 6 int setID(int num){ ID = num; } ; 7 8 private: 9 int ID; 10 friend class boost::serialization::access; 11 template<class Archive> void serialize(Archive& ar, 12 const unsigned int version) { 13 ar & BOOST_SERIALIZATION_NVP(ID); 14 } 15 }; 16 17 class MyChild : public MyParent { 18 public: 19 MyChild() {}; 20 ~MyChild() {}; 21 22 private: 23 friend class boost::serialization::access; 24 template<class Archive> void serialize(Archive& ar, 25 const unsigned int version) { 26 } 27 };

So we serialize out the child class and what do we get? Well actually it is very clean elegant empty file. Not what was intended, but with a small change to tell the compiler of the classes parent we are able to serialize out child classes and parents without a problem

1 ar & boost::serialization::make_nvp("MyParent", 2 boost::serialization::base_object<MyParent>(*this))

As you hopefully can see this tells the compiler what the object parent is and provides a reference to it so therefore you can serialize that out. Of course you can put this line at the beginning or end depending on how you want to structure your outputs, but to my brain coming first makes sense.

The final solution being:

1 class MyParent { 2 public: 3 MyParent() {}; 4 virtual ~MyParent() {}; 5 int getID(){ return ID; } ; 6 int setID(int num){ ID = num; } ; 7 8 private: 9 int ID; 10 friend class boost::serialization::access; 11 template<class Archive> void serialize(Archive& ar, 12 const unsigned int version) { 13 ar & BOOST_SERIALIZATION_NVP(ID); 14 15 16 } 17 }; 18 19 class MyChild : public MyParent { 20 public: 21 MyChild() {}; 22 ~MyChild() {}; 23 24 private: 25 friend class boost::serialization::access; 26 template<class Archive> void serialize(Archive& ar, 27 const unsigned int version) { 28 ar & boost::serialization::make_nvp("MyParent", 29 boost::serialization::base_object<MyParent>(*this)) 30 } 31 };


Stuart James  


12 Oct 2012 . .
Asus reason you may not want to purchase one Comments

transformer

A year and a half ago, I order an Asus N73SV. At the time I was incredible impressed with it’s state of the art spec great expandability. I knew at the time it was a bit of a gamble with Asus not being a major player in the laptop market and the price being quite a bit cheaper than its rivals for similar spec. After using for a year I have done upgrades to RAM 6gb –> 10gb and replaced HDD for a hybrid and a larger second drive. It has been a great laptop till recently things have gone a little wrong.

Now I am not blaming asus for its product the two components that have gone wrong are completely under my control but my issue comes with the service and availability of replacements(in the UK). The two parts that have gone wrong is the battery is now completely shot, lasting about 10 mins going to 70% and turning off, and the power cable getting damaged as seen above.

These are normal issues you hit with portable electrical products, replacing the parts though is proving not to be so easy. The battery is out of warranty so I just need a replacement, the transformer is in warranty but I don't really want to loose my laptop for a couple of weeks since it has become a very important part of my life replacing my home computer completely and having heavy usage in the office although accompanied by other computers. So sending it away wasn’t really tempting when I would be ordering another part anyway, also I am not about to pay £150 in labour fees to replace a battery.

So customer support was out, but I want the official replacements so called them, first time they just hung up on me a little concerning they don't have a queue system. Second time I got through promptly, and found out they don't sell the items over the phone you can go to the asus shop website (http://shop.asus.co.uk/) and order there. I am slightly embarrassed that I never actually found this in my googling around for official products. So went on the site after the call and they are sold out of most things and don't actually list anything to do with my laptop.

So what do you do? well look at contact page and call this UK website help line, and what charming welcoming voice do you hear? A nice recorded German lady speaking German that I don't understand, I assume it leads to options but I don't understand. So I have resorted to emailing them.

In summary, the point of this rant was to express that Asus sell great products but there are no official replacements easily available. For a company of which I have enjoyed many great products from, I am shocked they fell down so badly on such an easy thing they can make a great deal of money from.

Hopefully will be able to get the replacement parts soon and have something better to say about Asus!


Stuart James  


23 Sep 2012 . .
Skeletons from Sketches of Dancing Poses paper for VL/HCC 2012 Demo Comments

I have put together a quick demo for the upcoming conference. Sadly I wont be there to present the work but the main author Manuel J. Fonseca from IST is going to be there.

 

imageimage

 

Give it a play and let us know what you think. This is a heuristic approach to parsing of sketched postures into a skeleton.

Paper Details and Demo from: http://stuartjames.info/skeletons-from-sketches-of-dancing-poses.aspx


Stuart James  


08 Sep 2012 . .
Paralympic Swimming and Wheelchair Tennis, just wow Comments

DSC_0289

Flag raising after medals awarded

 

DSC_0291

The Crowd

 

DSC_0314

Women's medley

 

DSC_0318

So close for second and third!

 

DSC_0347

Designed wheelchair’s seem to help

 

DSC_0360

Power shot!

 

DSC_0367

 

DSC_0369DSC_0371

American guy on left was absolutely incredible, his competitor on the right.


Stuart James