Skip to content

Commit 3d944b2

Browse files
committed
Fix up some documentation bugs
1 parent 31c53db commit 3d944b2

File tree

2 files changed

+50
-49
lines changed

2 files changed

+50
-49
lines changed

constrainedrandom/randobj.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ def set_solver_mode(self,
9393
9494
Solvers are used in the following order:
9595
1. Naive solve - randomizing and checking constraints.
96-
For some problems, it is more expedient to skip this
97-
step and go straight to a MultiVarProblem.
96+
For some problems, it is more expedient to skip this
97+
step and go straight to a MultiVarProblem.
9898
2. Sparse solve - graph-based exporation of state space.
99-
Start with depth-first search, move to wider subsets
100-
of each level of state space until valid solution
101-
found.
99+
Start with depth-first search, move to wider subsets
100+
of each level of state space until valid solution
101+
found.
102102
3. Thorough solve - use constraint solver to get
103-
all solutions and pick a random one.
103+
all solutions and pick a random one.
104104
105105
If a solver step is enabled it will run, if disabled
106106
it won't run.

docs/howto.rst

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -733,46 +733,6 @@ We can mix temporary values with temporary constraints:
733733
print(r.op0, r.op1)
734734
735735
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-
def plus_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-
776736
``pre_randomize`` and ``post-randomize``
777737
----------------------------------------
778738

@@ -821,8 +781,49 @@ Optimization
821781

822782
This section deals with how to optimize ``constrainedrandom`` for a given problem.
823783

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+
def plus_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+
824825
Constraint solving algorithms
825-
=============================
826+
_____________________________
826827

827828
``constrainedrandom`` employs three approaches to solving constraints, in order:
828829

@@ -840,7 +841,7 @@ Construct a full constraint solution problem. Fully solve the CSP, finding all p
840841

841842

842843
Setting which solvers to use
843-
============================
844+
____________________________
844845

845846
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.
846847

@@ -859,7 +860,7 @@ The user can turn the other solvers on/off in the same manner. If a solver is no
859860
r.set_solver_mode(sparse=False, thorough=True)
860861
861862
Tweaking parameters
862-
===================
863+
___________________
863864

864865
``constrainedrandom`` has two main parameters that affect constraint solution, which can be set when constructing a ``RandObj``.
865866

0 commit comments

Comments
 (0)