本文整理汇总了Python中configuration.Configuration.parse_file方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.parse_file方法的具体用法?Python Configuration.parse_file怎么用?Python Configuration.parse_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类configuration.Configuration
的用法示例。
在下文中一共展示了Configuration.parse_file方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Configuration
# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import parse_file [as 别名]
"""
from configuration import Configuration
config = Configuration()
"""
This is testing the is_empty() function in configuration.py
It checks to see if the config file is empty
Input: config file
Expected output: False
"""
test = config.is_empty()
print test
config.parse_file('config')
test = config.is_empty()
print test
"""
This is testing the get_num_prof() function in configuration.py
It checks to see if the config file returns the correct number of professors
Input: config file (13 professors)
Expected output: 13
"""
num = config.get_num_prof()
print num
示例2: __init__
# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import parse_file [as 别名]
class Schedule:
"""
This is the schedule class, used to schedule the classes.
The schedule is a list of lists of chromosomes
The length of the list is the number of rooms*number of days*number of
hours
Each chromosome has a fitness, which is determined like this:
If the class uses a spare room, fitness++
If the room has enough seats for the class, fitness++
If the class needs a lab and the room has a lab, fitness++
If the professor teaching the class does not have an overlapping class \
,fitness++
The algorithm is run, until the total fitness is = 1.0
Total fitness = combined fitness/number of rooms * 4(best fitness)
Crossovers are where two schedules are combined at two random points,
taking the best chromosomes from either of the schedules
Mutations are where a chromosome is selected at random and moved to a
random location
Algorithm Logic:
read in data
initialize chromosome
get_overall_fitness
while overall fitness != 1.0
get crossover points
perform crossover
get mutation size
perform mutations
get overall fitness
return schedule
"""
def __init__(self,len_chromo_list = None, config = None):
"""
Initalizes the schedule
@param len_chromo_list: length of the new chromosome list
@param config: config object to base the schedule on
"""
if len_chromo_list is None:
self.chromo_list = []
else:
self.chromo_list = len_chromo_list*[None]
if config is None:
self.config = None
else:
self.config = config
#Holds the last location of every class in the list
self.hash_map = {}
#Holds the classes with fitness values of 4
self.best_of = {}
self.number_chromosomes = 0
#Number of chromosomes to swap
self.mutation_size = 0
#Overall fitness of the schedule
self.total_fitness = 0
#Hours in the day classes can be held
self.day_length = 12
#Days of the week classes can be held
self.num_days = 5
#Best fitness achievable. Needs to reflect calculate_fitness()
self.best_fitness = 4
def get_config(self):
"""
Loads the configuration of the classes, courses, rooms and professors
"""
if self.config is None:
self.config = Configuration()
#Hard coded the file for now, will change with Django interface
self.config.parse_file('config')
def init_chromosomes(self):
"""
Initalizes the schedule with random class placement
"""
#Checks to see chromo_list has a size
if not self.chromo_list:
if self.config is None:
print "You need to load a config,\
before initalizing chromosomes"
else:
#Initializes Empty List
self.chromo_list = ((self.day_length*self.num_days)*\
(self.config.get_num_rooms()))*[None]
#Seeds the random with system time
random.seed()
for classes in self.config.classes_list:
#.........这里部分代码省略.........