/* This software is copyright (c) 1997-2001 Giuseppe De Giacomo, Yves Lesperance, Hector Levesque, Ray Reiter, University of Toronto, York University, and Communications and Information Technology Ontario. All right are reserved. Use of this software is permitted for non-commercial research purposes, and it may be copied only for that use. All copies must include this copyright message. You may not redistribute it outside your institution without permission. If you are interested in a license for commercial use, contact Yves Lesperance at lesperan@cs.yorku.ca. This software and any documentation and/or information supplied with it is distributed on an as is basis. The copyright holders make no warranties, expressed or implied, including but not limited to implied warranties of merchantability and fitness for a particular purpose, regarding the documentation, functions or performance of such software, documentation and/or information. */ /*<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> OAA-INDIGOLOG INTERFACE Version 1.1 Alexei Lapouchnian, March 2001 <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>*/ /*GENERAL*******************************************************************/ :- multifile prim_action/1, prim_fluent/1, causes_val/4, poss/2, proc/2, exog_action/1. %OAA needs the following libraries included :- use_module(com_tcp, all). :- use_module(oaa, all). /*OAA AGENT INITIALIZATION **************************************************/ /* 1) Assumes that the main procedure is called 'control'. 2) The user has to provide the list of solvables through initial_solvables (e.g. initial_solvables([solvable(update_status(New_Value), [], [])]). 3) The user has to provide the name of the agent through agent_name predicate. 4) In order to block checking for incoming OAA events, the user can execute block_get_event primitive action. To unblock the checking, execute unblock_get_event action. */ % The entry point for agent (required for creation of executable). runtime_entry(start) :- start. % The initialization procedure for the IndiGolog-OAA interface. start :- % Connect to facilitator: com_Connect(parent, [], CInfo), format('Connected to ~p.~n',[CInfo]), % Register default callback for incoming events (messages): oaa_RegisterCallback(app_do_event, user:oaa_AppDoEvent), % Register user-defined solvables initial_solvables(S), % Provide agent name agent_name(N), % Register with facilitator oaa_Register(parent, N, S, []), %The agent is ready to accept OAA messages, but will not enter OAA main loop oaa_Ready(true), % Make sure oaa_get_event doesn't wait forever for incoming events oaa_SetTimeout(0.001), %Call the control procedure indigolog(control). % Specify callback procedures for solvables % General callback oaa_AppDoEvent(Goal, GoalParams) :- callback(Goal, GoalParams). /*OAA EVENT QUEUE MANAGEMENT************************************************/ %Declare global variable to hold the event queue :- dynamic oaa_event_queue/1. %Set the initial value oaa_event_queue([]). %Exo action - get_event exog_action(get_event). exog_occurs(get_event,E,H) :- %Get the OAA events oaa_loop, %If the queue is not empty, process it oaa_event_queue(Q), \+ Q = [], %Extract events if the queue is not empty extract_events(E,H,Q). %have a loop that will extract events until 'timeout' occurs %The events are appended to oaa_event_queue oaa_loop :- oaa_GetEvent(0, [], Event, Params), (Event==timeout -> true | (oaa_ProcessEvent(Event, Params), oaa_GetEvent(0, [], New_Event, New_Params)) ). %The user can block incoming OAA event checking prim_fluent(blocked_get_event). %Initially unblock the check initially(blocked_get_event, false). %By executing this action the user can block incoming OAA event check prim_action(block_get_event). poss(block_get_event, neg(blocked_get_event)). causes_val(block_get_event, blocked_get_event, true, true). %This action unblocks the check prim_action(unblock_get_event). poss(unblock_get_event, blocked_get_event). causes_val(unblock_get_event, blocked_get_event, false, true). %get_event is executed if it is not blocked poss(get_event, neg(blocked_get_event)). /*Processes incoming OAA events - adds them to IndiGolog program history*/ extract_events(E,H,[]) :- retract(oaa_event_queue(_)), assert(oaa_event_queue([])), indigo(E,H). %ground case extract_events(E,H,[Event|Rest]) :- trans(E,H,E1,H1), !, subst_sim(Event,Rest,E,H,E1,H1). extract_events(E,H,[Event|Rest]) :- !, extract_events(E,[Event|H],Rest). subst_sim(Event,Rest,E,H,E1,[sim(Event)|H]) :- !, extract_events(E1,[Event|H],Rest). subst_sim(Event,Rest,E,H,E1,H1) :- !, extract_events(E,[Event|H],Rest). %General callback - will be called for all user-defined solvables callback(Goal, Params) :- %Append new event to the queue retract(oaa_event_queue(Queue)), append(Queue,[Goal], New_Queue), asserta(oaa_event_queue(New_Queue)). /*END - OAA EVENT QUEUE MANAGEMENT ******************************************/ /*<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> END OF OAA-INDIGOLOG INTERFACE <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>*/