family_camp/schedule/deep.py
def fitness(self, debug=False):
        """Measure the number of violations of the validity criteria.
        The higher the number the worse it is.
        A value of 1 means no violations.
        """
        count = 1

        for s in self.session_inst:
            # Count the number of times we have the same camper in two sessions
            # that overlap.
            count += len([other_s for c in s.campers
                          for other_s in self.overlapping_sessions_map[s.session]
                          if c in self.session_inst_map[other_s].campers])

            # Count the number of times we have a family split accross two
            # sessions that overlap
            split_families = [g for g in s.family_groups
                              for other_s in self.overlapping_sessions_map[s.session]
                              if g in self.session_inst_map[other_s].family_groups]
            count += len(split_families)

            if debug:
                if len(split_families):
                    self.summary_file.write(
                        "\n\n== Families split accross two sessions ==\n")
                for g in split_families:
                    self.summary_file.write(
                        "{} Found in other session: {}\n".format(
                            str(g), str(s)))

            # How badly have we exceeded session limits?
            if len(s.campers) - s.session.activity.limit > 0:
                if debug:
                    self.summary_file.write(
                        "\n\n== Sessions exceeding size limit. ==\n")

                    self.summary_file.write("{} Exceeded limit: {} > {}\n".format(
                        str(s), len(s.campers), s.session.activity.limit))
                count += len(s.campers) - s.session.activity.limit

            # How badly are we below the minimum session size?
            if len(s.campers) < s.session.activity.min:
                if debug:
                    self.summary_file.write(
                        "\n\n== Sessions under session min. ==\n")

                    self.summary_file.write("{} Below min: {} > {}\n".format(
                        str(s), len(s.campers), s.session.activity.min))
                count += s.session.activity.min - len(s.campers)

        # How many campers are missing their priorities?
        for c in self.campers:
            activities = [s.session.activity
                          for s in self.session_inst
                          if c in s.campers]

            # How many campers are missing their priorities?
            missing = set(c.priorities) - set(activities)
            if len(missing):
                if debug:
                    self.summary_file.write("{} missing {}\n".format(
                        str(c), " ".join([str(_) for _ in missing])))
            count += len(missing)

            # How many campers are doing activities they did not request?
            unwanted = set(activities) - (set(c.priorities) | set(c.others))
            if len(unwanted):
                if debug:
                    self.summary_file.write("{} unwanted {}\n".format(
                        str(c), " ".join([str(_) for _ in unwanted])))
            count += len(unwanted)

            # How many times are campers doing the same activity more than
            # once?
            duplicates = len(activities) - len(set(activities))
            if duplicates:
                if debug:
                    self.summary_file.write("{} duplicated {}\n".format(str(c), duplicates))
            count += duplicates

        return count
Measure the number of violations of the validity criteria.
        The higher the number the worse it is.
        A value of 1 means no violations.
        
Measure the number of violations of the validity criteria.
The higher the number the worse it is.
A value of 1 means no violations.
Measure the number of violations of the validity criteria . The higher the number the worse it is . A value of 1 means no violations .
def fitness(self, debug=False):
        count = 1
        for s in self.session_inst:
            count += len([other_s for c in s.campers
                          for other_s in self.overlapping_sessions_map[s.session]
                          if c in self.session_inst_map[other_s].campers])
            split_families = [g for g in s.family_groups
                              for other_s in self.overlapping_sessions_map[s.session]
                              if g in self.session_inst_map[other_s].family_groups]
            count += len(split_families)
            if debug:
                if len(split_families):
                    self.summary_file.write(
                        "\n\n== Families split accross two sessions ==\n")
                for g in split_families:
                    self.summary_file.write(
                        "{} Found in other session: {}\n".format(
                            str(g), str(s)))
            if len(s.campers) - s.session.activity.limit > 0:
                if debug:
                    self.summary_file.write(
                        "\n\n== Sessions exceeding size limit. ==\n")
                    self.summary_file.write("{} Exceeded limit: {} > {}\n".format(
                        str(s), len(s.campers), s.session.activity.limit))
                count += len(s.campers) - s.session.activity.limit
            if len(s.campers) < s.session.activity.min:
                if debug:
                    self.summary_file.write(
                        "\n\n== Sessions under session min. ==\n")
                    self.summary_file.write("{} Below min: {} > {}\n".format(
                        str(s), len(s.campers), s.session.activity.min))
                count += s.session.activity.min - len(s.campers)
        for c in self.campers:
            activities = [s.session.activity
                          for s in self.session_inst
                          if c in s.campers]
            missing = set(c.priorities) - set(activities)
            if len(missing):
                if debug:
                    self.summary_file.write("{} missing {}\n".format(
                        str(c), " ".join([str(_) for _ in missing])))
            count += len(missing)
            unwanted = set(activities) - (set(c.priorities) | set(c.others))
            if len(unwanted):
                if debug:
                    self.summary_file.write("{} unwanted {}\n".format(
                        str(c), " ".join([str(_) for _ in unwanted])))
            count += len(unwanted)
            duplicates = len(activities) - len(set(activities))
            if duplicates:
                if debug:
                    self.summary_file.write("{} duplicated {}\n".format(str(c), duplicates))
            count += duplicates
        return count
def fitness ( self , debug = False ) : count = 1 for s in self . session_inst : count += len ( [ other_s for c in s . campers for other_s in self . overlapping_sessions_map [ s . session ] if c in self . session_inst_map [ other_s ] . campers ] ) split_families = [ g for g in s . family_groups for other_s in self . overlapping_sessions_map [ s . session ] if g in self . session_inst_map [ other_s ] . family_groups ] count += len ( split_families ) if debug : if len ( split_families ) : self . summary_file . write ( "\n\n== Families split accross two sessions ==\n" ) for g in split_families : self . summary_file . write ( "{} Found in other session: {}\n" . format ( str ( g ) , str ( s ) ) ) if len ( s . campers ) - s . session . activity . limit > 0 : if debug : self . summary_file . write ( "\n\n== Sessions exceeding size limit. ==\n" ) self . summary_file . write ( "{} Exceeded limit: {} > {}\n" . format ( str ( s ) , len ( s . campers ) , s . session . activity . limit ) ) count += len ( s . campers ) - s . session . activity . limit if len ( s . campers ) < s . session . activity . min : if debug : self . summary_file . write ( "\n\n== Sessions under session min. ==\n" ) self . summary_file . write ( "{} Below min: {} > {}\n" . format ( str ( s ) , len ( s . campers ) , s . session . activity . min ) ) count += s . session . activity . min - len ( s . campers ) for c in self . campers : activities = [ s . session . activity for s in self . session_inst if c in s . campers ] missing = set ( c . priorities ) - set ( activities ) if len ( missing ) : if debug : self . summary_file . write ( "{} missing {}\n" . format ( str ( c ) , " " . join ( [ str ( _ ) for _ in missing ] ) ) ) count += len ( missing ) unwanted = set ( activities ) - ( set ( c . priorities ) | set ( c . others ) ) if len ( unwanted ) : if debug : self . summary_file . write ( "{} unwanted {}\n" . format ( str ( c ) , " " . join ( [ str ( _ ) for _ in unwanted ] ) ) ) count += len ( unwanted ) duplicates = len ( activities ) - len ( set ( activities ) ) if duplicates : if debug : self . summary_file . write ( "{} duplicated {}\n" . format ( str ( c ) , duplicates ) ) count += duplicates return count
Measure the number of violations of the validity criteria.
Measure the number of violations of the validity criteria .
"""Measure the number of violations of the validity criteria.
        The higher the number the worse it is.
        A value of 1 means no violations.
        """ # Count the number of times we have the same camper in two sessions # that overlap. # Count the number of times we have a family split accross two # sessions that overlap # How badly have we exceeded session limits? # How badly are we below the minimum session size? # How many campers are missing their priorities? # How many campers are missing their priorities? # How many campers are doing activities they did not request? # How many times are campers doing the same activity more than # once?
self
debug