# Algorithm Design for Scheme Implementation

Based on the above analysis of four-stage Stackelberg game, we present an iteration algorithm to implement our scheme. For the cloud resource, it can update its cloud resource price to obtain a maximum utility and then announce this price to all brokers. Since the media cloud is not aware of the duration of each adjustment, the media cloud sets a waiting time *T _{wmc}* for the next strategy update. Similarly, as each broker is not aware of the duration of each evolution, it sets a waiting

*T*for the next strategy to update the size of the purchased cloud resource and the price to charge users. In the evolutionary game, each user randomly selects a broker to connect initially, and then changes his strategy to maximize his own utility. If a users utility is lower than the average utility of his community, this user may change his connection with a probability, denoted by

_{w},_{b}where *Uj* is the average utility of community *j*. When all users in the same community obtain an equal utility, the evolution will be completed. We present the algorithm by Algorithm 1.

Algorithm 1: Resource allocation iteration algorithm

- 1: Initially, the media cloud announces the price
*p(0)*to all brokers. - 2:
**Repeat** - 3:
**while***t < T*_{w>mc}**do** - 4: Each broker randomly determines the size of leased resource
*E*and the price**i***p*.**i** - 5:
**Repeat**. - 6:
**while**t <*T*_{w},b**do** - 7: Each user randomly makes connection.
- 8:
**Repeat**. - 9: Compute each user’s utility by (5.22).
- 10: Exchange connection information with each other in the community.
- 11: Calculate the average utility
*U*by (5.28).**j** - 12:
**if***U***j***> U***i, j****then** - 13: Change the connection with probability
*в*. - 14:
**else** - 15: Maintain the connection.
- 16:
**end if** - 17:
**Until**all users in the same community have the equal utility. - 18:
**end while** - 19: Update cloud resource size
*E***i***(т*) and the cloud resource price*p***i***(т*) by equations (5.36)-(5.39). - 20:
*т = т +*1 - 21:
**Until***E*and**i***p*are both unchanged.**i** - 22:
**end while** - 23: Update the price
*p(t*) by Eqs. (5.41), (5.42). - 24: t = t + 1
- 25:
**Until***p*is unchanged.