Repository navigation
How to propagate constraints through a layered @vsc.randobj hierarchy?
#267
Replies: 1 comment
|
The constraints are fine. The problem is that the sub-objects are declared with In pyvsc,
The fix is to declare every nested object you want solved as @vsc.randobj
class Packet:
def __init__(self):
self.size = vsc.rand_uint16_t()
self.payload = vsc.rand_attr(Container()) # was vsc.attr
@vsc.randobj
class Container:
def __init__(self):
self.type = vsc.rand_enum_t(CType)
self.size = vsc.rand_uint16_t()
self.a = vsc.rand_attr(PayloadA()) # was vsc.attr
self.b = vsc.rand_attr(PayloadB()) # was vsc.attrWith only that change, your test gives: The selected payload always gets length 5. The other payload stays random within its own Rule of thumb: use |
Uh oh!
There was an error while loading. Please reload this page.
I am building a layered data structure where a high-level object needs to control the size of a list buried several layers deep.
The hierarchy is:
The Goal
I want to constrain Packet.size in a randomize_with block and have that value "drill down" through the Container to set the actual length of the list inside the Payload.
The Problem
While randomizing the leaf-level Payload and the Container works fine, randomizing the Packet results in a SolveFailure. It seems like the solver sees the top-level constraint but cannot "connect the dots" to the size in the Container and the size at the bottom of the chain.
All reactions