Example #1
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]
Example #2
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]