`
turingfellow
  • 浏览: 135090 次
  • 性别: Icon_minigender_1
  • 来自: 福建省莆田市
社区版块
存档分类
最新评论

booktrading / buyer

    博客分类:
  • jade
阅读更多

<!--
 <H3>The buyer agent that purchases books for its user.</H3>

 The buyer agent comes with a user interface in which the
 human user can enter its purchase book orders consisting of
 a title, start price, price limit and a deadline. The agent
 subsequently tries to buy the book and changes the price
 according to the deadline.
-->
<agent xmlns="http://jadex.sourceforge.net/jadex"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://jadex.sourceforge.net/jadex
                      http://jadex.sourceforge.net/jadex-0.96.xsd"
    name="Buyer" package="jadex.examples.booktrading.buyer">

 <imports>
  <import>jadex.examples.booktrading.common.*</import>
  <import>jadex.adapter.fipa.SFipa</import>
  <import>java.util.*</import>
  <import>jadex.runtime.impl.*</import>
  <import>jadex.planlib.*</import>
 </imports>

 <capabilities>
  <capability name="procap" file="jadex.planlib.Protocols"/>
  <capability name="dfcap" file="jadex.planlib.DF"/>
 </capabilities>

 <beliefs>
  <beliefset name="orders" class="Order">
   <facts evaluationmode="dynamic">
    select $g.getParameter("order").getValue()
    from IRGoal $g in $goalbase.getGoals("purchase_book")
   </facts>
  </beliefset>
  
  <belief name="time" class="long" updaterate="1000">
   <fact>System.currentTimeMillis()</fact>
  </belief>
  
  <belief name="initial_orders" class="Order[]" exported="true"/>
  
  <beliefset name="negotiation_reports" class="NegotiationReport"/>
  
  <belief name="gui" class="Gui"/>
 </beliefs>

 <goals>
  <!--  Initiate negotiation rounds every 10 secs. -->
  <achievegoal name="purchase_book" recur="true" recurdelay="10000">
   <parameter name="order" class="Order">
    <bindingoptions>$beliefbase.initial_orders</bindingoptions>
   </parameter>
   <unique/>
   <creationcondition>$beliefbase.initial_orders!=null</creationcondition>
   <targetcondition>Order.DONE.equals($goal.order.getState())</targetcondition>
   <failurecondition>$beliefbase.time > $goal.order.getDeadline().getTime()</failurecondition>
  </achievegoal>
  
  <achievegoalref name="df_search">
   <concrete ref="dfcap.df_search"/>
  </achievegoalref>
  
  <achievegoalref name="cnp_initiate">
   <concrete ref="procap.cnp_initiate"/>
  </achievegoalref>
  
  <querygoalref name="cnp_evaluate_proposals">
   <concrete ref="procap.cnp_evaluate_proposals"/>
  </querygoalref>
 </goals>

 <plans>
  <plan name="purchase_book_plan">
   <parameter name="order" class="Order">
    <goalmapping ref="purchase_book.order"/>
   </parameter>
   <body class="PurchaseBookPlan" />
   <!-- <body>new PurchaseBookPlan()</body> -->
   <trigger>
    <goal ref="purchase_book"/>
   </trigger>
  </plan>
  
  <plan name="evaluate_proposals_plan">
   <parameter name="cfp" class="Object">
    <goalmapping ref="cnp_evaluate_proposals.cfp"/>
   </parameter>
   <parameter name="cfp_info" class="Object" optional="true">
    <goalmapping ref="cnp_evaluate_proposals.cfp_info"/>
   </parameter>
   <parameterset name="proposals" class="Object">
    <goalmapping ref="cnp_evaluate_proposals.proposals"/>
   </parameterset>
   <parameterset name="history" class="NegotiationRecord" optional="true">
    <goalmapping ref="cnp_evaluate_proposals.history"/>
   </parameterset>
   <parameterset name="acceptables" class="Object" direction="out">
    <goalmapping ref="cnp_evaluate_proposals.acceptables"/>
   </parameterset>
   <body class="EvaluateProposalsPlan" />
   <trigger>
    <goal ref="cnp_evaluate_proposals"/>
   </trigger>
  </plan>
 </plans>
 
 <expressions>
  <expression name="search_reports">
   select NegotiationReport $nr from $beliefbase.negotiation_reports
   where $nr.getOrder().equals($order)
   order by $nr.getTime()
   <parameter name="$order" class="Order"/>
  </expression>
 </expressions>

 <properties>
  <property name="service_seller">
   SFipa.createAgentDescription(null, SFipa.createServiceDescription(null, "service_seller", null))
  </property>
  <!--<property name="logging.level">java.util.logging.Level.FINE</property>-->
  <!--<property name="debugging">true</property>-->
 </properties>

 <configurations>
  <configuration name="default">
   <beliefs>
    <initialbelief ref="gui">
     <fact>new Gui($agent.getExternalAccess(), true)</fact>
    </initialbelief>
   </beliefs>
   <goals>
    <!--<initialgoal ref="purchase_book">
     <parameter ref="order">
      <value>new Order("All about agents",
       new Date(System.currentTimeMillis()+60000), 75, 110, true)</value>
     </parameter>
    </initialgoal>-->
   </goals>
  </configuration>
 </configurations>

</agent>package jadex.examples.booktrading.buyer;

import jadex.planlib.ParticipantProposal;
import jadex.runtime.Plan;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 *  Evaluate the received proposals.
 */
public class EvaluateProposalsPlan extends Plan
{
 /**
  *  The plan body.
  */
 public void body()
 {
  // Get order properties and calculate acceptable price.
  int acceptable_price = ((Integer)getParameter("cfp_info").getValue()).intValue();

  ParticipantProposal[] proposals = (ParticipantProposal[])getParameterSet("proposals").getValues();
  
  // Determine acceptables
  List accs = new ArrayList();
  for(int i=0; i<proposals.length; i++)
  {
   if(((Integer)proposals[i].getProposal()).intValue() <= acceptable_price)
    accs.add(proposals[i]);
  }

  // Sort acceptables by price.
  if(accs.size()>1)
  {
   Collections.sort(accs, new Comparator()
   {
    public int compare(Object arg0, Object arg1) {
     return ((Comparable) ((ParticipantProposal)arg0).getProposal())
      .compareTo(((ParticipantProposal)arg1).getProposal());
    }
   });
  }

  if(accs.size()>0)
   getParameterSet("acceptables").addValue(accs.get(0));
 }
}package jadex.examples.booktrading.buyer;

import jadex.adapter.fipa.AgentDescription;
import jadex.adapter.fipa.AgentIdentifier;
import jadex.examples.booktrading.common.NegotiationReport;
import jadex.examples.booktrading.common.Order;
import jadex.planlib.NegotiationRecord;
import jadex.planlib.ParticipantProposal;
import jadex.planlib.Selector;
import jadex.runtime.GoalFailureException;
import jadex.runtime.IGoal;
import jadex.runtime.Plan;
import jadex.util.SUtil;

import java.util.Comparator;
import java.util.Date;

/**
 * The plan tries to purchase a book.
 */
public class PurchaseBookPlan extends Plan
{
 //-------- methods --------

 /**
  * The body method is called on the
  * instatiated plan instance from the scheduler.
  */
 public void body()
 {
  // Get order properties and calculate acceptable price.
  Order order = (Order)getParameter("order").getValue();
  double time_span = order.getDeadline().getTime() - order.getStartTime();
  double elapsed_time = System.currentTimeMillis() - order.getStartTime();
  double price_span = order.getLimit() - order.getStartPrice();
  int acceptable_price = (int)(price_span * elapsed_time / time_span)
   + order.getStartPrice();

  // Find available seller agents.
  IGoal df_search = createGoal("df_search");
  df_search.getParameter("description").setValue(getPropertybase().getProperty("service_seller"));
  dispatchSubgoalAndWait(df_search);
  AgentDescription[] result = (AgentDescription[])df_search
   .getParameterSet("result").getValues();
  if(result.length == 0)
   fail();
  
  AgentIdentifier[] sellers = new AgentIdentifier[result.length];
  for(int i = 0; i < result.length; i++)
   sellers[i] = result[i].getName();
  //System.out.println("found: "+SUtil.arrayToString(sellers));

  // Initiate a call-for-proposal.
  IGoal cnp = createGoal("cnp_initiate");
  cnp.getParameter("cfp").setValue(order.getTitle());
  cnp.getParameter("cfp_info").setValue(new Integer(acceptable_price));
  cnp.getParameterSet("receivers").addValues(sellers);  
  try
  {
   dispatchSubgoalAndWait(cnp);
   
   NegotiationRecord rec = (NegotiationRecord)cnp.getParameterSet("history").getValues()[0];
   generateNegotiationReport(order, rec, acceptable_price);
   
   // If contract-net succeeds, store result in order object.
   order.setExecutionPrice((Integer)(cnp.getParameterSet("result").getValues()[0]));
   order.setExecutionDate(new Date());
  }
  catch(GoalFailureException e)
  {
   NegotiationRecord rec = (NegotiationRecord)cnp.getParameterSet("history").getValues()[0];
   generateNegotiationReport(order, rec, acceptable_price);
   
   fail();
  }
  //System.out.println("result: "+cnp.getParameter("result").getValue());
 }
 
 /**
  *  Generate and add a negotiation report.
  */
 protected void generateNegotiationReport(Order order, NegotiationRecord rec, double acceptable_price)
 {
  String report = "Accepable price: "+acceptable_price+", proposals: ";
  ParticipantProposal[] proposals = rec.getProposals();
  for(int i=0; i<proposals.length; i++)
  {
   report += proposals[i].getProposal()+"-"+proposals[i].getParticipant().getLocalName();
   if(i+1<proposals.length)
    report += ", ";
  }
  NegotiationReport nr = new NegotiationReport(order, report, rec.getStarttime());
  //System.out.println("REPORT of agent: "+getAgentName()+" "+report);
  getBeliefbase().getBeliefSet("negotiation_reports").addFact(nr);
 }
}

分享到:
评论

相关推荐

    电子商务API:用于电子商务网站的静态API

    没有作品/buyer/me GET 在标头中使用必需的承载JWT令牌调用API。 返回除私有细节(如密码)外的整个买家细节。 是作品/buyer/me PATCH 使用标头中的必需承载JWT令牌以及要更改的详细信息来调用API。 返回除私有细节...

    前端mpvue后端nodejs+thinkjs+mysql微信小程序商城(准备用uniapp重构并适配多端).zip

    服务端)小程序端技术栈mpvue + mpvue-router-patch + mpvue-entry + vuex + webpack + ES6/7 + flyio + mpvue-wxparse项目运行微信开发中工具选中mpvue-xbyjShop/buyer作为项目目录即可功能列表页面 首页 -- 完成 ...

    kitchens:小厨房

    kitchens :trophy: springboot springdata 接口调用说明api 全局 var NewApiKitcUrl = 'localhost:8080/kit/'; 所有在售的商品其中按商品类划分... PayCreate: NewApiKitcUrl + 'weixin/buyer/order/cancel',//支付创建

    SRM210 - SAP Enterprise Buyer 3.5 Configuration.pdf

    ### SAP Enterprise Buyer 3.5 Configuration (SRM210) 关键知识点解析 #### 一、课程目标与概述 本课程旨在使学习者能够掌握 SAP Enterprise Buyer (EBP) 3.5 版本的核心配置知识和技术应用要求,以便在实际项目...

    电子商务商城商品源码20111109

    ByteartRetailV3源码 功能介绍: Byteart Retail是一个基于.NET开发的企业级应用程序,...buyer/buyer:以采购人员角色登录,可以管理商品分类和商品信息 ?daxnet/daxnet:普通用户角色,不能对系统进行任何管理操作

    Oracle Supplier Network Buyer’s Guide to Connecting 11i Release

    Oracle Supplier Network Buyer’s Guide to Connecting 11i Release 4.3 Part No. B19153-01

    基于springboot+jpa实现java后台api接口,点餐系统源码+项目说明(高分毕设).zip

    - url:https://30paotui.com/buyer/product/list - 请求方式:get - 返回数据格式如下 ``` { "code": 100, "msg": "成功", "data": [ { "name": "热销", "type": 1, "foods": [ { "id": "5", "name": ...

    Javascript 制作图形验证码实例详解

    js 图形验证码制作 实际效果 第一步我们来到要展示验证码的页面,当我们按下营业执照的时候让其,弹出一...//1-在路由层进行设置,页面跳转到根目录下/buyer/vshop/info.ejs页面进行跳转,然后在回调函数中进行接口的调

    Oracle Procurement Buyer’s Guide to Punchout and Transparent Pun

    Oracle Procurement Buyer’s Guide to Punchout and Transparent Punchout 是一份为使用Oracle采购系统的买家提供的指南,专注于两种电子采购技术:Punchout 和 Transparent Punchout。这些技术是企业间电子商务...

    Buyer@Amazon-crx插件

    语言:日本語 买方@ amazon是一种方便使用的扩展。 从Amazon的产品页面创建一个单击的关联链接。 请使用“支持”选项卡进行评论。 买方@Amazon是一种方便使用的扩展。 从Amazon的产品页面创建一个单击的关联链接。...

    实验3-统计某电商网站买家收藏商品数量1

    数据集被称为`buyer_favorite1`,包含了买家ID、商品ID以及收藏日期三个字段,这些字段之间用制表符(`\t`)进行分隔。下面我们将详细探讨如何设计并实现这样的MapReduce程序,以及在实施过程中可能遇到的关键步骤和...

    Hadoop Buyers Guide

    This Buyer’s Guide presents a series of guidelines that you can use when searching for the essential Hadoop infrastructure that will be sustaining your organization for years to come.

    Steam-Bulk-Card-Buyer:此用户脚本会在您的 Steam 徽章页面上添加一个按钮,让您可以立即从 Steam 市场购买完成徽章所需的所有卡片

    Steam-Bulk-Card-Buyer 此用户脚本会在您的 Steam 徽章页面上添加一个按钮,让您可以立即从 Steam 市场购买完成徽章所需的所有卡片。警告的话! 我的版本是单击即可完成所有操作。 这意味着单击购买将购买卡片、重新...

    Buyer.rar_VHDL/FPGA/Verilog_VHDL_

    标题中的"Buyer.rar_VHDL/FPGA/Verilog_VHDL_"暗示了这是一个与电子设计自动化(EDA)相关的项目,特别关注于使用VHDL和Verilog编程语言在FPGA(Field-Programmable Gate Array)上实现的自动售货机系统。...

    2014-30-EU 电磁兼容EMC指令

    在当今高度电子化和自动化的社会中,电磁兼容性(EMC)已成为衡量电子产品和系统性能的重要指标。电磁兼容确保各类电气和电子设备能在复杂多变的电磁环境中稳定运行,避免相互干扰,保障了设备和系统的可靠性与安全...

    (eu) 2017/79 ecall system

    欧盟的ECALL系统是一项交通紧急呼叫系统,旨在提高交通事故发生时的救援效率,减少救援时间,降低事故后果的严重性。ECALL系统的法规要求主要体现在以下几个方面: 1. 法规的适用范围和背景:根据描述,欧盟已经...

    纯担保交易接口-create_partner_trade_by_buyer

    "纯担保交易接口-create_partner_trade_by_buyer"是支付宝提供的一种特定服务,旨在帮助网站所有者集成支付宝支付功能,尤其适用于非网店论坛系统的独立技术开发的网站。此接口允许买家在商家网站上进行购物时,资金...

    高级程序设计仓库管理系统

    关于一个仓库管理系统的完整程序... char buyer[12]; //采购员 char btel[12]; char provider[12];//供应商 char p_tel[13];//供应商电话 char return_date[11]; //归还时间 char out_date[11];//出库时间 };

    asp.net c#支付宝接口详细代码

    string transport, string ordinary_fee, string express_fee, string readonlys, string buyer_msg, string buyer, string buyer_name, string buyer_address, string buyer_zipcode, string buyer_tel, string ...

    sQL数据库课件,合并多个表中的数据

    这个查询会返回一个结果集,其中包含buyers表中的buyer_name,与sales表中的buyer_id和qty,只有当buyers表中的buyer_id与sales表中的buyer_id相匹配时才会显示。结果集中不会包含任何在其中一张表中没有对应匹配项...

Global site tag (gtag.js) - Google Analytics