在Jason用AgentSpeak创建英语拍卖

时间:2018-06-01 14:48:21

标签: artificial-intelligence agent multi-agent

我是Jason和Agentspeak的初学者。我有兴趣用一个Auctioneer和两个Bidders进行英国拍卖。我创建了以下文件,但是当我运行它们时,没有任何反应。我不知道在哪里问题是。你可以帮帮我吗?先谢谢!

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,_)).

1 个答案:

答案 0 :(得分:1)

一切听起来都有效,至少在杰森的观点上(忽略了你的应用背后的逻辑 - 英国拍卖)。

尝试使用调试工具:

  • 选项1:在“播放”按钮运行后,在“MAS控制台”中,您可以通过“调试”按钮启动调试器。在那里,您可以检查他们的精神状态,并逐步运行您的应用程序。
  • 选项2:如果您使用的是jEdit或Eclipse Jason的插件,您可以通过绿色错误图标启动正在运行的进程。
  • 选项3:打开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,_)).