Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

here is an example of one we did. so they implemented the basic depht first already we need to do the states and the alowed

image text in transcribed
image text in transcribed
here is an example of one we did.
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
so they implemented the basic depht first already we need to do the states and the alowed moves and any aditional information around that
Question 5 1101 You are given two R2 coins and two R5 coins that are initially arranged as shown below R2 RS R5 R2 The purpose of the game is to make a sequence of simple moves to bring the coins into their final positions as shown below R5 R5 R2 R2 A coin can be moved by either sliding it to the empty square next to the square it is currently occupying, or by hopping it over another com into an empty square The R2 coins can only be moved to the right, and the RS coins can only be moved to the left No backing up is allowed Write a Prolog program using the depth-first search program given below to find a sequence of legal moves to bring the coins from the given initial state to the desired final state You only need to give the representation of the initial state, the final state and the clauses for all the possible state changes represented by the predicate's' coins(Solution) initial state(Start). depth_first(0.L.Solution) depth_first(Path.Node. [Node I Path]) goal (Node) depth_first(Path, Node, Sol). s(Node , Nodel), depth_first([Node I Path]. Nodel Sol) Question 1 [10] The wounded soldiers problem: A number of wounded soldiers find themselves behind enemy lines. There is a bridge they can cross to safety but they only have limited time and one torch to get everyone across. The extent of their wounds have an effect on the time it takes each individual to get across. They have one torch and the soldiers that are not heavily wounded have to help the others across (two soldiers can cross at one time). One soldier needs to bring the torch back for the next crossing. You have the following information regarding the crossing time of each individual soldier at your disposal Soldier): 5 minutes Soldier 2: 10 minutes Soldier: 20 minutes Soldier: 25 minutes They only have 61 minutes to cross before the next patrol vehicle of the enemy arrives. Write a Prolog program using a depth-first search to find a sequence of crossings that will get all soldiers to the safe side in the required time. & dfs/2 dts (S, Maxtime) performs a depth-tirst search on the state space, producing Han answer path in S. MaxTime is the maximum time allowed for all the moves to complete soldier (Solution, MaxTime): anitial state(s) depth first (I,S, Solution, MaxTime). $depth_first/4 depth_first search with cycle detection. depth_first (Path, Node, [Node Path] , MaxTime) : - goal (Node). depth_first (Path, Node, Sol, TimeSoFar):- S (Node, Nodel, Time), not (member (Nodel, Path)), Timel is TimeSoFar-Time, Timel > 0, depth first([Node Path), Nodel, Sol, Timel). 1 op 8 initial and final states 8 initial state ([us, us, us, us, us]). goal ([s,s,s,s,s]). % Crossing time of individual soldiers time (s1,5). time (s2,10). time (s3, 20). time (s4, 25). & Get max crossing time of 2 soldiers crossing together 8 max (T1, T2, T2): - T2 > T1,!. max (T1, T2, T1). % % Valid crossings. The torch travels with every crossing $ Soldiers 1 and 2 cross to safe side s([X, Y, S3, S4, T), [Ti,T1, S3,S4, T1], Time) :- X = T, T, cross (T, TI), time (sl, 12), time (s2, T3), max (T2, T3, T4). Time is T4. % Soldiers 1 and 3 cross to safe side s([X, S2,Y, 54, T1, T1,52, T1,S4, T1], Time) :- X = T, Y = T, cross (T, TI) time (s1, 12), time (s3, T3), max (T2, T3, T4), Time is 14. % Soldiers 1 and 4 cross to safe side s([X, S2, S3, Y,T], [T1,S2,S3, T1, T1], Time) :- X = T, Y = T, cross (T, T1), 4 7 time (s1, T2), time (s4, T3), max (T2, T3, T4), Time is T4. % Soldiers 2 and 3 cross to safe side s([S1, X, Y, S4, T), [S1, T1, T1, S4, T1], Time) :- X = T, Y = T, cross (T, T1), time (s2, T2), time (s 3,13) max (T2, T3, T4), Time is T4. % Soldiers 2 and 4 cross to safe side s([S1, X, S3, Y,T), [S1, T1,S3, T1, T1], Time) :- X = T, Y = T, cross (T, T1), time (92, T2). time (s4, T3). max (T2, T3, T4), Time is T4. - % Soldiers 3 and 4 cross to safe side s([S1, S2, X, Y,T], [S1, S2, T1, T1, T1], Time) :- X = T) Y = T, cross (T, T1) time (83, 12) time (54,13), max (T2, T3, T4), Time is 14. % Soldier 1 crosses to unsafe side s([X, S2,S3,S4,T], [T1,S2,S3,S4, T1], Time) :- X = T, cross (T, T1), time (s1, T2), Time is T2. % Soldier 2 crosses to unsafe side s([S1, X, S3, S4,T], [S1, T1,S3,S4, T1], Time) :- X = T, cross (T, TI), time (s2, T2), Time is T2. % Soldier 3 crosses to unsafe side s([S1, S2, X, 54,T], [S1, S2, T1, S4, T1], Time) :- 5 COS48 X = T, cross (T, TI), time (s 3, T2), Time is T2. Time 13 12. % Soldier 4 crosses to unsafe side s([S1,S2,S3,X, T), [S1, S2, S3, T1, T1], Time):- X = T, cross (T, Tl), time (s4, T2), Time is 12. % The crossing is either from safe to unsafe, or from unsafe to safe cross (s, us). cross (us,s). member (X, IXIL). member (X, Y|L): - member (X,L). Test Results: Question 5 1101 You are given two R2 coins and two R5 coins that are initially arranged as shown below R2 RS R5 R2 The purpose of the game is to make a sequence of simple moves to bring the coins into their final positions as shown below R5 R5 R2 R2 A coin can be moved by either sliding it to the empty square next to the square it is currently occupying, or by hopping it over another com into an empty square The R2 coins can only be moved to the right, and the RS coins can only be moved to the left No backing up is allowed Write a Prolog program using the depth-first search program given below to find a sequence of legal moves to bring the coins from the given initial state to the desired final state You only need to give the representation of the initial state, the final state and the clauses for all the possible state changes represented by the predicate's' coins(Solution) initial state(Start). depth_first(0.L.Solution) depth_first(Path.Node. [Node I Path]) goal (Node) depth_first(Path, Node, Sol). s(Node , Nodel), depth_first([Node I Path]. Nodel Sol) Question 1 [10] The wounded soldiers problem: A number of wounded soldiers find themselves behind enemy lines. There is a bridge they can cross to safety but they only have limited time and one torch to get everyone across. The extent of their wounds have an effect on the time it takes each individual to get across. They have one torch and the soldiers that are not heavily wounded have to help the others across (two soldiers can cross at one time). One soldier needs to bring the torch back for the next crossing. You have the following information regarding the crossing time of each individual soldier at your disposal Soldier): 5 minutes Soldier 2: 10 minutes Soldier: 20 minutes Soldier: 25 minutes They only have 61 minutes to cross before the next patrol vehicle of the enemy arrives. Write a Prolog program using a depth-first search to find a sequence of crossings that will get all soldiers to the safe side in the required time. & dfs/2 dts (S, Maxtime) performs a depth-tirst search on the state space, producing Han answer path in S. MaxTime is the maximum time allowed for all the moves to complete soldier (Solution, MaxTime): anitial state(s) depth first (I,S, Solution, MaxTime). $depth_first/4 depth_first search with cycle detection. depth_first (Path, Node, [Node Path] , MaxTime) : - goal (Node). depth_first (Path, Node, Sol, TimeSoFar):- S (Node, Nodel, Time), not (member (Nodel, Path)), Timel is TimeSoFar-Time, Timel > 0, depth first([Node Path), Nodel, Sol, Timel). 1 op 8 initial and final states 8 initial state ([us, us, us, us, us]). goal ([s,s,s,s,s]). % Crossing time of individual soldiers time (s1,5). time (s2,10). time (s3, 20). time (s4, 25). & Get max crossing time of 2 soldiers crossing together 8 max (T1, T2, T2): - T2 > T1,!. max (T1, T2, T1). % % Valid crossings. The torch travels with every crossing $ Soldiers 1 and 2 cross to safe side s([X, Y, S3, S4, T), [Ti,T1, S3,S4, T1], Time) :- X = T, T, cross (T, TI), time (sl, 12), time (s2, T3), max (T2, T3, T4). Time is T4. % Soldiers 1 and 3 cross to safe side s([X, S2,Y, 54, T1, T1,52, T1,S4, T1], Time) :- X = T, Y = T, cross (T, TI) time (s1, 12), time (s3, T3), max (T2, T3, T4), Time is 14. % Soldiers 1 and 4 cross to safe side s([X, S2, S3, Y,T], [T1,S2,S3, T1, T1], Time) :- X = T, Y = T, cross (T, T1), 4 7 time (s1, T2), time (s4, T3), max (T2, T3, T4), Time is T4. % Soldiers 2 and 3 cross to safe side s([S1, X, Y, S4, T), [S1, T1, T1, S4, T1], Time) :- X = T, Y = T, cross (T, T1), time (s2, T2), time (s 3,13) max (T2, T3, T4), Time is T4. % Soldiers 2 and 4 cross to safe side s([S1, X, S3, Y,T), [S1, T1,S3, T1, T1], Time) :- X = T, Y = T, cross (T, T1), time (92, T2). time (s4, T3). max (T2, T3, T4), Time is T4. - % Soldiers 3 and 4 cross to safe side s([S1, S2, X, Y,T], [S1, S2, T1, T1, T1], Time) :- X = T) Y = T, cross (T, T1) time (83, 12) time (54,13), max (T2, T3, T4), Time is 14. % Soldier 1 crosses to unsafe side s([X, S2,S3,S4,T], [T1,S2,S3,S4, T1], Time) :- X = T, cross (T, T1), time (s1, T2), Time is T2. % Soldier 2 crosses to unsafe side s([S1, X, S3, S4,T], [S1, T1,S3,S4, T1], Time) :- X = T, cross (T, TI), time (s2, T2), Time is T2. % Soldier 3 crosses to unsafe side s([S1, S2, X, 54,T], [S1, S2, T1, S4, T1], Time) :- 5 COS48 X = T, cross (T, TI), time (s 3, T2), Time is T2. Time 13 12. % Soldier 4 crosses to unsafe side s([S1,S2,S3,X, T), [S1, S2, S3, T1, T1], Time):- X = T, cross (T, Tl), time (s4, T2), Time is 12. % The crossing is either from safe to unsafe, or from unsafe to safe cross (s, us). cross (us,s). member (X, IXIL). member (X, Y|L): - member (X,L). Test Results

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How does a scatterplot matrix differ from a basic scatterplot?

Answered: 1 week ago