computing optimal strategies in zero-sum matrix...

61
Computing Optimal Strategies in Zero-Sum Matrix Games Andrew Kindred Batchelor of Science in Computer Science with Honours The University of Bath April 2008

Upload: buimien

Post on 06-Mar-2018

219 views

Category:

Documents


1 download

TRANSCRIPT

Computing Optimal Strategies in Zero-Sum Matrix Games

Andrew Kindred

Batchelor of Science in Computer Science with Honours The University of Bath

April 2008

Computing Optimal Strategies in Zero-Sum Matrix Games

I

This dissertation may be made available for consultation within the University Library and may be photocopied or lent to other libraries for the purposes of consultation.

Signed:

Computing Optimal Strategies in Zero-Sum Matrix Games

II

Computing Optimal Strategies in Zero-Sum Matrix Games

Submitted by: Andrew Kindred

COPYRIGHT

Attention is drawn to the fact that copyright of this dissertation rests with its author. The Intellectual Property Rights of the products produced as part of the project belong to the University of Bath (see http://www.bath.ac.uk/ordinances/#intelprop).

This copy of the dissertation has been supplied on condition that anyone who consults it is understood to recognise that its copyright rests with its author and that no quotation from the dissertation and no information derived from it may be published without the prior written consent of the author.

Declaration

This dissertation is submitted to the University of Bath in accordance with the requirements of the degree of Batchelor of Science in the Department of Computer Science. No portion of the work in this dissertation has been submitted in support of an application for any other degree or qualification of this or any other university or institution of learning. Except where specifically acknowledged, it is the work of the author.

Signed:

Computing Optimal Strategies in Zero-Sum Matrix Games

III

Abstract

The study of game theory predominately makes use of matrices to simulate scenarios that can occur during a game. Solving these matrices to produce useful output can require many calculations. As this process is often performed by hand, it can be a lengthy procedure. To counteract this, a few applications are available which can solve these matrices using computer algorithms. However, after conducting research into these solutions it was discovered that they have major flaws and omit information that would be useful to a user. This creates a problem for an individual trying to solve a matrix game, as a hand-written method is time consuming, whereas a computational method is unreliable. This project therefore aims to create an application for zero-sum matrix games that can calculate optimal strategies for matrices provided by a user. The output will produce a solution with graphical elements backing up and illustrating the given answer.

Computing Optimal Strategies in Zero-Sum Matrix Games

i

Contents

Contents…………………………………………………………………………………… i

List of Figures…………………………………………………………………………….. iii

Acknowledgements………………………………………………………………………. iv

Introduction………………………………………………………………………………. 1

1.1 Problem Description…………………………………………………...……… 1 1.1.1 Aim…………………………………………………………………. 2 1.1.2 Why Undertake This Project?........................................................... 2 1.1.3 The Application……………………………………………………. 2 1.1.4 Problem Detail……………………………………………….…….. 2 1.2 Requirements Specification………………………………………………..…. 4 1.2.1 The Application…………………………………………….……… 4 1.2.2 Deliverables………………………………………………..………. 4 1.3 Project Plan…………………………………………………………………… 4 1.3.1 Project Phases………………………………………………..…….. 4 1.3.2 Deadlines…………………………………………………….…….. 5 1.4 Resources Required………………………………………………………….. 6 1.4.1 Computing Resources……………………………………………… 6 1.4.2 Human Resources………………………………………………….. 6 1.4.3 Literature Resources……………………………………………….. 6 Literature Survey………………………………………………………………………… 7

2.1 Introduction…………………………………………………………………… 7 2.2 Game Theory………………………………………………………………….. 8 2.2.1 Introduction to Game Theory………………………………………. 8 2.2.2 Elements of Game Theory………………………………………….. 8 2.3 Algorithm Design…………………………………………………….. ………11 2.4 Current Applications in the Market…………………………………... ………13 2.4.1 Evaluating Applications…………………………………… ………13 Requirements Analysis and Specification……………………………………….………20

Form Design……………………………………………………………………… ………23

4.1 The 2x2 Matrix……………………………………………………….. ………24 4.2 The Two-Row Matrix………………………………………………… ………25 4.3 The Two-Column Matrix……………………………………………... ………26

Computing Optimal Strategies in Zero-Sum Matrix Games

ii

Code Design………………………………………………………………………. ………28

5.1 The 2x2 Matrix……………………………………………………...... ………29 5.2 Matrices Larger than 2x2………………………………………........... ………30 5.3 The Two-Row Matrix………………………………………………… ………31 5.4 The Two-Column Matrix……………………………………………………...32 Testing…………………………………………………………………………….. ………33

6.1 Overall Test Strategy…………………………………………………. ………33 6.2 Areas of Particular Testing Interest…………………………………... ………34 Conclusion………………………………………………………………………... ………38

7.1 Aims and Requirements………………………………………………. ………38 7.2 Procedures Used and Problems Encountered………………………… ………39 7.3 Future Recommendations…………………………………………….. ………39 7.4 Final Conclusions…………………………………………………….. ………40 7.5 Further Developments………………………………………………... ………40 Bibliography……………………………………………………………………… ………42

Appendices……………………………………………………………………….. ………45

Appendix A – Source Code………………………………………………. ………45 Appendix B – Example Tests…………………………………………….. ………46

Computing Optimal Strategies in Zero-Sum Matrix Games

iii

List of Figures

Figure 1.1 Gantt Chart of Project Phases………………………………………………….. 5

Figure 2.1 A Graph Displaying Different Row Strategies…………………………………. 9

Figure 2.2 A Graph Showing Required Points to be Calculated in the Algorithm... ………12

Figure 2.3 The Matrix Game Solver………………………………………………. ………14

Figure 2.4 The Game Theory Tool………………………………………………... ………16

Figure 2.5 The Zero-Sum Game Solver……………………………………………………18

Figure 4.1 The 2x2 Matrix………………………………………………………… ………24

Figure 4.2 The Two-Row Matrix…………………………………………………. ………25

Figure 4.3 The Two-Column Matrix……………………………………………… ………26

Figure 5.1 Code for Drawing Graphs……………………………………………... ………31

Figure 6.1 Initial Error Found in Application…………………………………….. ………35

Figure 6.2 The Correct Solution to the Matrix Problem………………………….. ………36

Figure 7.1 Example of a Flat Line as Part of the Upper Bound…………………... ………41

Computing Optimal Strategies in Zero-Sum Matrix Games

iv

Acknowledgements

I would like to thank my project supervisor, Dr Nicolai Vorobjov, for his help - from the overall project idea through to finalising the dissertation. I would also like to thank Dave and Kathryn Kindred, and Marc Jones for all their help and support.

Computing Optimal Strategies in Zero-Sum Matrix Games

1

Chapter 1

Introduction

1.1 Problem Description

The origins of game theory lie in the 1944 publication by John von Neumann and Oskar Morgenstern called “Theory of Games and Economic Behavior”. This makes game theory a relatively new mathematical concept given the vast history of mathematics itself. Since then, “game theory has developed rapidly. It now has a central place in economic theory, and has contributed important insights to all areas of social science” [1]. Game theory is widely documented in books, and this is principally how the majority of people learn about the subject. A new learner of game theory has much to read to fully understand all the aspects of the subject. Developing a more efficient approach to the teaching of game theory would seem to have a distinct benefit. “Game theory is the logical analysis of situations of conflict and cooperation” [1]. A game needs to have at least two players, have a number of strategies, and end in some sort of payoff which determines the outcome of the game. A game with only a few strategies can be easily represented by a matrix showing the payoff each player will receive with each strategy they choose. A matrix with two players where every set of payoffs adds to zero is called a zero-sum game. “In general, a zero-sum game represents a closed system: everything that someone wins must be lost by someone else. Most parlor games are of the zero-sum type. Two person zero-sum games are sometimes called strictly competitive games” [2]. It is these zero-sum games that will be focused on in the project. I propose to create an application where the user will input a matrix containing payoffs for a two-person zero-sum game and then display the results of it graphically.

Computing Optimal Strategies in Zero-Sum Matrix Games

2

1.1.1 Aim The aim of my project is to develop an application that can take a set of payoffs in a matrix given to it by a user and display the best possible strategies for the given data. This will be done by producing a simple graph to show the optimal mixed strategy. The optimal strategy will be a probability distribution based on the set of original pure strategies. 1.1.2 Why undertake this project?

I feel that the topic of game theory is usually delivered in a very literature-based way, and that this can involve considerable time and effort in background reading. Showing the optimal results of a matrix game and a visual representation will make learning and understanding the elements of game theory much easier, and will create a helpful tool for solving such matrices. 1.1.3 The Application The application should be designed in an appropriate programming language. “It's important when choosing a programming language to choose the right language for the job. While there are many factors involved, one of the most important is certainly the fit of the tool to the project at hand” [3]. Choosing a suitable graphics element is also difficult, as “every program has varying strengths and weaknesses, there is never a single, obvious "best" choice” [4]. 1.1.4 Problem Detail

The end requirement is to construct and implement an algorithm for finding optimal strategies. “An optimal strategy is one which performs best against its objectives” [5]. In these matrix games each player will make a choice as to which strategy to use. The complete set of strategies for each player is their strategy profile which is displayed in the matrix. The optimal strategy for each player will either be a fixed strategy or a mixed strategy depending on whether or not the matrix has a saddle point. “A saddle point is an element of the matrix which is both the smallest element in its row and the largest element in its column” [6]. When a matrix contains one or multiple saddle points it is in the interest of both players to choose the strategy or strategies containing the saddle point value. More formally: If i and j are values in the matrix. (i0, j0) is a saddle point if (i0 is an optimal strategy for player 1 and j0 is the optimal strategy for player 2) and if for every i and j ij0 ≤ i0j0 ≤ i0j

Computing Optimal Strategies in Zero-Sum Matrix Games

3

When a matrix contains a saddle point the optimal strategy for both players is called a fixed strategy, and is quicker to calculate than a mixed strategy. A mixed strategy is needed in a matrix containing no saddle point. “In game theory a mixed strategy is a strategy which chooses randomly between possible moves. The strategy has some probability distribution which corresponds to how frequently each move is chosen” [7]. In a 2x2 matrix a mixed strategy can be easily calculated, as the rate at which each of the two strategies should be played must add up to 1. If choice one for the rows player is x and choice one for the columns player is y then the choices can be displayed as shown below: Choices for rows player (x, 1-x) Choices for columns player (y, 1-y) 0 ≤ x ≤ 1 0 ≤ y ≤ 1 However, in the study the work will be extended to look at 2xn or mx2 matrices. In matrices larger than a 2x2 matrix a different method is needed to calculate an optimal strategy. This method will display the choices of both players graphically. The resulting graphs show all the possible choices for each player, and from this the user will be able to calculate the upper envelope and lower envelope on the graph. For the rows player the optimal strategy will be the lowest point on the upper envelope, and for the columns player it will be the highest point on the lower envelope. These points on the graph show where two lines will cross that correspond to two rows or columns from the matrix. Therefore, using only the two choices from the graph, a 2x2 matrix can be created and thus an optimal strategy can be formulated. The specific technique for calculating these strategies will be explained in more detail later on in the study, although all the main points of the method that will need to be considered when finding these optimal strategies are explained above.

Computing Optimal Strategies in Zero-Sum Matrix Games

4

1.2 Requirements Specification

The most important requirement is to create an application that can calculate optimal strategies from a zero-sum matrix game given to it by a user. 1.2.1 The Application

• The application needs to be user friendly and such that the concepts of game theory can be easily assimilated and understood.

• It needs to be able to accept any type of payoff from the user and not cause an error. The application should accept integers given to it by the user and calculate the optimal strategies. If an incorrect input is given, then the system should not cause an error even if the entry is invalid. The user will then have the option to enter their input again.

• The application should be able to teach a user about game theory, and even an inexperienced user should be able to input a matrix and have the application calculate an optimal strategy for them. Therefore the application can be used by someone with the most basic of computer skills.

• The application needs to run on the windows operating system, since that is the system most users are familiar with.

• The project supervisor will need to be consulted during the course of the project to ensure that it stays on course and is in line with his research.

1.2.2 Deliverables

• The project needs to be completed by the stipulated deadline of 28th April 2008. • A literature review will need to be completed for 10th December 2007 - the

document is required for that date. • A plan of tasks to be completed will need to be created so that the project stays on

track.

1.3 Project Plan

1.3.1 Project Phases

The project will be split into three phases. These phases will be: Phase 1: Planning and literature review Phase 2: Creation of the application Phase 3: Conclusion and write up

Computing Optimal Strategies in Zero-Sum Matrix Games

5

1.3.2 Deadlines

Deliverable Target Completion Date Hand in Date Project Plan 22nd October 2007 22nd October 2007

Literature Review 3rd December 2007 10th December 2007 Final Report 18th April 2008 28th April 2008

The Gantt chart below in figure 1.1 shows when each of the phases explained above will be addressed.

Figure 1.1 – Gantt Chart of Project Phases

Computing Optimal Strategies in Zero-Sum Matrix Games

6

1.4 Resources Required To complete this project successfully the following resources are needed: 1.4.1 Computing Resources

• A suitable coding language is essential in which to write my application. These are available on the internet.

• I have some experience writing code in visual basic, java and ASP.Net; one of these languages may be appropriate. The language that is chosen will need to be able to have, or work well with, a graphics element or application.

• A PC/laptop will be required to program the application and to write up the final report. The computer will only need a basic specification, as handling the graphical part of the application will be the most demanding aspect of the system, and this will not require a high end processor or graphics card. These resources are available in most residences or on campus at the University of Bath.

• Few other resources are needed because the output of the application will be visual, and the input can be easily given to the system using a keyboard. This means that printers, scanners and speakers, etc. are not required.

1.4.2 Human Resources

• Access will be required to the project supervisor, Nicolai Vorobjov, when questions arise about the subject matter and how to proceed with the project.

1.4.3 Literature Resources

• It will be required to have access to a wide range of books on the subject of game theory and algorithm design. These should be easily accessible from the University of Bath library.

• It would be advantageous to look at other papers written on this subject which should also be available from the University of Bath library.

Computing Optimal Strategies in Zero-Sum Matrix Games

7

Chapter 2

Literature Survey

2.1 Introduction

Game theory is a relatively new area with respect to the history of mathematics. The first literature under the name of game theory was “the monumental Theory of Games and Economic Behaviour [1944]” [1]. The origins of the topic have been widely studied since their initial introduction in 1944. This study will be looking at zero-sum matrix games and calculating solutions to all possible inputs to the matrices. With this in mind it is important to research into work previously carried out on this subject. It is necessary to look at how exactly a zero-sum game is defined and how it is represented. Another point of interest is to show how these matrices represent the appropriate payoffs to the players of each individual game. These are the main areas of research into the background of game theory. Moving on from game theory the final program providing the calculations for this solution will need to be a complex algorithm. Therefore algorithm design will play a significant part in this study. The efficiency of algorithms and how they will aid the complexity of the eventual program built will be looked at. Finally, it is important to make sure this study is very much up to date with current advances in this field. Looking on the internet is the best way forward to make sure that the study is topical. This should help me to uncover potential solutions to this problem that are currently in place, and will help me to avoid mistakes that have been made in the past. The software that is used by these solutions could also direct me to which software to use when programming my final application.

Computing Optimal Strategies in Zero-Sum Matrix Games

8

2.2 Game Theory

2.2.1 Introduction to Game Theory As the mathematical area of game theory plays an important part in the solving of these matrices it is important to define exactly what game theory is and some of the relevant aspects of this topic. To understand game theory it is necessary to define exactly what is meant by a game. A game must have at least two players and from a given point in that game each player has a number of strategies available to them. Each player will have a final payoff attributed to them depending on the strategies they have chosen through the course of the game. 2.2.2 Elements of Game Theory In this study zero-sum games will be looked at. A zero-sum game means that for every gain one player receives the other player will receive an equal loss. “In general, a zero-sum game represents a closed system: everything that someone wins must be lost by someone else” [2]. Because of this, in a two-player game, matrices displaying zero-sum games need not display the payoff for each individual player. Only the player represented by the rows of the matrix needs to be shown, as the player represented by the columns payoff can be calculated from this value. For the columns player it will be the corresponding negative value of the rows player. This makes it easier to represent a game in the matrix. For example take the matrix below:

Player 1 Player 2 It is clear that this is a zero-sum game with every gain from Player 1 being the loss of Player 2 and vice versa. Therefore the above game can be represented as:

Player 1 Player 2 A game will offer two types of best strategy for a player depending on whether the matrix of the game has a saddle point or not. A saddle point is a payoff in the matrix where the value is less than or equal to any other payoff in its row, and greater than or equal to any payoff in its column. “A saddle point is a payoff that is simultaneously a row minimum and a column maximum” [8]. (See page 2 for a formal definition of a saddle point).

A B A (3, -3) (-1, 1) B (0, 0) (2, -2)

A B A 3 -1 B 0 2

Computing Optimal Strategies in Zero-Sum Matrix Games

9

Where a game has a saddle point the players will generally choose the strategy that encompasses that saddle point. However, if the matrix does not have a saddle point, then the players will do best to play a mixed strategy. “A player would only use a mixed strategy when she is indifferent between several pure strategies, and when keeping the opponent guessing is desirable - that is, when the opponent can benefit from knowing the next move” [9]. An appropriate optimum mixed strategy can be created using some mathematical methods. For example, take the matrix below:

Player 1

Player 2 It is clear that this matrix does not have a saddle point. Therefore in this instance it is important to be able to create a 2x2 matrix from the 3x2 matrix above so an optimal strategy can be found. To get to this stage the current matrix must be displayed graphically. It is said, “we can find an optimal mixed strategy by trans-forming the payoff matrix to a corresponding system of linear equations” [10]. This set of equations is shown on the graph below. Payoffs to Player 2

Player 1 A Player 1 B

Figure 2.1 – A Graph Displaying Different Row Strategies

A B A 3 -4 B 1 3 C -6 11

Computing Optimal Strategies in Zero-Sum Matrix Games

10

The graph shows the lines plotted on the graph for all the possible payoffs to Player 2. It displays all of Player 2’s strategies as a line plotted on the graph. For example, the line for Player 2 A starts at 3 and ends at -4 because those are the values found in the matrix for Player 2 strategy A. From this graph Player 2 will want to choose the lowest point on the upper envelope. The upper envelope or bound is a line across the graph of the current highest line in the graph. In figure 2.1 the upper bound starts off as the line of Player 2 A until it crosses with Player 2 B. The upper bound stays as Player 2 B until it crosses with Player 2 C. The upper bound then stays as Player 2 C until the end of the graph. A lower envelope or bound is a line across the graph of the current lowest line in the graph. The lowest point on the upper envelope in this case is the intersection of Player 2 A and Player 2 B. This means Player 2 C can be eliminated as an option. The matrix can be redrawn as such:

Player 1

Player 2 In a 2x2 matrix that does not contain a saddle point the best optimal mixed strategy can be calculated by working out the difference between the numbers in a row or column and then applying that probability to the opposite row or column once the number has been made absolute. This is the arithmetic or Odds method of finding a mixed strategy. This technique “provides an easy method for finding the optimal strategies for each player in a 2x2 game. It consists of the following steps:

i) subtract the two digits in column 1 and write the difference under column 2, ignoring sign.

ii) subtract the two digits in column 2 and write the difference under column 1, ignoring sign.

iii) similarly proceed for the two rows” [11].

For instance in the example above the probabilities are as follows: Player 1 A 7/9 Player 1 B 2/9 Player 2 A 2/9 Player 2 B 7/9 By using this graphical method it is hoped to solve games input by a user. The literature studied seems to suggest this method as the best way to solve a matrix of this type. “To solve the matrix of game theory, graphical method is the easiest compared to other methods such as dominance property, matrix method etc” [12].

A B A 3 -4 B 1 3

Computing Optimal Strategies in Zero-Sum Matrix Games

11

For my project the number of players in a game will be restricted to two, and one of the players is restricted to only having two strategies. This will create 2xn or mx2 matrices. The reason for this is that if a larger matrix than these above were created, it would pose a problem, as the optimal strategies would no longer be solvable by a simple graph. For example, if the matrices were 3xn and mx3, then the method would need to be calculated in three dimensions, which is beyond the scope of this project.

2.3 Algorithm Design The study of algorithms is a very broad subject and it is difficult to study in generality. “An algorithm is a definite list of well-defined instructions for completing a task; that given an initial state, will proceed through a well-defined series of successive states, eventually terminating in an end-state” [13] or in more general terms “an algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem” [14]. The importance of them in the case of this study is that the eventual application built to create optimum strategies in matrix games will need to have a fast, efficient algorithm to collate the input data given to it and output the correct solution. It is important to appropriately analyse an algorithm to check its efficiency and relevance. “Analyzing algorithms involves thinking about how their resource requirements-the amount of time and space they use-will scale with increasing input size” [15]. Finding the right algorithm for this project is clearly a very important aspect of the study, and careful initial planning in this area can save time later on. Making use of the knowledge from game theory it seems clear that, whilst using the matrix, the algorithm will need to find the start and end point on the graph for each choice a player has. Once the application has plotted these lines on the graph, the algorithm will then need to pinpoint where each of the lines representing each choice crosses over on the graph. Using this knowledge, the upper and lower envelope then needs to be calculated, depending on whether the matrix is 2xn or mx2. Once the envelopes have been calculated it should be easy to find out either the highest point of the lowest envelope or the lowest point of the upper envelope. Finally using the results computed so far, a 2x2 matrix can be calculated and the optimal strategies formed.

Computing Optimal Strategies in Zero-Sum Matrix Games

12

For instance using the example from above, the algorithm would need to calculate all the circled points in the diagram below. Payoffs to Player 2

Player 1 A Player 1 B

Figure 2.2 – A Graph Showing Required Points to be Calculated in the

Algorithm

The graphical element of the program should allow the application to find a specific value on the chosen line, i.e. so that x,y values of each line can be computed where the circled points above are shown. It is easy to declare that an algorithm should be efficient, but what does ‘efficient’ really mean with regard to algorithms. Kleinberg and Tardos say “An algorithm is efficient if, when implemented, it runs quickly on real input instances” [15]. This is a very general overview of algorithm efficiency. “Two measures of the efficiency of an algorithm are the number of floating point operations (flops) performed and the elapsed time” [16]. This is a more computational look at algorithm efficiency and allows efficiency to actually be measured rather than just estimated. Using the referenced ideas above, it is believed that the application will indeed benefit from the efficiency of the algorithm being the maximum possible. However, as long as the algorithm can find the optimal strategies in a reasonable time frame (say less than ten seconds) then the user should be satisfied. The important aspect is to not leave the user waiting for too long so that they feel the application is too slow or even not responding. It is also important to make sure the algorithm is coded well, so that a good algorithm design is not wasted. “Even good algorithms can run slowly when they are coded sloppily” [15]. Therefore the design of the code and running of the application is equally as important, if not more important, than the efficiency of the algorithm.

Computing Optimal Strategies in Zero-Sum Matrix Games

13

Another important factor regarding the algorithm is predicting the scale of data that will pass though it. One algorithm may run very well with a small amount of data, but struggle when overloaded. It is vital to be sure of the range of data that the application will have to deal with, and create an appropriate algorithm to deal with, both the highest and lowest range of data. Once the algorithm is built it will be necessary to test its efficiency using scenarios. One possibility is to use the worst case scenario, where the most complicated relevant input is given to the system to see at what speed it will then calculate solutions when put under the most pressure. The worst case scenario is often used because an average scenario is very difficult to calculate. To create an average case scenario random inputs would have to be entered into the system. It is difficult to define whether inputs of this type can ever really be random though, which makes this type of scenario testing unpopular with many. Because of these difficulties average case analysis can “become a quagmire” [15].

2.4 Current Applications in the Market

The volume of literature currently available on game theory is massive. Books, websites and other material are easily accessible for any reader. There are, however, fewer interactive styles of teaching this subject and solving matrices. When building an interactive method of finding optimal strategies in zero-sum matrix games, it is important to find other applications or work that has been completed on this subject. Using these examples it is hoped to identify potential sources that can be built upon, and also see where others may have made mistakes so that this project can ensure it does not replicate them. 2.4.1 Evaluating Applications

It is necessary to find some examples of systems that solve matrix games so that they can be evaluated to see what works well and what aspects could be omitted or improved.

Computing Optimal Strategies in Zero-Sum Matrix Games

14

2.4.1.1 Matrix Game Solver

Figure 2.3 – The Matrix Game Solver

There are some matrix game solvers on the internet; for example there is a website that advertises a “Matrix Game Solver” [17]. This solver contains a text box in which the user can input a matrix using spaces and new lines to separate values in the matrix. Once the user has input the matrix they are instructed to click on a command button which then posts a solution to the matrix in a second text box below the first one. The solution is given as the value of the game, and the optimal strategy for each player. The optimal strategies are given as decimal values adding up to a total of one for each player. I think this is a good idea, as it will be easy to distinguish between values when using the code to input the values into the algorithm. It also allows no limit on the number of rows and columns that can be entered into the matrix.

Computing Optimal Strategies in Zero-Sum Matrix Games

15

The problem with this layout is that for a large matrix the text box adds a scroll bar and it would be difficult to be able to display the whole matrix at the same time. Another issue with this system is that in larger matrices, containing entries of varying characters, the rows and columns can become out of line with each other making the matrix tricky to read and operate on. I think the fact that the solution is given as decimal values is adequate even if the presentation is not ideal. It appears to be an algorithm coping with a matrix of varying sizes which is a positive point. In addition, the algorithm is very quick to respond, from the moment when the command button is pressed, which is also beneficial. However, the application does seem to have its flaws. It does not always give the correct answer to a matrix containing a saddle point which would suggest that there are some problems with the algorithm. In summary, the Matrix Game Solver is a good application, as it offers simplicity and generally delivers an easy to understand and correct output. Nonetheless, it does have its drawbacks including some errors when saddle points are involved and a tricky interface with larger matrices.

Computing Optimal Strategies in Zero-Sum Matrix Games

16

2.4.1.2 Game Theory Tool

Figure 2.4 – The Game Theory Tool

The Game Theory Tool is advertised as “a utility for finite mathematics and finite mathematics and applied calculus” [18]. This tool is laid out as a grid and can accept up to a 5x5 matrix. The grid is a series of small text boxes aligned into rows and columns. The layout of this webpage is user friendly and, although it can only deal with matrices up to a 5x5, it does this well. If the input number is greater than twelve characters, then the whole number will not be displayed fully. This is an event that would not occur often. Once the matrix has been entered there are several options available to the user. Firstly, there are two tick boxes that can be switched to reveal the row or columns strategies when the matrix is solved. If the solve game command button is pressed when both boxes are ticked, then the application will give a solution in a text box under the matrix.

Computing Optimal Strategies in Zero-Sum Matrix Games

17

The solution gives the value of the game and the optimal strategies for each player as a decimal percentage of how many times that strategy should be played. Also, if a strategy is dominated, or deemed not worth using, then the application will put a red cross next to that row. If the solution has a saddle point, then that point will be made clear by marking off the other rows and columns with crosses. In this instance the optimal strategies are not written in the solution as they are not required. There are two other buttons that can be used once a solution is found: “check for saddle points”, and “reduce by dominance”. The check for saddle points button will not change the solution if saddle points have already been found, and will let the user know there are none if a mixed strategy is needed. The reduce by dominance button will put crosses next to rows or columns that have been dominated if they do not already have crosses by them from the matrix being solved. I think this webpage gives a good solution to the matrix games it is given and creates a clear representation of rows or columns that are dominated or when a saddle point exists. The information that is fed back to the user is sufficient to allow them to see the optimal strategies of both players. This application also has a function that allows the user to play the computer at the game governed by the matrix to see the strategies “play out” in a real scenario. The computer will pick the optimal strategy for itself and the user can pick strategies by clicking on rows to select them. The user can only play as the rows player. This functionality can be useful to see why the optimal strategies shown are indeed optimal. The major problem discovered with this application is that it does not deal very well with multiple saddle points, as it will only find the first one and then declare the other rows and columns obsolete. This is not the case as matrix games can have many saddle points. In conclusion, this webpage presents the data clearly to the user as well as a sufficient amount of data about solutions to matrix games. Playing out the games with the computer also adds an extra element. However, its failure to deal with multiple saddle points is a serious drawback of the application.

Computing Optimal Strategies in Zero-Sum Matrix Games

18

2.4.1.3 Zero-Sum Game Solver

Figure 2.5 – The Zero-Sum Game Solver

Another website states that “It is possible to solve a zero-sum game using the simplex algorithm or any other algorithm that can solve a linear programming problem” [19]. This webpage has a brief description of zero-sum games and then below the description a zero-sum game solver. The solver consists of a text box and two command buttons - submit and reset. The text box is where the user enters a matrix and the reset button clears all the text currently in the text box. The user must separate each row value with a comma, and each new row is made by creating a new line in the text box. There is no stated limit on how many rows and columns the application can deal with. However, the text box is limited to a certain number of characters on each line before it creates a new one, and a scroll bar is used for a large number of rows in the matrix. This is a very simple easily understood layout, although it lacks any matrix structure as columns can become very much out of line with each other. The simplistic approach does make it quick to learn and easy to use. Once the user has input the matrix they are instructed to click the submit command button. After this is done the webpage redirects to the solution page. The solution page shows the matrix in a neat table followed by the optimal strategy of the columns player. The value to the rows player is shown underneath this strategy. I think this application would be improved if the actual optimal strategy of the row player was given to the user as part of the solution. Furthermore, the separate solution page is not the best idea either, as it takes time to load and makes the user wait longer than necessary to see the solution. Also, there is no navigation back to the game solver from the solution page.

Computing Optimal Strategies in Zero-Sum Matrix Games

19

This application can deal with single saddle points creating the optimal solution for the columns player, but this is another application that does not correctly find multiple saddle points. Overall, the simplistic nature of this design makes it easy to use, but there are better presented matrix game solvers that can also create an optimal strategy for the rows player.

Computing Optimal Strategies in Zero-Sum Matrix Games

20

Chapter 3

Requirements Analysis and

Specification

The initial requirements phase was spent examining current solutions to the problem of calculating optimal strategies in zero-sum matrix games. Having done this, it was apparent that there are some aspects of finding optimal strategies that current applications in operation cannot calculate properly. The major one of these is to properly acknowledge the existence of multiple saddle points. Therefore being able to create an application that can achieve this goal is a priority. Creating a zero-sum matrix game solver that could deal with these multiple saddle points would then also generate an application that is an improvement on current programs in the market. Obviously it is also important to ensure that the program created is also able to perform all other calculations needed to properly solve a zero-sum matrix. The first requirement of the application is that it needs to be able to receive a user input of a matrix. Rather than continually prompt the user for values, a graphical user interface (GUI) is much more user friendly and reduces the time needed to input entry numbers into the computer. “A major advantage of GUIs is that they make computer operation more intuitive, and thus easier to learn and use” [20]. Therefore a GUI approach will be used to make best use of these advantages. Given that a matrix has a number of rows and columns, it is important that the user can easily see into which row and column they enter each number. The application will need a clear layout so that users are aware of the location of each number they input. The user will want to input a variety of different matrices, and so the application will be required to expand and reduce matrix rows and columns to allow the user to input the matrix they desire. However, this will still be bound by the constraints of the project which allow there to be either only two rows or only two columns.

Computing Optimal Strategies in Zero-Sum Matrix Games

21

There will need to be a way in which the user can reset a form should a mistake be made, or if they have finished with their current matrix and wish to begin again with a completely new one. Once a matrix has been input, the user then needs to be able to tell the application to solve the matrix. Thereafter, the application will need to check the matrix for saddle points. All values in the matrix will need to be checked to see if they are independently a saddle point - the application will definitely have to be able to cope with multiple saddle points. If multiple saddle points exist, they will be of the same value. “All saddle points in a game have the same payoff value” [21]. If a saddle point is found, then it needs to be pointed out to the user and the matrix is then considered solved. If multiple saddle points exist, then they all need to be highlighted to the user. After a saddle point or points in the matrix are verified the application will not need to perform any further calculations on the matrix. If a saddle point is not found in the matrix, then the application will be required to find a mixed strategy to solve the matrix. The application will need to condense the matrix into a 2x2 matrix, if it is not already this size. In addition, if it is not a 2x2 matrix then the application is required to plot a graph to create a graphical representation of the problem. Achieving an acceptable solution once this graph has been plotted will depend in this instance on whether the matrix has: (a) only two rows, or (b) only two columns. If (a) above, then the application will take the highest value in the lower envelope created by the graph and, using this, it can calculate the two columns that will be required for the optimal strategy. If (b) above, then the program will take the lowest value in the upper envelope created by the graph, and will be able to work out the two rows that are needed for the optimal strategy. Once a 2x2 matrix is created, then the percentage of times each strategy should be played can be calculated. The frequency that each strategy should be played then needs to be shown to the user for both rows and columns. This then solves the matrix and gives the user the optimal strategy. To be able to achieve the above criteria some key resources will be needed. The first of these is that an appropriate programming language is required. This is important as “the choice of the appropriate programming language can make or break a project” [22]. This language will be able to build an appropriate GUI so that the user can navigate around the final application with ease. The language also needs to have a way of displaying a graph for the user to view. This graph will need to be clear so that the user can appreciate what the graph is displaying. Another requirement of the program is that it will need to be a fast and efficient tool. It needs to have minimal loading times, if any at all, as part of its appeal is that it is vastly superior to a hand-written approach with regards to time taken to solve a matrix. To make sure this occurs the algorithm driving the code behind the GUI will need to be efficient and avoid unnecessary calculations.

Computing Optimal Strategies in Zero-Sum Matrix Games

22

The speed at which the user can navigate through the GUI to the appropriate screen is also of relevance here. The user needs to be able to click through menus quickly so the application must make it clear which menu options are relevant to the user at all times. No unnecessary forms or elements should be added.

Computing Optimal Strategies in Zero-Sum Matrix Games

23

Chapter 4

Form Design

The first decision when designing the software was to pick a language with which to build the final application. It was decided to use visual basic 6.0, as it is a well-established programming language, can handle graphical elements, and produce a user friendly GUI. “VB6 is a very good development tool” [23]. To produce a user friendly GUI the application has a main menu allowing the user to choose which type of matrix they would like to solve. The menu gives them the opportunity to choose between: (a) a 2x2 matrix, (b) a matrix containing only two rows, or (c) a matrix containing only two columns. Overall, the forms created have been designed to be very user friendly. Most of the buttons are clearly marked command buttons making them obvious to the user as something to click on and also obvious as to what function they perform. Text boxes have been used for the user input, as they ensure that the user is able to quickly add, delete, or edit data that they have input into the various matrices. The user will be required to enter values into the text boxes to create a matrix. Users must enter integers into the text boxes up to a maximum of four digits in length. Negative numbers will be accepted by the application. An initial potential issue was that combining a programming language to a graphics package could be overly complicated. As lines, shapes and figures are easily drawn in visual basic 6.0 it seemed in the interests of user friendliness to use these qualities of the programming language in the application. Graphs have been introduced to the more complex matrix types as an aid to the user to show how the final optimal strategy has been calculated. In designing the application it was decided that the end product would be to find optimal strategies for matrix games in a quick and efficient manner. This means that the application does not explain each step it performs in depth, hence keeping it running quickly and efficiently.

Computing Optimal Strategies in Zero-Sum Matrix Games

24

4.1 The 2x2 Matrix

Figure 4.1 – The 2x2 Matrix

The 2x2 matrix form shown in figure 4.1 is loaded if chosen by the user from the main menu. This is the simplest of the three matrix forms. The 2x2 matrix displays four text boxes so that the user can easily input numbers into a 2x2 matrix. The text boxes are clearly labelled A and B in the rows and columns. From the 2x2 matrix form screen the user can return to the menu by pressing a command button, reset the matrix or calculate optimal strategies. The menu button will close the form and return the user to the main menu. The reset button will reset all the values in all the text boxes and any previous results from past calculations. If the user presses the calculate optimal strategies button, then the application will solve the matrix. In the case of saddle points, the saddle point, or points, will be highlighted in red to the user to indicate their position in the matrix. An information label will also appear notifying the user of the saddle point or points and hence the solution to their matrix.

Computing Optimal Strategies in Zero-Sum Matrix Games

25

If a saddle point does not exist, then the result is shown as a mixed strategy. This is output to the user as a fraction, as to how often each row or column strategy should be played to create an optimum strategy. This is displayed in four text boxes that appear at the end of each column and row.

4.2 The Two-Row Matrix

Figure 4.2 – The Two-Row Matrix

The two-row matrix shown in figure 4.2 can be accessed by clicking the two-row matrix option from the main menu. Similarly to the 2x2 matrix, the two-row matrix has a menu button and reset button to return to the main menu and reset the matrix respectively. However, on this form the reset button is also used to reset the graph pane and the number of columns.

Computing Optimal Strategies in Zero-Sum Matrix Games

26

The two-row matrix form has a button that allows the user to add columns to the matrix up to a maximum of five. Initially only a 2x2 matrix is shown using four text boxes. After five columns have been added the user is notified that no more columns may be added. When the calculate optimal strategies button is used, if the matrix has a saddle point or points, then they will be highlighted in red and the user will be told of this. If there is no saddle point and there are more than two columns, then a graph is plotted displaying all the lines of the different columns to show the user where the lower bound is and what is the highest point on that lower bound. The user can see why certain columns will be needed for the final optimal strategy, which is then displayed in a 2x2 matrix form, showing fractions for how often each strategy should be played for each row and column.

4.3 The Two-Column Matrix

Figure 4.3 – The Two-Column Matrix

Computing Optimal Strategies in Zero-Sum Matrix Games

27

The two-column matrix shown in figure 4.3 will load if the user clicks the two-column option from the main menu. The two-column matrix also has a menu button and a reset button that returns the user to the main menu and resets the matrix and the graph pane respectively. The two-column matrix starts off as a 2x2 matrix containing four text boxes. The user can increase the number of rows to five, but the application will allow no more than five rows. As with the other forms the two-column matrix form has a calculate optimal strategies button. This button behaves in a similar way to the two-row matrix and saddle points are highlighted in red. However, the graph created is designed to find the lowest point on the upper bound of the graph. The user will then be able to see which rows are required for the final 2x2 matrix that will show the optimal strategy. The strategy is shown as fractions for each column and row.

Computing Optimal Strategies in Zero-Sum Matrix Games

28

Chapter 5

Code Design The application involves many complicated algorithms and some in-depth mathematics. Creating appropriate code therefore to minimise processing time and unnecessary calculations was key when designing the application. “Measuring an algorithm's efficiency is important, because when we have a problem to solve, there may be several suitable algorithms available. We would obviously like to select the best” [24]. Some of the major challenges in this section of the design were creating code to draw and manipulate the graphs created by the matrices, and making sure that code would work correctly on varying matrix sizes. The basic navigation of the application is relatively simple with forms being shown and closed where appropriate. As a user navigates away from one page it will be closed to make sure the focus of the user is then on the new form that has opened before them. The navigation is easy for the user as all types of matrix can be quickly accessed from the main menu, and this main menu can be accessed again in one button click at any one time. To allow for varying larger matrices, command buttons are placed on some forms to allow for more columns or rows to be added to the matrix. For this a hidden text box is used as a counter so that the application knows how many rows or columns it currently has. This then allows the application to use this hidden text box to make the appropriate text boxes appear when rows or columns are added. The limit for rows or columns is five and, if the user tries to add more than this number, then the application notifies them with a message on the screen that the matrix cannot be made larger. This message is on a timer and will disappear so as not to be a distraction after five seconds. The code behind the reset buttons is mainly a case of hiding and resetting values. The final fractions of the amount of times each strategy should be played are hidden and all the values in the text boxes are reset. The graphs contained in the picture boxes are also cleared by resetting the back colour. This code also resets the colour to white in text boxes that have been shown as red to indicate saddle points.

Computing Optimal Strategies in Zero-Sum Matrix Games

29

The most complicated part of the coding is behind the calculate optimal strategies buttons. These buttons calculate saddle points and optimal strategies as well as producing graphs in picture boxes.

5.1 The 2x2 Matrix The first aspect of designing these buttons was to be able to solve the 2x2 matrix. If a matrix has a saddle point then this creates an immediate optimal strategy. Therefore the first objective was to find any saddle points in the matrix. This is done by taking the values from the text boxes and comparing them against each other. As a saddle point is a row minimum and a column maximum, each value in the matrix is checked to see if it is smaller than or equal to the other value in its row, and larger than or equal to the other value in its column. If so then this is a saddle point. The “if” statements used in this part of the code must be separate and not use “else”, otherwise multiple saddle points are not found. If a saddle point is found it increments the saddle point flag and highlights the appropriate text box in red. After all the comparisons are made, this flag can then be used to determine whether any saddle points were found. If one has been found then the user is notified by a message on the screen. If more than one saddle point had been found the user is also notified of this. The messages displayed to the user are then displayed for five seconds on a timer so that the user can read them, but they are not a distraction for too long. This then concludes searching for saddle points, as the user has been notified if one exists, and also if it is one or multiple saddle points that have been found in the matrix. However, if the saddle point flag is still at zero, then the application must now search for a mixed strategy. The mixed strategy starts as an “else” from the saddle point flag being checked, as it is only needed if a saddle point has not been found. The solution of the mixed strategy is calculated as a fraction. The individual numerator for each row is found by subtracting the number for choice column A by choice column B and then ignoring the minus sign if it exists. This numerator is then used for the opposite row. This procedure is then followed in the same way for the columns. The fraction denominator is calculated by adding the values of the two row numerators. When designing this code, the first step was to make variables hold the differences for each row or column. These values then had to be absolute which is done by multiplying any negative numbers by minus one. Then variables will hold the absolute values of the difference for each row or column. That then becomes the numerator of the opposite row or column with the denominator for each row and column being the total of the two row numerators. Once the values are calculated they are displayed to the user. The code makes text boxes visible at the end of each row and column displaying the fraction that shows how often each strategy should be played. Labels to explain to the user what they are looking at are displayed at this point as well. That concludes the code for the 2x2 matrices which is used in all the forms.

Computing Optimal Strategies in Zero-Sum Matrix Games

30

5.2 Matrices larger than 2x2 For matrices larger than 2x2 the code to calculate optimal strategies is a little different. In this scenario, any saddle points of the matrix are still the first values to be found. The code for this is very similar to the 2x2 matrix code, but obviously there may be more than one number to check each other number against, now there are multiple numbers in rows or columns. However, if a particular value is a row minimum and a column maximum, it is highlighted in red and the user is notified of the result. The real difference in code for these larger matrices occurs if a saddle point does not exist. If a saddle point is not found, then a graph displaying values in the matrix is displayed. Firstly, the highest and lowest numbers in the matrix are found with a simple couple of “for” loops. Using these values the scale of the graph can be drawn to incorporate all the values of the matrix onto the picture element. Next the lines for each row or column of the graph, depending on whether it is a two-row or two-column graph, are drawn. This is done by using a “for” loop that loops enough times to draw all the lines depending on the number of rows and columns in the matrix. It does this by using the hidden text box flag that keeps track of how many extra rows or columns have been added, so the correct number of lines can be added to the graph. The “for” loop used for this has a “step” added to it so that the line of the graph is drawn every 0.25 units to create a straight line for the user to view. The lines on the graph are calculated by taking the first number (i) of the row or column, and then also calculating the difference between the numbers in the row or column by subtracting the first number in the row or column from the second number (j). This creates a straight line equation for each row or column as shown below: y = i + (j – i) * x where the letters i and j are replaced by the actual numbers. For every loop whilst drawing the graph lines, the colour of the line being drawn is changed so the user can differentiate between them.

Computing Optimal Strategies in Zero-Sum Matrix Games

31

The code for drawing these graphs is shown in figure 5.1 below:

For i = 0 To z

If i = 0 Then Picture1.ForeColor = vbRed

If i = 1 Then Picture1.ForeColor = vbBlue

If i = 2 Then Picture1.ForeColor = vbGreen

If i = 3 Then Picture1.ForeColor = vbYellow

If i = 4 Then Picture1.ForeColor = vbCyan

x = -10

y = nums(i * 2) + diff(i) * x

Picture1.CurrentX = x

Picture1.CurrentY = y

For x = -10 To 10 Step 0.25

y = nums(i * 2) + diff(i) * x

Picture1.Line -(x, y)

Next x

Next i

Figure 5.1 – Code for Drawing Graphs

In figure 5.1 the variable z is a count which is set to the amount of lines needed for the graph minus one. The nums array holds the values of each row and column of the matrix and the diff array holds the values of the difference between the two values in each row or column depending on whether the matrix is a two-row or two-column matrix. The next part of the code calculates the upper or lower bound of the graph, and at this point the difference in code between the two-row graph and two-column graph is significant. Therefore to describe these graphs the two types of matrix will be split into two sections.

5.3 The Two-Row Matrix In the two-row matrix the desired outcome is to find the highest point on the lower bound of the graph. Finding the lower bound and the highest point on it can be done at the same time. This can be calculated using a “for” loop. The “for” loop is from zero to one, as this spreads the whole way across the graph. The idea behind this “for” loop is to find out at every point on the graph the line with the lowest value, which creates the lower bound. A “step” of a very small number is used so that the value of each line can be very precise, allowing the graph to be accurate where one line stops being the lowest and another line starts being the lowest.

Computing Optimal Strategies in Zero-Sum Matrix Games

32

At each step the equation of each line is calculated and the value stored in a variable. This variable is compared to the others to see if it is the lowest. The lowest line at zero on the x-axis of the graph is then stored into an array. From this point on, the algorithm is only interested in a change in the lowest line on the graph. The algorithm will keep checking each line equation against the others at every “step” of the “for” loop, but it will only store a different value in the array if the lowest line changes. If the lowest line does change, then the array will store the number of the new lowest line and at what value on the y-axis the lowest line changed. This then continues until all the lowest lines, and at what y-axis value they change at, have been calculated. The code then needs to discover how many times the lines crossed each other so it can work out how many values it needs to compare. This is done by checking the array holding the names of the lowest lines in the graph. If there is no value held in the third slot of the array, then there was only one crossover between the lines, and therefore this will be the highest point on the lower bound. If no value is held in the fourth slot of the array, then there are two crossovers. The values at which the two crossovers take place are compared and the higher is chosen. This process continues with values being compared at any crossovers with the higher value being chosen. The two lines involved in the highest crossover will be the two columns needed for the optimal strategy. The two columns and rows needed for the 2x2 matrix are then found and so, using the code for solving a 2x2 matrix, a solution can be calculated and displayed to the user.

5.4 The Two-Column Matrix For the two-column matrix the lowest point on the upper bound is needed. For finding the upper bound and the lowest point on it, a “for” loop can be used in a similar way to the two-row matrix. The loop again is from zero to one with a “step” of a very small number. The difference in code for this type of matrix is that as the loop runs, the highest value of a line at any one time is needed to create the upper bound. The line that is highest at each point on the graph is put into an array every time a new line becomes the highest. In the same way as the two-row matrix all the highest lines at any point are recorded as well as the y-axis value when they change. The array of highest lines is checked to see whether a value exists in the third slot, then the fourth slot, and then this process continues to find out how many crossovers exist in the graph. If more than one crossover exists it will be compared to the others to find the lowest crossover point. This lowest crossover point will then be used to pick the two rows that correspond to the lines creating the crossover. The columns needed are the only two available and, once the rows needed for the optimal strategy have been found, a final 2x2 matrix can be solved using the code for mixed strategies for 2x2 matrices. This then completes the solution for the matrix.

Computing Optimal Strategies in Zero-Sum Matrix Games

33

Chapter 6

Testing

The main aspect of testing the application is making sure that for any matrix input by the user, an optimal solution can be found. This involves creating acceptable solutions for matrices with single saddle points, multiple saddle points and mixed strategies.

6.1 Overall Test Strategy A “test strategy should help in facilitating the communication of the test process and its effects on the entire project” [25]. The testing strategy is predominately based on testing outputs based on selected inputs to see if the correct solutions are given. However, other parts of the application need to be tested, for example navigation of the system and whether the content is displayed correctly. Initial testing involved making certain that the navigation around the application was successful. The testing ensured that each form could be accessed and that the main menu could be accessed from each form. This part of the testing also confirmed that all the navigation buttons were labelled appropriately, and sent the user to the correct place according to the button label. The next stage of testing was to check that all the basic command buttons were performing the correct tasks: these were the reset buttons and the adding of rows and columns buttons. The reset buttons were tested to check that all the values in text boxes were in fact reset, and all objects that had appeared in the course of a calculation were again hidden. The adding of rows and columns required testing to check that extra rows or columns were produced in the correct order, and that once five rows or columns had been added, no more were subsequently added. The testing checked that if the user tried to add a sixth column or row then one of the following texts was displayed to the user: Additional columns cannot be added Additional rows cannot be added

Computing Optimal Strategies in Zero-Sum Matrix Games

34

It was also important to check that these messages were hidden again after a certain time period so as not to distract the user. The most important testing area was then tackled. This was calculating the optimal strategies in the different sized matrices. First the 2x2 matrix form was tested. Inputs were designed to test that the code would correctly solve a matrix with a saddle point, multiple saddle points and mixed strategies. Saddle points were placed in every one of the four row and column combinations to check that wherever a saddle point occurred it would be found. Then the two-row and two-column matrices were tested. These matrices required testing to be sure that they could correctly find solutions for individual saddle points, multiple saddle points and mixed strategies. However, these scenarios also need to be checked in the different sized matrices available to the user as well. The graphs plotted for the mixed strategies were tested to check that the lines being drawn matched the matrix and also that they displayed the correct upper and lower bounds. The crossovers of the lines creating the highest or lowest point in a bound were tested to check they corresponded with the solution of the mixed strategy.

6.2 Areas of Particular Testing Interest When performing some initial testing a problem with the code was found for two-column or two-row matrices. If the row or column number was less than the total of five then sometimes the application would crash when the optimal strategies were being calculated. It was discovered that because some of the hidden rows or columns were not being used, they were setting the variables used in the algorithm to zero. This meant that if the upper bound for a two-column matrix was well below zero, then the hidden rows were being accepted as the upper bound and, since they contained no values, they were crashing the application (see fig 6.1). This was also happening in the two-row matrix if the lower bound was well above zero, with the hidden columns causing the system error.

Computing Optimal Strategies in Zero-Sum Matrix Games

35

To rectify this some “if” statements were created to take the value of the extra rows or columns only if they were not hidden. For the two-column matrix the variables of the initially hidden rows were set to very low numbers so that they would not interfere with the calculation. For the two-row matrix the variables used for the initially hidden columns were set to very high numbers.

Figure 6.1 – Initial Error Found in Application

The most complicated of the tests were ones involving either the two-column or two-row matrix. In this complex test example the two-row matrix will be shown being tested to find a mixed strategy using the column limit of five. This is also a specifically interesting test, as all the lines in the graph if output properly will become part of the lower bound at some point. This means the algorithm has to change between all the graph lines and pick out the highest of the four crossovers the graph should show. The application is then required to predict the correct output which should be using columns A and E (see fig 6.2).

Computing Optimal Strategies in Zero-Sum Matrix Games

36

Figure 6.2 – The Correct Solution to the Matrix Problem

From figure 6.2 it is clear to see that the test plotted the graph correctly and that the correct columns have been chosen in the final 2x2 matrix. To prove this final 2x2 matrix is indeed correct, the calculations to solve the 2x2 matrix will be shown below: Say the rows player plays choice A with probability x, and choice B with probability (1-x) as all probabilities must add up to 1. If the columns player’s expected values are then calculated for their choices A or E, then: Column A: x(1) + (1 – x)(3) = 3 – 2x Column E: x(2) + (1 – x)(1) = 1 + x

Computing Optimal Strategies in Zero-Sum Matrix Games

37

The columns player will not be able to take advantage of the rows player’s strategy if the two equations are the same: 3 – 2x = 1 + x 2 = 3x x = 2/3 Therefore if the rows player plays choice A 2/3 of the time, and choice B 1/3 of the time, they can be assured that they win at least 1 and 2/3 a unit per game. Column A: (2/3)(1) + (1/3)(3) = 1 and 2/3 Column E: (2/3)(2) + (1/3)(1) = 1 and 2/3 Using a similar calculation the columns player’s strategies can be found. Row A: x(1) + (1 – x)(2) = 2 - x Row B: x(3) + (1 – x)(1) = 1 + 2x 2 – x = 1 + 2x 1 = 3x x = 1/3 Here the columns player will choose A 1/3 of the time and choose E 2/3 of the time. This assures that the columns player will only let the rows player win on average 1 and 2/3 a unit per game. Row A: (1/3)(1) + (2/3)(2) = 1 and 2/3 Row B: (1/3)(3) + (2/3)(1) = 1 and 2/3 These calculations confirm that the application has managed to solve this more complex problem correctly, and has given the user an optimal strategy for their zero-sum matrix game. In a test scenario no amount of testing can ever deduce that an application is error free, although the application has had sufficient tests completed on it to suggest that for any type of matrix given, it can produce the correct solution.

Computing Optimal Strategies in Zero-Sum Matrix Games

38

Chapter 7

Conclusion

7.1 Aims and Requirements The aim of this project has been to create an application that could successfully solve zero-sum matrix games to avoid using a) lengthy hand-written methods, and b) unreliable computational methods currently available to users. Overall, the project achieves this objective and therefore produces a unique way of calculating solutions to matrix games. One of the main aims of creating the application was to enable it to calculate multiple saddle points from the matrices given. This was because some of the computational matrix solvers discovered in the research could not perform this. It was expected that it would be possible to write an application that could achieve this goal; the final application has succeeded in this task. Another aim was to create a solver of zero-sum matrix games so that it would be quicker to find solutions than using a hand-written method. For this it was important that the processing time of the algorithm was not excessive. In the literature survey it was defined that the algorithm should take no longer than ten seconds to find solutions. In the final application the solutions are found almost instantaneously and consistently in less than a second. With the hand-written method taking far more time than this to calculate optimal strategies, the application has succeeded in finding solutions faster than the hand-written method. The application fulfils the requirements set out by the aim in the project plan, in that it can take a set of payoffs in matrix form and display the best possible strategies for the given data. The application produces a graph and uses this graph to calculate optimal strategies for the user, based on the original pure strategies.

Computing Optimal Strategies in Zero-Sum Matrix Games

39

In addition, the application has remained within the constraints set out by the literature survey. This is due to the fact that the application will only allow matrices that are 2x2, 2xn and mx2 row/column size. This is to ensure that all possible matrices allowed by the application can be displayed and solved by a two-dimensional graph. If matrices of 3xn or mx3 were allowed, for example, then a three-dimensional graph would be required.

7.2 Procedures Used and Problems Encountered The building of the application was a comparatively straightforward procedure, with regard to which parts should be built in what order, and which could use previous parts of the application to avoid reproducing code. It was logical to begin with the standard 2x2 matrix, and the same code could then be used in the two-column and two-row matrices. No major difficulties were encountered whilst coding the 2x2 matrix, and this code was a very useful template for use with the other matrices. Using this template, the coding of the saddle points and the multiple saddle points of the other matrices could be coded using some of the same techniques. The hardest aspects of programming the application came when creating the graphs, and evaluating which rows or columns were needed for the optimal strategy in the case of mixed strategies. The method used in this project worked well to draw the graphs using line equations, and loops containing steps to draw the graphs. For working out the mixed strategies, for the two-row and two-column matrices, looping with a “step” of a minuscule number allows the application to find exactly when one line no longer becomes part of the upper or lower bound and another line takes over. This method has worked well, and fears that this process could greatly increase the processing time of the application have been allayed. One difficulty with this style of application is the number of different types of input and answer to have to deal with. This is because it is problematic to test the application for all potential input cases. Quite extensive testing is required to find and remove errors in the code and it is an easy mistake to omit an input type from the testing plan.

7.3 Future Recommendations The project manages to create a simple yet efficient way of solving zero-sum matrices and is reliable in doing so. Its reliability and speed of calculation are the main elements that set it apart from other methods that are used currently in this field of study. This project has set a benchmark that can hopefully now be built upon by others in the area of game theory. As the same code for parts of this project can be reused, a better way of tackling this project may be to increase testing early on, so code that can be reused is already working in many different scenarios. This avoids an issue manifested in this project: if the majority of testing is performed after the code is complete, then, when errors occur, the code has to be changed in many places.

Computing Optimal Strategies in Zero-Sum Matrix Games

40

The lessons learnt from this project are that fast and efficient computer algorithms can make a paper-based procedure obsolete. These computer algorithms, however, must be reliable to offer a truly preferable alternative method.

7.4 Final Conclusions Overall, the speed and reliability of the application are the most impressive qualities. The ease of use is also a great achievement, as it allows users with little computational skill to solve zero-sum matrices. The instant loading times, clear menus and obvious buttons are effective and commendable. To sum up, the project has succeeded in meeting its aims and objectives set out in both the project plan and the literature survey. It can solve zero-sum matrices quickly and efficiently, essentially rendering some other methods of solving these matrices as obsolete, for example a hand-written approach. The application built is also reliable and can correctly identify multiple saddle points, two key aspects that many computational zero-sum matrix solvers currently lack. It is due to these qualities that it can be used to further develop research into the study of game theory.

7.5 Further Developments There are a several ways in which this project could be expanded for future research. Continuing the development of the project has the potential to create an even more sophisticated tool for use in solving zero-sum matrix games. One way of furthering the project would be to find a way to alert the user of when more than two lines cross at exactly the same point, and to create an optimal strategy using more than a final 2x2 matrix. In this case, more than two rows or columns can be used in an optimal strategy, although the strategy will still be as effective as one containing only two rows and columns. The application currently deals with the above scenario by providing an optimal strategy with two rows and columns, but this additional function would show the user all the possible combinations of the strategy, even though this strategy would be just as optimal as the one currently used in the application. Another development could be to fully demonstrate all the possible strategies when a line in the upper or lower bound is horizontal across the graph. The application will currently show the optimal strategy at the left-hand most point of this horizontal line which is, in fact, an optimal strategy, but not the only possible one (see fig 7.1).

Computing Optimal Strategies in Zero-Sum Matrix Games

41

Figure 7.1 – Example of a Flat Line as Part of the Upper Bound

This development could then show the user all possible optimal strategies that could be used across the horizontal section of the graph. If the horizontal line becomes part of the upper or lower bound, then multiple optimal strategies could be available to the user. For example, in figure 7.1 the horizontal green line is the lowest point in the upper bound from the point where it crosses the blue line, to where it crosses the red line. In this case there is an optimal strategy available across the whole section of the green line at any point where it is part of the upper bound. This would also be the case if the horizontal line was part of the highest point in a lower bound. One final extension to the project could be to allow the matrices to expand to 3xn and mx3 rows/columns. This adds an extra dimension to the graphs being produced to solve these matrices. In this case the matrices will be solved by comparing planes, instead of lines looking at triangles created in a three-dimensional environment. The upper and lower bounds would still need to be calculated to find solutions to the matrices. However, the addition of the z-axis would greatly increase the complexity of the problem and any potential algorithm to solve it.

Computing Optimal Strategies in Zero-Sum Matrix Games

42

Bibliography

[1] STRAFFIN, P., 1993. Game theory and strategy. The mathematical association of

America, 1993. pp. ix – 3 [2] OWEN, G., 1982. Game Theory. Academic Press INC., 1982. pp. 10 [3] TCL DEVELOPER XCHANGE, Language Comparison [online]. Available from: http://www.tcl.tk/about/compare.html [Accessed 06.12.2007] [4] CHASTAIN, S. What’s the BEST Graphics Software? [online]. Available from: http://graphicssoft.about.com/od/findsoftware/a/bestsoftware.htm [Accessed 06.12.2007] [5] INSTITUTE OF TRANSPORT STUDIES, Glossary [online]. Leeds University. Available from: http://www.konsult.leeds.ac.uk/public/level1/sec17/index.htm [Accessed 03.12.2007]. [6] WIKIPEDIA, Saddle Point. In: Wikipedia: the free encyclopedia [online]. St Petersburg, Florida: Wikimedia Foundation. Available from: http://en.wikipedia.org/wiki/Saddle_point [Accessed 02.12.2007] [7] WIKIPEDIA, Mixed Strategy. In: Wikipedia: the free encyclopedia [online]. St Petersburg, Florida: Wikimedia Foundation. Available from: http://en.wikipedia.org/wiki/Mixed_strategy [Accessed 03.12.2007] [8] WANER, S., 1997. Game Theory [online]. Available from: http://people.hofstra.edu/Stefan_Waner/RealWorld/Summary9.html [Accessed 09 December 2007]

[9] SHOR, M., 2005. Mixed Strategy [online]. Available from: http://www.gametheory.net/dictionary/MixedStrategy.html [Accessed 09 December 2007]

Computing Optimal Strategies in Zero-Sum Matrix Games

43

[10] ANDERSSON, R., 2006. Pseudo-Optimal Strategies in No-Limit Poker [online]. Available from: http://www.cs.umu.se/education/examina/Rapporter/RickardAndersson.pdf [Accessed 10 December 2007] [11] GUPTA, K., 2007. Operations Research [online]. Chand, S. Available from: http://books.google.com/books?id=HFY8ROnNSOEC&pg=PA794&lpg=PA794&dq=2x2+matrix+mixed+strategy&source=web&ots=aocyEIz6E_&sig=KL23uUXy2Pur_rwRrQ2R2rkbPE8#PPA794,M1 [Accessed 10 December 2007]

[12] KUMAR, S. AND REDDY, D., 1999. European Journal of Operational Research [online]. Elsevier, Amsterdam. Available from: http://cat.inist.fr/?aModele=afficheN&cpsidt=1742275 [Accessed 10 December 2007]

[13] WIKIPEDIA, Algorithm. In: Wikipedia: the free encyclopedia [online]. St Petersburg, Florida: Wikimedia Foundation. Available from: http://en.wikipedia.org/wiki/Algorithm [Accessed 10 December 2007]

[14] WHATIS.COM, 2007. Algorithm [online]. Available from: http://whatis.techtarget.com/definition/0,,sid9_gci211545,00.html [Accessed 10 December 2007]

[15] KLEINBERG, JON, AND TARDOS, ÉVA, 2006. Algorithm Design. Boston: Pearson. pp. 29-31 [16] MET, 1996. Comparing efficiency of algorithms: flops and etime [online]. Available from: http://web.ift.uib.no/Fysisk/Teori/KURS/WRK/mat/chapter2_16.html [Accessed 08 December 2007] [17] ANON, Calculating the Solution of a Matrix Game [online]. Available from: http://www.math.ucla.edu/~tom/gamesolve.html [Accessed 08 December 2007] [18] WANER, S., AND COSTENOBLE, S. 2006. Game Theory Tool [online]. Available from: http://people.hofstra.edu/Stefan_Waner/gametheory/games.html [Accessed 09 December 2007] [19] LEVINE, D., What is a solution to a zero sum game? [online]. Department of Economics, UCLA. Available from: http://levine.sscnet.ucla.edu/Games/zerosum.htm [Accessed 09 December 2007] [20] THE LINUX INFORMATION PROJECT. 2004. GUI Definition [online]. Available from: http://www.linfo.org/gui.html [Accessed 16.04.2008]

Computing Optimal Strategies in Zero-Sum Matrix Games

44

[21] WANER, S., 2007. Finite mathematics topic summary: game theory [online]. Available from: http://www.zweigmedia.com/RealWorld/Summary3b.html [Accessed 19.04.2008] [22] SPINELLIS, D., 2006. Choosing a Programming Language [online]. Available from: http://www.dmst.aueb.gr/dds/pubs/jrnl/2005-IEEESW-TotT/html/v23n4.html [Accessed 20.04.2008] [23] KARABATSOS, J., 1998. GUI Computing [online]. Available from: http://www.avdf.com/aug98/art_vb001.html [Accessed 20.04.2008] [24] KRATCHANOV, K., 2004. Analysis and Design of Algorithms [online]. Available from: http://userspages.uob.edu.bh/itcs345/Website345/Course_Topics/Ch1sec1.1.htm [Accessed 20.04.2008] [25] KELLY, M., 2004. Developing a Project Test Strategy [online]. Available from: http://www.informit.com/articles/article.aspx?p=355875 [Accessed 20.04.2008]

Computing Optimal Strategies in Zero-Sum Matrix Games

45

Appendices

Appendix A – Source Code

The source code for the project can be found on the accompanying CD. The CD contains an executable from which the application can be run, and the source code of each of the forms in the project.

Computing Optimal Strategies in Zero-Sum Matrix Games

46

Appendix B – Example Tests

The 2x2 Matrix

Test for a single saddle point

Computing Optimal Strategies in Zero-Sum Matrix Games

47

Test for multiple saddle points

Test for a mixed strategy

Computing Optimal Strategies in Zero-Sum Matrix Games

48

Two-Column Matrix

Tests for a single saddle point

Computing Optimal Strategies in Zero-Sum Matrix Games

49

Tests for multiple saddle points

Computing Optimal Strategies in Zero-Sum Matrix Games

50

Tests for a mixed strategy

Computing Optimal Strategies in Zero-Sum Matrix Games

51

Two-Row Matrix

Tests for a single saddle point

Computing Optimal Strategies in Zero-Sum Matrix Games

52

Tests for multiple saddle points

Computing Optimal Strategies in Zero-Sum Matrix Games

53

Tests for a mixed strategy