-
Notifications
You must be signed in to change notification settings - Fork 0
/
SapNego.scr
148 lines (132 loc) · 3.28 KB
/
SapNego.scr
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//$ ~/scribbler/scribble/scribblec-assrt.sh -assrt -fair -z3 -batch SapNego.scr
//$ sessionstar SapNego.scr Negotiate C
module SapNego;
type <fstar> "int" from "" as int;
// C = Consumer, P = Producer
global protocol Negotiate(role C, role P)
{
propose(initialPrice: int) from C to P;
//do NegoAux(C, P); @'[initialPrice]'
do NegoAux(C, P); @'P[initialPrice] C[initialPrice]'
}
aux global protocol NegoAux(role C, role P)
//@'[prop: int = 0]' {
@'P[propP: int = 0] C[propC: int = 0]' {
choice at P
{
accpt(confirmedPrice1: int) from P to C;
@"propP = confirmedPrice1"
confirm() from C to P;
}
or
{
counter(counterOfferPrice: int) from P to C;
@"counterOfferPrice < propP || counterOfferPrice > propP"
// TODO: swap C/P roles via do
choice at C
{
accpt(confirmedPrice2: int) from C to P;
@"counterOfferPrice = confirmedPrice2"
confirm() from P to C;
}
or
{
counter(countercounter: int) from C to P;
@"(countercounter < counterOfferPrice || countercounter > counterOfferPrice)
&& (countercounter < propC || countercounter > propC)"
//do NegoAux(C, P); @'[countercounter]'
do NegoAux(C, P); @'P[countercounter] C[countercounter]'
}
or
{
reject() from C to P;
}
}
or
{
reject() from P to C;
}
}
/* FIXME:
// C = Consumer, P = Producer
global protocol Negotiate(role C, role P)
{
propose(initialPrice: int) from C to P;
do NegoAux(C, P); @'P[initialPrice]'
}
aux global protocol NegoAux(role C, role P) @'P[prop: int = 0]' {
choice at P
{
accpt(confirmedPrice1: int) from P to C;
@"prop = confirmedPrice1"
confirm() from C to P;
}
or
{
counter(counterOfferPrice: int) from P to C;
@"counterOfferPrice < prop || counterOfferPrice > prop" // !!!
choice at C
{
accpt(confirmedPrice2: int) from C to P;
@"counterOfferPrice = confirmedPrice2"
confirm() from P to C;
}
or
{
counter(countercounter: int) from C to P;
@"(countercounter < counterOfferPrice || countercounter > counterOfferPrice)
&& (countercounter < prop || countercounter > prop)"
do NegoAux(C, P); @'P[countercounter]'
}
or
{
reject() from C to P;
}
}
or
{
reject() from P to C;
}
}
//*/
/*
global protocol NegotiateOrig(role C, role P)
{
propose(initialPrice: int) from C to P;
do NegoOrigAux(C, P); @'[initialPrice]'
}
aux global protocol NegoOrigAux(role C, role P) @'[prop: int = 0]' {
choice at P
{
accpt(confirmedPrice1: int) from P to C;
@"prop = confirmedPrice1"
confirm() from C to P;
}
or
{
counter(counterOfferPrice: int) from P to C;
@"counterOfferPrice < prop || counterOfferPrice > prop"
choice at C
{
accpt(confirmedPrice2: int) from C to P;
@"counterOfferPrice = confirmedPrice2"
confirm() from P to C;
}
or
{
counter(countercounter: int) from C to P;
@"(countercounter < counterOfferPrice || countercounter > counterOfferPrice)
&& (countercounter < prop || countercounter > prop)"
do NegoOrigAux(C, P); @'[countercounter]'
}
or
{
reject() from C to P;
}
}
or
{
reject() from P to C;
}
}
//*/