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

📄 oaa.pl

📁 SRI international 发布的OAA框架软件
💻 PL
📖 第 1 页 / 共 5 页
字号:
    \+ var(G), \+ var(P),
    !,
    Address = unknown, Goal = G, Params = P.
icl_GoalComponents(G, Address, Goal, Params) :-
    \+ var(G),
    !,
    Address = unknown, Goal = G, Params = [].
icl_GoalComponents(Goal, unknown, Goal, []) :-
    !.
icl_GoalComponents(Address:Goal, Address, Goal, []) :-
    !.
icl_GoalComponents(Goal::Params, unknown, Goal, Params) :-
    !.
icl_GoalComponents(Address:Goal::Params, Address, Goal, Params) :-
    !.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Permissions and parameter lists
%
% These procedures are used in processing solvables permissions, and
% parameter lists of all kinds (including those used with solvables,
% those contained in events, and those used in calls to various
% library procedures).
% 
% All permissions and many parameters have default values.
% 
% Permissions and parameters lists have a standard form, as defined by
% the predicates below.  To save bandwidth and promote readability, a
% "perm" or "param" list in standard form OMITS default values.  For
% easier processing (e.g., comparing/merging param lists), boolean
% params in standard form always include a single argument 'true' or
% 'false'.
% 
% In definitions of solvables and calls to documented library
% procedures, it's OK to include default params in a Params list, if
% desired.  For boolean params, when the intended value is 'true', it's
% OK just to specify the functor, for example, instead of
% cache(true), it's OK just to include 'cache'.
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% icl_standardize_perms(+Perms, +KeepDefaults, -Standardized).

icl_standardize_perms([], _KeepDefaults, []).
icl_standardize_perms([Perm | Perms], KeepDefaults, [SPerm | SPerms]) :-
    icl_perm_standard_form(Perm, SPerm),
    ( KeepDefaults ; (\+ icl_perm_default(SPerm)) ),
    !,
    icl_standardize_perms(Perms, KeepDefaults, SPerms).
icl_standardize_perms([_Perm | Perms], KeepDefaults, SPerms) :-
    icl_standardize_perms(Perms, KeepDefaults, SPerms).

icl_perm_standard_form(Perm, SPerm) :-
    atom(Perm),
    !,
    SPerm =.. [Perm, true].
icl_perm_standard_form(Perm, Perm).

icl_perm_default(call(true)).
icl_perm_default(read(true)).
icl_perm_default(write(true)).

% icl_standardize_params(+Params, +KeepDefaults, -Standardized).
% 
% Normally there's no need to keep the default value of a param,
% but there are exceptional situations.  If KeepDefaults is true,
% default values are kept.

icl_standardize_params([], _, []).
icl_standardize_params([Param | Rest], KeepDefaults, AllStandardized) :-
    icl_param_standard_form(Param, FullStandardized),
    ( KeepDefaults ->
	Standardized = FullStandardized
    | otherwise ->
	icl_remove_default_params(FullStandardized, Standardized)
    ),
    icl_standardize_params(Rest, KeepDefaults, RestStandardized),
    append(Standardized, RestStandardized, AllStandardized).

% icl_param_standard_form(+Param, -StandardParams).
%
% Maps from an element of a parameter list to a list of elements
% in standardized form.  The parameter list element can be from
% any context (from a call to Solve, AddTrigger, AddData, etc.).

    % block/1 is needed for backwards compatibility.  We changed to
    % blocking/1 because block is a sicstus keyword.
icl_param_standard_form(block(Value), [blocking(Value)]) :-
    !.
    % broadcast has been retained, as a synonym for reply(none):
icl_param_standard_form(reply(false), [reply(none)]) :-
    !.
    % broadcast has been retained, as a synonym for reply(none):
icl_param_standard_form(broadcast, [reply(none)]) :-
    !.
icl_param_standard_form(broadcast(true),  [reply(none)]) :-
    !.
icl_param_standard_form(broadcast(false),  [reply(true)]) :-
    !.
icl_param_standard_form(address(Addr),  [address(SAddr)]) :-
    !,
    icl_standardize_address(Addr, SAddr).
% Possible future use:
% icl_param_standard_form(executor_address(Addr),  [executor_address(SAddr)]) :-
%     !,
%     icl_standardize_address(Addr, SAddr).
    % direct_connect just means that self is to handle the execution
    % of the goal (instead of the facilitator):
icl_param_standard_form(direct_connect,  [direct_connect(true)]) :-
    !.
icl_param_standard_form(owner(Addr),  [owner(SAddr)]) :-
    !,
    icl_standardize_address(Addr, SAddrL),
    SAddrL = [SAddr].
icl_param_standard_form(strategy(query), [parallel_ok(true)]) :-
    !.
icl_param_standard_form(strategy(action),  
			[parallel_ok(false), solution_limit(1)]) :-
    !.
icl_param_standard_form(strategy(inform),  
			[parallel_ok(true), reply(none)]) :-
    !.
icl_param_standard_form(callback(Mod:Proc), [callback(Mod:Proc)]) :-
    !.
icl_param_standard_form(callback(Proc), [callback(user:Proc)]) :-
    !.
% The elements within propagate may currently be: up/1, down/1, up_limit/1,
% down_limit/1.
icl_param_standard_form(propagate(Element), [propagate([Element])]) :-
    \+ is_list(Element),
    !.
icl_param_standard_form(Param,  [SParam]) :-
    atom(Param),
    !,
    SParam =.. [Param, true].
icl_param_standard_form(Param, [Param]).

icl_param_default(from(unknown)).
icl_param_default(priority(5)).
icl_param_default(utility(5)).
icl_param_default(if_exists(append)).
icl_param_default(type(procedure)).
icl_param_default(private(false)).
icl_param_default(single_value(false)).
icl_param_default(unique_values(false)).
icl_param_default(synchronize(false)).
icl_param_default(rules_ok(true)).
icl_param_default(bookkeeping(true)).
icl_param_default(persistent(false)).
icl_param_default(at_beginning(false)).
icl_param_default(do_all(false)).
icl_param_default(reflexive(true)).
icl_param_default(parallel_ok(true)).
icl_param_default(reply(true)).
icl_param_default(blocking(true)).
icl_param_default(cache(false)).
icl_param_default(flush_events(false)).
icl_param_default(recurrence(when)).
icl_param_default(unique_name(false)).

% params for oaa_SaveData
icl_param_default(save_declares(true)).
icl_param_default(save_clauses(true)).
icl_param_default(save_triggers(true)).

% params for oaa_LoadData
icl_param_default(clear(true)).

% The value of propagate/1 is itself a parameter list.  By making this
% default an empty list, we indicate that each of ITS possible elements gets
% the default value.
icl_param_default(propagate([])).

% These are default values for parameters WITHIN the propagate/1 parameter,
% which is itself a parameter list:
icl_param_default(up(false)).
icl_param_default(down(false)).
% The default for these is no limit, indicated by a var:
icl_param_default(up_limit(_)).
icl_param_default(down_limit(_)).

icl_remove_default_params([], []).
icl_remove_default_params([Param | Rest], Removed) :-
    icl_param_default(Param),
    !,
    icl_remove_default_params(Rest, Removed).
icl_remove_default_params([Param | Rest], [Param | Removed]) :-
    icl_remove_default_params(Rest, Removed).

% icl_GetParamValue(+Param, +ParamList).
%
% Param must have a functor, but its argument(s) can be either ground
% or variables.  E.g., persistent(X).
%
% To get or test the value of a parameter that has a default, it is
% best to call icl_GetParamValue.  For a parameter that has no default,
% you can use icl_GetParamValue OR memberchk.

icl_GetParamValue(Param, ParamList) :-
    predicate_skeleton(Param, Skel),
    memberchk(Skel, ParamList),
    !,
    Skel = Param.
icl_GetParamValue(Param, _ParamList) :-
    predicate_skeleton(Param, Skel),
    icl_param_default(Skel),
    !,
    Skel = Param.

% icl_GetNestedParamValue(+SubParam, +Param, +ParamList).
%
% Use this when the value of a parameter is ITSELF a param list, as
% with the propagate parameter.  For example:
%
% Given param list Params = [propagate([up(true)])],
% Use icl_GetNestedParamValue(up(U), propagate, Params)
% to get U = true.

icl_GetNestedParamValue(SubParam, ParamName, ParamList) :-
    Param =.. [ParamName, SubList],
    icl_GetParamValue(Param, ParamList),
    icl_GetParamValue(SubParam, SubList).

% icl_GetPermValue(+Permission, +PermissionList).


icl_GetPermValue(Perm, PermList) :-
    predicate_skeleton(Perm, Skel),
    memberchk(Skel, PermList),
    !,
    Skel = Perm.
icl_GetPermValue(Perm, _PermList) :-
    predicate_skeleton(Perm, Skel),
    icl_perm_default(Skel),
    !,
    Skel = Perm.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% name:    icl_ConsistentParams(+Test, +ParamList)
% purpose: Often used in solvable declarations to filter on a certain
% 	   condition.
% definition: 
%          Test a param list: if one or more values are given in a parameter 
% 	   list for parameter ParamName, then ParamValue must be defined as
% 	   one of the values to succeed.  If ParamValue is NOT defined, then
%	   icl_ConsistentParams succeeds.
% example:
%    A natural language parser agent can only handle English definitions:
%
%        convert(nl, icl,Input,Params,Output) :- 
%        	icl_ConsistentParams(language(english),Params).
%
%    if "language(english)" is defined in parameter list of a solve request, 
%       the nl agent will receive the request.  
%    if "language(spanish)" is defined in the parameter list, the nl agent
%       WILL NOT receive the request.
%    if no language parameter is specified, the request WILL be sent
%    if "language(X)" is specified, the request WILL be sent to the nl agent
% remarks:
%    - Test may contain either a single predicate or a list of test predicates,
%      in which case icl_ConsistentParams will execute all consistency tests.
%    - Interesting note: icl_ConsistentParams() checks consistency as a 
%      relation between the two arguments, so it doesn't matter which argument
%      specifies the test list and which the parameters to test.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

icl_ConsistentParams(_TestList, []) :- !.
icl_ConsistentParams([], _ParamList) :- !.
icl_ConsistentParams([Test|RTest], [P1|RParams]) :- !,
   ParamList = [P1|RParams],
   predicate_skeleton(Test, TestWithVars),
   (memberchk(TestWithVars, ParamList) ->
      memberchk(Test, ParamList)
   | true),
   icl_ConsistentParams(RTest, ParamList).
% either Test or Params is NOT a list
icl_ConsistentParams(Test, Param) :-
	(Test = [_|_] ->
	   NewTest = Test
	|  NewTest = [Test]),
	(Param = [_|_] ->
	   NewParam = Param
	|  NewParam = [Param]),
	icl_ConsistentParams(NewTest, NewParam).



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Agent identity and addressing
%
% Every agent (including facilitators) has a symbolic name, a full address,
% and a local address (or "local ID"), FOR EACH OPEN CLIENT CONNECTION AND
% EACH OPEN SERVER CONNECTION.  
% A full address has the form:
%     addr(tcp(Host,Port))              for a server connection 
%                                         (if TCP is protocol)
%     addr(tcp(Host,Port), LocalID)     for a client connection.
%
% Even though it doesn't appear in the full address, a facilitator also
% has a local ID, for consistency -- but this isn't normally used by a client
% agent. The
% local ID of a client agent is assigned to it by its facilitator, which
% passes the client's full address to the client at connection time.
% 
% Full addresses are globally unique, and local addresses are unique with
% respect to a facilitator.  Symbolic names are NOT unique in any sense.
% 
% The local ID happens to be an integer, but developers should not rely
% on this.
%
% Since a facilitator must have exactly 1 (server) connection with connection
% id 'fac_listener', and a
% client (non-facilitator) must have exactly 1 (client) connection with
% connection ID 'parent' (although they may have other
% connections with other connection ids), we have the notion of a
% "primary address".  The primary address for a facilitator is the
% full address for its fac_listener connection, and for a client is the
% full address for its parent connection.
% 

⌨️ 快捷键说明

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