【问题标题】:Create an English Auction with AgentSpeak in Jason在 Jason 中使用 AgentSpeak 创建英语拍卖
【发布时间】:2018-11-11 17:59:46
【问题描述】:

我是 Jason 和 Agentspeak 的初学者。我对与一个 Auctioneer 和两个 Biders 进行英语拍卖很感兴趣。我创建了以下文件,但是当我运行它们时,没有任何反应。我不知道在哪里问题是。你能帮我吗?提前谢谢!

ActioneerGUI.JAVA

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import jason.architecture.*;
import jason.asSemantics.ActionExec;
import jason.asSyntax.ASSyntax;
import jason.asSyntax.Literal;

import javax.swing.*;

/** example of agent architecture's functions overriding */
public class AuctioneerGUI extends AgArch {

    JTextArea jt;
    JFrame    f;
    JButton auction;

    int auctionId = 0;

    public AuctioneerGUI() {
        jt = new JTextArea(10, 30);
        auction = new JButton("Start new auction");
        auction.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                auctionId++;
                Literal goal = ASSyntax.createLiteral("start_auction", ASSyntax.createNumber(auctionId));
                getTS().getC().addAchvGoal(goal, null);
                auction.setEnabled(false);
            }
        });

        f = new JFrame("Auctioneer agent");
        f.getContentPane().setLayout(new BorderLayout());
        f.getContentPane().add(BorderLayout.CENTER, new JScrollPane(jt));
        f.getContentPane().add(BorderLayout.SOUTH, auction);
        f.pack();
        f.setVisible(true);
    }

    @Override
    public void act(ActionExec action) { //, List<ActionExec> feedback) {
        if (action.getActionTerm().getFunctor().startsWith("show_winner")) {
            jt.append("Winner of auction  " + action.getActionTerm().getTerm(0));
            jt.append(" is " + action.getActionTerm().getTerm(1) + "\n");
            action.setResult(true);
            actionExecuted(action);

            auction.setEnabled(true); // enable GUI button
        } else {
            super.act(action); // send the action to the environment to be performed.
        }
    }

    @Override
    public void stop() {
        f.dispose();
        super.stop();
    }
}

actioneer.asl

// this agent manages the auction and identify the winner

initial_value (8).

+!start_auction(N)   // this goal is created by the GUI of the agent
    <- .broadcast(tell, auction(N));
       .broadcast(tell, initial_value (IV)).

// announce current bid
@pb2[atomic]
+place_bid(N,_)     // receives bids and checks for new winner
   :  .findall(b(V,A),place_bid(N,V)[source(A)],L) &
      .length(L,2)  // all 2 expected bids was received
   <- .max(L,b(V,W));
      .broadcast(tell, current_bid(CB)).


@pb1[atomic]
+place_bid(N,_)     // receives bids and checks for new winner
   :  .findall(b(V,A),place_bid(N,V)[source(A)],L) &
      .length(L,2)  // all 2 expected bids was received
   <- .max(L,b(V,W));
      .print("Winner is ",W," with ", V);
      show_winner(N,W); // show it in the GUI
      .broadcast(tell, winner(W));
      .abolish(place_bid(N,_)).

auction.mas2j

// English auction

MAS auction {

    infrastructure: Centralised

    agents: ag1;
            ag2;
            auctioneer agentArchClass AuctioneerGUI;
}

ag2.asl

max_bid (10).

@lbid
+auction(N)[source(S)] : true
   <- .send(S, tell, place_bid(N,0)).

+place_bid(N,CB):CB<MB  
    <-place_bid(N,CB)[source(A)];
     .send(S, tell, place_bid(N,CB+1)).

+place_bid(N,CB):CB=MB  
    <-place_bid(N,CB)[source(A)];
     .send(S, tell, place_bid(N,CB)).

+place_bid(N,CB):CB>MB  
    <-.abolish(place_bid(N,_)).

ag1.asl

max_bid (9).

@lbid
+auction(N)[source(S)] : true
   <- .send(S, tell, place_bid(N,0)).

+place_bid(N,CB):CB<MB  
    <-place_bid(N,CB)[source(A)];
     .send(S, tell, place_bid(N,CB+1)).

+place_bid(N,CB):CB=MB  
    <-place_bid(N,CB)[source(A)];
     .send(S, tell, place_bid(N,CB)).

+place_bid(N,CB):CB>MB  
    <-.abolish(place_bid(N,_)).

【问题讨论】:

    标签: artificial-intelligence agent multi-agent


    【解决方案1】:

    听起来一切正常,至少在 Jason 看来是这样(忽略您的应用程序背后的逻辑 - 英式拍卖)。

    尝试使用调试工具:

    • 选项 1:通过“播放”按钮运行后,在“MAS 控制台”中,您可以通过“调试”按钮启动调试器。在那里您可以检查他们的心理状态并逐步运行您的应用程序。
    • 选项 2:如果您使用的是 jEdit 或 Eclipse Jason 的插件,您可以通过绿色错误图标启动正在运行的进程。
    • 选项 3:打开 Jason 的调试网页。当你运行你的应用程序(和 它编译得很好)你可能会看到一条消息,比如“Jason Http Server 运行在http://192.168.0.10:3273"上,这里 192.168.0.10 是您的 IP 地址(因此,它会根据您的计算机/网络配置而变化)。
    • 选项 4:添加一些调试消息。

    就像我在auctioneer.asl 中所做的那样:

    // this agent manages the auction and identify the winner
    
    initial_value(8).
    
    +!start_auction(N)   // this goal is created by the GUI of the agent
        <-  .print("Start a new auction!!!");
            .broadcast(tell, auction(N));
            .broadcast(tell, initial_value (IV)).
    
    // announce current bid
    @pb2[atomic]
    +place_bid(N,_)     // receives bids and checks for new winner
       :    .findall(b(V,A),place_bid(N,V)[source(A)],L) &
            .length(L,2)  // all 2 expected bids was received
       <-   .print("place_bid was received.");
            .max(L,b(V,W));
            .broadcast(tell, current_bid(CB)).
    
    
    @pb1[atomic]
    +place_bid(N,_)     // receives bids and checks for new winner
       :  .findall(b(V,A),place_bid(N,V)[source(A)],L) &
          .length(L,2)  // all 2 expected bids was received
       <- .max(L,b(V,W));
          .print("Winner is ",W," with ", V);
          show_winner(N,W); // show it in the GUI
          .broadcast(tell, winner(W));
          .abolish(place_bid(N,_)).
    

    【讨论】:

      猜你喜欢
      • 2018-09-28
      • 2015-03-29
      • 2015-09-15
      • 2012-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-17
      • 2014-01-31
      相关资源
      最近更新 更多