class TestHierarchyBadInput(unittest.TestCase):
    def setUp(self):

        self.Students, self.Projects, self.Supervisors = Hierarchy(1), Hierarchy(2), Hierarchy(3)

        """
        Some Supervisors
        """
        self.KB = Agent("1", self.Supervisors, capacities=[0, 1], preferences=None, abilities=None, name="Ken Brown")
        self.UK = Agent("2", self.Supervisors, capacities=[1, 2], preferences=None, abilities=None, name="Uli Kraehmer")
        self.RS = Agent("3", self.Supervisors, capacities=[2, 2], preferences=None, abilities=None, name="Richard Steiner")
        self.TB = Agent("4", self.Supervisors, capacities=[1,3], preferences=None, abilities=None, name="Tara Brendle")
        self.AB = Agent("5", self.Supervisors, capacities=[0,1], preferences=None, abilities=None, name="Andy Baker")

        """
        Some projects
        """
        self.Hopf = Agent("1", self.Projects, capacities=[0, 1], preferences=[self.UK, self.KB, self.AB],abilities=None
                          , name="Hopf algebras")
        self.Alg_no = Agent("2", self.Projects, capacities=[0, 1], preferences=[self.KB, self.AB], abilities=None,
                            name="Algebraic number theory")
        self.Cat_thy = Agent("3", self.Projects, capacities=[0, 1], preferences=[self.RS, self.UK], abilities=None,
                             name="Category Theory")
        self.Group_thy = Agent("4", self.Projects, capacities=[0, 1], preferences=[self.TB, self.AB], abilities=None,
                               name="Group Theory")
        self.Topology = Agent("5", self.Projects, capacities=[0, 1], preferences=[self.AB, self.TB, self.RS],
                              abilities=None, name="Topology")

        """
        Some students
        """
        self.Paul = Agent("0700874", self.Students, [0, 1], preferences=[self.Hopf, self.Alg_no, self.Group_thy],
                          abilities=None, name="Paul Gilmartin")
        self.Scott = Agent("0700875", self.Students, [0, 1], preferences=[self.Alg_no, self.Hopf], abilities=None,
                           name="Scott Gilmartin")
        self.Jim = Agent("0700876", self.Students, [0, 1], preferences=[self.Cat_thy, self.Topology, self.Hopf], abilities=None,
                         name="Jimmy Boyd")
        self.Rachael = Agent("0700877", self.Students, [0,1], preferences=[self.Group_thy, self.Alg_no, self.Cat_thy],
                             abilities=None, name="Rachael Hayhoe")
        self.Nameless = Agent("0700878", self.Students, [0,1], preferences=[self.Topology], abilities=None, name=None)


    def test_add_agent_wrong_level(self):
        self.assertRaises(ValueError, self.Projects.add_agent, self.UK)
        self.assertRaises(ValueError, self.Supervisors.add_agent, self.Paul)

    def test_preferred_wrong_subset(self):
        self.Students.add_agent(self.Paul)
        self.Students.add_agent(self.Scott)
        self.assertRaises(ValueError, self.Students.preferred, [self.Rachael, self.Scott])
    def setUp(self):

        self.Students, self.Projects, self.Supervisors = Hierarchy(1), Hierarchy(2), Hierarchy(3)

        """
        Some Supervisors
        """
        self.KB = Agent("1", self.Supervisors, capacities=[0, 1], preferences=None, abilities=None, name="Ken Brown")
        self.UK = Agent("2", self.Supervisors, capacities=[1, 2], preferences=None, abilities=None, name="Uli Kraehmer")
        self.RS = Agent("3", self.Supervisors, capacities=[2, 2], preferences=None, abilities=None, name="Richard Steiner")
        self.TB = Agent("4", self.Supervisors, capacities=[1,3], preferences=None, abilities=None, name="Tara Brendle")
        self.AB = Agent("5", self.Supervisors, capacities=[0,1], preferences=None, abilities=None, name="Andy Baker")

        """
        Some projects
        """
        self.Hopf = Agent("1", self.Projects, capacities=[0, 1], preferences=[self.UK, self.KB, self.AB],abilities=None
                          , name="Hopf algebras")
        self.Alg_no = Agent("2", self.Projects, capacities=[0, 1], preferences=[self.KB, self.AB], abilities=None,
                            name="Algebraic number theory")
        self.Cat_thy = Agent("3", self.Projects, capacities=[0, 1], preferences=[self.RS, self.UK], abilities=None,
                             name="Category Theory")
        self.Group_thy = Agent("4", self.Projects, capacities=[0, 1], preferences=[self.TB, self.AB], abilities=None,
                               name="Group Theory")
        self.Topology = Agent("5", self.Projects, capacities=[0, 1], preferences=[self.AB, self.TB, self.RS],
                              abilities=None, name="Topology")

        """
        Some students
        """
        self.Paul = Agent("0700874", self.Students, [0, 1], preferences=[self.Hopf, self.Alg_no, self.Group_thy],
                          abilities=None, name="Paul Gilmartin")
        self.Scott = Agent("0700875", self.Students, [0, 1], preferences=[self.Alg_no, self.Hopf], abilities=None,
                           name="Scott Gilmartin")
        self.Jim = Agent("0700876", self.Students, [0, 1], preferences=[self.Cat_thy, self.Topology, self.Hopf], abilities=None,
                         name="Jimmy Boyd")
        self.Rachael = Agent("0700877", self.Students, [0,1], preferences=[self.Group_thy, self.Alg_no, self.Cat_thy],
                             abilities=None, name="Rachael Hayhoe")
        self.Nameless = Agent("0700878", self.Students, [0,1], preferences=[self.Topology], abilities=None, name=None)
Exemple #3
0
 def __init__(self, csv_file,
              delimiter=",", level=None, randomise=False,
              quoting=csv.QUOTE_NONE, first_line=True,
              higher_agent=None, agents_to_id=None):
     self.randomise = randomise
     self.delimiter = delimiter
     self.quoting = quoting
     self.level = level
     self.first_line = first_line
     self.file = csv_file
     if level:
         self.hierarchy = Hierarchy(level)
     else:
         self.hierarchy = None
     if higher_agent:
         self.higher_agent = higher_agent
     else:
         self.higher_agent = {}
     if agents_to_id:
         self.agents_to_id = agents_to_id
     else:
         self.agents_to_id = {}
class TestHierarchyGoodInput(unittest.TestCase):
    def setUp(self):

        self.Students, self.Projects, self.Supervisors = Hierarchy(1), Hierarchy(2), Hierarchy(3)

        """
        Some Supervisors
        """
        self.KB = Agent("1", self.Supervisors, capacities=[0, 1], preferences=None, abilities=None, name="Ken Brown")
        self.UK = Agent("2", self.Supervisors, capacities=[1, 2], preferences=None, abilities=None, name="Uli Kraehmer")
        self.RS = Agent("3", self.Supervisors, capacities=[2, 2], preferences=None, abilities=None, name="Richard Steiner")
        self.TB = Agent("4", self.Supervisors, capacities=[1,3], preferences=None, abilities=None, name="Tara Brendle")
        self.AB = Agent("5", self.Supervisors, capacities=[0,1], preferences=None, abilities=None, name="Andy Baker")

        """
        Some projects
        """
        self.Hopf = Agent("1", self.Projects, capacities=[0, 1], preferences=[self.UK, self.KB, self.AB],abilities=None
                          , name="Hopf algebras")
        self.Alg_no = Agent("2", self.Projects, capacities=[0, 1], preferences=[self.KB, self.AB], abilities=None,
                            name="Algebraic number theory")
        self.Cat_thy = Agent("3", self.Projects, capacities=[0, 1], preferences=[self.RS, self.UK], abilities=None,
                             name="Category Theory")
        self.Group_thy = Agent("4", self.Projects, capacities=[0, 1], preferences=[self.TB, self.AB], abilities=None,
                               name="Group Theory")
        self.Topology = Agent("5", self.Projects, capacities=[0, 1], preferences=[self.AB, self.TB, self.RS],
                              abilities=None, name="Topology")

        """
        Some students
        """
        self.Paul = Agent("0700874", self.Students, [0, 1], preferences=[self.Hopf, self.Alg_no, self.Group_thy],
                          abilities=None, name="Paul Gilmartin")
        self.Scott = Agent("0700875", self.Students, [0, 1], preferences=[self.Alg_no, self.Hopf], abilities=None,
                           name="Scott Gilmartin")
        self.Jim = Agent("0700876", self.Students, [0, 1], preferences=[self.Cat_thy, self.Topology, self.Hopf], abilities=None,
                         name="Jimmy Boyd")
        self.Rachael = Agent("0700877", self.Students, [0,1], preferences=[self.Group_thy, self.Alg_no, self.Cat_thy],
                             abilities=None, name="Rachael Hayhoe")
        self.Nameless = Agent("0700878", self.Students, [0,1], preferences=[self.Topology], abilities=None, name=None)

    def test_add_agent_1(self):
        self.Supervisors.add_agent(self.KB)
        self.assertEqual(self.Supervisors.agents, [self.KB])
        self.assertEqual(self.Supervisors.agent_to_name, {self.KB: self.KB.name})

    def test_add_agent_2(self):
        self.Projects.add_agent(self.Hopf)
        self.Projects.add_agent(self.Alg_no)
        self.assertEqual(self.Projects.agents, [self.Hopf, self.Alg_no])
        self.assertEqual(self.Projects.agent_to_name, {self.Hopf: self.Hopf.name, self.Alg_no: self.Alg_no.name})

    def test_number_of_agents_1(self):
        self.assertEqual(self.Students.number_of_agents, 0)

    def test_number_of_agent_2(self):
        self.Students.add_agent(self.Paul)
        self.Students.add_agent(self.Scott)
        self.assertEqual(self.Students.number_of_agents, 2)

    def test_preferred(self):
        self.Students.add_agent(self.Rachael)
        self.Students.add_agent(self.Jim)
        self.Students.add_agent(self.Scott)
        self.assertEqual(self.Students.preferred([self.Rachael, self.Scott]), sorted({self.Hopf, self.Group_thy, self.Cat_thy,
                                                                               self.Alg_no}, key=lambda x: x.id))

    def test_all_preferred(self):
        pass

    def test_set_name(self):
        self.Supervisors.set_name(self.KB, "Kenny")
        self.assertEqual(self.KB.name, "Kenny")
        self.assertEqual(self.Supervisors.agent_to_name, {self.KB: "Kenny"})

    def test_name_to_agent(self):
        pass

    def test_add_names(self):
        self.Alan = Agent("0700890", self.Students)
        self.Students.add_agent(self.Alan)
        self.Students.add_names({self.Alan: "Alan Smith"})
        self.assertEqual(self.Students.agent_to_name, {self.Alan:"Alan Smith"})

    def test_give_names(self):
        self.Projects.add_agent(self.Hopf)
        self.Projects.add_names({self.Hopf: "Noetherian Hopf Algebras"})
        self.Projects.give_names()
        self.assertEqual(self.Hopf.name, "Noetherian Hopf Algebras")

    def test_max_preferences_length(self):
        self.Students.add_agent(self.Paul)
        self.Students.add_agent(self.Scott)
        self.assertEqual(self.Students.max_preferences_length, 3)

    def test_max_abilities_length(self):
        pass
Exemple #5
0
 def set_hierarchy(self, level):
     self.level = level
     self.hierarchy = Hierarchy(level)
Exemple #6
0
class FileData(object):
    def __init__(self, csv_file,
                 delimiter=",", level=None, randomise=False,
                 quoting=csv.QUOTE_NONE, first_line=True,
                 higher_agent=None, agents_to_id=None):
        self.randomise = randomise
        self.delimiter = delimiter
        self.quoting = quoting
        self.level = level
        self.first_line = first_line
        self.file = csv_file
        if level:
            self.hierarchy = Hierarchy(level)
        else:
            self.hierarchy = None
        if higher_agent:
            self.higher_agent = higher_agent
        else:
            self.higher_agent = {}
        if agents_to_id:
            self.agents_to_id = agents_to_id
        else:
            self.agents_to_id = {}

    def __repr__(self):
        return "LEVEL_{}_Data".format(self.level)

    def id_to_agents(self):
        return {id_number: agent for agent, id_number in
                self.agents_to_id.iteritems()}

    def set_higher_agent(self, higher_agent):
        self.higher_agent = higher_agent

    def set_hierarchy(self, level):
        self.level = level
        self.hierarchy = Hierarchy(level)

    def results(self):
        opened_file = open(self.file, "r")
        reader = csv.reader(opened_file,
                            delimiter=self.delimiter,
                            quoting=self.quoting)
        results = []
        for i, row in enumerate(reader):
            if i == 0 and self.first_line:
                continue
            results.append(Line([x.strip() for x in row if x]))
        opened_file.close()
        return results

    def set_agents_and_ids(self):
        results_copy = deepcopy(self.results())
        if self.randomise:
            shuffle(results_copy)
        preferences = None
        for i, line in enumerate(results_copy):
            if line.raw_preferences:
                preferences = [self.higher_agent.get(preference) for
                               preference in line.raw_preferences]
            agent = Agent(i + 1,
                          self.hierarchy,
                          capacities=line.capacities,
                          preferences=preferences,
                          name=line.raw_name)
            self.hierarchy.add_agent(agent)
            self.agents_to_id[agent] = agent.id