이번엔 두 시간에 걸친 옥션 모델 만들기였다...
아...빡세더라..ㅋㅋ

Process of Auction Model
Procedure and Design
Supplier inverntory 내의 10개의 product와 그 초기 가격 1 PD#1 2000
2 PD#2 2200
3 PD#3 1800
4 PD#4 1600
5 PD#5 2500
6 PD#6 3000
7 PD#7 3300
8 PD#8 2800
9 PD#9 1900
10 PD#10 3500
Customer의 최대 입찰 가격과 입찰 탄력성
Cus #1 (Initial Price of Product)* 2.0 240
Cus #2 (Initial Price of Product)* 2.2 220
Cus #3 (Initial Price of Product)* 1.9 260
Cus #4 (Initial Price of Product)* 2.4 300
Cus #5 (Initial Price of Product)* 2.1 280
총 7개의 파일을 작성했으며, 개략적인 내용은 주석으로 확인하시길...(좀 질렸음...ㅋㅋ)
어디서 오류가 나는지 잡기 위해서 중간 중간 프린트문을 넣었는데
모두 주석처리한 채로 그냥 두었다.
결과는 파일로 출력된다.
아...빡세더라..ㅋㅋ
Process of Auction Model
- Supplier가 Auctioneer에게 판매할 상품의 경매를 요청한다. (이때 상품의 초기 시작 가격 (Initial Price)을 같이 보낸다.) ' 위 그림의 청색 라인이 경매 시작 신호선이다.
- Auctioneer는 N개의 Customer에게 Supplier에게 받은 동일한 메시지를 전달하여 경매가 시작 되었음을 알린다.
- 각각의 Customer는 자신만의 가격 탄력성 (Price Elasticity)와 최대 입찰 가능 가격(Maximum Boundary Price)을 가지고 있다.
- 최초의 입찰에서는 각각의 Customer가 입찰 가격으로 Auctioneer로부터 전달 받은 초기 입찰 가격에 자신의 가격 탄력성 안에서 가격을 설정(Rand 함수를 이용하여 자신의 가격 탄력성 안에서 랜덤 하게 선택한다.) 하여 입찰 가격을 정해 Auctioneer에게 보낸다. ->빨간색 점선
First Bidding Price = Initial Price from Auctioneer + Rand(Price Elasticity of Customer) - 첫 번째 입찰을 받은 Auctioneer는 최초 입찰에서 최고가를 입찰한 Customer와 입찰 최고가를 각각의 Customer 및 Supplier에게 보낸다.
- 두 번째 입찰은 Customer가 각각의 자신의 최대 입찰 가격을 넘지 않는 범위에서 최초 입찰 가격에 자신의 가격 탄력성을 더한 가격을 입찰한다. 이미 최초 입찰에서 자신의 최대 입찰 가격을 넘은 Customer는 입찰을 포기(Bidding price = 0) 한다.
IF (Highest Price of Previous Bidding < Maximun Price Boundary){
Bidding Price = Highest Price of Previous Bidding + Rand(Price Elasticity of Customer)
ELSE
Bidding Price = 0; - 5번을 다시 실행
- 입찰은 총 5회 진행 된다. (※ 5회 이전에 입찰자가 1명만 남은 경우에는 그 입찰자의 입찰가격을 낙찰 가격으로 하고 경매를 종료 시킨다.) 5회 입찰 진행 후 최고가를 입찰한 Customer가 낙찰되며, 낙찰 가격을 모든 Customer와 Supplier에 공지 하고 경매는 종료 된다.
- 경매 종료 메시지를 전달받은 Supplier는 재고에 남아있는 상품의 경매 요청 메시지를 최초 가격과 함께 Auctioneer에게 전달한다.
- 1~9의 과정을 반복하여 supplier에 더 이상 재고가 존재하지 않을 경우 시스템을 종료한다.
Procedure and Design
- DEVS로 구성 시 만들어지는 1개의 Digraph 모델과 3종류의 Component(Atomic Model)와 3종류의 Message로 구성된다.
- Auction: gpt.java를 수정하여 만든다. (Digraph Model)
- Supplier : genr.java를 수정하여 만든다.
Supplier는 자신의 상품이 저장된 Inventory를 가진다.
또한, Auctioneer로부터 받은 Result Message를 통해 경매가 종료되었을 경우 Start Message를 전송하여 새로운 상품의 경매를 요청한다.
[필수 variables] 상품 저장소 (int형 2차원 배열 inventory-상품번호와 시작가격 포함) - Auctioneer : proc.java를 수정하여 만든다.
Auctioneer는 Supplier로부터 Start Message를 입력받아 경매의 시작을 알린다.
또한, Customer의 입찰정보를 저장할 리스트를 포함하며 Customer들로부터 Bidding Message를 입력 받아 리스트를 갱신, 최고 입찰자 및 입찰가에 대한 정보를 Result Message를 통해 공지한다.
[필수 variables] 입찰 리스트 (int형 2차원 배열 bitList - 입찰자와 입찰가격 포함)
입찰 카운트 (int형 count - 한계값은 5이며 5가 넘을 경우 0으로 셋팅)
최고 입찰자 (string형 max_bidder), 최고 입찰 가격 (int형 max_price), 낙찰자 (String형 end_bidder), 낙찰 가격 (end_price) - Customer : proc.java를 수정하여 만든다.
자신의 판매전략에 맞춰 입찰가를 선정하나 만약 선정된 가격이 입찰 한도를 초과할 경우 입찰가를 0으로 조정한다.
그리고, 만약 경매가 종료되었을 경우에는 Bidding Message를 발생시키지 않고 입찰가를 0으로 재조정한다.
[필수 variables] 입찰가 (int형 bid_price), 가격 탄력성(int형 PE), 입찰 한도(int형 MBP), 현재가격 (int형 posted_price) - 3 Messages ' job.java를 수정하여 만든다.
- Start Message: Supplier ' Auctioneer, Auctioneer ' Customer로 전달된다.
경매 시작을 알리는 메시지로 초기 시작 가격을 가지고 있다.
[필수 variables] 상품 번호( int형 product_num), 시작가격( int형 initial_price) - Bidding Message: Customer ' Auctioneer로 전달되는 메시지로 각 Customer의 정보와 입찰 가격을 포함하고 있다.
[필수 variables] 입찰자 번호(int형 customer_num), 입찰가격(int형 bidding_price) - Result Message: Auctioneer ' Customer, Supplier로 전달되는 메시지로 현재 경매의 진행 상황 및 최고가와 최고가를 입찰한 Customer의 정보를 포함한다.
[필수 variables] 진행상황(string형 status), 최고가(int형 highest_price), 최고입찰자(string형 highest_bidder)
- Start Message: Supplier ' Auctioneer, Auctioneer ' Customer로 전달된다.
Supplier inverntory 내의 10개의 product와 그 초기 가격 1 PD#1 2000
2 PD#2 2200
3 PD#3 1800
4 PD#4 1600
5 PD#5 2500
6 PD#6 3000
7 PD#7 3300
8 PD#8 2800
9 PD#9 1900
10 PD#10 3500
Customer의 최대 입찰 가격과 입찰 탄력성
Cus #1 (Initial Price of Product)* 2.0 240
Cus #2 (Initial Price of Product)* 2.2 220
Cus #3 (Initial Price of Product)* 1.9 260
Cus #4 (Initial Price of Product)* 2.4 300
Cus #5 (Initial Price of Product)* 2.1 280
총 7개의 파일을 작성했으며, 개략적인 내용은 주석으로 확인하시길...(좀 질렸음...ㅋㅋ)
어디서 오류가 나는지 잡기 위해서 중간 중간 프린트문을 넣었는데
모두 주석처리한 채로 그냥 두었다.
결과는 파일로 출력된다.
// SingleAuction.java
// modifued by Aettie Ji
// April 21st, 2009
package SimpArc;
import java.awt.*;
import simView.*;
import genDevs.modeling.*;
import genDevs.simulation.*;
import GenCol.*;
public class SingleAuction
extends ViewableDigraph {
int customer_num = 5;
double customer_inform[][]; // customer_inform
public SingleAuction() {
super("SingleAuction");
customer_inform = new double[customer_num][2]; // customer_inform
customer_inform[0][0] = 2.0; // 최고입찰가격
customer_inform[0][1] = 240; // 가격 탄력성
customer_inform[1][0] = 2.2; // 최고입찰가격
customer_inform[1][1] = 240; // 가격 탄력성
customer_inform[2][0] = 1.9; // 최고입찰가격
customer_inform[2][1] = 260; // 가격 탄력성
customer_inform[3][0] = 2.4; // 최고입찰가격
customer_inform[3][1] = 300; // 가격 탄력성
customer_inform[4][0] = 2.1; // 최고입찰가격
customer_inform[4][1] = 280; // 가격 탄력성
ViewableAtomic s = new Auction_Supplier("Supplier", 0);
ViewableAtomic a = new Auctioneer("Auctioneer", customer_num);
for (int i = 0; i < customer_num; i++) {
String customer_name = "Customer_" + i;
double MBP = customer_inform[i][0];
double PE = customer_inform[i][1];
ViewableAtomic c = new Auction_Customer(customer_name, i, MBP, PE);
add(c);
addCoupling(c, "bidout", a, "bidin" + i);
addCoupling(a, "start", c, "in");
addCoupling(a, "out", c, "pricein");
}
add(s);
add(a);
addCoupling(s, "start", a, "in");
addCoupling(a, "out", s, "result");
// initialize();
showState();
/*
preferredSize = new Dimension(484, 145);
g.setPreferredLocation(new Point(13, 18));
p.setPreferredLocation(new Point(195, 18));
t.setPreferredLocation(new Point(193, 80));
*/
}
/**
* Automatically generated by the SimView program.
* Do not edit this manually, as such changes will get overwritten.
*/
public void layoutForSimView() {
preferredSize = new Dimension(816, 409);
( (ViewableComponent) withName("Customer_2")).setPreferredLocation(new
Point(528, 173));
( (ViewableComponent) withName("Customer_0")).setPreferredLocation(new
Point(502, 15));
( (ViewableComponent) withName("Supplier")).setPreferredLocation(new Point(
50, 144));
( (ViewableComponent) withName("Customer_1")).setPreferredLocation(new
Point(520, 105));
( (ViewableComponent) withName("Customer_4")).setPreferredLocation(new
Point(516, 340));
( (ViewableComponent) withName("Customer_3")).setPreferredLocation(new
Point(490, 247));
( (ViewableComponent) withName("Auctioneer")).setPreferredLocation(new
Point(238, 102));
}
}
// Acution_Supplier.java
// modifued by Aettie Ji
// April 21st, 2009
package SimpArc;
import simView.*;
import java.lang.*;
import genDevs.modeling.*;
import genDevs.simulation.*;
import GenCol.*;
public class Auction_Supplier
extends ViewableAtomic {
protected double int_arr_time;
protected int count;
protected entity job;
double inventory[][];
result_message r_msg;
public Auction_Supplier(String name, double Int_arr_time) {
super(name);
addInport("result");
addOutport("start");
int_arr_time = Int_arr_time;
}
public void initialize() {
holdIn("active", int_arr_time);
job = new entity("job");
r_msg = new result_message("RESULT", "end", "", 0);
// phase = "passive";
// sigma = INFINITY;
count = 0;
inventory = new double[10][2];
inventory[0][0] = 1;
inventory[0][1] = 2000;
inventory[1][0] = 2;
inventory[1][1] = 2200;
inventory[2][0] = 3;
inventory[2][1] = 1800;
inventory[3][0] = 4;
inventory[3][1] = 1600;
inventory[4][0] = 5;
inventory[4][1] = 2500;
inventory[5][0] = 6;
inventory[5][1] = 3000;
inventory[6][0] = 7;
inventory[6][1] = 2300;
inventory[7][0] = 8;
inventory[7][1] = 2800;
inventory[8][0] = 9;
inventory[8][1] = 1900;
inventory[9][0] = 10;
inventory[9][1] = 3500;
super.initialize();
}
public void deltext(double e, message x) {
Continue(e);
if (phaseIs("passive")) {
for (int i = 0; i < x.getLength(); i++) {
if (messageOnPort(x, "result", i)) {
job = x.getValOnPort("result", i);
r_msg = (result_message) job;
//System.out.println("Result Port로 Auctioneer로부터 결과 메시지 받음");
if (r_msg.status == "progree") { //경매진행중, 판매요청불가
phase = "passive";
//System.out.println("결과 메시지의 status == progree, 경매진행중");
}
else if (r_msg.status == "end") { //경매종료, 판매요청가능
count++;
//System.out.println("결과 메시지의 status == end" + "\t" + (count - 1) +
// " 번 째 상품 경매종료");
if (count < 10) {
//System.out.println("=====================" + count +
// "번째 경매 대기=======================");
holdIn("active", int_arr_time);
}
else {
System.exit(0);
}
}
}
}
}
}
public void deltint() {
passivate();
job = new entity("none");
}
public message out() {
//System.out.println(name+" out count "+count);
message m = new message();
content con = makeContent("start",
new start_message("START", inventory[count][0],
inventory[count][1]));
m.add(con);
/*System.out.println("start port로 Auctioneer에게 시작 메시지보냄: " + "\n" +
"================" + count +
"번째 경매 시작: " + "Inventory : " + inventory[count][0]
+ "\t" + "Initial Price : " + inventory[count][1] +
"==============");*/
return m;
}
public void showState() {
super.showState();
}
public String getTooltipText() {
return
super.getTooltipText()
+ "\n" + " int_arr_time: " + int_arr_time
+ "\n" + " count: " + count;
}
}// Auctioneer.java
// modifued by Aettie Ji
// April 21st, 2009
package SimpArc;
import genDevs.modeling.*;
import genDevs.simulation.*;
import GenCol.*;
import simView.*;
import java.io.RandomAccessFile;
public class Auctioneer
extends ViewableAtomic {
protected entity job;
//protected double processing_time;
double list[][];
double sort[][];
int count; //입찰카운트, 총 5회진행
String max_bidder; //최고입찰자
double max_price; //최고입찰가
//경매기록 파일 작성
RandomAccessFile out;
start_message s_msg;
bidding_message b_msg;
int customer_num; //경매참여자수
int case_num; //어떤 메시지 입력을 받는가 구별
int check[]; //입찰자의 입찰여부 체크
double temp1, temp2; //정렬 등을 위한 임시변수
String status; //현재 상태를 받기위한 변수
public Auctioneer() {
this("Auctioneer", 20);
}
public Auctioneer(String name, int num) {
super(name);
customer_num = num;
list = new double[customer_num][2];
sort = new double[customer_num][2];
check = new int[customer_num];
for (int i = 0; i < customer_num; i++) {
addInport("bidin" + i); //각 customer bidout과 연결
list[i][0] = i;
list[i][1] = 1;
sort[i][0] = i;
sort[i][1] = 1;
check[i] = 0;
}
addInport("in"); //start message from supplier
addOutport("out"); //result message to supplier
//addOutport("priceout");
addOutport("start");
try {
out = new RandomAccessFile("biddingHistory.txt", "rw");
System.out.println(
"****************************파일생성***************************");
}
catch (Exception e) {
System.out.println("Can't open file " + e);
}
}
public void initialize() {
phase = "passive";
sigma = INFINITY;
job = new entity("job");
max_bidder = "";
max_price = 0;
count = 0;
case_num = 0;
temp1 = 0;
temp2 = 0;
s_msg = new start_message("START", 0, 0);
b_msg = new bidding_message("BID", 0, 0);
super.initialize();
}
public void deltext(double e, message x) {
Continue(e);
if (phaseIs("passive")) {
for (int i = 0; i < x.getLength(); i++) {
if (messageOnPort(x, "in", i)) {
job = x.getValOnPort("in", i);
s_msg = (start_message) job;
//System.out.println("In Port로 supplier로부터 시작 메시지 받음");
try {
out.writeBytes("Product Num : " + s_msg.product_num + "\t"
+ "Initial Price : " + s_msg.initial_price + "\n");
}
catch (Exception ex) {
System.out.println("Can't Write " + ex);
}
case_num = 1;
holdIn("busy", 0);
}
}
for (int j = 0; j < customer_num; j++) {
for (int i = 0; i < x.getLength(); i++) {
if (messageOnPort(x, "bidin" + j, i)) {
job = x.getValOnPort("bidin" + j, i);
b_msg = (bidding_message) job;
//System.out.println("Bidin Port로 customer로부터 입찰 메시지 받음");
list[j][0] = b_msg.customer_num;
list[j][1] = b_msg.bidding_price;
if (list[j][1] == 0) {
check[j] = 0;
//System.out.println("Customrt_" + j + "는 입찰하지 않았음");
}
else if (list[j][1] != 0) {
check[j] = 1;
case_num = 2;
//System.out.println("Customrt_" + j + "는 입찰 하였음");
}
}
}
}
if (case_num == 2) {
count++;
//System.out.println(count + " 번째 입찰======================");
for (int k = 0; k < customer_num; k++) {
sort[k][0] = list[k][0];
sort[k][1] = list[k][1];
}
//bubble sort
for (int a = 0; a < customer_num - 1; a++) {
for (int b = a + 1; b < customer_num; b++) {
if (sort[a][1] > sort[b][1]) {
temp1 = sort[a][0];
sort[a][0] = sort[b][0];
sort[b][0] = temp1;
temp2 = sort[a][1];
sort[a][1] = sort[b][1];
sort[b][1] = temp2;
//System.out.println("Sorting");
}
}
}
max_bidder = "Customer " + sort[0][0];
max_price = sort[0][1];
//System.out.println("max_bidder :" + max_bidder + "\t" + "max_price :" +
// max_price);
try {
out.writeBytes("----------Bidding count : " + count + "---------" +
"\n");
for (int b = 0; b < customer_num; b++) {
out.writeBytes("Customer :" + list[b][0] + "\t" + list[b][1] +
"\n"); //경매과정 list[][]출력
}
out.writeBytes("Max Bidder :" + max_bidder + "\t" + "Max Price :" +
max_price + "\n"); //누가 maxbidder인지 출력
}
catch (Exception ex) {
System.out.println(ex);
}
holdIn("busy", 0);
}
}
}
public void deltint() {
passivate();
job = new entity("none");
}
public void deltcon(double e, message x) {
deltint();
deltext(0, x);
}
public message out() {
message m = new message();
if (phaseIs("busy")) {
if (case_num == 1) {
m.add(makeContent("start", s_msg));
//System.out.println("Start Port로 customer에게 시작 메시지 보냄");
}
else if (case_num == 2) {
if (count < 5) {
int participant = 0;
for (int a = 0; a < customer_num; a++) {
participant += check[a];
}
//System.out.println(participant + " 명 입찰");
if (participant >= 2) {
status = "progree";
}
else {
count = 0;
status = "end";
}
}
else if (count >= 5) {
count = 0;
status = "end";
}
m.add(makeContent("out",
new result_message("RESULT", status, max_bidder,
max_price)));
//System.out.println("Out port로 Supplier, Customer에게 결과 메시지보냄: " + "\n" +
// "상태 : " + status + "MaxBidder : " + max_bidder
// + "\t" + "MaxPrice : " + max_price);
}
}
return m;
}
public void showState() {
super.showState();
// System.out.println("job: " + job.getName());
}
public String getTooltipText() {
return
super.getTooltipText()
+ "\n" + "job: " + job.getName();
}
}
// Auction_Customer.java
// modifued by Aettie Ji
// April 21st, 2009
package SimpArc;
import genDevs.modeling.*;
import genDevs.simulation.*;
import GenCol.*;
import simView.*;
public class Auction_Customer
extends ViewableAtomic {
protected entity job;
int num;
double bid_price; //입찰가
double PE; //가격 탄력성
double MBP; //최고입찰한도
double real_MBP; //실제 최고입찰가
double posted_price; //현재 시장가
start_message s_mess;
bidding_message b_mess;
result_message r_mess;
public Auction_Customer() {
//this("Auction_Customer",20);
}
public Auction_Customer(String name, int n, double m, double p) {
super(name);
addInport("pricein"); //result_messge
addOutport("bidout"); //bidding_message
addInport("in"); //start_message
num = n;
MBP = m;
PE = p;
}
public void initialize() {
phase = "passive";
sigma = INFINITY;
job = new entity("job");
s_mess = new start_message("START", 0, 0);
b_mess = new bidding_message("BIDDING", 0, 0);
r_mess = new result_message("RESULT", "end", "", 0);
super.initialize();
}
public void deltext(double e, message x) {
Continue(e);
if (phaseIs("passive")) {
for (int i = 0; i < x.getLength(); i++) {
if (messageOnPort(x, "in", i)) {
job = x.getValOnPort("in", i);
s_mess = (start_message) job;
//System.out.println("In Port로 Auctioneer로부터 start 메시지 받음");
real_MBP = s_mess.initial_price * MBP; //실제입찰한도
bid_price = s_mess.initial_price + (int) (Math.random() * PE); //첫번째 입찰가
holdIn("busy", 0);
}
}
for (int i = 0; i < x.getLength(); i++) {
if (messageOnPort(x, "pricein", i)) {
job = x.getValOnPort("pricein", i);
r_mess = (result_message) job;
//System.out.println("pricein Port로 Auctioneer로부터 result 메시지 받음");
posted_price = r_mess.highest_price;
if (r_mess.status == "progree") {
if (posted_price < real_MBP) {
bid_price = posted_price + (int) (Math.random() * PE);
}
else {
bid_price = 0;
}
}
else {
bid_price = 0;
}
holdIn("busy", 0);
}
}
}
}
public void deltint() {
passivate();
job = new entity("none");
}
public void deltcon(double e, message x) {
deltint();
deltext(0, x);
}
public message out() {
message m = new message();
if (phaseIs("busy")) {
m.add(makeContent("bidout", new bidding_message("BIDDING", num, bid_price)));
}
//System.out.println("Bidout Port로 Auctioneer에게 bidding 메시지 보냄");
return m;
}
public void showState() {
super.showState();
// System.out.println("job: " + job.getName());
}
public String getTooltipText() {
return
super.getTooltipText()
+ "\n" + "job: " + job.getName();
}
}// start_message.java
// modifued by Aettie Ji
// April 21st, 2009
package SimpArc;
import genDevs.modeling.*;
import genDevs.simulation.*;
import GenCol.*;
public class start_message
extends entity {
public double product_num; // 상품 번호
public double initial_price; // 초기 가격
public start_message(String name, double num, double ip) {
super(name);
product_num = num;
initial_price = ip;
}
}// bidding_message.java
// modifued by Aettie Ji
// April 21st, 2009
package SimpArc;
import genDevs.modeling.*;
import genDevs.simulation.*;
import GenCol.*;
public class bidding_message
extends entity {
public int customer_num; //입찰자정보
public double bidding_price; //입찰가격
public bidding_message(String name, int num, double bp) {
super(name);
customer_num = num;
bidding_price = bp;
}
}// result_message.java
// modifued by Aettie Ji
// April 21st, 2009
package SimpArc;
import genDevs.modeling.*;
import genDevs.simulation.*;
import GenCol.*;
public class result_message
extends entity {
public String status; // 경매진행상태
public String highest_bidder; // 최고 입찰자
public double highest_price; // 최고 가격
public result_message(String name, String s, String hb, double hp) {
super(name);
status = s;
highest_bidder = hb;
highest_price = hp;
}
}'HotStudy+-+ > ...*ETC*...' 카테고리의 다른 글
| [Semantic Web] Survey of Ontology Engineering Methodologies (0) | 2009/04/27 |
|---|---|
| [Advanced Software Engineering] Single Auction Model (0) | 2009/04/22 |
| [Advanced Software Engineering] Minimum Load First Scheduling Model (0) | 2009/04/07 |
| [Advanced Software Engineering] Round Robin Scheduling Model (0) | 2009/04/01 |


