Artificial Intelligence Programs For Programming in Python

Traveling Salesman Problem ( TSP )] Artificial Intelligence Programs For Master Leval Programming in Python from iter tools import permutations def distance(point1, point2): >>> distance([3,4],[0,0]) 5.0 >>> distance([3,6],[10,6]) 7.0 return ((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2) ** 0.5 def total_distance(points): all the points are in the given order. >>> total_distance([[1,2],[4,6]]) 5.0 >>> total_distance([[3,6],[7,6],[12,6]]) 9.0 return sum([distance(point, points[index + 1]) for index, point in enumerate(points[:-1])]) def travelling_salesman(points, start=None): Time complexity is O(N!), so never use on long lists. >>> travelling_salesman([[0,0],[10,0],[6,0]]) ([0, 0], [6, 0], [10, 0]) >>> travelling_salesman([[0,0],[6,0],[2,3],[3,7],[0.5,9],[3,5],[9,1]]) ([0, 0], [6, 0], [9, 1], [2, 3], [3, 5], [3, 7], [0.5, 9]) """ if the start is None: start = points[0] return min([perm for perm ...

MongoDB Exercises Practice Solution Exercise First

MongoDB Exercises Practice Solution Exercise 
MongoDB Exercises Practice Solution Exercise
Practice This All Examples
Exercise 3

=> Create database EMP and Make Collection With name "EMPL" and Follow Queries 

=>Created Database
> use emp
switched to DB emp

=>Create Collection
> db.createCollection("empl")

=>Insert Records Into EMPL Collection
> db.empl.insert([
{no:1,name:"ST",salary:2000,role:"OB"},
{no:2,name:"MSD",salary:1500,role:"WK"},
{no:3,name:"YS",salary:1000,role:"ALR"},
{no:4,name:"RD",salary:1000,role:"MOB"},
{no:5,name:"RS",salary:500,role:"OB"},
{no:6,name:"BK",salary:500,role:"MOB"},
{no:7,name:"VK",salary:300,role:"BW"},
{no:8,name:"JB",salary:400,role:"BW"},
{no:9,name:"HP",salary:400,role:"ALR"},
{no:10,name:"VS",salary:300,role:"OB"}])

=>Display Data in Proper Format
>db.empl.find().pretty()

=>Update Salary Of Employee where Name is "ST" by +8000
>db.empl.update({name:"ST"},{$inc:{salary:8000}})

=>Update Salary Of All Employee by giving an increment of +4000 each
>db.empl.update({},{$inc:{salary:4000}},{multi:true})

=>update role of "MSD" as "C and WK"
>db.empl.update({name:"MSD"},{$set:{role:"c and WK"}})

=>Add a New Field remark to document with name "RS" set Remark as WC
>db.emp.update({name:"RS"},{$set:{remark:"WC"}})

=>Add a New Field As Number 11,name AK,Salary 10000,role coch without using insert statement. But for Doing So You should have a Record Added woth number 11.
>db.empl.update({no:11},{$set:{no:11,name:"AK",salary:10000,role:"coch"}},{upsert:true})

=>remove added New Field
>db.empl.update({name:"RD"},{$unset:{remark:"WC"}})

=>Update the Field "RD" by multiplying with salary by 2
>db.empl.update({name:"RD"},{$mul:{salary:2}})

=>To Find Document From the empl collection where name begins with S
>db.empl.find({name:/^S/})

=>To Find Document From the empl collection where name begins with R
>db.empl.find({name:/^R/})

=>To Find Document From the empl collection where name ends with K
>db.empl.find({name:/K$/})

=>To Find Document From the empl collection where name ends with D
>db.empl.find({name:/S$/})

=>To Find Document From the empl collection where name has S in any position
>db.empl.find({name:/S/})
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
Regular Expression
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
(Note: Use Case sensitive allow For that write in Option: "i")

=> To Find Document From the empl collection where name begins with S
>db.empl.find({name:{$regex:"^S"}})

=> To Find Document From the empl collection where name begins with S
>db.empl.find({name:{$regex:"S",$options:"i"}})
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
 Use of $in and $nin (in and notin)
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

(Note: There will not use {} braces in that $in and $nin)


=> Display Documents where in empl collection Field have OB,MOB 
>db.empl.find({role:{$in:["OB","MOB"]}})

=> Display Documents where in empl collection Field not have OB,MOB
>db.empl.find({role:{$nin:["OB","MOB"]}})



Comments

Post a Comment

Popular posts from this blog

Simple Basic Commands For MongoDB

Artificial Intelligence Programs For Programming in Python