Code Monkey home page Code Monkey logo

Comments (2)

alwilson avatar alwilson commented on September 23, 2024

You can use try-except blocks to catch randomize_with() failures. You can also run with solve_fail_debug=1 on the failure to see diagnostics for the failure.

import vsc
import random

@vsc.randobj
class my_item_c:
    def __init__(self):
        self.a = vsc.rand_uint8_t()
        self.b = vsc.rand_uint8_t()

    @vsc.constraint
    def ab_c(self):
        self.a + self.b < 10

my_item = my_item_c()

for _ in range(10):
    v = random.randrange(0, 20)
    try:
        with my_item.randomize_with() as it:
            it.a == v
        print(f'(a == {v}) hit')
    except:
        print(f'(a == {v}) unsolvable')
        try:
            with my_item.randomize_with(solve_fail_debug=1) as it:
                it.a == v
        except:
            pass

Output:

(a == 9) hit
Solve failure: set 'solve_fail_debug=1' for more details
(a == 14) unsolvable
Problem Set: 2 constraints
  <unknown>:
    ((a + b) < 10);
  <unknown>:
    (a == 14);

(a == 3) hit
(a == 6) hit
(a == 1) hit
Solve failure: set 'solve_fail_debug=1' for more details
(a == 18) unsolvable
Problem Set: 2 constraints
  <unknown>:
    ((a + b) < 10);
  <unknown>:
    (a == 18);

(a == 2) hit
(a == 0) hit
(a == 4) hit
Solve failure: set 'solve_fail_debug=1' for more details
(a == 18) unsolvable
Problem Set: 2 constraints
  <unknown>:
    ((a + b) < 10);
  <unknown>:
    (a == 18);

from pyvsc.

mballance avatar mballance commented on September 23, 2024

There isn't currently a direct method for doing this, since the randomize allows the field values to be overwritten. Please file an enhancement request if this is functionality you need.

from pyvsc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.