Advertisement
Guest User

Untitled

a guest
Jul 5th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. import math,random
  2. import matplotlib.pyplot as plt
  3.  
  4. def interact(p1,p2):
  5. interaction=0
  6. A=random.getrandbits(3)
  7. daughters=[]
  8. B=0
  9. if A<=3:
  10. B=random.getrandbits(1)
  11. interaction=1
  12.  
  13.  
  14. if interaction==1:
  15. if (p1=='E' or p2=='E') and (p1=='N' or p2=='N') and B==1:
  16. #print'ABSORBTION'
  17. daughters.append('H')
  18. elif (p1=='E' or p2=='E') and (p1=='N' or p2=='N') and B==0:
  19. #print'NEUTRON TRANSMUTATION'
  20. daughters.append('H')
  21. daughters.append('E')
  22. elif (p1=='NOBLE' and p2=='E') or (p1=='E' and p2=='NOBLE'):
  23. daughters.append('NOBLE')
  24. else:
  25. #print'NO INTERACTION'
  26. daughters.append(p1)
  27. daughters.append(p2)
  28. else:
  29. #print'NO INTERACTION'
  30. daughters.append(p1)
  31. daughters.append(p2)
  32. return daughters
  33.  
  34. def fusion(fuel,t,p):
  35. products=[]
  36. if fuel=='H':
  37. if t>=2000 and p>=50:
  38. products.append('N')
  39. products.append('P')
  40. products.append('E')
  41. products.append('PLASMA')
  42. products.append('NOBLE')
  43. else:
  44. products.append(fuel)
  45.  
  46. elif fuel=='NOBLE':
  47. if t>=5000 and p>=100:
  48. products.append('N')
  49. products.append('P')
  50. products.append('E')
  51. products.append('PLASMA')
  52. products.append('CO2')
  53. else:
  54. products.append(fuel)
  55.  
  56. elif fuel=='CO2':
  57. if t>=9500 and p>=200:
  58. products.append('O2')
  59. products.append('P')
  60. products.append('N')
  61. products.append('PLASMA')
  62. products.append('E')
  63. else:
  64. products.append(fuel)
  65. elif fuel=='O2':
  66. if t>=9700 and p>=250:
  67. products.append('BRMT')
  68. products.append('P')
  69. products.append('N')
  70. products.append('PLASMA')
  71. products.append('E')
  72. else:
  73. products.append(fuel)
  74. else:
  75. products.append(fuel)
  76. return products
  77.  
  78. popt=[]
  79. ppt=[]
  80. intt=[]
  81. fust=[]
  82. end=0
  83. zoo=['E','N']
  84. t=0
  85. temp=float(3500)
  86. pres=float(100)
  87. time=0
  88.  
  89. while t<=25:
  90. if temp>9725:
  91. temp=float(9725)
  92. if pres>256:
  93. pres=float(256)
  94. c=0
  95. pp=0
  96. intc=0
  97. fusc=0
  98. print''
  99. print''
  100. print'### - ITERATION',t
  101. print'TEMP',temp
  102. print'PRES',pres
  103. print'NEUTRONS',zoo.count('N')
  104. print'ELECTRONS',zoo.count('E')
  105. print'PHOTONS',zoo.count('P')
  106. print'HYDROGEN',zoo.count('H')
  107. print'NOBLE',zoo.count('NOBLE')
  108. print'CO2',zoo.count('CO2')
  109. print'OXYGEN',zoo.count('O2')
  110. print'ZOO SIZE',len(zoo)
  111. for i in zoo:
  112. prt=zoo[c]
  113. if prt=='E' or prt=='N':
  114. prt=zoo.pop(c)
  115. find=0
  116. for j in range(len(zoo)):
  117. p2=zoo[j]
  118. if (prt=='E' and p2=='N') or (prt=='N' and p2=='E'):
  119. find=1
  120. this=j
  121. break
  122. if find==1:
  123. prt2=zoo.pop(this)
  124. products=interact(prt,prt2)
  125. if products!=[prt,prt2] and products!=[prt2,prt]: #we have a winner!
  126. intc+=1
  127. for j in products:
  128. zoo.append(j)
  129. else:
  130. zoo.append(prt)
  131. elif prt=='PLASMA':
  132. if random.getrandbits(1)==1:
  133. zoo.pop(c)
  134. c+=1
  135. print''
  136. print'PRE-FUSION'
  137. print'NEUTRONS',zoo.count('N')
  138. print'ELECTRONS',zoo.count('E')
  139. print'PHOTONS',zoo.count('P')
  140. print'HYDROGEN',zoo.count('H')
  141. print'NOBLE',zoo.count('NOBLE')
  142. print'CO2',zoo.count('CO2')
  143. print'OXYGEN',zoo.count('O2')
  144. print'INTERACTIONS',intc
  145. print'ZOO SIZE',len(zoo)
  146. presS=pres
  147. for i in zoo:
  148. A=zoo.pop(0)
  149. B=fusion(A,temp,presS)
  150. if len(B)>1:
  151. fusc+=1
  152. pres+=float(0.2)
  153. for j in B:
  154. zoo.append(j)
  155. if j=='P' and len(B)>1:
  156. pp+=1
  157. ppt.append(pp)
  158. popt.append(len(zoo))
  159. intt.append(intc)
  160. fust.append(fusc)
  161. print''
  162. print'FINAL'
  163. print'NEUTRONS',zoo.count('N')
  164. print'ELECTRONS',zoo.count('E')
  165. print'PHOTONS',zoo.count('P')
  166. print'HYDROGEN',zoo.count('H')
  167. print'NOBLE',zoo.count('NOBLE')
  168. print'CO2',zoo.count('CO2')
  169. print'OXYGEN',zoo.count('O2')
  170. print'FUSIONS',fusc
  171. print'PHOTONS PRODUCED',pp
  172. print'ZOO SIZE',len(zoo)
  173. t+=1
  174. temp+=100
  175. print'END SIZE',len(zoo)
  176. plt.plot(range(t),popt)
  177. plt.xlabel('TIME')
  178. plt.ylabel('POPULATION')
  179. plt.show()
  180.  
  181. plt.plot(range(t),intt)
  182. plt.xlabel('TIME')
  183. plt.ylabel('INTERACTIONS')
  184. plt.show()
  185.  
  186. plt.plot(range(t),fust)
  187. plt.xlabel('TIME')
  188. plt.ylabel('FUSION EVENTS')
  189. plt.show()
  190.  
  191. plt.plot(range(t),ppt)
  192. plt.xlabel('TIME')
  193. plt.ylabel('PHOTONS PRODUCED')
  194. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement