示例#1
0
	def __init__(self, fpath, palantir=True):
		"""
		Constructor of the statistics object. Used to reconstruct trajectory with all its data.
		
		@param fpath relative filepath to the saved trajectory
		"""
		
		if palantir:	# trajectory format from palantir-search
			with open( fpath, 'rb') as f:
				prob, x, ms = cPickle.load(f)
		else:
			# get trajectory
			try:
				best, x = load_trajectory( fpath )
			except:
				raise Exception('ERROR: could not load trajectory')

			# reconstruct a problem instance
			try:
				prob = mga_incipit( seq=[fb.moon for fb in best.traj]+[best.next_moon.moon], tof = [ [0,300] ]*(len(x)/4) )
			except:
				raise Exception('ERROR: could not instantiate problem')
		
		params = lambertization(prob, x)
		self.seq, self.common_mu, self.n_legs, self.initial, self.T, self.t_P, self.r_P, self.v_P, self.DV, self.close_d = lambertization(prob, x)
		if palantir:
			self.best = None
		else:
			self.best = best
		self.x = x
		self.prob = prob
示例#2
0
def incipit_file_load(fpath, verbose=False):
	""" used to load a incipit file from fast_incipits 
	
		@return a list of all feasible incipits found in that file
	"""
	filename = fpath.split('/')[-1]
	
	# rebuild problem from file name
	probdata = filename.lower().split('_')

	seq = [ eval(d) for d in probdata[:4] ]
	prob = mga_incipit( seq=seq, tof=[[0,300]]*len(seq) )

	# open up the pickle jar
	with open( fpath, 'rb' ) as f:
		l = cPickle.load( f )

	l.sort( key = lambda x : x.f[0] )

	#We look for good solutions in l
	sol = [] 
	for idx, ind in enumerate(l):
		# check for fitness mismatch
		if fitness_mismatch( prob, (ind.x,ind.f[0]), print_mismatch=False ) > 1.:
			if verbose:
				print "Fitness Mismatch: the loaded trajectory seems to be wrongly interpreted"
			continue

		# check for too early start dates induced by an old bug 
		if ind.x[0] < 7305.0:
			if verbose:
				print "Start epoch out of bounds!!"
			continue

		# check for excessive DV
		try:
			DV,DT = prob.compute_DV_DT(ind.x)
		except ValueError:
			print 'something went wrong with incipit ' + filename
			continue

		for v,t in zip(DV,DT):
			if v > 0.1/2000 * 0.5 * DAY2SEC * t:
				if verbose:
					print "Excessive DV detected: low-thrustability endangered"			
				#break
		else:	# this is executed if no break occured in the preceeding for-loop
			sol.append( (idx, ind) )	# append only if we do not have to deal with super high DV

	#No solution has been found!!
	if len(sol) == 0:
		if verbose:
			print "No Feasible Solution In Input File!"
		return []
	
	return [incipit_stats(ind, filename, t[0], *lambertization(prob, t[1].x)) for t in sol]
示例#3
0
def incipit_problem(fpath, verbose=False):
	""" Loads a file with the incipit and returns a list of 2-tuples, containing
	the incipit-problem.obj and the chromosome """
	### REFACTOR this to avoid redundancy with incipit_file_load!
	file_name = fpath.split('/')[-1]
	
	# rebuild problem from file name
	probdata = file_name.lower().split('_')

	seq = [ eval(d) for d in probdata[:4] ]
	prob = mga_incipit( seq=seq, tof=[[0,300]]*len(seq) )

	# open up the pickle jar
	with open( fpath, 'rb' ) as f:
		l = cPickle.load( f )

	l.sort( key = lambda x : x.f[0] )

	#We look for good solutions in l
	sol = [] 
	for ind in l:
		# check for fitness mismatch
		if fitness_mismatch( prob, (ind.x,ind.f[0]), print_mismatch=False ) > 1.:
			if verbose:
				print "Fitness Mismatch: the loaded trajectory seems to be wrongly interpreted"
			continue

		# check for too early start dates induced by an old bug 
		if ind.x[0] < 7305.0:
			if verbose:
				print "Start epoch out of bounds!!"
			continue

		# check for excessive DV
		try:
			DV,DT = prob.compute_DV_DT(ind.x)
		except ValueError:
			print 'something went wrong with incipit ' + file_name
			continue

		for v,t in zip(DV,DT):
			if v > 0.1/2000 * 0.5 * DAY2SEC * t:
				if verbose:
					print "Excessive DV detected: low-thrustability endangered"			
				break
		else:	# this is executed if no break occured in the preceeding for-loop
			sol.append(ind)	# append only if we do not have to deal with super high DV

	#No solution has been found!!
	if len(sol) == 0:
		if verbose:
			print "No Feasible Solution In Input File!"
		return []
	
	return [(prob, ind.x) for ind in sol]
示例#4
0
def trajectory_file_load(fpath, verbose=False):
	""" used to load a trajectory file dump from tree search module """
	# get trajectory
	try:
		best, x = load_trajectory( fpath )
	except:
		raise Exception('ERROR: could not load trajectory')

	# reconstruct a problem instance
	try:
		prob = mga_incipit( seq=[fb.moon for fb in best.traj]+[best.next_moon.moon], tof = [ [0,300] ]*(len(x)/4) )
	except:
		raise Exception('ERROR: could not instantiate problem')
	
	pop = population(prob)
	pop.push_back(x)
	
	return incipit_stats(pop.champion, fpath.split('/')[-1], 0, *lambertization(prob, x))
示例#5
0
	def dump(self, filepath):
		""" dumps its chromosome and the related incipit problem  in a file specified by filepath. """
		with open(filepath, 'wb') as f:
			cPickle.dump( (mga_incipit(seq=self.seq, tof=[[0,300]]*self.n_legs), self.x), f)
		print 'Plonk.'
示例#6
0
	def get_problem(self):
		""" constructs an incipitproblem out of the statistics-object. """
		return mga_incipit( seq=self.seq, tof=[[0,300]]*self.n_legs )