operations research – Hamish Thorburn /stor-i-student-sites/hamish-thorburn PhD Student, STOR-i Centre for Doctoral Training Mon, 08 Nov 2021 10:32:11 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.4 Choose your own adventure – Defending a target with Stackelberg Security Games /stor-i-student-sites/hamish-thorburn/2020/04/28/choose-your-own-adventure-defending-a-target-with-stackelberg-security-games/?utm_source=rss&utm_medium=rss&utm_campaign=choose-your-own-adventure-defending-a-target-with-stackelberg-security-games Tue, 28 Apr 2020 21:01:00 +0000 http://www.lancaster.ac.uk/stor-i-student-sites/hamish-thorburn/?p=277 In today’s CYOA, you are in charge of security for a supermarket. As is the times, dried pasta and toilet paper are currently in high demand, and the store manager has asked that you make sure that these are protected. She’s tells you that while she wants to prevent as much theft as possible, she would also like to determine if the thieves are more interested in the toilet paper or the pasta (as this will help the police catch the criminals). Having taken your instructions, you start to prepare for the first night on the job.

If you fall asleep on the job the first night, go to 1. If you decide to set up some patrols, go to 2.

1.

In a completely unsurprising turn of events, you awake to see all the pasta has gone. Your boss finds out you were asleep, and is furious. You are:

  1. Fired
  2. A moron

Thanks for playing! If you want to try again without being a moron, go to 2.

2.

You decide to set up some patrols between the two aisles. While planning your patrols, you start to realise that this seems a lot like a (SSG).

A SSG is a type of game in which a defender (you) plays against an attacker (the thieves). In this game the attacker will try to attack (i.e. steal from) one of the targets (the toilet paper and pasta). The attacker and defender both have a utility (associated with each target) if an attack is successful (generally positive for the attacker, and negative for the defender). The way the game works is that each turn, the defender picks a strategy to cover/guard each target with a certain probability (which you can think of as the proportion of time each shift you spend patrolling each aisle), then the attacker (seeing this) chooses a target to attack. After reading up on this, you decide to plan your coverage strategy for that night.

If you just decide to patrol the pasta aisle, go to 3. If you just decide to patrol the toilet paper, go to 4. If you decide to patrol them both equally, go to 5.

3.

You spend a few nights just patrolling the pasta, and no one comes near it. But – surprise! – every morning, you find that all the toilet paper is gone.

Is COVID-19 Coronavirus Leading To Toilet Paper Shortages? Here Is ...

You try to explain to your boss that you were guarding the pasta, but it’s not good enough. You are fired

Thank you for playing! If you want to try a more sophisticated strategy, feel free to try again!

4.

You spend a few nights just patrolling the toilet paper, and don’t see a soul. But every morning, you find that all the pasta has been taken (in a development you really should have seen coming).

Dani Dyer tries to panic buy but shelves are empty | Daily Mail Online

You try to explain to your boss that you were guarding the toilet paper, but it’s not good enough. You are fired.

Thank you for playing! If you want to try a more sophisticated strategy, feel free to try again!

5.

You devise a patrol strategy that covers the two targets with equal probability. And you have some success – you manage to scare off a few attacks. But some are also getting through.

You notice that they always seem to be going for the pasta. You think back to the SSG, and remember that there is a utility for the attacker for a (successful) attack on each target. Assuming they get nothing for attacking a defended target, you realise that their expected utility for attacking a target is:

(1 – prob target is defended) * utility from a successful attack.

You also assume that they will always attack the target with the highest expected utility. Therefore, if you’re covering the two targets equally, then the thieves must prefer to steal pasta to toilet paper. You think you can use this to thwart them.

If you decide to change patrols to just defend the pasta, go to 6. If you decide to gradually increase the probability of defending the pasta, go to 7.

6.

You think the thieves only care about the pasta. Therefore, you can simply defend that, and you’ll prevent all robberies! You switch the patrol to just stay by the pasta, and encounter nothing during the night. Triumphantly, you walk to your bosses office, on the way, passing the toilet paper aisle, which should be completely stoc-

Is COVID-19 Coronavirus Leading To Toilet Paper Shortages? Here Is ...
You may have made an error.

Thinking back, you realise that while you were certain that the thieves preferred pasta to toilet paper, you hadn’t actually established that they didn’t care about toilet paper at all.

If you decide to gradually increase the probability of defending the pasta, go to 7.

7.

You gradually increase the probability of defending the pasta, and then (when you’re defending it two-thirds of the time), the thieves go back to stealing the toilet paper. You realise this means that the thieves enjoy pasta twice as much as toilet paper. And this also means that you can’t patrol more effectively than you are now. You take this to your boss and she’s happy. She passes this information onto the police, who round up the thieves using this new piece of evidence (how this helps them is unclear, but you’re pleased you could help).

Congratulations! You’ve unwittingly determined the attackers utility by “…observing the best response of the attacker” (Blum, Haghtalab, Procaccia, 2015). As you build your security business, you start to learn about more sophisticated methods to determine attacker utilities, such as solving linear programs for each target, or using Monte Carlo Tree Searches. But for now, you bask in your success, knowing you have saved the day.

References

Blum, A., Haghtalab, N., & Procaccia, A. D. (2015). Learning to play stackelberg security games. Available . (This post was inspired by Section 1 of this chapter).

]]>
Choose your own adventure – Simulation input uncertainty /stor-i-student-sites/hamish-thorburn/2020/03/05/choose-your-own-adventure-simulation-input-uncertainty/?utm_source=rss&utm_medium=rss&utm_campaign=choose-your-own-adventure-simulation-input-uncertainty Thu, 05 Mar 2020 13:35:00 +0000 http://www.lancaster.ac.uk/stor-i-student-sites/hamish-thorburn/?p=204 Today’s post will be a choose your own adventure. Follow the prompts and see where you end up!

You’re the star of the story! Choose from 3 possible endings!

In today’s adventure, your a humble graduate data analyst trying to streamline queues in an airport for STORi airways, by choosing the right number of check-in desks to open. Due to recent events, the airline is on the brink of bankruptcy, and so this is a very important task. You aren’t very good at analytical calculations, so you decide to simulate the queue to determine the answer.

You ask your boss for some data on arrival numbers are service times. He gives you the arrival times for 50 arrivals all occuring on one day, and the service time for these arrivals.

Right! Time to crack on! You build you simulation model, and get some results for it. You determine the mean waiting time for customers for different numbers of check-in desks. To be safe, you also calculate a 95% around these waiting times.

You’re about to take these results to your boss when you have a thought – your dataset on arrivals and service times wasn’t very big. What if it was taken on a slow day? Or the day after the Christmas party, so all the check-in staff were a bit sluggish? What if you can’t trust this data that you made all these decisions on?
If you think “Nah, it’s probably fine” and go to your boss anyway, go to 1. If you think, “Hang on, I better think about this a bit more”, go to 2.

1.

You take your results to your boss, and he seems thrilled. He immediately puts your suggestions into practise. You’re the hero of the office – everyone’s looking up to you, there’s talk of a promotion. But then, a few weeks later you get called back to your boss. You go into his office and the CEO is also there. They’re both furious – somehow the number of complaints from customers about waiting times has gone up. You’re shocked – you ran a simulation! How could this have happened? You bosses pull up the new stats on waiting times. The average times are far longer than you suggested. Don’t worry, you prepared for this. You calmly explain to you boss that the averages may be different, but they should still be in the 95% confidence interval you calculated – they should have known it could be bad. Your boss (who did not seem to appreciate your back-talk) points out that the wait times are even longer than the worst predicted by the confidence interval. You stammer and try to think of an explanation. But it’s too late – the company has already taken a massive hit in revenue, and the boss asks you to clean out your desk…

Thank you for playing this choose your own adventure! If you are upset at being fired, feel free to try again and see if Input Uncertainty could have saved you!

2.

You do some reading and come across “Foundations and methods of stochastic simulation” by Barry Nelson. Flicking through it, you come across “Input Uncertainty”, and you realise you’ve struck gold. The book describes the idea that because the data you’ve used to estimate the inputs to your model is inherently random, this will increase the variability in the outputs, and that you should account for it. But how? The book only gives two suggestions – try and collect more real-world data to reduce input uncertainty, or something called “bootstrapping”

If you go to your boss and ask for more real-world data, go to 3. If you give bootstrapping a go, go to 4.

3.

You go to your boss and ask for more real-world data, explaining your concerns. He tells you (a bit insincerely, in your opinion) that he understands your concerns but time and money are tight, so you’ll have to make do with the data you have.

If you go back and give bootstrapping a go, go to 4.

4.

You start doing bootstrapping. You struggle at first – “resampling? What the hell is that?” you think to yourself. However, the more you try, the more you understand. You start to get the concept – basically, you simply re-draw observations from the data you were given to calculate a new mean each time.

From

Eventually, by doing this enough, you get a sense of the variability among the means – which, you realise with joy, is your input uncertainty! By using this, you re-calculate the confidence intervals (which are much wider now).

If you take these new confidence intervals to your boss, go to 5. If you think you should try something more sophisticated, go to 6.

5.

You go to your boss with your estimates and your confidence intervals. He reads them, and his face falls. “Good work, but this isn’t great news. We pretty much can’t determine anything from this analysis. The company is looking at some dark times ahead”.

Three months, and a number of layoffs later, you realise that maybe there were some more sophisticated methods you could’ve used. However, it’s now too late. The revenues are falling, and the company is looking at more layoffs.

Say goodbye to your bonus.

Congratulations! You didn’t get fired! But that’s about the best you can say about your performance. To see what would’ve happened if you tried something a bit more sophisticated, feel free to try again!

6.

You find a paper giving a very nice review of methods of input uncertainty. It seems that there are a few different methods you can take – and they all have pros and cons. There seem to be three different approaches you could take: bayesian model averaging, meta-model assisted bootstrapping and something called the delta-method.

If you decide to use the Delta-method, go to 7. If you decide to use Meta-Model Assisted Bootstrapping, go to 8. If you decide to use Bayesian Model Averaging, go to 9.

7.

You chose to look into the Delta-method – I dunno, greek letters are cool? – are get to work. You see that the method which uses known mathematical results to decompose output variance into simulation variance and input uncertainty variance. You rapidly decide that this is too mathematical for you, and decide to go back and try one of the other methods.

I didn’t work hard through a maths degree to use maths in real life, goddammit!

If you decide to use Meta-Model Assisted Bootstrapping, go to 8. If you decide to use Bayesian Model Averaging, go to 9.

8.

You decide to do Meta-model Assisted Bootstrapping – it’s got the word “Meta” in it, so you think it sounds cool – and get to work. You realise it involves using the results from a bootstrapped sample to try and model a relationship between the inputs and outputs. This model is then used to determine the input uncertainty. This is easy to do since you’ve only got two parameters, and the simulation is reasonably quick. You complete your work and take your results to your manager. He’s astounded – the results are fantastic and show really well how much variability the company should expect around arrival times. Your recommendations are implemented immediately. It works well, and there are no huge unexpected fluctuations. You are hailed as a hero of the office – not bad for your first year out.

Although the first year has really aged you

Thank you for playing this choose your own adventure! If you want to see what would have happened if you ignored Input Uncertainty, feel free to go back and try again!

9.

You decide to do Bayesian Model Averaging – you’ve heard lots of stats people talk about Bayesian stats, so you think it’s a smart idea – and get to work. Bayesian Model Averaging is similar to bootstrapping, but you weight your bootstrap samples by how likely you think they are, based on your prior knowledge of the sample. That is, when re-taking the sub-samples, make it more likely to select a sub-sample which is more likely given your prior information. However, you don’t really seem to have much prior information to weight your samples on. You talk to you manager about this, and he helps you determine some appropriate priors to use. From this you can create some good confidence intervals for your estimates. Your manager is impressed, and they implement your recommendations immediately. It works well, and there are no huge unexpected fluctuations. You are hailed as a hero of the office – not bad for your first year out.

Although the first year has really aged you

Thank you for playing this choose your own adventure! If you want to see what would have happened if you ignored Input Uncertainty, feel free to go back and try again!

References

Nelson, B. (2013). Foundations and methods of stochastic simulation: a first course. Springer Science & Business Media.

]]>
Heuristics in Optimisation /stor-i-student-sites/hamish-thorburn/2020/02/07/heuristics-in-optimisation/?utm_source=rss&utm_medium=rss&utm_campaign=heuristics-in-optimisation /stor-i-student-sites/hamish-thorburn/2020/02/07/heuristics-in-optimisation/#comments Fri, 07 Feb 2020 08:20:26 +0000 http://www.lancaster.ac.uk/stor-i-student-sites/hamish-thorburn/?p=154 Another fortnight, and another 10 presentations on research in STOR-i. The current phases of the MRes program is starting to introduce us to the different research areas that we may be able to choose our PhD topic in. There was also a fantastic performance by the ¶¶Òõ̽̽App Korfball team at BUCS North Regional competition, which you can see for yourself on the .

Not to boast or anything

Korfball brilliance aside, one of the research topics we’ve seen was from Dr Ahmed Kheiri (a lecturer in the ¶¶Òõ̽̽App Management School) called “Heuristic methods in hard computational problems”. This is an area I’ve previously had some experience in, so I thought it would be a good idea to dive a bit deeper into this.

An overview of optimisation

Optimisation is the general area of maths of finding the highest or lowest solution to a problem, often given some constraints. A very simple example of this is a furniture maker, who has a certain amount of wood, and needs to decide how many chairs or tables to make to maximise profit, given the limits to the amount of wood each requires, and the amount of time they have to work on the problem. This problem could be formulated as:

Maximise (profit per chair x number of chairs made) + (profit per table x number of tables made)

subject to:

(wood used per chair x number of chairs made) + (wood used per table x number of tables made) ≤ Total wood available

and

(time taken to make a chair x number of chairs made) + (time taken to make a table x number of tables made) ≤ How much time they have

and finally

Number of chairs and number of tables are integers (i.e. you can’t make half a table/chair)

I’ll also use this problem to introduce some terminology:

  • The objective function is the mathematical expression you are trying to maximise/minimise. In this example, it is the first expression containing the profits of the chairs and tables.
  • The constraints are the mathematical expressions which you have to abide by to solve the problem. In our example, these are the expressions saying you can’t use more wood or time than you have.
  • The decision variables (often just called the variables) are the values that you can change to optimise the objective function. This this example, the variables are the number of tables and chairs to make.
  • If some given values of the variables satisfy the constraints, this is called a feasible solution.
  • The set of all feasible solutions (i.e. every possible combination of tables and chairs that we could make with our wood and time) is called the solution space.

This is a very simple optimisation problem, and you could probably find solution to it quite quickly (either , or through ). However, these sorts of problems can quickly get out of hand. What if you actually have more products than you can make from your wood? What if the first few chairs sell for a higher cost than the next few? What if you have to sell chairs and tables as a set?
The more complicated the problem is, the (computationally) harder it will be to solve exactly. However, if you’re willing to cheat a bit, there are some methods that can help.

Heuristics

A heuristic is really any optimisation technique/algorithm for finding a good or approximate solution very quickly. It can be something as simple as the following:

  1. Randomly pick any feasible solution to the problem, and take it as the current best solution.
  2. Randomly pick any new feasible solution to the problem.
  3. If the new solution is better than your current best solution, replace your current best solution with the new one
  4. Repeat steps 2 and 3 until you are satisfied that you either have a good enough solution, or you are sick of running the algorithm.

There are two points about the above algorithm. Firstly, it will (the longer you do it) find a better solution; but secondly, there’s no guarantee that it’ll get there any time soon, or any guarantee that it’ll get close to the true best solution. This is because it’s just randomly jumping all over the solution space. It’s not actually looking for a good solution – it’s just stumbling around, hoping to find one.

A better heuristic will often try to move in the “direction” of better solutions. A classic example of this is the gradient descent method:

  1. Pick a point in the solution space. Call this your current best solution
  2. Calculate the gradient of the solution space at your current best solution
  3. Move a step in the solution space in the direction of the gradient. Call this new point your current best solution.
  4. Repeat until the gradient equals (or is suitably close to) 0.

The basic idea is to imagine putting a ball on the surface of the solution space, and letting it roll down, it will eventually settle in the lowest point. A very good gif of this is shown below (taken from the )

Source:

Think of your solution space as the surface of a table. Gradient descent is kind of like putting a ball table and simply letting the ball roll down to find the lowest point.

It’s quite clear from the above gif that this is a much better heuristic. However, there are still situations in where this doesn’t work to well. Imagine we have the following objective function:

If you can imagine placing a ball at the red point, it will roll down and settle at the “minimum” at the blue point. While this is the minimum for this bit of the solution space (we call this a local minimum), it completely misses the true minimum (or global minimum) at the green point.

In general, the more complicated the function, the more sophisticated the heuristics needed to find a good solution.

Optimal wind turbine placement

Moving back to the presentation by Dr Kheiri, we look at the problem of optimal wind turbine placement. To quote the presentation:

The problem involves finding the optimal positions of wind turbines in a 2
dimensional plane, such that the cost of energy is minimised taking into
account several factors such as wind speed, turbines features, wake effects and
existence of obstacles

This problem will have many local minima, and so gradient decent will probably fail if we tried to use it.

The way this was solved in the paper was to use a genetic algorithm. This is a heuristic which tries to mimic natural selection in animal populations. The idea is that you generate a population of solutions, then you pick pairs of solutions from this population and from them “breed” new solutions, which have features from both of their “parent solutions”. The new solutions are then evaluated and the strongest (i.e. the best) survive, and the others are discard. This new solutions are then used to breed more solutions, and the process is repeated until you decide to stop.

Applying this to our wind turbine problem, we first set up our data as a binary vector of 1s and 0s. We do this by diving the plane into a 2-dimensional grid, with at most 1 turbine in each cell. Therefore, each cell is now associated with a binary variable, which takes the value of 1 if there is a turbine in it, and 0 otherwise. The decision then is which cells to but a wind turbine in (i.e. assign to a value of 1) and which to leave. From our matrix of 1s and 0s, we simply organise it into one long vector of turbine locations (mainly for computationaly simplicity), as shown in the gif below (in this example, every cell is a 1, but in truth, they will be a mix of 1s and 0s).

Apologies, my animations skills aren’t exactly pixar level

Once have set this up, we can start our genetic algorithm. First, we then generate a bunch of solutions, pair them off, and start breeding new solutions from these pairs. The breeding has two aspects:

  1. Crossover: This is taking some parts of both the mother and father solution, and incorporating these into the child solution
  2. Mutation: Randomly changing some aspect of the child solution. This helps the algorithm avoid getting stuck in a local minimum.

The breeding is shown below (again, in this example, the mother and father are the same, but in reality, they will be different).

Queue some Marvin Gaye

We then see how good all these child solutions are, and keep the best ones. From these, we breed more new solutions, keep the best, and so on. We keep doing this until we are satisfied we have a good solution.

Hyper-heuristics

By this point, you probably are starting to realise the many different types of heuristic you could use to solve an optimisation problem. However, this leads to an obvious question – how do you chose which one? Some will converge quite quickly (e.g. gradient descent) whereas some will be more robust against local minima (genetic algorithms). In general there is no such right answer.

However, for a given problem, it is possible to apply a number of different heuristics, and then use a hyper-heuristic (also called a meta-heuristic). The way it works is to start with a number of low-level heuristics. You then run them over the problem, and (when you would normally iterate you one chosen heuristic) you switch between heuristics. This could be as simple as changing between the breeding rules in genetic algorithms, or switch search methods altogether. Ideally, you would also keep track of how each heuristic is doing as you go, and use this information to help chose your next heuristic.

In summary

  • Heuristics are methods to help you quickly find a “good” solution to an optimisation problem (but not necessarily the best “solution”)
  • They can range from pretty much useless (random search), to quick but error-prone (gradient descent) to slow and robust (genetic algorithm)
  • There’s no “one best” heuristic. Each hang strengths and weaknesses which suit different problems.
  • Moving forward, one of the big developments will be the use of hyper-heuristics, to determine which is the best method to use for your problem.

]]>
/stor-i-student-sites/hamish-thorburn/2020/02/07/heuristics-in-optimisation/feed/ 1