-
Notifications
You must be signed in to change notification settings - Fork 60
/
default_model.py
45 lines (35 loc) · 1.38 KB
/
default_model.py
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
# Copyright (c) 2020-2023 Renata Hodovan, Akos Kiss.
#
# Licensed under the BSD 3-Clause License
# <LICENSE.rst or https://opensource.org/licenses/BSD-3-Clause>.
# This file may not be copied, modified, or distributed except
# according to those terms.
import random
from .model import Model
class DefaultModel(Model):
"""
Default decision model implementation.
"""
def choice(self, node, idx, weights):
"""
The decision is solely based upon the provided ``weights``.
Parameters ``node`` and ``idx`` are unused.
"""
# assert sum(weights) > 0, 'Sum of weights is zero.'
return random.choices(range(len(weights)), weights=weights)[0]
def quantify(self, node, idx, cnt, start, stop):
"""
After generating the minimum expected items (``start``) and before
reaching the maximum expected items (``stop``), quantify decides about
the expansion of the optional items based on a random binary decision.
Parameters ``node``, ``idx``, ``cnt``, ``start``, and ``stop`` are
unused.
"""
return bool(random.getrandbits(1))
def charset(self, node, idx, chars):
"""
A single character is chosen randomly from the set of possible options
(``chars``).
Parameters ``node`` and ``idx`` are unused.
"""
return chr(random.choice(chars))