-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbidding.nls
116 lines (103 loc) · 3.64 KB
/
bidding.nls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
;;; File to be included in stock_market.nlogo
;;;
;;; Bidding modules for "stock market" NetLogo Models
;;;
;;; Version 1.0 (2015) Jihe GAO ( jihe.gao@jiejiaotech.com)
;;; Adapted to NetLogo 5.1 (2015)
;;;
;;; Requirements: breeds needed to have following two variables:
;;; breeds-own [ long-orders short-orders ]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;; long-orders
;; There is nothing magical about biddings: they are simply items
;; of a specific list. Check list processing in NetLogo. However
;; here are some usefull procedures.
;;; creates a new bidding. (does not stores it in bidding memory).
to-report create-bidding [b-price content]
report (list b-price content)
end
;;; reports type of a bidding.
to-report get-bidding-price [bel]
report first bel
end
;; reports the content of bidding
to-report bidding-content [bel]
report item 1 bel
end
;; Adding information to the biddings structure
to add-long-bidding [bel]
if member? bel long-orders [stop]
set long-orders lput bel long-orders
if length long-orders > 200 [set long-orders but-first long-orders]
end
;; Removing a bidding from the list of biddings.
to remove-long-bidding [bel]
set long-orders remove bel long-orders
end
;; Adding information to the biddings structure
to add-short-bidding [bel]
if member? bel short-orders [stop]
set short-orders lput bel short-orders
if length short-orders > 200 [set short-orders but-first short-orders]
end
;; Removing a bidding from the list of biddings.
to remove-short-bidding [bel]
set short-orders remove bel short-orders
end
;;; return true if a specific bidding belong to the set of biddings
to-report exists-long-bidding [bel]
ifelse member? bel long-orders [report true] [report false]
end
;;; Reports true if a bidding in the form of ["b-type" etc etc etc ...] exist in biddings list
to-report exist-long-orders-of-price [b-price]
let blfs filter [first ? = b-price] long-orders
ifelse empty? blfs [report false] [report true]
end
;;; return true if a specific bidding belong to the set of biddings
to-report exists-short-bidding [bel]
ifelse member? bel short-orders [report true] [report false]
end
;;; Reports true if a bidding in the form of ["b-type" etc etc etc ...] exist in biddings list
to-report exist-short-orders-of-price [b-price]
let blfs filter [first ? = b-price] short-orders
ifelse empty? blfs [report false] [report true]
end
;;; Returns all biddings of b-type in a list
to-report long-orders-of-price [b-price]
report filter [first ? = b-price] long-orders
end
;;; Returns all biddings of b-type in a list
to-report short-orders-of-price [b-price]
report filter [first ? = b-price] short-orders
end
;;; Returns the first bidding of a certain type and removes it
to-report get-long-bidding [b-price]
ifelse exist-long-orders-of-price b-price
[let bel first filter [first ? = b-price] long-orders
remove-long-bidding bel
report bel
]
[report false]
end
to-report get-short-bidding [b-price]
ifelse exist-short-orders-of-price b-price
[let bel first filter [first ? = b-price] short-orders
remove-short-bidding bel
report bel
]
[report false]
end
to-report read-first-long-bidding-of-price [b-price]
report first long-orders-of-price b-price
end
to-report read-first-short-bidding-of-price [b-price]
report first short-orders-of-price b-price
end
;to update-long-bidding [bel]
; remove-long-bidding read-first-long-bidding-of-price get-first-long-bidding-price bel
; add-long-bidding bel
;end
;to update-short-bidding [bel]
; remove-short-bidding read-first-short-bidding-of-price get-first-short-bidding-price bel
; add-short-bidding bel
;end