Professional Documents
Culture Documents
COMSATS University Islamabad Lahore Campus: Midterm Terminal Examination - Fall 2021
COMSATS University Islamabad Lahore Campus: Midterm Terminal Examination - Fall 2021
COMSATS University Islamabad Lahore Campus: Midterm Terminal Examination - Fall 2021
Course Title: Artificial Intelligence - Lab Course Code: CSC462 Credit Hours: 1(0,1)
Course Dr. Atifa Athar Programme Name: BS Computer Science
Instructor/s:
Semester: 6th Batch: SP19 Section C Marks: 25
Due on 11-11-2021 Time 80+10 Mins
Name: Nabeel Ahmad Registration no: SP19-BCS-114
No late submissions will be accepted.
you are required to be submit solution using attached template only.
Upload your solution to the google classroom
Section: 1
Question No 1. Marks: 10
Write a complete program of A* in python for the following graph to find the most cost-effective path
to reach from start state A to final state G. (Attach the code). Print the program output as well.
Code:
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 11 13:50:38 2021
@author: Nabeel
"""
Graph = {
"A" : [("B",2),("E",3)],
"B" : [("A",2),("C",1),("G",9)],
"E" : [("A",3),("D",6)],
"C" : [("B",1)],
"G" : [("B",9),("D",1)],
"D" : [("E",6),("G",1)]
}
Heuristics = {
"A" : 11,
"B" : 6,
"E" : 7 ,
"C" : 99,
"G" : 0,
"D" : 1
}
def getHeuristic(n):
return Heuristics[n]
if s == e:
return z
if s not in x:
print("Node not found")
if e not in x:
print("Node not found")
for n in x[s]:
node = getHeuristic(n[0])
if node < lowest:
lowest = node
lowestNode = n[0]
if lowestNode not in z:
np = calGraph(x, y, lowestNode, e, z)
if np != 'null':
return np
return None
Outputs:
Section: 2
Question No 2. Marks: 5 + 10 = 15
Construct a Semantic network for the following statements in neo4j
1. Diana has a cat named “Marie”.
2. Marie has white fur.
3. John is the only son of Diana.
4. Jill doesn’t love horses but loves cats.
5. Jill is the stepsister of John.
1.1. Write a cypher statement to add Diana likes to grow plants.
1.2. Write a cypher statement to modify Jill is the stepsister of John = > Jill is the real sister of
John
1.3. Write cypher statements to delete following statements Marie has white fur.
1.4. Write cypher statements to find the answer of following queries:
a. Who is the son of Diana?
b. Which animal Jill loves?
Graph code:
Create (a:Cat {name:'Marie',fur:'White'}),(b:Cat{name:'Cat'}),(c:Horses {name:'Horses'}),
(d:Person {name:'Diana'}),(e:Person{name:'John'}),(f:Person{name:'Jill'}),
(a)- [:Is_a] -> (b),
(d)- [:Has_cat] -> (a),
(e)- [:Son_of] -> (d),
(f)- [:Does_nt_Love] -> (c),
(f)- [:Loves] -> (a),
(f)- [:Step_Sister] -> (e)
1.1
Match (n:Person {name:'Diana'})
Create (n)- [:Likes_To_Grow] -> (p:Plants {name:'Plants'})
1.2
Match (j:Person {name:'Jill'}) - [r:Step_Sister] -> (m:Person {name:'John'})
Delete r
Create (j)- [:Real_Sister] -> (m)
1.3
Match (n:Cat{name:'Marie'})
Remove n.fur
1.4
Match (n:Person{name:'Diana'})
Return n.Son
1.5
Match (j:Person {name:'Jill'})
Return j.Loves