; SIMPREMI
;
; Program for Proteus
;
; (C) 2003-2004 Simone Zanella Productions
;
; This program simulates a price generator; these are the default parameters:
; 3 operators that, independently, randomly give prices to customers
; 57 prices per our to be given away
; 450 customers
#!proteus -z
DefCustomers = 450
DefPrices = 57
DefOperators = 3
IF STREQ(ARGV(5), "?")
CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) " operators prices_per_hour customers_per_hour"
ABORT 0
FI
IF GE(ARGC, 5)
N = ARGV(5)
IF GE(ARGC, 6)
W = ARGV(6)
IF GE(ARGC, 7)
G = ARGV(7)
ELSE
; Number of customers to be served in one hour
G = DefCustomers
FI
ELSE
; Number of prices to be assigned in one hour
W = DefPrices
; Number of customers to be served in one hour
G = DefCustomers
FI
ELSE
; Number of operators
N = DefOperators
; Number of prices to be assigned in one hour
W = DefPrices
; Number of customers to be served in one hour
G = DefCustomers
FI
; Prices to be assigned in one hour by each operator
WT = FDIV(W, N)
; Initial percentage for each operator
P = SUB(MUL(FDIV(W, G), 100), 2)
; Likelyhood delta (positive or negative) when Win happens
Delta = 0.01
MaxDelta = 0.1
Term = VECNEW(N)
R = MyInitRand()
FOR X = 1 TO N
V = VECNEW(4)
VECSET(Term, X, V)
VECSET(V, 1, R)
VECSET(V, 2, 0)
VECSET(V, 3, QUEUENEW())
VECSET(V, 4, P)
ADD(@R, 7)
NEXT
X = 0
WHILE LE(X, G)
FOR Y = 1 TO N
Win(Y)
NEXT
ADD(@X, N)
LOOP
CONSOLELN "Wins:"
S = ""
FOR X = 1 TO N
S = LTRIM(S " " PADR("-- Operator " X " --", 20, " "), " ")
NEXT
CONSOLELN S
V = VECGET(Term, 1)
Q = VECGET(V, 3)
M = QUEUELEN(Q)
FOR Y = 1 TO M
S = ""
FOR X = 1 TO N
V = VECGET(Term, X)
Q = VECGET(V, 3)
S = LTRIM(S " " PADR(DEQUEUE(Q), 20, " "), " ")
NEXT
CONSOLELN S
NEXT
S = ""
FOR X = 1 TO N
V = VECGET(Term, X)
H = VECGET(V, 2)
S = LTRIM(S " " PADR("Wins total: " H, 20, " "), " ")
NEXT
CONSOLELN S
ABORT 0
FUNCTION Win(nterm)
V = VECGET(_Term, nterm)
H = VECGET(V, 2)
P = VECGET(V, 4)
IF GE(H, PUB(WT))
vinto = 0
ELSE
K = MyRandom()
IF LE(K, P)
vinto = 1
ELSE
vinto = 0
FI
VARIAZIONE = PUB(Delta)
IF vinto
IF GT(P, 0)
SUB(@P, VARIAZIONE)
FI
ELSE
IF LT(P, 100)
ADD(@P, VARIAZIONE)
FI
FI
IF vinto
INC(@H)
FI
FI
; Update H and P for the operator
VECSET(V, 2, H)
VECSET(V, 4, P)
ENQUEUE(VECGET(V, 3), vinto)
RETURN
FUNCTION MyInitRand()
; Initialize seed, based on time
RETURN ADD(CLOCK(), TIMETOSEC(TIME()))
FUNCTION MyRandom()
; Return a number between 1 and 100
RETURN INC(MOD(RANDOM(-1), 100))