# This program plots solutions to the replicator equations

from MADSEngine import *
from pylab import *

# Set the parameter values

# Set integration step size
dt = .01

# Set number of transients to keep from plotting, i.e if you
# want to see limit cycles
nTransients = 40000

# Total number of iterates to integrate
nIterates = 50000

# Tiebreaking parameter
# -1 <= e <= 1
ex = .5
ey = -.3

# Controls the agent's memory loss rate
# 0 <= alpha < 1
alphaX = .07#.02 (convergence to fixed point), .007 (Quasiperiodic Torus)  
alphaY = .0

# Controls the agent's adaptation rate
# beta >=0
betaX = 1.
betaY = 2.

# Set initial conditions.
u = -log(array([0.2,0.4,0.4]))
v = -log(array([0.1,0.5,0.4]))

# Run the simulation
XAgent,YAgent = MADS_Simulation(ex,ey,alphaX,alphaY,betaX,betaY,u,v,nIterates,dt)

# Initialize arrays for holding transformed coordinates
XTrans = []
YTrans = []

# Transform the coordinates for plotting
for i in range(nTransients,nIterates):
    XTrans.append(CoorTrans(XAgent[i]))
    YTrans.append(CoorTrans(YAgent[i]))

XTrans = array(XTrans)
YTrans = array(YTrans)

# Plot the solutions
plot(XTrans[:,0],XTrans[:,1])
plot(YTrans[:,0]+1,YTrans[:,1])

# Plots the triangular phase space
plot([-.5,0.,.5,-.5],[0.,.5*sqrt(3.),.0,.0])
plot([-.5+1.,0.+1.,.5+1.,-.5+1.],[0.,.5*sqrt(3.),.0,.0])

show()
