networks and graphs 204.302 in 2005. introduction many decision science problems can be modelled...

23
Networks and Graphs 204.302 in 2005

Upload: dennis-dawson

Post on 17-Jan-2016

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

Networks and Graphs

204.302 in 2005

Page 2: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

Introduction

• Many Decision Science problems can be modelled using what are called graphs or networks.

• A network is just a specific form of a graph so we’ll concentrate on graphs first.

• Some basic definitions are required to talk graphs.

Page 3: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

Basic definitions

• A graph is made up of nodes and edges.• Nodes are the points of interest on many graphs that represent the

state of the scenario, or a location.• Edges explain how we can move from one state to another.• Nodes often get called points while edges are called arcs in some

books.• Edges can be directed or undirected.• An undirected edge could be drawn as two directed edges in some

situations.

Page 4: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

A Simple graph

• This graph has four nodes, and a number of edges both directed and undirected.

Page 5: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

Important ideas in graphs

• Just because two lines touch doesn’t mean they intersect.• An edge joins two nodes and nothing else.• Edges can be directed or undirected, with an arrow head on directed

edges.• A directed edge starts at an initial node and ends at a terminal node.• Sometimes we replace an undirected edge by a pair of directed edges

for completeness and/or clarity.• We have such terms as indegree, outdegree and degree to worry

about.

Page 6: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

More important definitions

• A chain of edges connects a set of nodes.• A path is a chain that has logical start and end points. These

are called source and sink nodes respectively.• A cycle/tour/loop is a set of directed edges that can be

traversed to get back to a starting point.• An Euler tour passes through all edges in a graph, while a

Hamiltonian tour passes through all nodes (once and only once in both cases).

• A graph that has no cycles may be called a tree if all pairs nodes are connected by paths. If the graph is not connected, the edges may form a forest.

Page 7: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

Graphs in Decision Science

• When using graphs to model scenarios we will usually try to start somewhere and end up somewhere else.

• This gives us a network.• Networks start with a source and end at a sink node.• This will help when modelling a physical network such

as water and other utilities or distribution networks for products.

Page 8: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

A simple network

• Note that the nodes in this graph have specific labels for the source and the sink nodes.

Page 9: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

Capacities and costs

• When modelling we usually will have constraints or costs associated with particular edges on the network.

• It is these considerations that determine the amount of flow along a particular edge – denoted xij

• Nodes usually get numbered, making the definition of edges and their costs or capacities easier.

• For example 0 6 xij 6 uij.

• Note that xij=-xji if an edge is undirected.

• The cost of each direction is not necessarily the same in all contexts, meaning that a pair of directed edges is easier to work with.

Page 10: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

Cycles in graphs and networks

• A cycle exists when you can walk a path from a node to itself along directed edges.

• Two well known cycles, or tours or loops, are the Euler and Hamiltonian tours.

• An Eulerian tour passes along all edges in a graph.

• A Hamiltonian tour passes through all nodes in a graph.

Page 11: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

Shortest path problems

• These problems arise in many circumstances.• Finding costs for shipping products in transportation

networks with many choices is a common example.• A less common example would be speech recognition.

Page 12: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

Dijkstra’s Algorithm

• Finds shortest path from one node to all others.• Forms the basics for such problems as travelling times. We start with a network

of nodes and edges with distances on the edges.• Give the source the label 0 and all other nodes 1.• Start at the source node and give each connected node a label related to the

distance between the source and that node.• Move to work on the node that has the minimum label attached to it, and label

all nodes connected to that node. N.B. some labels may be altered here. If this occurs you only relabel a node if the new label would be less than the current label.

• Repeat this last step until all nodes are labelled.• The label of the sink node is then the minimum distance from source to sink.

Page 13: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

An example

• When travelling from Wellington to Auckland we could follow a number of routes. Which pass through various towns and cities.

• The atlas shows the distances between various towns but not the whole path we should take.

Page 14: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

The North Island

• Taken straight from the Shell Oil NZ road atlas of New Zealand.

• Numbers refer to travel times.

• A more complete set of travel times is in the file TravelTimes.xls.

Page 15: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

A reduced graph

Page 16: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

Starting off

• We’ll start in Wellington, at the bottom of the North Island, and the left of the graph on the previous slide.

• From Wellington, we could go to Levin or Woodville. We’d label both nodes with the time taken to get there from Wellington, and indicate the fact that we came from Wellington.

• Then we choose the minimum of the two, and work on using Levin as the current node.

• This allows us to label Bulls and Palmy, with the sum of the distance to Levin from Wellington and the time it takes from Levin to each place.

• Let’s finish the job together.

Page 17: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

Backtracking

• In the end, we need to back track the journey to know where to go.

• If we label the nodes with two bits of information at each stage it will help.

• So, When labelling a node in Dijkstra’s algorithm, it would help to mark the graph somehow. Your choice, but in an exam it needs to be clear.

• For example, Put a small arrow head on the edge when you label a node. Cross old marks when re-labelling a node.

Page 18: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

In the end…

• The total time to Auckland from Wellington is 550 minutes if you drive at 80km/h.

• We didn’t really need to mark some parts of the graph, but the algorithm does anyway.

• Some paths could be deleted from the graph. Pairs of options near New Plymouth and nodes with degree less than three.

Page 19: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

When can we use Dijkstra’s algorithm?

• Dijkstra’s algorithm can only be used when the edge weights or costs are all non-negative.

• If a negative cost exists, we will risk getting a node with a temporary label that is lower than a node that has a permanent label.

• Then there is a chance that this permanent label may need to be re-considered.

• Enter the Bellman-Ford algorithm.

Page 20: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

The Bellman-Ford algorithm

• Gives every node a temporary label.• Works on edges rather than nodes in each iteration.• For every edge relabel the terminal node (if it should

be) with the cost of getting from the initial node to that node.

• Repeat the relabelling as many times as there are nodes.

• Try once more. If it changes any node labels the problem is unbounded.

Page 21: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

Two scenarios

• Trading vessels make a loss on some legs of a journey in order to make the bigger profits on the other legs of their travels.

• Financial markets can also have a negative number to consider.

• We can avoid multiplication of ratios by taking logs and adding. This may result in a negative number to factor in.

Page 22: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

Algorithms for finding all shortest paths

• The Floyd-Warshall algorithm finds all shortest paths within a graph.

• We start with a distance matrix, and augment every cell in the matrix at each iteration.

• We assume that distance from a node to itself is zero.

• For every element dij of the distance matrix:dij *= mink {dik + dkj}

Page 23: Networks and Graphs 204.302 in 2005. Introduction Many Decision Science problems can be modelled using what are called graphs or networks. A network is

The North Island example again

• Just looking at a subset of the North Island towns. (Wellington, Levin, Woodville, Palmy, Bulls, and Wanganui.)

• We start with a 6×6 matrix. (almost all of the table in the notes.)

• Note that some pairs of towns are not connected by edges but are connected by paths.

• Let’s use the EXCEL worksheet again.