Game Theory: An Example in R
The Maze Runner - James Dashner, source:https://dogearedanddogtagged.com/2015/02/16/the-maze-runner-james-dashner/

Game Theory: An Example in R

It was not my usual stint to explore optimization problems or looking into game theory. It was something that I would avoid at all costs as this was an area out of my context and exposure. Coincidentally and uncannily, I stumbled upon a challenge that requires me to solve a problem and I am bestowed with the sacred task of writing an algorithm in R for this challenge. Since it is an R script that was required, I pounced on the problem statement and start to bang my head on the wall, pulling my hair (not too much to spare anyway...) off, putting my thinking caps on steroids, with an expectation to solve it within day. 

This challenge was actually taken from the ACM International Collegiate World Finals Programming Contest 2011, Problem F. Here's a quick look into the problem statement:

Problem: F
You are the director of Awesomely Complex Machines (or short: ACM), a company producing advanced machinery using even more advanced machinery. The old production machinery has broken down, so you need to buy new production machines for the company. Your goal is to make as much money as possible during the restructuring period. During this period you will be able to buy and sell machines and operate them for profit while ACM owns them. Due to space restrictions, ACM can own at most one machine at a time. During the restructuring period, there will be several machines for sale. Being an expert in the advanced machines market, you already know the price P i and the availability day D i for each machines M i . Note that if you do not buy machine M i on day D i then somebody else will buy it and it will not be available later. Needless to say, you cannot buy a machine if ACM has less money than the price of the machine. If you buy a machine M i on day D i then ACM can operate it starting on day D i + 1. Each day that the machine operates, it produces a profit of G i dollars for the company.
You may decide to sell a machine to reclaim a part of its purchase price any day after you’ve bought it. Each machine has a resale price R i for which it may be resold to the market. You cannot operate a machine on the day that you sell it, but you may sell a machine and use the proceeds to buy a new machine on the same day. Once the restructuring period ends, ACM will sell any machine that it still owns. Your task is to maximize the amount of money that ACM makes during the restructuring.

Input:
The input consists of several test cases. Each test case starts with a line containing three positive integers N , C , and D . N is the number of machines for sale (N ≤ 10 5 ), C is the number of dollars with which the company begins the restructuring (C ≤ 10 9 ), and D is the number of days that the restructuring lasts ( D ≤ 10 9 ). Each of the next N lines describes a single machine for sale. Each line contains four integers D i , P i , R i and G i denoting (respectively) the day on which the machine is for sale, the dollar price for which it may be bought, the dollar price for which it may be resold and the daily profit generated by operating the machine. These numbers satisfy the following conditions:
1 ≤ D i ≤ D
1 ≤ R i P i ≤ 10 9
1 ≤ G i ≤ 10 9
The last test case is followed by a line containing three zeros.
Output:
For each test case, display its case number followed by the largest number of dollars that ACM can have at the end of day D + 1 . Follow the format of the sample output.

I have uploaded the input test file and the sample solution in R code. To test the solution, all you need is to download these two files into the same directory, open up the R code, edit the first line of code and change the directory where you saved these files. Copy all codes in the script, open up R console and paste the code. You should get this output:

 

 

 

I have not performed any error testing in this solution (e.g. checking for the number of N lines after each case). This R implementation will add to the already publicly available C++ and Python solutions online.

The game semantics and logic in game theory and optimization are increasingly gaining popularity in businesses where key stakeholders are looking for the 'best way' to strategize and 'win the game' for their businesses and optimize operations within the organizations. I call this type of analysis as 'prescriptive' as opposed to the other 3 relatives: descriptive, predictive, and adaptive. As crucial as it is to predictive analysis, prescriptive analysis are built upon a deep understanding and foundation on descriptive analysis. Without a proper guidance from the descriptive analysis, it is hard to kick off a prescriptive or predictive analysis.

There are similarities in nature for extracting insights from text which often involves complex logic and unscrambling language semantics into a semi-structured, structured, and entities-relationships. In summary, optimizations, game theory, prescriptive analysis are very distinct which forks into a different track by its own. Data scientists who are capable of performing all different tracks in data science domain (descriptive, prescriptive, predictive, adaptive, social media analysis, BI design, setting up analytic platforms) are extremely valuable and touted as unicorn data scientists.

Hauz L.

Project Manager at Upwork

6 年

Hi Could you be still having the R code? really interesting material

回复
Maximilian Jackson

Leveraging data for the #freedomtodrive #f2d

8 年

Organizations these days need to be smarter. We have so much tools, methodologies and now technology that are proven since the 1950s.

要查看或添加评论,请登录

Garrett Teoh Hor Keong的更多文章

社区洞察

其他会员也浏览了