You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/howto.rst
+44-43Lines changed: 44 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -733,46 +733,6 @@ We can mix temporary values with temporary constraints:
733
733
print(r.op0, r.op1)
734
734
735
735
736
-
Ordering hints
737
-
--------------
738
-
739
-
Sometimes, a randomization problem is much easier to solve if the variables are considered in a specific order.
740
-
741
-
Consider this example:
742
-
743
-
.. code-block:: python
744
-
745
-
import random
746
-
747
-
from constrainedrandom import RandObj
748
-
749
-
750
-
random.seed(0)
751
-
r = RandObj()
752
-
r.add_rand_var("x", range(100))
753
-
r.add_rand_var("y", range(100))
754
-
defplus_one(x, y):
755
-
return y == x +1
756
-
r.add_constraint(plus_one, ("x", "y"))
757
-
r.randomize()
758
-
759
-
In the above example, ``y`` must equal ``x + 1``. If we randomize the two variables at the same time and check the constraints, this is hard to get right randomly (a probability of 0.001).
760
-
761
-
If we randomize the variables in an order, e.g. ``x`` first then ``y`` second, the problem becomes trivially easy. We can hint to the library what order might be most performant using ordering hints.
762
-
763
-
The ``order`` argument to ``add_rand_var`` allows us to specify what order to attempt to solve the variables with respect to one another. It defaults to ``order=0`` if not specified.
764
-
765
-
.. code-block:: python
766
-
767
-
# Solve x first, then y
768
-
r.add_rand_var("x", range(100), order=0)
769
-
r.add_rand_var("y", range(100), order=1)
770
-
771
-
Many problems will be faster to solve if the user specifies a sensible ordering hint. (Obviously, the above problem is a bit silly, and in practice the user should only randomize one variable and then add one to it.)
772
-
773
-
.. warning::
774
-
It is possible to significantly slow down the solver speed with bad ordering hints, so only use them when you are sure the order you've specified is faster.
775
-
776
736
``pre_randomize`` and ``post-randomize``
777
737
----------------------------------------
778
738
@@ -821,8 +781,49 @@ Optimization
821
781
822
782
This section deals with how to optimize ``constrainedrandom`` for a given problem.
823
783
784
+
Ordering hints
785
+
______________
786
+
787
+
Sometimes, a randomization problem is much easier to solve if the variables are considered in a specific order.
788
+
789
+
Consider this example:
790
+
791
+
.. code-block:: python
792
+
793
+
import random
794
+
795
+
from constrainedrandom import RandObj
796
+
797
+
798
+
random.seed(0)
799
+
r = RandObj()
800
+
r.add_rand_var("x", range(100))
801
+
r.add_rand_var("y", range(100))
802
+
defplus_one(x, y):
803
+
return y == x +1
804
+
r.add_constraint(plus_one, ("x", "y"))
805
+
r.randomize()
806
+
807
+
In the above example, ``y`` must equal ``x + 1``. If we randomize the two variables at the same time and check the constraints, this is hard to get right randomly (a probability of 0.001).
808
+
809
+
If we randomize the variables in an order, e.g. ``x`` first then ``y`` second, the problem becomes trivially easy. We can hint to the library what order might be most performant using ordering hints.
810
+
811
+
The ``order`` argument to ``add_rand_var`` allows us to specify what order to attempt to solve the variables with respect to one another. It defaults to ``order=0`` if not specified.
812
+
813
+
.. code-block:: python
814
+
815
+
# Solve x first, then y
816
+
r.add_rand_var("x", range(100), order=0)
817
+
r.add_rand_var("y", range(100), order=1)
818
+
819
+
Many problems will be faster to solve if the user specifies a sensible ordering hint. (Obviously, the above problem is a bit silly, and in practice the user should only randomize one variable and then add one to it.)
820
+
821
+
.. warning::
822
+
It is possible to significantly slow down the solver speed with bad ordering hints, so only use them when you are sure the order you've specified is faster.
823
+
824
+
824
825
Constraint solving algorithms
825
-
=============================
826
+
_____________________________
826
827
827
828
``constrainedrandom`` employs three approaches to solving constraints, in order:
828
829
@@ -840,7 +841,7 @@ Construct a full constraint solution problem. Fully solve the CSP, finding all p
840
841
841
842
842
843
Setting which solvers to use
843
-
============================
844
+
____________________________
844
845
845
846
Some problems may be better suited to certain solvers. The ``set_solver_mode`` function allows the user to turn each solver on or off. The order that the solvers run in as described above cannot be changed.
846
847
@@ -859,7 +860,7 @@ The user can turn the other solvers on/off in the same manner. If a solver is no
859
860
r.set_solver_mode(sparse=False, thorough=True)
860
861
861
862
Tweaking parameters
862
-
===================
863
+
___________________
863
864
864
865
``constrainedrandom`` has two main parameters that affect constraint solution, which can be set when constructing a ``RandObj``.
0 commit comments