def Demo(): #__CLOUD_SERVICES__################################################## # Define Network and Domain Network = CreateNetworkExample(ex=5) Domain = CloudServices(Network=Network,gap_alpha=2) # Set Method eps = 1e-2 Method = HeunEuler_LEGS(Domain=Domain,P=BoxProjection(lo=eps),Delta0=1e0,NTopLEs=3) # Initialize Starting Point Start = np.ones(Domain.Dim) # Calculate Initial Gap gap_0 = Domain.gap_rplus(Start) # Set Options Init = Initialization(Step=-1e-3) Term = Termination(MaxIter=1e5,Tols=[(Domain.gap_rplus,1e-12*gap_0)]) Repo = Reporting(Requests=[Domain.gap_rplus,'Step','F Evaluations', 'Projections','Data',Domain.eig_stats, 'Lyapunov']) Misc = Miscellaneous() Options = DescentOptions(Init,Term,Repo,Misc) # Print Stats PrintSimStats(Domain,Method,Options) # Start Solver tic = time.time() CloudServices_Results = Solve(Start,Method,Domain,Options) toc = time.time() - tic # Print Results PrintSimResults(Options,CloudServices_Results,Method,toc) x = CloudServices_Results.PermStorage['Data'][-1] print('p,q,Q,pi,Nash?') print(x[:Domain.Dim//2]) print(x[Domain.Dim//2:]) print(Domain.Demand(x)[0]) print(Domain.CloudProfits(x)) print(all(Domain.Nash(x)[0]))
def Demo(): #__CLOUD_SERVICES__################################################## # Define Network and Domain Network = CreateNetworkExample(ex=5) Domain = CloudServices(Network=Network, gap_alpha=2) # Set Method eps = 1e-2 Method = HeunEuler_LEGS(Domain=Domain, P=BoxProjection(lo=eps), Delta0=1e0) # Initialize Starting Point Start = np.ones(Domain.Dim) # Calculate Initial Gap gap_0 = Domain.gap_rplus(Start) # Set Options Init = Initialization(Step=-1e-3) Term = Termination(MaxIter=1e5, Tols=[(Domain.gap_rplus, 1e-12 * gap_0)]) Repo = Reporting(Requests=[ Domain.gap_rplus, 'Step', 'F Evaluations', 'Projections', 'Data', Domain.eig_stats, 'Lyapunov' ]) Misc = Miscellaneous() Options = DescentOptions(Init, Term, Repo, Misc) # Print Stats PrintSimStats(Domain, Method, Options) # Start Solver tic = time.time() CloudServices_Results = Solve(Start, Method, Domain, Options) toc = time.time() - tic # Print Results PrintSimResults(Options, CloudServices_Results, Method, toc) x = CloudServices_Results.PermStorage['Data'][-1] print('p,q,Q,pi,Nash?') print(x[:Domain.Dim // 2]) print(x[Domain.Dim // 2:]) print(Domain.Demand(x)[0]) print(Domain.CloudProfits(x)) print(all(Domain.Nash(x)[0]))
def plotFigure6(saveFig=False): print('CloudServices BoA') msg = 'This method will run for about a week.\n' +\ 'Email [email protected] for the results .npy file directly.\n' +\ 'Continue? (y/n) ' cont = input(msg) if cont != 'y': return # Define Network and Domain Network = CreateNetworkExample(ex=2) Domain = CloudServices(Network=Network,gap_alpha=2) # Set Method eps = 1e-2 Method = HeunEuler_LEGS(Domain=Domain,P=BoxProjection(lo=eps),Delta0=1e0) # Set Options Init = Initialization(Step=-1e-3) Term = Termination(MaxIter=1e5) Repo = Reporting(Requests=['Data','Step']) Misc = Miscellaneous() Options = DescentOptions(Init,Term,Repo,Misc) args = (Method,Domain,Options) sim = Solve # Print Stats PrintSimStats(Domain,Method,Options) # Construct grid grid = [np.array([.5,3.5,6])]*Domain.Dim grid = ListONP2NP(grid) grid = aug_grid(grid) Dinv = np.diag(1./grid[:,3]) # Compute results results = MCT(sim,args,grid,nodes=16,limit=40,AVG=0.00, eta_1=1.2,eta_2=.95,eps=1., L=16,q=8,r=1.1,Dinv=Dinv) ref, data, p, iters, avg, bndry_ids, starts = results # Save results sim_data = [results,Domain,grid] np.save('cloud_'+time.strftime("%Y%m%d_%H%M%S"),sim_data) # Plot BoAs obs = (4,9) # Look at new green-tech company consts = np.array([3.45,2.42,3.21,2.27,np.inf,.76,.97,.75,1.03,np.inf]) txt_locs = [(1.6008064516129032, 1.6015625), (3.2, 3.2), (3.33, 2.53)] xlabel = '$p_'+repr(obs[0])+'$' ylabel = '$q_'+repr(obs[1])+'$' title = 'Boundaries of Attraction for Cloud Services Market' fig, ax = plotBoA(ref,data,grid,obs=obs,consts=consts,txt_locs=txt_locs, xlabel=xlabel,ylabel=ylabel,title=title) if saveFig: plt.savefig('BoA.png',bbox_inches='tight') return fig, ax
def plotFigure5(saveFig=False): print('Demand Curve') # Define Network and Domain Network = CreateNetworkExample(ex=2) Domain = CloudServices(Network=Network) Domain2 = CloudServices(Network=Network,poly_splice=False) # Define parameters for demand function i = 0 j = 3 pi = np.arange(0,.8,.001) pJ = .01 qi = qJ = 1 # Compute demand for curve both with and without polynomial splice Q = np.zeros_like(pi) Q2 = Q.copy() t = np.zeros_like(pi) for p in range(len(pi)): _Q, _t = Domain.Demand_ij(i,j,pi[p],qi,pJ,qJ) _Q2, _ = Domain2.Demand_ij(i,j,pi[p],qi,pJ,qJ) Q[p] = _Q Q2[p] = _Q2 t[p] = _t # Compute critical points: (in)elasticity, splice, zero-utility e = pi[np.argmax(t >= 1/np.sqrt(2))] Qe = Q[np.argmax(t >= 1/np.sqrt(2))]/12. p0 = pi[np.argmax(t >= Domain.t0)] Qp0 = Q[np.argmax(t >= Domain.t0)]/12. pf = pi[np.argmax(t >= Domain.tf)] Qpf = Q[np.argmax(t >= Domain.tf)]/12. fig = plt.figure() ax = fig.add_subplot(111) # Plot demand curve Qij, = ax.plot(pi,Q/12.,'k-', linewidth=5) exp, = ax.plot(pi,Q2/12.,'k--', linewidth=5) ax.plot(p0,Qp0,'ow',markersize=10) ax.plot(pf,Qpf,'ow',markersize=10) eps = .05 ax.plot([-eps,.8+eps],[0,0],'k-.') ax.plot([0,0],[-eps,1+eps],'k-.') # Annotate critical points ax.annotate('inelastic', xy=(.04, .97), xycoords='data', xytext=(.1, .7), textcoords='data', arrowprops=dict(arrowstyle='simple',facecolor='black'), ha='center', va='center', size=18, ) ax.annotate('elastic', xy=(e, Qe), xycoords='data', xytext=(e+.2, Qe+.2), textcoords='data', arrowprops=dict(frac=0.1,headwidth=10,width=4, facecolor='black',shrink=.1), ha='center', va='center', size=18, ) ax.annotate('splice', xy=(p0, Qp0), xycoords='data', xytext=(p0+.2, Qp0+.2), textcoords='data', arrowprops=dict(frac=0.1,headwidth=10,width=4, facecolor='black',shrink=.1), ha='center', va='center', size=18, ) ax.annotate('zero-cutoff', xy=(pf, Qpf+.02), xycoords='data', xytext=(pf, Qpf+.2*np.sqrt(2)), textcoords='data', arrowprops=dict(frac=0.1,headwidth=10,width=4, facecolor='black',shrink=.1), ha='center', va='center', size=18, ) ax.set_xlim(-eps,.8+eps) ax.set_ylim(-eps,1+eps) leg = plt.legend([Qij,exp], [r'$Q_{ij}^{}$', r'$H_{i}e^{-t_{ij}^2}$'], fontsize=20,fancybox=True) plt.setp(leg.get_texts()[0], fontsize='20', va='center') plt.setp(leg.get_texts()[1], fontsize='20', va='bottom') plt.axis('off') if saveFig: plt.savefig("Demand.png",bbox_inches='tight') return fig, ax
def Demo(): #__CLOUD_SERVICES__################################################## # Define Network and Domain Network = CreateNetworkExample(ex=2) Domain = CloudServices(Network=Network, gap_alpha=2) # Set Method eps = 1e-2 Method = HeunEuler_LEGS(Domain=Domain, P=BoxProjection(lo=eps), Delta0=1e0) # Set Options Init = Initialization(Step=-1e-3) Term = Termination(MaxIter=1e5) Repo = Reporting(Requests=['Data', 'Step']) Misc = Miscellaneous() Options = DescentOptions(Init, Term, Repo, Misc) args = (Method, Domain, Options) sim = Solve # Print Stats PrintSimStats(Domain, Method, Options) # Construct grid grid = [np.array([.5, 3.5, 6])] * Domain.Dim grid = ListONP2NP(grid) grid = aug_grid(grid) Dinv = np.diag(1. / grid[:, 3]) # Compute results results = MCT(sim, args, grid, nodes=16, limit=40, AVG=0.00, eta_1=1.2, eta_2=.95, eps=1., L=16, q=8, r=1.1, Dinv=Dinv) ref, data, p, iters, avg, bndry_ids, starts = results # Save results sim_data = [results, Domain, grid] np.save('cloud_' + time.strftime("%Y%m%d_%H%M%S"), sim_data) # Plot BoAs obs = (4, 9) # Look at new green-tech company consts = np.array( [3.45, 2.42, 3.21, 2.27, np.inf, .76, .97, .75, 1.03, np.inf]) txt_locs = [(1.6008064516129032, 1.6015625), (3.2, 3.2), (3.33, 2.53)] xlabel = '$p_' + repr(obs[0]) + '$' ylabel = '$q_' + repr(obs[1]) + '$' title = 'Boundaries of Attraction for Cloud Services Market' figBoA, axBoA = plotBoA(ref, data, grid, obs=obs, consts=consts, txt_locs=txt_locs, xlabel=xlabel, ylabel=ylabel, title=title) # Plot Probablity Distribution figP, axP = plotDistribution(p, grid, obs=obs, consts=consts)