Vector of function pointers

This is just a small tip on how to define a vector of function pointers in C++ and how to call functions stored in it:

#include <vector>
#include <iostream>

typedef int (*fptr)(int, int);
int foo(int a, int b) { return a + b; }
int bar(int a, int b) { return a * b; }

int main()
{
    std::vector<fptr> f;
    f.push_back(foo);
    f.push_back(bar);

    std::cout << f[0](2, 3)
        << f[1](2, 3)
        << std::endl;
    return 0;
} 

That’s it. Next, this example could be extend to replace old-fashion function pointers with function objects.

Hierarchical Task Network (HTN)

In artificial intelligence, the hierarchical task network, or HTN, is an approach to automated planning in which the dependency among actions can be given in the form of networks.

Planning problems are specified in the hierarchical task network approach by providing a set of tasks, which can be:

  1. primitive tasks, which roughly correspond to the actions of STRIPS;
  2. compound tasks, which can be seen as composed of a set of simpler tasks;
  3. goal tasks, which roughly corresponds to the goals of STRIPS, but are more general.

A primitive task is an action that can be executed. A compound task is a complex task composed of a sequence of actions. A goal task is a task of satisfying a condition. The difference between primitive and other tasks is that the primitive actions can be directly executed. Compound and goal tasks both require a sequence of primitive actions to be performed; however, goal tasks are specified in terms of conditions that have to be made true, while compound tasks can only be specified in terms of other tasks via the task network outlined below.

Constraints among tasks are expressed in form of networks, called task networks. A task network is a set of tasks and constraints among them. Such a network can be used as the precondition for another compound or goal task to be feasible. This way, one can express that a given task is feasible only if a set of other actions (those mentioned in the network) are done, and they are done in such a way that the constraints among them (specified by the network) are satisfied. One particular formalism for representing hierarchical task networks that has been fairly widely used is TAEMS.

A task network can for example specify that a condition is necessary for a primitive action to be executed. When this network is used as the precondition for a compound or goal task, it means that the compound or goal task requires the primitive action to be executed and that the condition must be true for its execution to successfully achieve the compound or goal task.

The best-known domain-independent HTN-planning software is:

HTN is a useful way to provide the planning engine with information about the hierarchical structure of the planning domain. HTN-like planning (as it is practically used) has the same expressivity (i.e. can solve the same domains) as STRIPS. The theoretical model of HTN is strictly more expressive than STRIPS, but cannot be directly used because of its undecidability.

Example of HTN:

image

How to Master C++

From several days, I’ve posted a question on C++ Professionals Group on LinkedIn asking this question. Below the summary of people posts:

– General Tips for mastering in general:
* Practice is important as reading "Arne De Herdt"
* Ability to understand others code. "John Phillips" & "Jason Felice"
* It’s about software design not understanding syntax and semantic! "Ricardo Machado" & "John Phillips" & "Jason Felice"
* Understanding source code of developed compilers and making your own compiler. "kumar sundaram"
* Involve yourself in Boost ( http://www.boost.org ) "John Phillips"
* Understanding multiple programming paradigms will will give you good ideas for better design in all of them "John Phillips"
* Understand algorithms and their implementation. "John Phillips"
* Understand software design at scales larger than algorithms. "John Phillips"
* Understand how to work effectively over time. "John Phillips"
* Becoming involved in an Open Source project is a good way to do improve your cognition for others code. "Jason Felice"

– Recommended Books:
* Thinking in C++: http://www.planetpdf.com/developer/article.asp?ContentID=6634 "Tiago Correia"
* Art of Computer Programming Series – Donald E. Knuth "Tiago Correia"
* C++ Templates: The Complete Guide – David Vandervoode and Nicolai Josuttis "Ricardo Machado"
* Effective C++ – Scott Meyers "Ricardo Machado"
* Modern C++ Design: Generic Programming and Design Patterns Applied – Andrei Alexandrescu "Ricardo Machado"
* Design Patterns – Gamma, Helm, Johnson and Vlissides "Ricardo Machado"
* The C++ Programming Language (Third Edition and Special Edition) – Bjarne Stroustrup "Nabil Shams"
* C++ Primer – Stanley Lippman and Josee Lajoie "Zohar Efrati"
* More Effective C++ – Scott Meyers "Thomas J. Mueller"
* Effective STL – Scott Meyers "Thomas J. Mueller"
* Exceptional C++ – Herb Sutter "Thomas J. Mueller"
* More Exceptional C++ – Herb Sutter "Vladimir Ivin"
* C++ for Real Programmers – Jeff Alger plus the other two "Vladimir Ivin"
* Standard Template Library – Nicolai M. Josuttis "John Phillips"
* Template Metaprogramming – Abrahams and Gurtovy "John Phillips"
* Generative Programming book – Eiseneker and Krysznewski "John Phillips"
* POSA Series "John Phillips"
* Code Complete – Steve McConnell "John Phillips"
* Introduction to Algorithms – Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein "John Phillips"
* The Pragmatic Programmer – Andrew Hunt and David Thomas "Jason Felice"
* C++ In-Depth "Rob Meijer"

– You can view authors of these tips at links below
Arne De Herdt
Tiago Correia
John Phillips
Ricardo Machado
kumar sundaram
Nabil Shams
Zohar Efrati
Thomas J. Mueller
Vladimir Ivin
Rob Meijer
Jason Felice