Presentation is loading. Please wait.

Presentation is loading. Please wait.

Professor Fuhua Lin. Scenario: Domestic Robot Bartender The domestic robot is ordered by its owner to get him beer from the refrigerator. However, the.

Similar presentations


Presentation on theme: "Professor Fuhua Lin. Scenario: Domestic Robot Bartender The domestic robot is ordered by its owner to get him beer from the refrigerator. However, the."— Presentation transcript:

1 Professor Fuhua Lin

2 Scenario: Domestic Robot Bartender The domestic robot is ordered by its owner to get him beer from the refrigerator. However, the robot has been programmed by the department of health to avoid giving too much beer to its owner. The limit is ten (10) beers per day. As a result, the robot will obey its master and get him beer as long as he is not over the limit for the number of beers he can consume for the day. Beers are ordered from one of three particular supermarkets by the robot. Each supermarket uses a different price for the beer they sell each day. If there is beer in the fridge, the robot will get one and server it to its master when ordered. However, if there is no beer in the fridge, the robot will take the following actions: Find out which of the three contracted supermarket has the lowest price for beer that day. The robot will then place an order to this supermarket with the lowest price for beer. The supermarket will accept the order and deliver the beers to the owner’s address, where they are then placed in the refrigerator. The robot will then serve the owner a beer. This scenario will repeat itself until the owner reaches the limit for the number of beers he can consume for the day as determined by the department of health.

3 Design The system includes a robot agent, the owner agent and three supermarket agents, as a result, when the system start up all five agents will be started. The robot agent is responsible to server its owner agent beers, until he reaches the limit that he is allowed to consume for the day, as prescribe by the department of health. The supermarket agents are responsible for providing the robot agent with the price for beer when it is requested and delivering the beers ordered by the robot to the robot’s owner residence if its supermarket was selected to provide the order for beers. To accomplish the scenario described, the system will make use of the communication support available in Jason of the well known Contact Net protocol (CNP).

4 The Scenario in Prometheus Notations

5

6 Project File DomesticRobot.mas2j MAS domestic_robot { infrastructure: Centralised environment: HouseEnv(gui) // use "nogui" as parameter to not show the GUI agents: robot; owner; supermarket #3; }

7 Robot Agent : initial belief and rules /* Initial beliefs and rules */ // initially, I believe that there is some beer in the fridge available(beer, fridge). // my owner should not consume more than 10 beers a day :-) limit(beer,10). /* rules */ too_much(B) :-.date(YY,MM,DD) &.count(consumed(YY,MM,DD,_,_,_,B), QtdB) & limit(B,Limit) & QtdB > Limit. all_proposals_received(CNPId) :-.count(introduction(participant,_), NP) & // number of participants.count(propose(CNPId,_), NO) & // number of proposes received.count(refuse(CNPId), NR) & // number of refusals received NP = NO + NR. /* Initial goals */ Stock(Beer, N) Robot agent At(robot, Place) To determine whether the owner already drank the maximum number of beers allowed per day. This verification is based on the number of consumed beliefs. When the robot gives a beer to the owner it adds a belief to Remember that; this belief has the form +consumed(Year, Month, Day, Hour, Minute, Second, beer) In plan @h1. has(owner, beer)

8 Robot Agent (cont’):plans to achieve the goal:!has(owner, beer) /* Plans */ +!has(owner, beer) : available(beer, fridge) & not too_much(beer) <- !at(robot, fridge); open(fridge); get(beer); close(fridge); !at(robot, owner); hand_in(beer); ?has(owner, beer); // test a goal // remember that another beer has been consumed.date(YY, MM, DD);.time(HH, NN, SS); +consumed(YY, MM, DD, HH, NN, SS, beer). +!has(owner, beer) : not available(beer, fridge) // Contact the Supermarket and order beer based on the lowest contract price <- !startCNP(1, fix(computer)). +!has(owner, beer) : too_much(beer) & limit(beer, L) <-.concat("The Department of Health does not allow me to give you more than ", L, " beers a day! I am very sorry about that!",M);.send(owner, tell, msg(M)). Robot agent At(robot, fridge) Open(fridge) Get(beer) Hand_in(beer) close(fridge) Move_towards(Place) Achieve: order(beer, N) tell: too_much(beer) At(robot, owner)

9 Robot walks to a place until it perceives either at(robot, fridge) or at(robot, owner) -!has(_,_) : true <-.current_intention(I);.print("Failed to achieve goal '!has(_,_)'. Current intention is: ",I). +!at(robot,P) : at(robot,P) <- true. +!at(robot,P) : not at(robot,P) <- move_towards(P); !at(robot,P). // when the supermarket makes a delivery, try the 'has' goal again +delivered(beer,_Qtd,_OrderId)[source(Supermarket)] : true <- +available(beer, fridge);.print("Beer has just been delivered"); !has(owner, beer). External action Goal deletion Walk until … Main the goal At(robot, Place)

10 Robot agent (con’t) Perceive the beer stock and Belief updating // when the fridge is opened, the beer stock is perceived and thus the available belief is updated +stock(beer, 0) : available(beer, fridge) <- -available(beer, fridge). +stock(beer, N) : N > 0 & not available(beer, fridge) <- -+available(beer, fridge). +?time(T) : true <- time.check(T). Important topic!

11 CNP Protocol // Additions from CNP protocol // start the CNP +!startCNP(Id, Task) <-.print("Waiting participants...");.wait(2000); // wait participants introduction +cnp_state(Id, propose); // remember the state of the CNP.findall(Name, introduction(participant, Name), LP);.print("Sending CFP to ", LP);.send(LP, tell, cfp(Id, Task)); // the deadline of the CNP is now + 4 seconds, so // the event +!contract(Id) is generated at that time.at("now +4 seconds", { +!contract(Id) }). Generate the event +!contract(Id) 4 seconds from now.

12 Robot agent // receive proposal // if all proposal have been received, don't wait for the deadline @r1 +propose(CNPId,_Offer) : cnp_state(CNPId, propose) & all_proposals_received(CNPId) <- !contract(CNPId). // receive refusals @r2 +refuse(CNPId) : cnp_state(CNPId,propose) & all_proposals_received(CNPId) <- !contract(CNPId).

13 Robot agent // this plan needs to be atomic so as not to accept // proposals or refusals while contracting @lc1[atomic] +!contract(CNPId) : cnp_state(CNPId, propose) <- -+cnp_state(CNPId, contract);.findall(offer(O, A), propose(CNPId, O)[source(A)],L);.print("Offers are ", L); L \== []; // constraint the plan execution to at least one offer.min(L, offer(WOf, WAg)); // sort offers, the first is the best.print("Winner is ",WAg," with ", WOf); !announce_result(CNPId, L, WAg); -+cnp_state(CNPId, finished).

14 // nothing to do, the current phase is not 'propose' @lc2 +!contract(_). -!contract(CNPId) <-.print("CNP ", CNPId, " has failed!"). +!announce_result(_, [], _). // announce to the winner +!announce_result(CNPId,[offer(_,WAg)|T], WAg) <-.send(WAg,tell,accept_proposal(CNPId)); !announce_result(CNPId, T, WAg);.print("Order the beer with the winner"); !order_beer(WAg). // announce to others +!announce_result(CNPId,[offer(_, LAg)|T], WAg) <-.send(LAg, tell, r eject_proposal(CNPId)); !announce_result(CNPId, T, WAg).

15 +!order_beer(WAg) <-.send(WAg, achieve, order(beer,5));.print("Placing Order with ", WAg, " now!"); !at(robot,fridge). // go to fridge and wait there.

16 Owner Agent // The owner agent simply gets a beer, drinks a beer and randomly communicates with the robot agent to get the time. /* Initial goals */ !get(beer). // initial goal: get a beer !check_bored. // initial goal: verify whether I am getting bored +!get(beer): true <-.send(robot, achieve, has(owner, beer)). +has(owner, beer) : true <- !drink(beer). -has(owner, beer) : true <- !get(beer) robot owner Achieve: has(owner, beer) sip(beer) Has(owner, beer) tell: toomuch(beer)

17 Owner Agent // while I have beer, sip +!drink(beer) : has(owner, beer) <- sip(beer); !drink(beer). +!drink(beer) : not has(owner, beer) <- true. +!check_bored : true <-.random(X);.wait(X*5000+2000); // i get bored at random times.send(robot, askOne, time(_), R); // when bored, I ask the robot about the time.print(R); !!check_bored. +msg(M)[source(Ag)] : true <-.print("Message from ",Ag,": ",M); -msg(M).

18 Owner agent (con’t) // while I have beer, sip +!drink(beer) : has(owner, beer) <- sip(beer); !drink(beer). +!drink(beer) : not has(owner, beer) <- true. +!check_bored : true <-.random(X);.wait(X*5000+2000); // i get bored at random times.send(robot, askOne, time(_), R); // when bored, I ask the robot about the time.print(R); !!check_bored. +msg(M)[source(Ag)] : true <-.print("Message from ",Ag,": ",M); -msg(M).

19 Supermarket Agent The supermarket agent starts with an initial belief of a random price for its service offered to the robot agent. Once the robot agent initiates the CNP auction each supermarket agent sends its price to the robot. Depending on the price of the service sent to the robot, the robot agent either sends back a message indicating whether the supermarket agent won or loss the auction. The supermarket agent responds by printing a message of whether it won or loss. If it won it waits for a message from the robot agent asking for a delivery of 5 more beers.

20 Supermarket Agent last_order_id(1). // initial belief // gets the price for the product, a random value between 100 and 110. price(_Service, X) :-.random(R) & X = (10*R)+100. plays(initiator, robot). /* Plans */ // send a message to the initiator introducing myself as a participant +plays(initiator, In) :.my_name(Me) <-.send(In, tell, introduction(participant, Me)). robot Supermarket 1 Deliver(beer, N) tell: delivered(beer, N, Ordered) Supermarket 2 Supermarket 3 cnp tell: introduction(participant, Me)

21 tell: propose(CNPId, Offer) Supermarket Agent // answer to Call For Proposal @c1 +cfp(CNPId,Task)[source(A)] : plays(initiator, A) & price(Task, Offer) <- +proposal(CNPId,Task,Offer); // remember my proposal.send(A, tell, propose(CNPId, Offer)). robot Supermarket 1 Deliver(beer, N) tell: delivered(beer, N, Ordered) Supermarket 2 Supermarket 3 cnp tell: introduction(participant, Me)

22 Supermarket agent @r1 +accept_proposal(CNPId) : proposal(CNPId, Task, Offer) <-.print("My proposal '",Offer,"' won CNP ", CNPId, " for ",Task,"!"). // do the task and report to initiator @r2 +reject_proposal(CNPId) <-.print("I lost CNP ", CNPId, "."); -proposal(CNPId, _, _). // clear memory // plan to achieve the goal "order" for agent Ag +!order(Product, Qtd)[source(Ag)] : true <- ?last_order_id(N); OrderId = N + 1; -+last_order_id(OrderId); deliver(Product, Qtd);.send(Ag, tell, delivered(Product, Qtd, OrderId)). tell: propose(CNPId, Offer) robot Supermarket 1 tell: delivered(beer, N, Ordered) Supermarket 2 Supermarket 3 cnp tell: introduction(participant, Me)

23 Testing results

24 Screenshot 2

25 Jason eclipse plugin The run instructions are very simple for this simulation. Eclipse was used with the Jason plugin which can be found at the following url: http://jasonplugin.wikidot.com/guia-do-usuario. The plugin is dropped into the eclipse plugin directory. http://jasonplugin.wikidot.com/guia-do-usuario After opening the project in eclipse the user simply needs to right click on the DomesticRobot.mas2j and select run in Jason. This will initialize all the agents and display the GUI with the console which prints out the statements programmed into the agents.


Download ppt "Professor Fuhua Lin. Scenario: Domestic Robot Bartender The domestic robot is ordered by its owner to get him beer from the refrigerator. However, the."

Similar presentations


Ads by Google