当前位置: 首页>>代码示例>>Python>>正文


Python Configuration.get_num_rooms方法代码示例

本文整理汇总了Python中configuration.Configuration.get_num_rooms方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.get_num_rooms方法的具体用法?Python Configuration.get_num_rooms怎么用?Python Configuration.get_num_rooms使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在configuration.Configuration的用法示例。


在下文中一共展示了Configuration.get_num_rooms方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_course_by_id

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import get_num_rooms [as 别名]
This is testing the get_course_by_id() function in configuration.py
It checks to see if the correct course ID and course name
Input: config file (ID: 5)
Expected output: 5 Descrete Mathematic I
"""
course = config.get_course_by_id(5)
print str(course.id) + " " + course.name


"""
This is testing the get_num_rooms() function in configuration.py
It checks to see if the correct number of rooms is returned
Input: config file (3 rooms)
Expected output: 3
"""
num = config.get_num_rooms()
print num


"""
This is testing the get_room_by_id() function in configuration.py
It checks to see if the correct room name, seat number, and lab is returned 
Input: config file (ID: 2)
Expected output: Unknown
"""
room = config.get_room_by_id(2)
print str(room.name) + " " + str(room.seat_num) + " " + str(room.lab)


"""
This is testing the get_num_classes() function in configuration.py
开发者ID:bpross,项目名称:MyCourses-Scheduler,代码行数:33,代码来源:config_test.py

示例2: __init__

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import get_num_rooms [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:
#.........这里部分代码省略.........
开发者ID:bpross,项目名称:MyCourses-Scheduler,代码行数:103,代码来源:schedule.py


注:本文中的configuration.Configuration.get_num_rooms方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。