Example #1
0
	def testForErrors(self):
		#ensure that NO PATH doesn't result in infinite loop
		path1 = sc.a_star_search(dis_map,time_map3,'Big Ben','Library')
		path2 = sc.a_star_search(dis_map,time_map3,'Library','Big Ben')
		#ensure that LOC NOT IN TIME_MAP doesn't result in error
		path3 = sc.a_star_search(dis_map,time_map2,'Somewhere','Library')
		path4 = sc.a_star_search(dis_map,time_map2,'Big Ben','Somewhere')

		self.assertEqual([],path1)
		self.assertEqual([],path2)
		self.assertEqual([],path3)
		self.assertEqual([],path4)
Example #2
0
	def test9(self):
		# One way streets
		# Testing if the code won't break despite some of the streets being only one way.
		expand.expand_count = 0
		path = sc.a_star_search(dis_map, time_map8, 'Lighthouse', 'Cinema')
		self.assertEqual(path, ['Lighthouse', 'Campus', 'Beach', 'Whole_Food', 'Cinema'])
		self.assertEqual(expand.expand_count, 5)
Example #3
0
 def test8(self):
     expand.expand_count = 0;
     path = sc.a_star_search(dis_map_extra_Z, time_map_extra_Z, 'Ryan_Field', 'Cinema')
     print(path)
     print(expand.expand_count)
     self.assertEqual(path, ['Ryan_Field', 'YWCA', 'Cinema'])
     self.assertEqual(expand.expand_count, 3)
Example #4
0
	def testExploreManyPaths(self):
		# This test explores many paths and does not assume the path to the destination is found too soon
		expand.expand_count = 0
		path = sc.a_star_search(dis_map, time_map1, 'Stagger Hall', 'College Column')
		self.assertEqual(['Stagger Hall', 'Hackathon Laboratory', 'College Column'], path)
		# expand all but Big Cannon and College Column
		self.assertEqual(5, expand.expand_count)
Example #5
0
	def test7(self):
		# Self Loop
		# There is a self loop at the beginning node. The search should still
		# proceed as normal because graph search won't look at the beginning node twice.
		expand.expand_count = 0
		path = sc.a_star_search(dis_map, time_map6, 'YWCA', 'Campus')
		self.assertEqual(path, ['YWCA', 'Ryan_Field', 'Lighthouse', 'Campus'])
		self.assertEqual(expand.expand_count, 5)
Example #6
0
	def test6(self):
		# Island
		# The test should return an empty list because we are trying to
		# reach an unreachable node that isn't connected to anything.
		expand.expand_count = 0
		path = sc.a_star_search(dis_map, time_map5, 'Campus', 'YWCA')
		self.assertEqual(path, [])
		self.assertEqual(expand.expand_count, 6)
Example #7
0
	def test8(self):
		# Big Exit
		# There is only one path to get past the first two nodes in the
		# beginning. The path cost is ridiculously high, but the search should
		# still go through it because graph search won't consider going backwards.
		expand.expand_count = 0
		path = sc.a_star_search(dis_map, time_map7, 'YWCA', 'Campus')
		self.assertEqual(path, ['YWCA', 'Cinema', 'Whole_Food', 'Campus'])
		self.assertEqual(expand.expand_count, 3)
Example #8
0
def main():
	dis_map = {'Campus': {'Campus': 0, 'Whole_Food': 3, 'Beach': 5, 'Cinema': 5, 'Lighthouse': 1, 'Ryan Field': 2, 'YWCA':12},
				'Whole_Food': {'Campus': 3,  'Whole_Food': 0, 'Beach': 3, 'Cinema': 3, 'Lighthouse': 4, 'Ryan Field': 5, 'YWCA':8},
				'Beach': {'Campus': 5,  'Whole_Food': 3, 'Beach': 0, 'Cinema': 8, 'Lighthouse': 5, 'Ryan Field': 7, 'YWCA':12,},
				'Cinema': {'Campus': 5,  'Whole_Food': 3, 'Beach': 8, 'Cinema': 0, 'Lighthouse': 7, 'Ryan Field': 7, 'YWCA':2},
				'Lighthouse': {'Campus': 1, 'Whole_Food': 4, 'Beach': 5, 'Cinema': 7, 'Lighthouse': 0, 'Ryan Field': 1, 'YWCA':15},
				'Ryan Field': {'Campus': 2, 'Whole_Food': 5, 'Beach': 7, 'Cinema': 7, 'Lighthouse': 1, 'Ryan Field': 0, 'YWCA':12},
				'YWCA': {'Campus': 12, 'Whole_Food': 8, 'Beach': 12, 'Cinema': 2, 'Lighthouse': 15, 'Ryan Field': 12, 'YWCA':0}}
	time_map1 = {'Campus': {'Campus': None, 'Whole_Food': 4, 'Beach': 3, 'Cinema': None, 'Lighthouse': 1, 'Ryan Field': None, 'YWCA': None},
				'Whole_Food': {'Campus': 4,  'Whole_Food': None, 'Beach': 4, 'Cinema': 3, 'Lighthouse': None, 'Ryan Field': None, 'YWCA': None},
				'Beach': {'Campus': 4,  'Whole_Food': 4, 'Beach': None, 'Cinema': None, 'Lighthouse': None, 'Ryan Field': None, 'YWCA': None},
				'Cinema': {'Campus': None,  'Whole_Food': 4, 'Beach': None, 'Cinema': None, 'Lighthouse': None, 'Ryan Field': None, 'YWCA': 2},
				'Lighthouse': {'Campus': 1, 'Whole_Food': None, 'Beach': None, 'Cinema': None, 'Lighthouse': None, 'Ryan Field': 1, 'YWCA': None},
				'Ryan Field': {'Campus': None, 'Whole_Food': None, 'Beach': None, 'Cinema': None, 'Lighthouse': 2, 'Ryan Field': None, 'YWCA': 5},
				'YWCA': {'Campus': None, 'Whole_Food': None, 'Beach': None, 'Cinema': 3, 'Lighthouse': None, 'Ryan Field': 5, 'YWCA': None}}
	student_score5 = sc.a_star_search(dis_map,time_map1, 'Ryan Field', 'Beach')
	gold_score5 = {'Ryan Field': {'YWCA': 17, 'Lighthouse': 7}, 'Lighthouse': {'Ryan Field': 10, 'Campus': 8}, 'Campus': {'Lighthouse': 9, 'Beach': 6, 'Whole_Food': 10}}
	if check_score_equal(student_score5,gold_score5):
		print "pass A* search for time map5"
	else:
		print "Fail A* search for time map5"
		exit(1)
	exit(0)
Example #9
0
 def test10(self):
     expand.expand_count = 0
     path = sc.a_star_search(dis_map, time_map6, 'Campus', 'Ryan_Field')
     self.assertEqual(path, ['Campus', 'Whole_Food',
                             'Cinema', 'YWCA', 'Ryan_Field'])
     self.assertEqual(expand.expand_count, 6)
Example #10
0
 def test9(self):
     expand.expand_count = 0
     path = sc.a_star_search(dis_map, time_map5, 'Campus', 'YWCA')
     self.assertEqual(path, [])
     self.assertEqual(expand.expand_count, 4)
Example #11
0
 def test8(self):
     expand.expand_count = 0
     path = sc.a_star_search(dis_map, time_map1, 'Frankfurt', 'Cinema')
     self.assertEqual(path, [])
     self.assertEqual(expand.expand_count, 0)
Example #12
0
 def test7(self):
     expand.expand_count = 0
     path = sc.a_star_search(dis_map, time_map1, 'Campus', 'Waldalgesheim')
     self.assertEqual(path, [])
     self.assertEqual(expand.expand_count, 0)
Example #13
0
	def testNeighbor(self):
		expand.expand_count = 0
		path = sc.a_star_search(dis_map, time_map1, 'Big Ben', 'Big Cannon Hall')
		self.assertEqual(['Big Ben', 'Big Cannon Hall'], path)
		self.assertEqual(1, expand.expand_count)
Example #14
0
 def test6(self):
     expand.expand_count = 0
     path = sc.a_star_search(dis_map0, time_map0, 'A', 'G')
     self.assertEqual(path, ['A', 'B', 'E', 'F', 'G'])
     self.assertEqual(expand.expand_count, 6)
     print(path)
Example #15
0
 def test4(self):
     expand.expand_count = 0
     path = sc.a_star_search(dis_map, time_map4, 'Campus', 'Cinema')
     self.assertEqual(path, ['Campus', 'Lighthouse', 'Ryan_Field', 'YWCA', 'Cinema'])
     self.assertEqual(expand.expand_count, 6)
Example #16
0
	def testExploreManyPathDifferentTimes(self):
		expand.expand_count = 0
		path = sc.a_star_search(dis_map, time_map2, 'Stagger Hall', 'College Column')
		self.assertEqual(['Stagger Hall', 'College Column'], path)
		self.assertEqual(4, expand.expand_count)
Example #17
0
	def testDirectRouteDifferentTimes(self):
		expand.expand_count = 0
		path = sc.a_star_search(dis_map, time_map2, 'Big Ben', 'Stagger Hall')
		self.assertEqual(['Big Ben', 'Big Cannon Hall', 'Stagger Hall'], path)
		self.assertEqual(3, expand.expand_count)
Example #18
0
	def testDirectRoute(self):
		expand.expand_count = 0
		path = sc.a_star_search(dis_map, time_map1, 'Big Ben', 'Stagger Hall')
		self.assertEqual(['Big Ben', 'Hackathon Laboratory', 'Stagger Hall'], path)
		self.assertEqual(3, expand.expand_count)
Example #19
0
def main():
    data1 = [
        "2000000000", "0101111111", "0100000000", "0101111111", "0101000001",
        "0101010110", "0101010000", "0100011110", "0011111110", "1011111110",
        "1011111111", "1000000003"
    ]
    gold_df1 = [
        "5444444444", "5141111111", "5144444444", "5141111111", "5141444441",
        "5141414114", "5141414444", "5144411114", "5511111114", "1511111114",
        "1511111111", "1555555555"
    ]

    gold_bf1 = [
        "5444444444", "5141111111", "5144444444", "5141111111", "5141444441",
        "5141414110", "5141414440", "5144411110", "5511111110", "1511111110",
        "1511111111", "1555555555"
    ]

    data2 = [
        "0000000000", "1111110101", "0300010101", "1111010101", "0001010101",
        "0100010101", "1111010101", "0000000101", "0111111100", "0000000101",
        "0111111120", "0000000010"
    ]

    gold_df2 = [
        "0000005554", "1111115151", "0555515151", "1111515151", "4441515151",
        "4144515151", "1111515151", "4444555151", "4111111154", "4444444151",
        "4111111154", "4444444414"
    ]

    gold_bf2 = [
        "4444445554", "1111115151", "0555515151", "1111515151", "4441515151",
        "4144515151", "1111515151", "4444555151", "4111111154", "4440000151",
        "4111111154", "4000000014"
    ]

    student_df1 = sc.dfs(init_map(data1))
    if check_map_equal(student_df1, init_map(gold_df1)):
        print "Pass dfs for map1"
    else:
        print "Fail dfs for map1"
        exit(1)

    student_bf1 = sc.bfs(init_map(data1))
    if check_map_equal(student_bf1, init_map(gold_bf1)):
        print "Pass bfs for map1"
    else:
        print "Fail bfs for map1"
        exit(1)

    student_df2 = sc.dfs(init_map(data2))
    if check_map_equal(student_df2, init_map(gold_df2)):
        print "Pass dfs for map2"
    else:
        print "Fail dfs for map2"
        exit(1)

    student_bf2 = sc.bfs(init_map(data2))
    if check_map_equal(student_bf2, init_map(gold_bf2)):
        print "Pass bfs for map2"
    else:
        print "Fail bfs for map2"
        exit(1)

    dis_map = {
        'Campus': {
            'Campus': 0,
            'Whole_Food': 3,
            'Beach': 5,
            'Cinema': 5,
            'Lighthouse': 1,
            'Ryan Field': 2,
            'YWCA': 12
        },
        'Whole_Food': {
            'Campus': 3,
            'Whole_Food': 0,
            'Beach': 3,
            'Cinema': 3,
            'Lighthouse': 4,
            'Ryan Field': 5,
            'YWCA': 8
        },
        'Beach': {
            'Campus': 5,
            'Whole_Food': 3,
            'Beach': 0,
            'Cinema': 8,
            'Lighthouse': 5,
            'Ryan Field': 7,
            'YWCA': 12,
        },
        'Cinema': {
            'Campus': 5,
            'Whole_Food': 3,
            'Beach': 8,
            'Cinema': 0,
            'Lighthouse': 7,
            'Ryan Field': 7,
            'YWCA': 2
        },
        'Lighthouse': {
            'Campus': 1,
            'Whole_Food': 4,
            'Beach': 5,
            'Cinema': 7,
            'Lighthouse': 0,
            'Ryan Field': 1,
            'YWCA': 15
        },
        'Ryan Field': {
            'Campus': 2,
            'Whole_Food': 5,
            'Beach': 7,
            'Cinema': 7,
            'Lighthouse': 1,
            'Ryan Field': 0,
            'YWCA': 12
        },
        'YWCA': {
            'Campus': 12,
            'Whole_Food': 8,
            'Beach': 12,
            'Cinema': 2,
            'Lighthouse': 15,
            'Ryan Field': 12,
            'YWCA': 0
        }
    }
    time_map1 = {
        'Campus': {
            'Campus': None,
            'Whole_Food': 4,
            'Beach': 3,
            'Cinema': None,
            'Lighthouse': 1,
            'Ryan Field': None,
            'YWCA': None
        },
        'Whole_Food': {
            'Campus': 4,
            'Whole_Food': None,
            'Beach': 4,
            'Cinema': 3,
            'Lighthouse': None,
            'Ryan Field': None,
            'YWCA': None
        },
        'Beach': {
            'Campus': 4,
            'Whole_Food': 4,
            'Beach': None,
            'Cinema': None,
            'Lighthouse': None,
            'Ryan Field': None,
            'YWCA': None
        },
        'Cinema': {
            'Campus': None,
            'Whole_Food': 4,
            'Beach': None,
            'Cinema': None,
            'Lighthouse': None,
            'Ryan Field': None,
            'YWCA': 2
        },
        'Lighthouse': {
            'Campus': 1,
            'Whole_Food': None,
            'Beach': None,
            'Cinema': None,
            'Lighthouse': None,
            'Ryan Field': 1,
            'YWCA': None
        },
        'Ryan Field': {
            'Campus': None,
            'Whole_Food': None,
            'Beach': None,
            'Cinema': None,
            'Lighthouse': 2,
            'Ryan Field': None,
            'YWCA': 5
        },
        'YWCA': {
            'Campus': None,
            'Whole_Food': None,
            'Beach': None,
            'Cinema': 3,
            'Lighthouse': None,
            'Ryan Field': 5,
            'YWCA': None
        }
    }
    time_map2 = {
        'Campus': {
            'Campus': None,
            'Whole_Food': 12,
            'Beach': 3,
            'Cinema': None,
            'Lighthouse': 1,
            'Ryan Field': None,
            'YWCA': None
        },
        'Whole_Food': {
            'Campus': 4,
            'Whole_Food': None,
            'Beach': 4,
            'Cinema': 3,
            'Lighthouse': None,
            'Ryan Field': None,
            'YWCA': None
        },
        'Beach': {
            'Campus': 4,
            'Whole_Food': 4,
            'Beach': None,
            'Cinema': None,
            'Lighthouse': None,
            'Ryan Field': None,
            'YWCA': None
        },
        'Cinema': {
            'Campus': None,
            'Whole_Food': 4,
            'Beach': None,
            'Cinema': None,
            'Lighthouse': None,
            'Ryan Field': None,
            'YWCA': 2
        },
        'Lighthouse': {
            'Campus': 1,
            'Whole_Food': None,
            'Beach': None,
            'Cinema': None,
            'Lighthouse': None,
            'Ryan Field': 1,
            'YWCA': None
        },
        'Ryan Field': {
            'Campus': None,
            'Whole_Food': None,
            'Beach': None,
            'Cinema': None,
            'Lighthouse': 2,
            'Ryan Field': None,
            'YWCA': 7
        },
        'YWCA': {
            'Campus': None,
            'Whole_Food': None,
            'Beach': None,
            'Cinema': 5,
            'Lighthouse': None,
            'Ryan Field': 5,
            'YWCA': None
        }
    }
    student_score1 = sc.a_star_search(dis_map, time_map1, 'Campus', 'Cinema')
    student_score2 = sc.a_star_search(dis_map, time_map2, 'Campus', 'Cinema')
    gold_score1 = {
        'Whole_Food': {
            'Beach': 16,
            'Campus': 13,
            'Cinema': 7
        },
        'Campus': {
            'Lighthouse': 8,
            'Beach': 11,
            'Whole_Food': 7
        }
    }
    gold_score2 = {
        'Ryan Field': {
            'YWCA': 11,
            'Lighthouse': 11
        },
        'Whole_Food': {
            'Beach': 19,
            'Campus': 16,
            'Cinema': 10
        },
        'Lighthouse': {
            'Ryan Field': 9,
            'Campus': 7
        },
        'Beach': {
            'Whole_Food': 10,
            'Campus': 12
        },
        'Campus': {
            'Lighthouse': 8,
            'Beach': 11,
            'Whole_Food': 15
        }
    }

    if check_score_equal(student_score1, gold_score1):
        print "pass A* search for time map1"
    else:
        print "Fail A* search for time map1"
        exit(1)

    if check_score_equal(student_score2, gold_score2):
        print "pass A* search for time map2"
    else:
        print "Fail A* search for time map2"
        exit(1)
    exit(0)
Example #20
0
 def test3(self):
     expand.expand_count = 0
     path = sc.a_star_search(dis_map, time_map3, 'Campus', 'Cinema')
     self.assertEqual(path, ['Campus', 'Whole_Food', 'Cinema'])
     self.assertEqual(expand.expand_count, 5)
Example #21
0
	def testForOneNodePath(self):
		#ensure a path like [start] can be returned
		path = sc.a_star_search(dis_map,time_map1,'Big Ben','Big Ben')
		self.assertEqual(['Big Ben'],path)
Example #22
0
 def test5(self):
     expand.expand_count = 0
     path = sc.a_star_search(dis_map, time_map1, 'Ryan_Field', 'Beach')
     self.assertEqual(path, ['Ryan_Field', 'Lighthouse', 'Campus', 'Beach'])
     self.assertEqual(expand.expand_count, 4)
Example #23
0
	def test_cross_map(self):
		expand.expand_count = 0
		path = sc.a_star_search(dis_map, time_map1, 'YWCA', 'Campus')
		self.assertEqual(path, ['YWCA', 'Ryan_Field', 'Lighthouse', 'Campus'])
		self.assertEqual(expand.expand_count, 5)
Example #24
0
 def test6(self):
     expand.expand_count = 0
     path = sc.a_star_search(dis_map, time_map1, 'Campus', 'Campus')
     self.assertEqual(path, ['Campus'])
     self.assertEqual(expand.expand_count, 0)
Example #25
0
	def testAlphabeticalTieBreaks(self):
		path = sc.a_star_search(dis_map2,time_map3,'Hackathon Laboratory','Multicultural Center')
		self.assertEqual(['Hackathon Laboratory','College Column','Multicultural Center'],path)