-
I have created randobj's that store rangelist values in their properties. These properties are then used in constraints. My problem is that updating the value of a rangelist-holding property to a new rangelist has no effect. Constraints seem to remember only the initial rangelist that is stored in a property. The example below illustrates the problem. The Selector.available property is initialized to Is this expected? Is there a good workaround? I realize that instead of being a rangelist, Selector.available could be of type list_t. However, this would lose the efficiency representing large sets of contiguous integers in a rangelist. import vsc
@vsc.randobj
class Selector:
def __init__(self):
self.available = vsc.rangelist((0, 999))
self.selected = vsc.rand_uint64_t()
@vsc.constraint
def max_c(self):
self.selected.inside(self.available)
selector = Selector()
outStr = "A:"
for i in range(10):
selector.randomize()
outStr += "\t" + str(selector.selected)
print(outStr)
# Change the range that numbers are selected from.
selector.available = vsc.rangelist((1000, 1999))
outStr = "B:"
for i in range(10):
selector.randomize()
outStr += "\t" + str(selector.selected)
print(outStr)
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@msmftc, interesting usage of rangelist! Certainly not one I had in mind when implementing the construct, but seems useful and valid to me. The core issue, here, is that rangelist doesn't currently provide a mechanism for updating the rangelist data model. Assigning to the attribute simply points 'available' to a new rangelist while the constraint is still looking at the old one. |
Beta Was this translation helpful? Give feedback.
@msmftc, interesting usage of rangelist! Certainly not one I had in mind when implementing the construct, but seems useful and valid to me. The core issue, here, is that rangelist doesn't currently provide a mechanism for updating the rangelist data model. Assigning to the attribute simply points 'available' to a new rangelist while the constraint is still looking at the old one.
I'll create an enhancement request for this and plan to look at it in the near future. Shouldn't be too difficult to support updating a rangelist...