Академический Документы
Профессиональный Документы
Культура Документы
Declarations:
(Object Robot ^initial-position {(0,0,0) to (10,10,0)} ^currentposition {(0,0,0) to (10,10,0)} ^goal {Turn-On-Switch} ^status
{NYC, Done})
(Object Switch ^position {((0, 0, 0) to (0, 10, 10)), ((0, 10, 0) to
(10, 10, 10)), ((10, 0, 0) to (10, 10, 10)), ((0, 0, 0) to (10, 0, 10))}
^status {on, off})
The Knowledge-Base :
Cases:
1. Switch is already on:
a. Nothing to do; just inform;
2. Switch is off; Robot NOT at the Switch position:
a. Walk up to the Switch position; Turn Switch on;
Walk back to the original position;
3. Switch is off; Robot is originally at the Switch position:
a. Turn Switch on; Remain in the original position;
R1 /* Case # 1 */
If (
(Object Robot ^goal = Turn-On-Switch ^status = NYC)
(Object Switch ^status = on)
Then
(Command Execute (Robot, shout, Sir, the switch is already
on))
(modify Robot ^status = Done)
)
R2 /* Case # 2 */
If (
(Object Robot ^initial-position = (x, y, 0) ^current-position = (x,
y, 0) ^goal = Turn-On-Switch ^status = NYC)
(Object Switch ^position = (p, q, r) ((p <> x) OR (q <>
y))^status = off)
Then
(Command Execute (Robot, Move, (x, y, 0), (p, q, 0)))
(Command Execute (Robot, Shout, Sir, I am moving to position
of the switch)
(modify Robot ^current-position = (p, q, 0))
(Command Execute (Robot, shout, Sir, the switch is changed
from off to on))
(modify Switch ^status = on)
(Command Execute (Robot, Move, (p, q, 0), (x, y, 0)))
(Command Execute (Robot, Shout, Sir, I am moving back to my
initial position)
(modify Robot ^current-position = (x, y, 0) ^status = Done)
)
R3 /* Case # 3 */
If (
(Object Robot ^initial-position = (x, y, 0) ^current-position = (x,
y, 0) ^goal = Turn-On-Switch ^status = NYC)
(Object Switch ^position = (x, y, z) ^status = off)
Then
(Command Execute (Robot, shout, Sir, the switch is changed
from off to on))
(modify Switch ^status = on)
(modify Robot ^status = Done)
)
Assume that,
If the Switch is above the ground by 7 feet or more, then the
robot needs a ladder to climb and turn the Switch on;
The ladder will always be on the ground but anywhere in
the room;
Write FOPL Rules using OPS5 like language.
/* R1, R2 and R3 rules will be the same as before, if the Switch is
at lower than 7 feet height */
R1 /* Case # 1 */
If (
(Object Robot ^goal = Turn-On-Switch ^status = NYC)
(Object Switch ^status = on)
Then
(Command Execute (Robot, shout, Sir, the switch is already
on))
(modify Robot ^status = Done)
)
R2 /* Case # 2 */
If (
(Object Robot ^initial-position = (x, y, 0) ^current-position = (x,
y, 0) ^goal = Turn-On-Switch ^status = NYC)
(Object Switch ^position = (p, q, r) (r < 7) ((p <> x) OR (q <>
y))^status = off)
Then
(Command Execute (Robot, Move, (x, y, 0), (p, q, 0)))
(Command Execute (Robot, Shout, Sir, I am moving to position
of the switch)
R4 /* Case # 1 */
If (
(Object Robot ^initial-position = (x, y, 0) ^current-position = (x,
y, 0) ^goal = Turn-On-Switch ^status = NYC)
(Object Switch ^position = (p, q, r) (r >= 7) ((p <> x) OR (q <>
y)) ^status = off)
(Object Ladder ^ initial-position = (x1, y1, 0) ^current-position
= (x1, y1, 0) ((x1 <> x) AND (x1 <> p)) OR (y1 <> y) AND (y1 <>
q)))
Then
(Command Execute (Robot, Shout, Sir, I am moving to the
position of the Ladder)
(Command Execute (Robot, Move, (x, y, 0), (x1, y1, 0)))
(modify Robot ^current-position = (x1, y1, 0))
(Command Execute (Robot, Shout, Sir, I am pushing the Ladder
to the position of the Switch)
(Command Execute (Robot, Push Ladder, (x1, y1, 0), (p, q, 0)))
(modify Ladder ^current-position = (p, q, 0))
(modify Robot ^current-position = (p, q, 0))
(Command Execute (Robot, Shout, Sir, I am Climbing on the
Ladder)
(Command Execute (Robot, Climb up the Ladder)
(Command Execute (Robot, shout, Sir, the switch is changed
from off to on))
(modify Switch ^status = on)
(Command Execute (Robot, Shout, Sir, I am Climbing down the
Ladder)
(Command Execute (Robot, Climb down the Ladder)
(Command Execute (Robot, Shout, Sir, I am putting the Ladder
back to its initial position)
(Command Execute (Robot, Push Ladder, (p, q, 0), (x1, y1, 0)))
R5 /* Case # 2 */
If (
(Object Robot ^initial-position = (x, y, 0) ^current-position = (x,
y, 0) ^goal = Turn-On-Switch ^status = NYC)
(Object Switch ^position = (p, q, r) (r >= 7) ((p <> x) OR (q <>
y)) ^status = off)
(Object Ladder ^ initial-position = (x, y, 0) ^current-position =
(x, y, 0))
Then
(Command Execute (Robot, Shout, Sir, I am pushing the Ladder
to the position of the Switch)
(Command Execute (Robot, Push Ladder, (x, y, 0), (p, q, 0)))
(modify Ladder ^current-position = (p, q, 0))
(modify Robot ^current-position = (p, q, 0))
(Command Execute (Robot, Shout, Sir, I am Climbing on the
Ladder)
(Command Execute (Robot, Climb up the Ladder)
(Command Execute (Robot, shout, Sir, the switch is changed
from off to on))
(modify Switch ^status = on)
R6 /* Case # 3 */
If (
(Object Robot ^initial-position = (x, y, 0) ^current-position = (x,
y, 0) ^goal = Turn-On-Switch ^status = NYC)
(Object Switch ^position = (p, q, r) (r >= 7) ((p <> x) OR (q <>
y)) ^status = off)
(Object Ladder ^ initial-position = (p, q, 0) ^current-position =
(p, q, 0))
Then
(Command Execute (Robot, Shout, Sir, I am moving up to the
Ladder)
(Command Execute (Robot, Move, (x, y, 0), (p, q, 0)))
(modify Robot ^current-position = (p, q, 0))
(Command Execute (Robot, Shout, Sir, I am Climbing on the
Ladder)
(Command Execute (Robot, Climb up the Ladder)
(Command Execute (Robot, shout, Sir, the switch is changed
from off to on))
(modify Switch ^status = on)
R7 /* Case # 4 */
If (
(Object Robot ^initial-position = (x, y, 0) ^current-position = (x,
y, 0) ^goal = Turn-On-Switch ^status = NYC)
(Object Switch ^position = (x, y, r) (r >= 7) ^status = off)
(Object Ladder ^ initial-position = (p, q, 0) ^current-position =
(p, q, 0) ((p <> x) OR (q <> y)))
Then
(Command Execute (Robot, Shout, Sir, I am moving to the
position of the Ladder)
(Command Execute (Robot, Move, (x, y, 0), (p, q, 0)))
(modify Robot ^current-position = (p, q, 0))
(Command Execute (Robot, Shout, Sir, I am pushing the Ladder
to the position of the Switch)
(Command Execute (Robot, push Ladder, (x1, y1, 0), (p, q, 0)))
(modify Ladder ^current-position = (x, y, 0))
(modify Robot ^current-position = (x, y, 0))
(Command Execute (Robot, Shout, Sir, I am Climbing on the
Ladder)
(Command Execute (Robot, Climb up the Ladder)
R8 /* Case # 5 */
/* Home Assignment: please write this rule */