Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
997588c
water_jug.ipynb
manasvi03 Dec 6, 2020
c3edff3
Missionary & cannibal
manasvi03 Dec 6, 2020
0c0f842
Create TASK_8 - BFS
manasvi03 Dec 6, 2020
a1404f6
Create TASK_9 - DFS
manasvi03 Dec 6, 2020
5542eee
Create TASK_10 - Depth Limited Search
manasvi03 Dec 6, 2020
07c0525
Create TASK_11 - Iterative Deepening Search
manasvi03 Dec 6, 2020
d25c257
Create TASK_12 - A* Algorithm
manasvi03 Dec 6, 2020
b080717
Create TASK_13 - AO* Algorithm
manasvi03 Dec 6, 2020
21daf5c
Create TASK_14 - MP Neuron for Logic Gates
manasvi03 Dec 6, 2020
627df62
Create TASK_15 - Single Layer Perceptron for AND
manasvi03 Dec 6, 2020
dcf9bf1
Create TASK_16 - Single Layer Perceptron for AND-NOT
manasvi03 Dec 6, 2020
11dea73
Add files via upload
manasvi03 Dec 6, 2020
f358f1c
Create TASK_18 - Linear Separability AND
manasvi03 Dec 6, 2020
34989f1
Create TASK_19 - Linear Separability OR
manasvi03 Dec 6, 2020
65e3d2a
Create TASK_20 - Adaline Algorithm
manasvi03 Dec 6, 2020
a053ce0
Create TASK_21 -
manasvi03 Dec 6, 2020
89ad1c9
Rename TASK_21 - to TASK_21 - Madaline Neural Network
manasvi03 Dec 6, 2020
7bccd2d
Create TASK_22 - Back Propagation
manasvi03 Dec 6, 2020
bcb6fd1
Create TASK_23 - Bidirectional Association Memory Network
manasvi03 Dec 6, 2020
2a4069b
Create TASK_24 - Hopfield Network
manasvi03 Dec 6, 2020
4188141
Create TASK_25 - Fuzzy Set Operations
manasvi03 Dec 6, 2020
0aede52
Create TASK_26 - Fuzzy Relations and Operations
manasvi03 Dec 6, 2020
45ec04d
Add files via upload
manasvi03 Dec 6, 2020
ccac999
Create TASK_28 - Genetic Algorithm
manasvi03 Dec 6, 2020
6a26ab1
Create TASK_29 - Counter Propagation Algorithm
manasvi03 Dec 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Manasvi Vashishtha-4th yr-Section C/TASK_10 - Depth Limited Search
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from collections import defaultdict
class Graph:
def __init__(self,vertices):
self.V = vertices
self.graph = defaultdict(list)
def addEdge(self,u,v):
self.graph[u].append(v)
def DLS(self,src,target,maxDepth):
if src == target : return True
if maxDepth <= 0 : return False
for i in self.graph[src]:
if(self.DLS(i,target,maxDepth-1)):
return True
return False
def IDDFS(self,src, target, maxDepth):
for i in range(maxDepth):
if (self.DLS(src, target, i)):
return True
return False
g = Graph (7);
g.addEdge(0, 1)
g.addEdge(0, 2)
g.addEdge(1, 3)
g.addEdge(1, 4)
g.addEdge(2, 5)
g.addEdge(2, 6)
target = int(input("enter the node to be searched"));
maxDepth = int(input("enter the depth"));
src = 0
if g.IDDFS(src, target, maxDepth) == True:
print ("Target is reachable from source " +
"within max depth")
else :
print ("Target is NOT reachable from source " +
"within max depth")
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from collections import defaultdict

class Graph:

def __init__(self,vertices):

self.V = vertices
self.graph = defaultdict(list)
def addEdge(self,u,v):
self.graph[u].append(v)

def DLS(self,src,target,maxDepth):
if src == target : return True
if maxDepth <= 0 : return False

for i in self.graph[src]:
if(self.DLS(i,target,maxDepth-1)):
return True
return False
def IDDFS(self,src, target, maxDepth):
for i in range(maxDepth):
if (self.DLS(src, target, i)):
return True
return False


g = Graph (7);
g.addEdge(0, 1)
g.addEdge(0, 2)
g.addEdge(1, 3)
g.addEdge(1, 4)
g.addEdge(2, 5)
g.addEdge(2, 6)

target = int(input("enter the node to be searched"));
maxDepth = int(input("enter the depth"));
src = 0
found = 1
while(found):
if g.IDDFS(src, target, maxDepth) == True:
print ("Target is reachable from source " +
"within max depth : ")
print(maxDepth)
found = 0
else :
maxDepth = maxDepth +1
79 changes: 79 additions & 0 deletions Manasvi Vashishtha-4th yr-Section C/TASK_12 - A* Algorithm
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
grid = [[0, 1, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0]]

heuristic = [[9, 8, 7, 6, 5, 4],
[8, 7, 6, 5, 4, 3],
[7, 6, 5, 4, 3, 2],
[6, 5, 4, 3, 2, 1],
[5, 4, 3, 2, 1, 0]]

init = [0, 0]
goal = [len(grid)-1, len(grid[0])-1]
cost = 1

delta = [[-1, 0 ], # go up
[ 0, -1], # go left
[ 1, 0 ], # go down
[ 0, 1 ]] # go right

delta_name = ['^', '<', 'v', '>']

def search(grid,init,goal,cost,heuristic):
# ----------------------------------------
# modify the code below
# ----------------------------------------
closed = [[0 for col in range(len(grid[0]))] for row in range(len(grid))]
closed[init[0]][init[1]] = 1

expand = [[-1 for col in range(len(grid[0]))] for row in range(len(grid))]
action = [[-1 for col in range(len(grid[0]))] for row in range(len(grid))]

x = init[0]
y = init[1]
g = 0
f = g + heuristic[x][y]

open = [[f, g, x, y]]

found = False # flag that is set when search is complete
resign = False # flag set if we can't find expand
count = 0

while not found and not resign:
if len(open) == 0:
resign = True
return "Fail"
else:
open.sort()
open.reverse()
next = open.pop()
f = next[0]
g = next[1]
x = next[2]
y = next[3]

expand[x][y] = count
count += 1

if x == goal[0] and y == goal[1]:
found = True
else:
for i in range(len(delta)):
x2 = x + delta[i][0]
y2 = y + delta[i][1]
if x2 >= 0 and x2 < len(grid) and y2 >=0 and y2 < len(grid[0]):
if closed[x2][y2] == 0 and grid[x2][y2] == 0:
g2 = g + cost
f = g2 + heuristic[x2][y2]
open.append([f, g2, x2, y2])
closed[x2][y2] = 1

return expand

result = search(grid,init,goal,cost,heuristic)

for el in result:
print (el)
183 changes: 183 additions & 0 deletions Manasvi Vashishtha-4th yr-Section C/TASK_13 - AO* Algorithm
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
struct node
{
int data;
vector< vector<node* >* >v;
bool mark;
bool solved;
};
int edge_cost=0;
void insert(node* root)
{
cout<<"Enter data of node :"<<endl;
cin>>root->data;
//vector<vector<node*> >vec=root->v;
cout<<"Enter number of OR nodes for value "<<root->data<<" :"<<endl;
int or_no;
cin>>or_no;
for(int i=0;i<or_no;i++)
{
vector<node*>* ans=new vector<node*>;
cout<<"Enter number of AND nodes for "<<i+1<<" or node for value "<<root->data<<" :"<<endl;
int and_no;
cin>>and_no;
for(int j=0;j<and_no;j++)
{
node* n=new node;
n->solved=false;
n->mark=false;
insert(n);
(*ans).push_back(n);
//cout<<"inserted node with value"<<n->data<<endl;
}
root->v.push_back(ans);
}

}
void aostar(node* root)
{
vector<node*>* min_ans=new vector<node*>;
(*min_ans).push_back(root);
while(!root->solved)
{
node* next_node=root;
stack<node*>st;
while(next_node && next_node->mark)
{
if((next_node->v).size()==0)
{
root->solved=true;
return;
}
int cost=INT_MAX;
st.push(next_node);
for(unsigned int i=0;i<next_node->v.size();i++)
{
vector<node*>*ans=(next_node->v)[i];
vector<node*> ans_v=*ans;
int temp_cost=0;
for(unsigned int j=0;j<(ans_v.size());j++)
{
node* n=ans_v[j];
temp_cost+=n->data;
}
if(temp_cost<cost)
{
min_ans=ans;
cost=temp_cost;
}
}
vector<node*> min_ans_v=*min_ans;
next_node=NULL;
for(unsigned int j=0;j<min_ans_v.size();j++)
{
if(min_ans_v[j]->mark)
{
next_node=min_ans_v[j];
break;
}
}

}

vector<node*> min_ans_v=*min_ans;
for(unsigned int j=0;j<min_ans_v.size();j++)
{
node* n=min_ans_v[j];
cout<<"Exploring :"<<n->data<<endl;
int final_cost=INT_MAX;
if(n->v.size()==0)
{
n->mark=true;
}
else{
for(unsigned int i=0;i<n->v.size();i++)
{
vector<node*>*ans=(n->v)[i];
vector<node*> ans_v=*ans;
int temp_cost=0;
for(unsigned int j=0;j<(ans_v.size());j++)
{
node* n=ans_v[j];
temp_cost+=n->data;
temp_cost+=edge_cost;
}
if(temp_cost<final_cost)
{
final_cost=temp_cost;
}
}
n->data=final_cost;
n->mark=true;
}
cout<<"Marked : "<<n->data<<endl;
}

for(int i=0;i<20;i++) cout<<"=";
cout<<endl;
while(!st.empty())
{
node* n=st.top();
cout<<n->data<<" ";
st.pop();
int final_cost=INT_MAX;
for(unsigned int i=0;i<n->v.size();i++)
{
vector<node*>*ans=(n->v)[i];
vector<node*> ans_v=*ans;
int temp_cost=0;
for(unsigned int j=0;j<(ans_v.size());j++)
{
node* n=ans_v[j];
temp_cost+=n->data;
temp_cost+=edge_cost;
}
if(temp_cost<final_cost)
{
min_ans=ans;
final_cost=temp_cost;
}
}
n->data=final_cost;
}
cout<<endl;
next_node=root;

}
}
void print(node* root)
{
if(root)
{
cout<<root->data<<" ";
vector<vector<node*>* >vec=root->v;
for(unsigned int i=0;i<(root->v).size();i++)
{
vector<node*>* ans=(root->v)[i];
vector<node*> ans_v=*ans;
for(unsigned int j=0;j<ans_v.size();j++)
{
node* n=ans_v[j];
print(n);
}
}
}
return;
}

int main()
{
node* root=new node;
root->solved=false;
root->mark=false;
insert(root);cout<<endl;
cout<<"Enter the edge cost: "<<endl;cin>>edge_cost;cout<<endl;
cout<<"The tree is as follows :"<<endl;
print(root);
cout<<endl;
aostar(root);
cout<<"The minimum cost is : "<<root->data<<endl;
return 0;
}
Loading