In this paper, Bayesian network (BN) and ant colony optimization (ACO) techniques are combined in order to find the best path through a graph representing all available itineraries to acquire a professional competence. The combination of these methods allows us to design a dynamic learning path, useful in a rapidly changing world. One of the most important advances in this work, apart from the variable amount of pheromones, is the automatic processing of the learning graph. This processing is carried out by the learning management system and helps towards understanding the learning process as a competence-oriented itinerary instead of a stand-alone course. The amount of pheromones is calculated by taking into account the results acquired in the last completed course in relation to the minimum score required and by feeding this into the learning tree in order to obtain a relative impact on the path taken by the student. A BN is used to predict the probability of success, by taking historical data and student profiles into account. Usually, these profiles are defined beforehand; however, in our approach, some characteristics of these profiles, such as the level of knowledge, are classified automatically through supervised and/or unsupervised learning. By using ACO and BN, a fitness function, responsible for automatically selecting the next course in the learning graph, is defined. This is done by generating a path which maximizes the probability of each user's success on the course. Therefore, the path can change in order to adapt itself to learners' preferences and needs, by taking into account the pedagogical weight of each learning unit and the social behaviour of the system.