-
Hi all, I'm still working my way through the PMASIAUJ book and have just finished implementing section C of Exercise 1 in Chapter 5, where we are asked to
for the vacuum cleaner example. I probably went a bit further than the exercise intended, but I'm trying to make sure I understand all this. What I did works, but curious if there is a more idiomatic or preferred way to accomplish this. Briefly, here's what I did. I made my grid world 10x10 using the same setup as the Domestic Robot example. Then I randomly initialized some dirty squares and set my vacuum agent to the task of cleaning the room. I did not try to do anything fancy as far as navigation or pathfinding, since that seemed beyond the scope of what I'm trying to do. So I just have the vacuum jump to the upper left square (it starts in a random location) and then navigate from left to right until it hits the rightmost square, then it jumps "down and full left" then starts going right again, lather rinse repeat until the numdirty(X) percept is 0. In my Environment / Model I insert percepts for how many squares to the right remain available and how many rowsn down remain available. My AgentSpeak code looks like this:
Initially the 'visited_upper_left' percept is missing so the first action executed is the goto_upper_left. From there the vacuum starts navigating right, suck()'ing any dirty squares, and so on until it's finished. It quits by calling succeed_goal(cleanroom) when no more dirty squares remain. Calling stopMAS is just a convenience so the program quits so it's easy to just up-arrow in my terminal and hit ENTER to run it again. :-) This works, but I'd love to hear if there are markedly better ways to go about this, or really any other feedback the experts might have. Full source code available here. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi Phillip, great you are progressing! (and animating the discussion about Jason) Initial reaction:
|
Beta Was this translation helpful? Give feedback.
Hi Phillip, great you are progressing! (and animating the discussion about Jason)
Initial reaction:
good you opted for a goal oriented approach instead of an event oriented!
equality tests like X == 0 are usually unnecessary in logic programming, unification may be used in place. For instance
+numdirty(X) : (X == 0)...
->+numdirty(0) ...
. It occurs in @C5 too.it seems several intentions for goal
cleanroom
will be running, triggered by the last plan. Maybe it is better to ensure just one intention. Couldcleanroom
be an initial goal?not clear why you have to add the atomic annotations for the plans... (maybe it is related to 3.)
plans
c2
andc4
seems the same... could it be th…