Untitled

 avatar
unknown
plain_text
2 years ago
955 B
17
Indexable
h1 = {
    'A': 12,
    'B': 9,
    'C': 9,
    'D': 5,
    'E': 7,
    'F': 7,
    'G': 0,
    'H': 2,
    'I': 1,
}

graph = {
    'A': [['B', 4], ['C', 1]],
    'B': [['D', 4]],
    'C': [['E', 2], ['G', 15]],
    'D': [['E', 1], ['H', 4]],
    'E': [['F', 4], ['H', 7]],
    'F': [['H', 4]],
    'G': [],
    'H': [['I', 1]],
    'I': [['G', 2]],
}


student = {
    'A': 13,
    'B': 10,
    'C': 10,
    'D': 6,
    'E': 8,
    'F': 8,
    'G': 0,
    'H': 3,
    'I': 2,
}

def consistency_check(x):
    consistent = True
    for y in graph[x]:
        v = y[0]
        cost = y[1]
        if student[x] > student[v] + cost:
            consistent = False
            break
    
    if consistent == False:
        print(x + ' is not consistent')
    
def domination_check(x):
    if student[x] < h1[x]:
        print('the heuristic of ' + x + ' is not dominating')
    
    
for key in student:
    consistency_check(key)
    domination_check(key)
Editor is loading...
Leave a Comment