network – Libby Daniells /stor-i-student-sites/libby-daniells STOR-i Student Wed, 20 Sep 2023 16:24:53 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.4 The Travelling Salesman Problem /stor-i-student-sites/libby-daniells/2020/04/21/the-travelling-salesman-problem/?utm_source=rss&utm_medium=rss&utm_campaign=the-travelling-salesman-problem Tue, 21 Apr 2020 08:28:18 +0000 http://www.lancaster.ac.uk/stor-i-student-sites/libby-daniells/?p=400 The Travelling Salesman Problem (TSP) is a classic optimization problem within the field of operations research. It was first studied during the 1930s by several applied mathematicians and is one of the most intensively studied problems in OR.

The TSP describes a scenario where a salesman is required to travel between \(n\) cities. He wishes to travel to all locations exactly once and he must finish at his starting point. The order in which the cities are visited is not important but he wishes to minimize the distance traveled. This problem can be describes as a network, where the cities are represented by nodes which are connected by edges that carry a weight describing the time or distance it takes to travel between cities.

This problem may sounds simple and using a brute force method in theory it is: calculate the time to transverse all possible routes and select the shortest. However, this is extremely time consuming and as the number of cities grows, brute force quickly becomes an infeasible method. A TSP with just 10 cities has 9! or 362,880 possible routes, far too many for any computer to handle in a reasonable time. The TSP is an NP-hard problem and so there is no polynomial-time algorithm that is known to efficiently solve every travelling salesman problem.

Because of how difficult the problem is to solve optimally we often look to heuristics or approximate methods for the TSP to improve speed in finding the solution and closeness to the optimal solution.

The TSP can be divided into two types: the asymmetric travelling salesman problem (ASTP) where the distance from A to B is different to that from B to A and the symmetric travelling salesman problem (STSP) where the distance from A to B is the same as from B to A. For example, the ASTP may arise in cities such as Lancaster where there are one-way roads that make travelling more varied. In this blog I will be focusing on the STSP and outline two of the most basic heuristic algorithms in which to solve them.

Nearest Neighbor Algorithm

One of the simplest algorithms for approximately solving the STSP is the nearest neighbor method, where the salesman always visits the nearest city. The process is as follows:

  1. Select a starting city.
  2. Find the nearest city to your current one and go there.
  3. If there are still cities not yet visited, repeat step 2. Else, return to the starting city.

Using the nearest neighbor algorithm on the below symmetric travelling salesman problem starting at city A, we would then travel to city B followed by D and C, returning back to A. This gives a total length of 18, which in this case is indeed optimal. However, the nearest neighbor algorithm does not always achieve optimality.

Figure 1

For example if we change the weight slightly:

Figure 2

The solution using the nearest neighbor algorithm starting again at A will result in the Route A -> C -> B -> D -> A, resulting in a route of weight 15. But this is not optimal. If we instead took the route A -> B -> D -> C -> A the weight would be 14, a slight improvement on that obtained by the algorithm. Therefore the algorithm achieved a sub-optimal result.

This algorithm under worst-case performance is \(\mathcal{O}(n^2)\), much better than the brute force method (which is \(\mathcal{O}(n!)\)). It is easy to implement but the greediness of the algorithm does cause it to run quite a high risk of not obtaining the optimal route.

Greedy Approach Algorithm

Before we delve into the next algorithm to tackle the TSP we need the definition of a cycle. A cylce in a network is defined as a closed path between cities in which no city is visited more than once apart from the start and end city. The order of a node or city is the number of edges coming in or out of it.

The greedy algorithm goes as follows:

  1. Sort all of the edges in the network.
  2. Select the shortest edge and add it to our tour if it does not violate any of the following conditions: there are no cycles in our tour with less than \(n\) edges or increase the degree of any node (city) to more than 2.
  3. If we have \(n\) edges in our tour stop, if not repeat step 2.

Applying this algorithm to the STSP in Figure 1, we begin by sorting the edge lengths:

B <-> D = 2, A <-> B = 4, C <-> D =5, A <-> D =6, A <-> C =7, C <-> B =8

We then add the routes B <-> D, A <-> B and C <-> D to our tour without problem. We cannot add A <-> D to our tour as it would create a cycle between the nodes A, B and D and increase the order of node D to 3. We therefore skip this edge and ultimately add edge A <-> C to the tour. This results in the same solution as obtained by the nearest neighbor algorithm.

If we then apply the method to the STSP given in Figure 2 we obtain the optimal route: A -> B -> C -> D -> A. This is an improvement on what was achieved by the nearest neighbor algorithm.

This algorithm is \(\mathcal{O}(n^2\log_2(n))\), higher than that of the nearest neighbor algorithm with only a small improvement in optimality.

References and Further Reading

As said above, these are only two of the most basic algorithms used to obtain an approximate solution to the travelling salesman problem and there are many more sophisticated methods. If you wish to read more about these, I would suggest reading the following two papers:

  • Nilsson, C., (2003). Heuristics for the Traveling Salesman Problem. Linkoping University.
  • Abdulkarim, H., Alshammari, I., (2015). Comparison of Algorithms for Solving Traveling Salesman Problem. International Journal of Engineering and Advanced Technology 4(6).
]]>
Directed Acyclic Graphs (DAGs) /stor-i-student-sites/libby-daniells/2020/03/24/directed-acyclic-graphs-dags/?utm_source=rss&utm_medium=rss&utm_campaign=directed-acyclic-graphs-dags Tue, 24 Mar 2020 13:55:06 +0000 http://www.lancaster.ac.uk/stor-i-student-sites/libby-daniells/?p=327 In my last two blog posts I focused on how to analyse the results of clinical trials through both Meta Analysis and Simultaneous Inference. Here we’re going to take a step back and look at how we choose a suitable model with relevant variables considered.

Directed Acyclic Graphs (DAGs) are used as a visual representation of associations between variables or factors in models. I first came across them in an Epidemiological context during the MATH464 course on Principles of Epidemiology given by here at ¶¶Òõ̽̽App and thought I’d share the basic concepts with you all. Although I’ll discuss them in an epidemiology setting, DAGs can be used in a variety of applications to demonstrate associations and causal effects.

We’ll start with a simple definition of what DAGs are:

  • Directed – all variables in the graph are connected by arrows.
  • Acyclic – if we start at a variable X, following the path of the arrows we shouldn’t be able to get back to X.
  • Graph – we have nodes which represent factors/variables and arrows that represent causal effects of one factor on another.

Another useful definition is that of a path: a path is any consecutive sequence of arrows regardless of their direction. A backdoor path is where we start a path by moving in the wrong direction down an arrow.

The idea of a DAG is best illustrated through an example. The following example was outlined by Williams et. al (2018) in which the factors affecting obesity in children were considered:

This DAG suggests that a low parental education may increase the amount of screen time a child is engaging in, hence reducing their level of physical exercise. This in turn will increase their risk of obesity. Parental education is also a cause of obesity, hence, parental education is a common cause of both increased screen time and obesity. This is what we call a confounder variable which we’ll return to later.

We say that any two variables are d-connected if there is an unblocked path between two variables, this usually implies they are dependent on one another.

Within DAGs we have several types of variables, all of which need to be handled in different ways when considering how to analyse a model:

  • Collider – a node where two arrows meet.
  • Confounder – Pearl’s (2009) definition of confounding is the existence of an open backdoor path between two variables X and Y.
  • Mediator – an intermediate variable that lies on the causal pathway between two variables.

If we extend the previous example to include self-esteem in the model:

In this example, self-esteem is a collider as both obesity and increased screen time reduce self-esteem. Physical exercise is a mediator between screen time and obesity as it lies on the causal pathway. Finally, parental education is a confounder as it both increases screen time and obesity and hence creates a backdoor path between the two.

Now we have constructed a DAG, how do we use this to create a statistical model? We use the following rules to decide which variables to control for. We can control for a variable in several ways including conditioning on a variable by using the variable as a covariate in the regression model, stratifying by the variable or using matching techniques in trial recruitment.

D-seperation Rules (Palmer, 2018):

  • If no variables are conditioned on, a path is blocked if and only if there is a collider located somewhere on the pathway between exposure and outcome.
  • Conditioning on a confounder blocks the path.
  • If we condition on a collider it doesn’t block the path, in fact, it creates a path between exposure and control. This may mask the true relationship between two variables or indicate a relationship when none in fact exists. This is known as collider bias.
  • Also, a collider that has a descendant that has been conditioned on doesn’t block the path.
A is a collider
Conditioning on a collider opens a pathway between A and C
Conditioning on a descendant of a collider also opens a pathway between A and C

If we control for a confounder we reduce bias but if we adjust for a collider we increase bias. Collider bias is responsible for many cases of bias in modelling and is often not dealt with properly (Barrett, M. (2020)). This is what makes DAGs such a useful tool in modelling. It gives a visual representation of how things are associated with one another and can indicate where bias is being induced in models.

Modelling through DAGs may be easy for simple situations with only a few variables but it gets very complicated very quickly when the number of variables and associations increases.

For further reading, I would recommend the paper by Evandt et. al (2018) in which they use DAGs to model the association between road traffic noise and sleep disturbances by considering variables such as socioeconomic status and lifestyle. However, to see how DAGs are applied outside of an epidemiological setting I would recommend the paper by Al-Hawri et. al (2019), where they use DAGs to model wireless sensor networks.

I hope you enjoyed this blog post on DAGs!

References

  • Al-Hawri, E., Correia, N., Barradas, A., (2020). DAG-Coder: Directed Acyclic Graph-Based Network Coding for Reliable Wireless Sensor Netowrks. IEEE Access 8.
  • Barrett, M., (2020). An Introduction to Directed Acyclic Graphs. Cran R Project: https://cran.r-project.org/web/packages/ggdag/vignettes/intro-to-dags.html
  • Evandt, J., Oftedal, B., Hjertager Krog, N., Nafstad, P., Schwarze, P., Marit Aasvang, G., (2016). A population-based study on nighttime road traffic noise and insomnia. SLEEP, 40(2).
  • Palmer, T., (2018). Principles of Epidemiology MATH464 Lecture Notes. ¶¶Òõ̽̽App.
  • Pearl, J., (2009). Causality: Models, Reasoning and Inference. Cambridge University Press 2nd Edition.
  • Sttorp, M., Siegerink, B., Jager, K., Zoccali, C., Deker, F., (2015). Graphical Presentation of Confounding in Directed Acyclic Graphs. Nephrology Dialysis Transplantation, 30(9).
  • Williams, T., Bach, C., Mattiesen, N., Henriksen, T., Gagliardi, L., (2018). Directed Acyclic Graphs: A Tool for Causal Studies in Pediatrics. Pediatric Research, 84(4).
]]>