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

📄 liboaa.java

📁 SRI international 发布的OAA框架软件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        results[1]=fullGoal;
        results[2]= new IclList();
      }
    }
    if (results[0]!=null)
      return results;
    return null;
  }

  /**
   * Permissions and parameter lists
   * <p>
   * 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).
   * <p>
   * All permissions and many parameters have default values.
   * <p>
   * 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'.
   * <p>
   * 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'.
   * <p>
   *
   */

  /**
   * Standardizes a permissions list, removing defaults if requested
   * <p>
   *    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.
   * <p>
   * @param perms    A list containing permission terms.
   * @param keepDefaults  True if defaults values are kept.
   * @return   null if fail.
   * <p>
   */
  private IclTerm icl_standardize_perms(IclTerm perms, boolean keepDefaults) {
    IclList result = new IclList();
    if (perms.isList()) {
      IclTerm currentTerm = null; // Useless, for debug purpose only
      IclTerm standard = null;

      for(ListIterator e = perms.listIterator(); e.hasNext();) {
        currentTerm = (IclTerm)(e.next());
        standard = icl_perm_standard_form(currentTerm);

        // There is no default value for this param, so it is added
        if (icl_perm_default(standard)==null) {
          result.add(standard);
        } else
          // There is a default value for this param and keepDefaults is true, so it is added
          if (keepDefaults) {
            result.add(standard);
          }

      }
    }
    return result;
  }

  /**
   * returns a copy of perm in standard permission form
   * <p>
   * remarks: call --> call(true)
   * <p>
   */
  private IclTerm icl_perm_standard_form(IclTerm perm) {
    IclTerm result = perm;
    if (perm.isStr()) {
      result = new IclStruct(((IclStr)perm).toUnquotedString(), new IclStr("true"));
    }
    return result;
  }

  /**
   * returns true if perm unifies with a default permission
   * <p>
   * @return null if unification fails, the unified term otherwise.
   * <p>
   */
  private IclTerm icl_perm_default(IclTerm perm) {
    IclTerm result = null;
    if (perm.isStruct() && (perm.size() == 1))
      result = IclUtils.termParamValue(ToFunctor.getInstance().from(perm),
				       perm.getTerm(0),
				       perm_default_list) ;
    return result;
  }

  /**
   * Standardizes a params list, removing defaults if requested
   * <p>
   *    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.
   * <p>
   * @param  params      A list containing parameter terms.
   * @param  keepDefaults   True if defaults values are kept.
   * @return null if fails.
   * <p>
   */
  private IclTerm icl_standardize_params(IclTerm params, boolean keepDefaults) {
    IclList result = new IclList();
    if (params != null && params.isList()) {
      IclTerm currentTerm = null; // Useless, for debug purpose only
      IclTerm currentTermInList = null; // Useless, for debug purpose only
      IclList standard = null; // icl_param_standard_form returns an IclList

      // One more enumeration because a param can be a list.
      // i.e [parallel_ok, solution_limit]
      for(ListIterator e = params.listIterator(); e.hasNext();) {
        currentTerm = (IclTerm)(e.next());
        standard = icl_param_standard_form(currentTerm);
	for(ListIterator e2 = standard.toArrayList().listIterator(); e2.hasNext();) {
          currentTermInList = (IclTerm)(e2.next());

          // There is no default value for this param, so it is added
          if (icl_param_default(currentTermInList)==null) {
            result.add(currentTermInList);
          } else
            // There is a default value for this param and keepDefaults is true, so it is added
            if (keepDefaults) {
              result.add(currentTermInList);
            }
        }
      }
    }
    return result;
  }

  /**
   * Returns a copy of parameter in standard parameter form
   * <p>
   * @param    param  the imput parameter
   * @return  the params list in standard form
   */
  private IclList icl_param_standard_form(IclTerm param) {
    boolean isStruct = param.isStruct();
    int arity = param.size();
    IclList result = new IclList();

    if (isStruct && (arity == 1) &&
	(ToFunctor.getInstance().from(param).equals("reply")) &&
	((param.getTerm(0)).toString().equals("false")))
      result.add (new IclStruct("reply", new IclStr("none")));
    else
      /* We replace "block" by "blocking" so Sixuts prolog does not get confused
	 because "block" is part of its keywords.
      */
      if (isStruct && (arity == 1) && (ToFunctor.getInstance().from(param).equals("block")))
	result.add(new IclStruct("blocking", param.getTerm(0)));
      else
	if (isStruct && (arity == 1) && (ToFunctor.getInstance().from(param).equals("broadcast")) &&
	    ((param.getTerm(0)).toString().equals("false")))
	  result.add(new IclStruct("reply", new IclStr("true")));
	else
	  if ((arity == 0) && (param.toIdentifyingString().equals("broadcast")))
	    result.add(new IclStruct("reply", new IclStr("none")));
	  else
	    if (isStruct && (arity == 1) && (ToFunctor.getInstance().from(param).equals("address"))) {
	      IclTerm newAddr = icl_standardize_address(param.getTerm(0));
	      result.add(new IclStruct("address", newAddr));
	    }
	    else
	      if (isStruct && (arity == 1) && (ToFunctor.getInstance().from(param).equals("strategy")) &&
		  (param.getTerm(0).toString().equals("query")))
		result.add(new IclStruct("parallel_ok", new IclStr("true")));
	      else
		if (isStruct && (arity == 1) && (ToFunctor.getInstance().from(param).equals("strategy")) &&
		    (param.getTerm(0).toString().equals("action"))) {
		  result.add(new IclStruct("parallel_ok",
					   new IclStr("false")));
		  result.add(new IclStruct("solution_limit",
					   new IclInt(1)));
		}
		else
		  if (isStruct && (arity == 1) && (ToFunctor.getInstance().from(param).equals("strategy")) &&
		      (param.getTerm(0).toString().equals("inform"))) {
		    result.add(new IclStruct("parallel_ok",
					     new IclStr("true")));
		    result.add(new IclStruct("reply", new IclStr("none")));
		  }
		  else
		    if (param.isStr())
		      result.add(new IclStruct(((IclStr)param).toUnquotedString(),
					       new IclStr("true")));
		    else
		      result.add(param);
    return result;
  }

  /**
   * returns true if param unifies with a default parameter
   * <p>
   * @return null if unification fails, the unified term otherwise.
   */
  private IclTerm icl_param_default(IclTerm param) {
    IclTerm result = null;
    if (param.isStruct() && (param.size() == 1))
      result = IclUtils.termParamValue(ToFunctor.getInstance().from(param), param.getTerm(0),
				       param_default_list) ;
    return result;
  }

  /**
   * Extracts or tests the value of a parameter list, using defaults.
   * <p>
   * To simply extractFor a parameter that has no default, you can use
   *      iclGetParamValue  OR memberchk.
   * <p>
   * Param must be a partially or fully-instantiated structure
   *    (atom form will not work)
   * <p>
   * <h3>Examples</h3>
   * <pre>
   * 1)
   *    param : priority(P)
   *    paramList : [priority(5), param(2)]
   *
   *    return : priority(5)
   *
   * 2)
   *    param : priority(P)
   *    paramList : [level(5), param(2)]
   *
   *    return : priority(5) // Default value since not in list
   * </pre>
   * <p>
   */
  public final IclTerm iclGetParamValue(IclTerm param, IclTerm paramList) {
    IclTerm result = null;
    if (param.isStruct() && (param.size() == 1) &&
	paramList.isList()) {
      IclTerm p;
      if ((p=IclUtils.termParamValue(ToFunctor.getInstance().from(param),null, paramList))!=null) {
        result = Unifier.getInstance().unify(param, p);
      } else
        if ((p=IclUtils.termParamValue(ToFunctor.getInstance().from(param),
				      null, param_default_list))!=null) {
          result = Unifier.getInstance().unify(param, p);
        }
    }
    return result;
  }

  /**
   * 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.
   */

  public final IclTerm iclGetNestedParamValue(IclTerm subParam, IclTerm param, IclTerm paramList) {
    IclTerm result = null;
    IclTerm tempResult = null;
    tempResult = iclGetParamValue(param, paramList);
    if (tempResult != null)
      result = iclGetParamValue(subParam, tempResult);
    return result;
  }


  /**
   * Searches for elt in a list .
   * <p>
   * @param    elt    A term to search for
   * @param    aList  A list to search in
   *
   * @return  TRUE if elt is contained in aList
   *
   */
  public final static boolean memberchk(IclTerm elt, IclTerm aList) {
    IclTerm result = null;

    if ((elt == null) || (aList == null))
      return false;

    for (int k = 1; ((result == null) && (k <= aList.size())); k++) {
      result = Unifier.getInstance().unify(elt, aList.getTerm(k - 1));
    }

    return (result != null);
  }

  /**
   * To get or test the value of a parameter that has a default,
   * it is best to call iclGetPermValue.
   * <p>
   * For a parameter that has no default, you can use
   *    iclGetPermValue OR memberchk.
   * <p>
   * Perm must be a partially- or fully-instantiated structure
   *   (atom form will not work)
   * <p>
   * @param    perm      A permission type
   * @param    permList  A permission list to search in
   * @return      true if passes the permission check
   */
  public final IclTerm iclGetPermValue(IclTerm perm, IclTerm permList) {
    IclTerm result = null;
    if (perm.isStruct() && (perm.size() == 1) &&
	permList.isList()) {
      IclTerm p;
      if ((p=IclUtils.termParamValue(ToFunctor.getInstance().from(perm), null, permList))!=null) {
        result = Unifier.getInstance().unify(perm, p);
      } else
        if ((p=IclUtils.termParamValue(ToFunctor.getInstance().from(perm), null, perm_default_list))!=null) {
          result = Unifier.getInstance().unify(perm, p);
        }
    }
    return result;
  }

  /* THIS FUNCTION DOES NOT NEED TO BE IMPLEMENTED IN JAVA UNLESS WE
     NEED TO PORT THE FACILITATOR AGENT TO JAVA.
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     % name:    iclConsistentParams(+Test, +ParamList)
     % purpose: Often used in solvable declara

⌨️ 快捷键说明

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