⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oaa.pl

📁 SRI international 发布的OAA框架软件
💻 PL
📖 第 1 页 / 共 5 页
字号:
%*****************************************************************************
%   File    : oaa.pl
%   Primary Authors  : Adam Cheyer, David Martin
%   Purpose : Prolog version of library for the Open Agent Architecture
%   Updated : 12/98
% 
%   ------------------------------------------------------------------------
%   The contents of this file are subject to the OAA  Community Research 
%   License Version 2.0 (the "License"); you may not use this file except 
%   in compliance with the License. You may obtain a copy of the License 
%   at http://www.ai.sri.com/~oaa/.  Software distributed under the License 
%   is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either 
%   express or implied. See the License for the specific language governing 
%   rights and limitations under the License.  Portions of the software are 
%   Copyright (c) SRI International, 1999.  All rights reserved.  
%   "OAA" is a registered trademark, and "Open Agent Architecture" is a 
%   trademark, of SRI International, a California nonprofit public benefit 
%   corporation.
%   ------------------------------------------------------------------------
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Note: internal functions use the naming convention oaa_function_name(), 
%     while public predicates use oaa_PublicPredicate().
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Version 2.0 (change oaa_version assertion)
%   - corrects FromAgt in do_events by changing event format to include this
%     info.
%   - messages are only sent to READY agents.  For previous versions, an
%     agent may be either READY or just OPEN.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Version 2.2 (change oaa_version assertion)
%   - triggers have 2 new arguments, OpMask and Template, and
%     more general semantics.  Backwards compatibility is provided.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Version 3.0 (change oaa_version assertion)
%   - primitives changed to start with oaa_ (and _icl) prefixes
%   - Major restructuring and cleanup, including many new capabilities,
%     for first public release (a.k.a. "OAA 2")
%*****************************************************************************



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Documentation: Event communication patterns for OAA primitives
%
%  Asynchronous communication events between client agents and a facilitator 
%  are at the heart of the agent library and facilitator implementations.
%  Here we describe the communication message activity for the OAA 
%  primitives defined in an OAA library.
%
%-----------------------------------------------------------------------------
% oaa_Register(ConnectionId, AgentName, Solvables, Params)
%
%    Handshaking between Client and Facilitator at startup time
%
%    client->Fac:	ev_connect(AgentInfoList)
%    client<-Fac:	ev_connected(FacInfoList)
%-----------------------------------------------------------------------------
% oaa_Ready(ShouldPrint)
%
%    Notification to facilitator that client is ready to participate
%
%    client->Fac:	ev_ready(SymbolicName)
%-----------------------------------------------------------------------------
% oaa_Declare(Solvs,CPerms,CParams,Params,-Declared),
%    oaa_Undeclare(Solvs,Params,-Undeclared),
%    oaa_Redeclare(+Solvable,+NewSolvable,+Params),
%
%    Registration of client solvables and data declaractions with Facilitator
%
%    client->Fac:	ev_post_declare(Mode,Solvs,P)  Mode = add,remove,replace
%
%    if client agent is a NODE facilitator
%	node->parent:		ev_register_solvables(Mode,Solvs,MyName,P)
%   
%    client<-Fac:	ev_reply_declared(Mode, Solvs, P, Declared)
%-----------------------------------------------------------------------------
%  oaa_Solve(Goal, Params)
%
%    Delegation of simple or compound goals across agent community
%
%    client->Fac: 	ev_solve(GoalId, G, P)
%
%       Fac->client:	ev_solve(Id, G, P) 
%	Fac<-client:	ev_solved(Id, Requestees, Solvers, G, P, Solutions)
%    Also, if propagation is requested:
%       Fac->OtherFac:	ev_solve(Id, G, P)
%	Fac<-OtherFac:	ev_solved(Id, Requestees, Solvers, G, P, Solutions) 
%
%    client<-Fac:	ev_solved(Id, Requestees, Solvers, G, P, Solutions)
%
%-----------------------------------------------------------------------------
% oaa_AddData(Data,Params), oaa_RemoveData(D,P), oaa_ReplaceData(D,P)
% oaa_LoadData(D,Params), oaa_SaveData(D,Params)
%
%    Delegation/manipulation of data across agent community
%
%    client->Fac:	ev_update_data(GoalId, Mode, Data, Params)  
%                               Mode = add,remove,replace,load,save
%       Fac->client:	ev_update_data(GoalId, Mode, Data, Params), 
%	Fac<-client:	ev_data_updated(GoalId, Mode, Data, Params, 
%                                       Requestees, Updaters)
%    client<-Fac:	ev_data_updated(GoalId, Mode, Data, Params, 
%                                       Requestees, Updaters)
%
%-----------------------------------------------------------------------------
% oaa_AddTrigger(Type, Condition, Action, Params), oaa_RemoveTrigger(T,C,A,P)
%
%    Installation/removal of triggers delegated across agent community
%
%    client->Fac:	ev_update_trigger(GoalId,Mode,T,C,A,P)  
%                               Mode = add,remove
%       Fac->client:	ev_update_trigger(Id, Mode,T,C,A,P), 
%	Fac<-client:	ev_trigger_updated(Id,Mode,T,C,A,P,Requestees,Updaters)
%    client<-Fac:	ev_trigger_updated(Id,Mode,T,C,A,P,Requestees,Updaters)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Publicly defined primitives exported by the OAA agent library
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

:- module(oaa,
	  [icl_GetParamValue/2,
	   icl_GetNestedParamValue/3,
	   icl_GetPermValue/2,
	   icl_BasicGoal/1,
	   icl_GoalComponents/4,
	   icl_ConsistentParams/2,
	   icl_BuiltIn/1,
	   icl_ConvertSolvables/2,
	   oaa_LibraryVersion/1,
	   oaa_Connect/4,
	   oaa_SetupCommunication/1,
	   oaa_Register/4,
	   oaa_RegisterCallback/2,
	   oaa_ResolveVariables/1,
	   oaa_Ready/1,
	   oaa_MainLoop/1,
	   oaa_SetTimeout/1,
	   oaa_GetEvent/4,
	   oaa_ProcessEvent/2,
	   oaa_Interpret/2,
	   oaa_DelaySolution/1,
	   oaa_ReturnDelayedSolutions/2,
	   oaa_AddDelayedContextParams/3,
	   oaa_PostEvent/2,
	   oaa_CanSolve/2,
	   oaa_Version/3,
	   oaa_Ping/3,
	   oaa_Declare/5,
	   oaa_Undeclare/3,
	   oaa_Redeclare/3,
	   oaa_AddData/2,
	   oaa_RemoveData/2,
	   oaa_ReplaceData/3,
	   oaa_LoadData/2,
           oaa_SaveData/2,
	   oaa_CheckTriggers/3,
	   oaa_AddTrigger/4,
	   oaa_RemoveTrigger/4,
	   oaa_Solve/1,
	   oaa_Solve/2,
	   oaa_InCache/2,
	   oaa_AddToCache/2,
	   oaa_ClearCache/0,
	   oaa_TraceMsg/2,
	   oaa_ComTraceMsg/3,
	   oaa_Inform/3,
	   % oaa_Id/1,
	   oaa_Address/3,
	   oaa_PrimaryAddress/1,
	   oaa_Name/1
	  ]).

%*****************************************************************************
%* RCS Header and internal version
%*****************************************************************************

% rcs version number
rcsid('$Header: /home/zuma1/OAA/CVSRepository/oaa2/src/oaalib/prolog/oaa.pl,v 1.58 2005/04/02 03:58:30 martin Exp $').

%# Comments starting "%#" indicate changes made by David Carter and Ralph 
%# Becket, for Sicstus adaptation of OAA1, and moved to
%# to OAA2 by David Martin.

:- op(599,yfx,::).
:- op(200, xfy, [ \ ]).
:- op(600, xfy, '==>').

%*****************************************************************************
% Include files
%*****************************************************************************

%# We take the existence of a source_info flag to be a safe
%# if-and-only if test that we're using Sicstus Prolog.

current_prolog(Prolog) :-
  (prolog_flag(source_info, _) -> Prolog=sicstus;
   Prolog=quintus).

%# The set of library modules to be loaded depends on the Prolog.

:- ( prolog_flag(source_info, _) -> 
  % sicstus
  use_module(library(lists)),
  use_module(library(charsio)),
  use_module(library(terms)),
  use_module(library(sockets)),
  use_module(library(system)),
  use_module(spcompat) % extra code for compatibility under Sicstus.
|
% quintus
%  AC: removed tcp library because defined below.  On PCs, this
%  creates a conflict to load two different versions of the same library.
%  use_module(library(tcp)),
  use_module(library(basics)),
  use_module(library(readsent)),
  use_module(library(lists)),
  use_module(library(sets)),
  use_module(library(strings)),
  use_module(library(files)),
  use_module(library(environ)),  % read environment vars
  use_module(library(ctr)),
  use_module(library(charsio)),  % for sprintf and with_output_to_chars
  use_module(library(ask)),      % for ask_oneof
  use_module(library(samsort)),  % for samsort(Ordered,Raw,Sort)
  use_module(library(date))      % for now(Time)
).


% Hack: On UNIX load regular tcp library
% On PC, we have modified the tcp library to add one function
% so we load the local version, not the one in the library directory.
:- ( prolog_flag(source_info, _) -> 
     % Sicstus; tcp functions are in spcompat.pl
     true
   | prolog_flag(host_type, ix86) ->
     % Quintus / pc: local tcp
     use_module(tcp, [tcp_now/1, tcp_time_plus/3])
   | otherwise -> 
     % Quintus / unix: library tcp
     use_module(library(tcp), [tcp_now/1, tcp_time_plus/3])
   ).


%*****************************************************************************
% IMPORTANT: COM module.  We don't want to hard code the name of the
% file that contains module 'com'.  So, when this file is loaded,
% we first check to see if module 'com' is already present, then
% we check to see if the file containing 'com' has been specified
% on the command line, and if neither of those works, we load the
% default file (./com_tcp).
% 
% In the case where the module has already been
% loaded, the following seems like the right thing to do:
%     :- use_module(com, _File, all).
% BUT when compiling, this approach results in "undefined" errors from
% qcon.  Thus, for now, in oaa.pl, we are explicitly using com: with all
% calls to the com module.
%*****************************************************************************

:- ( current_predicate(_, com:_) ->
       use_module(com, _File, all)
   | unix(argv(ListOfArgs)), append(_, ['-com', File | _], ListOfArgs) ->
       use_module(File, all)
   | otherwise ->
       use_module(com_tcp, all)
   ).
      

%*****************************************************************************
% Global variables
%*****************************************************************************
:- dynamic 	
		oaa_already_loaded/1,   % record if file already loaded
                oaa_solvables/1,        % list of agent capabilities
                oaa_trigger/5,          % a built-in solvable
		oaa_trace/1, 		% trace mode: on or off
		oaa_com_trace/1,	% com_trace mode: on or off
		oaa_debug/1, 		% debug mode: on or off
		oaa_cache/2,		% cached solutions
		oaa_event_buffer/1,	% buffer of waiting events
		oaa_waiting_for/2,	% used for recursive blocking solve
		oaa_waiting_event/1,    %    problem...
		oaa_timeout/1,		% tcp timeout value (use oaa_SetTimeout)
		oaa_delay_table/5,	% table of delayed solutions
		oaa_delay/2,		% the current goal is delayed
		oaa_data_ref/3,         % bookkeeping for 'data' solvables
		oaa_current_contexts/2, % Solve parameters to be propagated
		oaa_doevent_priority/1, % Priority for current do_event call
		oaa_callback/2,         % Record of app-specific callbacks
		oaa_save_files/1,       % Record of all files used in current oaa_SaveData
		oaa_current_output/1,   % Record of the output stream/file in use.
		oaa_should_close_file/0, % remembers if we need to close last save file
    % These may appear in setup.pl:
                oaa_host/1,             % for root, my host; otherwise, 
		                        % host of my parent
                oaa_port/1,             % ... similarly ...
                valid_passwords/1.        % list of valid passwords



% Version numbers used to be floats.  After 3.2, we changed format AND
% brought the number in sync with the external version number.  So we
% went from '3.2' to [2,3]. The corresponding external versions were
% 2.2.1 and then 2.3.0.
oaa_LibraryVersion([2,3]).

     % solvables shared by all agents
     % Note: all built-in DATA solvables must be declared dynamic to avoid
     % QP warnings and exceptions.
oaa_built_in_solvables([
  % TBD: If we do away with TriggerId, we could use param
  % unique_values(true).
  solvable(oaa_trigger(_TriggerId, _Type, _Condition, _Action, _Params), 
                       [type(data)], [write(true)])
]).

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -