Konor Unyelioglu has a four-part series on solving game theoretical problems with Apache Spark. Part one lays out the scenario:

One application of game theory is finding optimal resource allocation. For example, as discussed in this article, resource management for heterogeneous wireless networks involves sharing network links, e.g. 3G, Wi-Fi, WiMAX, LTE, between mobile devices of different types and different bandwidth needs. In such environments, game theory algorithms can be effectively used to decide which devices must be allocated to which network resources. Similarly, game theory can be used for allocation of cloud computing resources, e.g. CPU, storage, memory or network bandwidth, between resource clients, as discussed in this article (also see here). The concept of Mobile Edge Computing, where mobile devices offload computationally intensive tasks to the small scale computing servers located in the network edge, could utilize game theory concepts for resource allocation, as studied here.

Using game theory for resource allocation is not limited to cloud computing or telecommunications. For example, in a recent study, a technique was developed based on game theory for efficient distribution of water supply to consumers. Optimum decision making for traffic flow control at major traffic intersections can also be modeled using concepts from game theory, as studied in this article.

Part two defines an algorithm for maximizing utility given the finite set of resources:

Consider Q_{i}(P) defined previously for i = 1, …, N. Let Q_{i}^{1}(P) be defined as the K-dimensional vector where the j-th entry is 1 if and only if there exists an element in Q_{i}(P) where the j-th entry is greater than 0, j = 1,…, K. In other words, if the j-th entry of Q_{i}^{1}(P) is 0 then for every element in Q_{i}(P) the j-th entry must be 0; if the j-th entry of Q_{i}^{1}(P) is 1 then for at least one element in Q_{i}(P) the j-th entry must be 1.

Part 1 starts with the initial price vector at 0, i.e. P = 0, and then at each iterative step finds a new price vector, built on the previous one, that minimizes C(P). At each step, the newly constructed price vector is guaranteed to be no less than the previous one. When the price vector no longer increases, i.e. the newly constructed and previous price vectors are equal, the optimal price P^{o} has been reached. Along with P^{o} we also obtain Q_{i}^{1}(P^{o}), i = 1, …, N, which we call *optimal assignments*. If the j-th entry of Q_{i}^{1}(P^{o}) = 0 then agent i will not be allocated any units of resource type j. On the other hand, if the j-th entry of Q_{i}^{1}(P^{o}) = 1 then agent i may be allocated some units of resource type j in Part 2 of the algorithm, although not necessarily.

Part three lays out some helper methods for solving the problem in Spark:

For an agent i, the method `getMaxUtility()`

below calculates V_{i}(P) at price P, i.e. it solves the maximization problem:

max _{x ∈ Xi }{U_{i}(x) – P * x}

where X_{i} is the consumption set of the agent.

Recall that

- U
_{i} = [u_{i1} u_{i2} … u_{iK}]^{T} - U
_{i}(x) = U_{i}^{T} * x = ∑ _{j = 1, 2, …, K } (u_{ij} * x_{ij}) - U
_{i}(x) – P * x = ∑ _{j = 1, 2, …, K } (u_{ij} – p_{j})* x_{ij}

Part four shows us the code for the solution and wraps up:

In this article, we discussed an algorithm based on game theory for optimal resource allocation. The algorithm provides a fairness-based equilibrium where every agent (bidder) maximizes its utility and the resource manager (auctioneer) maximizes the price of the resources it is allocating. In addition, all the available units are allocated across all resource types and no agent is forced to take more than it is willing to. The algorithm is based on economist Ausubel’s Efficient Dynamic Auction Method.

We showed via two examples that the algorithm can be applied to different types of resource allocation problems. In one example, we applied the algorithm to allocate cloud computing resources, e.g. CPU, memory, bandwidth, to computing clients. Secondly, we applied the algorithm to a logistics example where various types of goods are transported over shared transportation resources.

If you were to create a parlor game around things guaranteed to show up in Curated SQL, “Game theory with Apache Spark” is way up on the list. If somebody does a post combining Apache Kafka with agorics, that’s an instant link too.