File: ga_list.py

package info (click to toggle)
python-scipy 0.3.2-6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,572 kB
  • ctags: 20,326
  • sloc: ansic: 87,138; fortran: 51,876; python: 47,747; cpp: 2,134; objc: 384; makefile: 175; sh: 83
file content (53 lines) | stat: -rw-r--r-- 1,441 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from ga_util import *
import UserList
import copy

class ga_list(UserList.UserList):
	def data_clone(self):
		new = shallow_clone(self)
		new.data = map(lambda x: x.clone(),self.data)
		return new		
	def touch(self): pass
	def __setslice__(self, i, j, list):
		if type(list) == type(self.data): self.data[i:j] = list
		else: self.data[i:j] = list.data
	def __getslice__(self, i, j):
		new = shallow_clone(self)
		new.data = self.data[i:j]
		new.touch()
		return new
	def __add__(self, list):
		new = shallow_clone(self)
		if type(list) == type(self.data): new.data = self.data + list			
		else: new.data = self.data + list.data			
		new.touch()
		return new
	def __radd__(self, list):
		new = shallow_clone(self)
		if type(list) == type(self.data): new.data = list + self.data		
		else:	new.data = list.data + self.data			
		new.touch()
		return new
	def __mul__(self, n):
		new = shallow_clone(self)
		new.data = self.data*n
		new.touch()
		return new
	__rmul__ = __mul__
	def __cmp__(self, other): return cmp(self.__dict__,other.__dict__)
	
class gene_list(ga_list):
	pass
	"""
	def __setitem__(self, i, item):
 		if(hasattr(item,'_value')): self.data[i] = item
 		else: self.data[i]._value = item
	def __setslice__(self, i, j, list):
		if type(list) == type(self.data):
			if(hasattr(list[0],'_value')): 
				self.data[i:j] = list
			else:
				for k in range(i,j): self.data[k]._value = list[i]	
		else:
			self.data[i:j] = list.data
	"""