A method for adapting a constraint solver, an electronic device and a storage medium
By constructing a tree structure of constraint expressions in chip verification and adapting to different constraint solvers, the problem of low efficiency and insufficient accuracy of constraint solvers in the existing technology in solving complex constraint problems is solved, and a more efficient and accurate solution is achieved. Accurate constraint solving.
Patent Information
- Application Number
- CN202410981947.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2044-07-22
AI Technical Summary
In the field of chip verification, existing constraint solvers have problems with low solving efficiency and inaccurate results when dealing with complex constraint problems. Especially when the constraint expressions contain different operation types, it is difficult for the target solver to effectively disassemble and match them. .
By obtaining the sequence of constraint solvers to be adapted and their adapted operation types, a tree structure of constraint expressions is constructed, the tree structure is traversed to obtain the operation types, and the constraint expressions are disassembled to adapt to different constraint solvers sub-constraints. The sub-constraints obtained by each constraint solver are the types of operations it is good at, improving solution efficiency and accuracy.
It improves the solving efficiency of the constraint solver and the accuracy of the solution results, ensuring that each constraint solver handles the type of operations it is good at, thereby improving the overall computing performance.
Smart Images

Figure CN118504486B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of chip verification, and in particular to a method for adapting a constraint solver, an electronic device and a storage medium. Background Art
[0002] In the field of chip verification, constraint satisfaction problems are often encountered in various scenarios to ensure that the functional correctness and performance indicators of the design meet predefined specifications. For example, in logic function verification, the Boolean function relationship or other logical relationship between logic gates, combinational logic circuits and sequential logic circuits needs to be satisfied, or in timing constraints, the timing design is verified by checking whether the delay constraints on all signal paths are satisfied, or in the layout and routing stage, the constraints designed to ensure the minimum spacing or avoid short circuits, etc. Constraint satisfaction problems are also designed in low-power verification, formal verification or random constraints. Many problems in the field of chip verification can be converted into constraint problems, so that they can be solved using general constraint solvers.
[0003] The general solvers used for solving constraint problems include SAT (Boolean satisfiability problem) solvers, SMT (Satisfiability modulo theories) solvers, CSP (Constraint satisfaction problem) solvers, and BDD (Binary decision diagram)-based solvers. Each type of solver is good at solving different problems. Among them, SAT solvers are good at solving bit operations; SMT solvers are good at solving combinatorial problems, such as constraint problems that combine arithmetic, Boolean logic, arrays, etc.; CSP solvers are good at arithmetic operations, relational operations, and set relational operations; BDD solvers are good at dealing with the representation and optimization of Boolean functions.
[0004] At present, when dealing with constraint problems, the corresponding constraint problems are usually classified in advance according to the operation type, divided into different operation categories, and then the appropriate target solver is matched according to the operation category, and the problem is solved by the target solver. When each constraint expression in a complex constraint problem includes different operation types, it will be classified according to the pre-set priority rules, and the expression will be divided into corresponding categories, and then solved by the corresponding target solver. However, when there are operation types in the constraint expression that the target solver is not good at, the target solver will have low solution efficiency and inaccurate solution results. Therefore, there is an urgent need for a method to improve the computational efficiency and accuracy of the constraint solver. Summary of the invention
[0005] In view of the above technical problems, the technical solution adopted by the present invention is: a method for adapting a constraint solver, the method comprising the following steps:
[0006] S100, obtaining N types of constraint solver sequences CS to be adapted and their adapted operation types; wherein CS={CS1, CS2, …, CS i ,…,CS N}, CS i is the i-th constraint solver in CS, and the value of i ranges from 1 to N.
[0007] S200, obtaining a constraint expression exp of a constraint solver to be adapted.
[0008] S300, constructing a tree structure tree of the constraint expression according to exp.
[0009] S400, traverse the tree to obtain the operation type, and obtain the constraint conditions P={P1,P2,…,P i ,…,P N}, P i To adapt to CS i The constraint condition of P i =(V,VM i ,VMC(i),CC i ,CF), V is the original variable set of all variables in exp, VM i To adapt to CS i The current intermediate variable set generated, VMC(i) is the variable in CS except CS i Other intermediate variable sets of all constraint solvers except CC i For CS i The newly generated sub-constraint set, CF, is the remaining constraint set that cannot be matched by any of the N types of constraint solvers; i The jth current intermediate variable VM ij and its newly added sub-constraint CC ij The generation steps include:
[0010] S410, obtaining the last updated tree structure tree'.
[0011] S420, traverse upward from the leaf nodes of tree´, and adapt CS according to the traversal i The operation type obtains the maximum subtree subtree that is suitable for i , and according to subtree i Get CS i The jth subexpression subexp ij .
[0012] S430, create CS i The jth current intermediate variable VM ij .
[0013] S440, subtree in tree´ i Replace with a bound VM ij 's node to obtain the updated tree structure tree".
[0014] S450, according to VM ij and subexp ij Generate CS i New sub-constraint CC ij .
[0015] In addition, the present invention also provides a non-transitory computer-readable storage medium, in which at least one instruction or at least one program is stored, and the at least one instruction or the at least one program is loaded and executed by a processor to implement the above method.
[0016] In addition, the present invention also provides an electronic device, including a processor and the above-mentioned non-transitory computer-readable storage medium.
[0017] The present invention has at least the following beneficial effects:
[0018] The present invention provides a method, electronic device and storage medium for adapting a constraint solver. The method pre-sets different types of constraint solvers and their adapted operation types, and adapts the operation types of sub-expressions of a constraint expression to different constraint solvers, thereby decomposing the constraint expression into multiple sub-constraints adapted to different constraint solvers. The sub-constraints obtained by each constraint solver are all operation types that the current constraint solver is good at, thereby improving the solution efficiency of the constraint solver and the accuracy of the solution results. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0020] Figure 1 A flowchart of a method for adapting a constraint solver provided in Embodiment 1 of the present invention;
[0021] Figure 2 A comparison flow chart before and after traversing the tree structure provided in the first embodiment of the present invention;
[0022] Figure 3A flow chart of a method for adapting a constraint solver provided in Embodiment 2 of the present invention. DETAILED DESCRIPTION
[0023] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0024] Embodiment 1
[0025] See also Figure 1 , which shows a flow chart of a method for adapting a constraint solver, the method comprising the following steps:
[0026] S100, obtaining N types of constraint solver sequences CS to be adapted and their adapted operation types; wherein CS={CS1, CS2, …, CS i ,…,CS N}, CS i is the i-th constraint solver in CS, and the value of i ranges from 1 to N.
[0027] Optionally, the type of constraint solver is a SAT (Boolean satisfiability problem) solver, a SMT (Satisfiability modulo theories) solver, a CSP (Constraint satisfaction problem) solver, or a BDD (Binary decision diagram) based solver. Other types of solvers in the prior art also fall within the protection scope of the present invention.
[0028] Among them, there are different types of constraint solvers in CS.
[0029] The adapted operation type refers to the operation type that the constraint solver is good at.
[0030] Optionally, the operation type adapted by the SAT solver is bit operation, and the non-adaptive operation type is arithmetic operation, relational operation and arithmetic operation. The operation types adapted by the CSP solver are arithmetic operation, relational operation and set relational operation, and the non-adaptive operation type is bit operation. The operation type adapted by the SAT solver and the CSP solver is logical operation. In the prior art, other constraint solvers and their adapted operation types also fall within the protection scope of the present invention.
[0031] S200, obtaining a constraint expression exp of a constraint solver to be adapted.
[0032] The constraint problem includes variables, constants and constraint expressions, wherein the variables are signed or unsigned bit vectors with fixed bit width.
[0033] The constraint expression includes operands and operators, and the operands are constants or variables.
[0034] Optionally, the operator is one or more of a logical operator, a bit operator, an arithmetic operator, a relational operator, an if-then-else operator, and a set relational operator. In the prior art, other operators included in the expression also fall within the protection scope of the present invention.
[0035] As an example, the constraint problem is: x is a random variable of an 8-bit vector, and the constraint expression is: x>0&&x<11.
[0036] S300, constructing a tree structure tree of the constraint expression according to exp.
[0037] It should be noted that S300 converts the text expression exp into a structured expression tree, and the structured expression is more conducive to computer processing.
[0038] Each node in the tree is an operand or an operator, and the edges between nodes are the relationships between nodes.
[0039] The methods of constructing a tree structure according to expressions in the prior art all fall within the protection scope of the present invention.
[0040] S400, traverse the tree to obtain the operation type, and obtain the constraint conditions P={P1,P2,…,P i ,…,P N}, P i To adapt to CS i The constraint condition of P i =(V,VM i ,VMC(i),CC i ,CF), V is the original variable set of all variables in exp, VM i To adapt to CS i The current intermediate variable set generated, VMC(i) is the variable in CS except CS i Other intermediate variable sets of all constraint solvers except CC i For CS i The newly generated sub-constraint set, CF, is the remaining constraint set that cannot be matched by any of the N types of constraint solvers.
[0041] Among them, the operation type of the sub-expression corresponding to the maximum subtree obtained by traversing the tree is matched to a constraint solver that is good at processing the current operation type.
[0042] Among them, P i Can be empty. When the tree is traversed, if there is no matching CS in the tree i When the operation type is P i Is empty.
[0043] Among them, the original variable set V of all sub-constraints in P is the same, which is all the variables in exp. After traversing the tree, V is obtained.
[0044] Among them, VM i Each intermediate variable in VM is created when adapting the current constraint solver. i Each intermediate variable in CC i There is a corresponding new sub-constraint in VM i The number of elements in CC i The number of elements in VM is equal. i The newly added sub-constraints in are defined as the mapping relationship between each current intermediate variable and the sub-expression in the exp it replaces.
[0045] Among them, when VM in VMC(i) rp The subtree where the VM is located i VM in ij When replacing, VM rp To adapt the rth constraint solver CS r The pth current intermediate variable VM generated rp , in CC ij Include VM rp By analogy, all generated intermediate variables will appear in all adapted sub-expressions. Therefore, when adapting CS i The constraint condition P i Includes all variables and intermediate variables: V, VM i , VMC(i). Similarly, the constraint sub-conditions adapted to other constraint solvers also include all variables and intermediate variables.
[0046] Each remaining constraint in the remaining constraint set CF is a constraint corresponding to an operation type that cannot be adapted after being adapted to the N types of constraint solvers. The remaining constraint sets of all sub-constraint conditions in P are the same.
[0047] Further, P i The jth current intermediate variable VM ij and its newly added sub-constraint CC ijThe adaptation steps include:
[0048] S410, obtaining the tree structure tree' updated last time by adaptation.
[0049] During the traversal process, each adaptation is performed based on the last updated tree structure.
[0050] S420, traverse upward from the leaf nodes of tree´, and adapt CS according to the traversal i The operation type obtains the maximum subtree subtree that is suitable for i , and according to subtree i Get CS i The jth subexpression subexp ij .
[0051] Among them, subtree i The steps to obtain include:
[0052] S421, traverse upward from the leaf node along the path to the root node. When the operation type of the traversed node is adapted to CS i , continue to traverse upwards; when the operation type of the traversed operator node does not match CS i When , fall back to the last traversal of the adaptation CS i The operator node of the traversal is then returned to continue traversing on another branch. The method for determining the operation type to which the node belongs is: when traversing to the operator node, the operation type is determined according to the operator node.
[0053] S422, after traversing all potential paths, the traversal ends and the subtree is obtained i .
[0054] After traversing the entire tree, multiple matching CS can be obtained. i The largest subtree of .
[0055] In the prior art, other methods for obtaining subtree i All of the methods fall within the protection scope of the present invention.
[0056] S430, create CS i The jth current intermediate variable VM ij .
[0057] S440, subtree in tree´ i Replace with a bound VM ij 's node to obtain the updated tree structure tree".
[0058] Among them, bind VM ijThe nodes are leaf nodes in the tree". The nodes in the tree include variables, operators and intermediate variables.
[0059] S450, according to VM ij and subexp ij Generate CS i New sub-constraint CC ij .
[0060] Optional, VM ij and CC ij Meets: CC ij :=VM ij ==subexp ij Among them, ":=" is the definition symbol, which is CC ij The constraint sub-condition is defined as "VM ij ==subexp ij ”, “VM ij ==subexp ij "Indicates using VM ij Represents subexp ij In the prior art, other VM ij and subexp ij Methods of defining constraints also fall within the scope of protection of the invention.
[0061] As an example, when the VM ij When the subexpression represented is "a|(b&c)", CC ij Meets: CC ij :=VM ij ==a|(b&c).
[0062] As a preferred embodiment, S400 further includes:
[0063] S470, obtaining a remaining constraint set CF, wherein the hth remaining constraint CF ih The steps to obtain include:
[0064] S471, when traversing upward from the leaf node of tree´, obtain the target operation type to which the traversed node belongs. When the target operation type is incompatible with all N types of constraint solvers, obtain the hth incompatible subtree Usubtree ih ; and according to Usubtree ih Get the hth unsuitable subexpression Usubexp ih The method for determining the target operation type to which the node belongs is: when traversing to the operator node, the target operation type is determined according to the operator node.
[0065] S472, create the hth intermediate variable VFh .
[0066] S473, according to VF h and Usubexp ih Generate the hth remaining constraint CF of CF ih .
[0067] In the prior art, other methods for obtaining the residual constraint set all fall within the protection scope of the present invention.
[0068] As a preferred embodiment, S400 also includes: when the operation type of the current operator being traversed is compatible with L-type constraint solvers, and the last adapted constraint solver is one of the L-type constraint solvers, adapting the current operator to the last adapted constraint solver.
[0069] It is understandable that during the traversal process, the largest subtree subtree that is adapted i Replaced with the intermediate variable VM ij And update the tree structure tree″, and when traversing the next node, the traversal is based on tree″. When all traversals are completed, all constraints of all constraint solvers adapted by exp are obtained.
[0070] As an example, CS={CS1,CS2}, where CS1 is a SAT solver, CS2 is a CSP solver, CS1 is suitable for bitwise and logical operations, and CS2 is suitable for arithmetic, relational, set relational, and logical operations. The constraint expression is: g->((x+(y×z))>(a|(b&c))), the tree structure of the constraint expression is tree, see Figure 2 (a) shows the tree. First, adapt CS1, traverse upward from the leaf nodes of the tree, and obtain the largest subtree subtree1 that adapts CS1. The sub-expression corresponding to subtree1 is "a|(b&c)". Create the first intermediate variable VM of CS1 11 , using VM 11 Replace subtree1 and update the tree structure to get tree´, according to VM 11 Generate the first new sub-constraint with subtree1: CC 11 :=VM 11 ==(a|(b&c)). The tree structure of tree´ is as follows Figure 2 As shown in (b), CS2 is then adapted, and tree´ is traversed upward from the leaf nodes to obtain the largest subtree subtree2 that is adapted to CS2. The sub-expression corresponding to subtree2 is “((x+(y×z))> VM 11". Create the first intermediate variable VM of CS2 21 , using VM 21 Replace subtree2 and update the tree structure to get tree″, according to VM 21 Generate the first new sub-constraint with subtree2: CC 21 :=VM 21 ==((x+(y×z)) > VM 11 The tree structure of tree" is as follows Figure 2 As shown in (c), since the last remaining operator is "->", the operation type of this logical operation is compatible with both CS1 and CS2. Since the last adapted constraint solver is CS2, in order to optimize the algorithm, we continue to adapt CS2 at this time, traverse upward from the leaf node of tree", and obtain the largest subtree subtree3 that is adapted to CS2. The sub-expression corresponding to subtree3 is "g->VM 21 ". Create the second intermediate variable VM of CS2 22 , using VM 22 Replace subtree3, and finally replace the tree structure with a node, according to VM 22 And subtree3 generates the second new sub-constraint: CC 22 :=VM 22 ==g->VM 21 After the traversal is completed, the constraints P={P1,P2} suitable for each type of constraint solver are obtained, where P1=(V,VM1,VM2,CC1,CF) and P2=(V,VM2,VM1,CC2,CF). The original variable set V={a,b,c,x,y,z,g}, VM1={VM 11},VM2={VM 21 ,VM 22},CC1={CC 11},CC2={CC 21 ,CC 22},CF= .
[0071] In summary, the present invention provides a method for adapting a constraint solver, which presets different types of constraint solvers and their adapted operation types, converts the constraint expression to be adapted into a tree structure, adapts the obtained operation type to the preset different types of constraint solvers in the process of traversing the tree structure, replaces the adapted maximum subtree with a node of an intermediate variable, and then continues to traverse and adapt, and finally completes the decomposition of the constraint expression into multiple sub-constraints adapted to different constraint solvers, and the sub-constraints obtained by each constraint solver are all operation types that the current constraint solver is good at, thereby improving the solution efficiency of the constraint solver and the accuracy of the solution results.
[0072] Embodiment 1 of the present invention also provides a non-transitory computer-readable storage medium, which can be set in an electronic device to store at least one instruction or at least one program related to implementing a method in the method embodiment. The at least one instruction or the at least one program is loaded and executed by the processor to implement the method provided in the above embodiment.
[0073] Embodiment 1 of the present invention further provides an electronic device, including a processor and the aforementioned non-transitory computer-readable storage medium.
[0074] Embodiment 1 of the present invention further provides a computer program product, which includes program code. When the program product is run on an electronic device, the program code is used to enable the electronic device to execute the steps of the method according to various exemplary embodiments of the present invention described above in this specification.
[0075] The method provided in the first embodiment of the present invention can improve the solving efficiency and solving accuracy of each solver, but there may be dependencies between multiple sub-constraints adapted by different constraint solvers. When N constraint solvers jointly solve the same constraint expression, the sub-constraints may wait for each other, resulting in low computing efficiency. Therefore, based on the first embodiment, the present invention also provides a second embodiment, which optimizes the collaborative process of N constraint solvers to improve computing efficiency.
[0076] Embodiment 2
[0077] See also Figure 3 , which shows a flow chart of a collaborative method based on multiple constraint solvers, the method comprising:
[0078] P100, obtain N types of constraint solvers CS.
[0079] Optionally, the constraint solver may also be a core algorithm of the constraint solver.
[0080] P200, obtain the constraint conditions P of each type of constraint solver in CS that adapts the constraint expression exp, where the constraints of each type of constraint solver include the original variable set V of all variables in exp, the current intermediate variable set VM generated by the current constraint solver, the other intermediate variable sets VMC of all constraint solvers except the current constraint solver, the newly added sub-constraint set CC generated by the current constraint solver, and the remaining constraint set CF that cannot be matched by N types of constraint solvers.
[0081] It should be noted that the constraint solver CS, constraint expression exp, constraint condition P and the steps for obtaining the same in the first embodiment are all applicable to the second embodiment and will not be described in detail.
[0082] As can be seen from the first embodiment, the i-th constraint solver CS i VM i The jth current intermediate variable VM ij The steps of obtaining include: when the subexpression subexp of exp ij The operation type and the i-th constraint solver CS i When the operation type that the binding is good at is adapted, subexp ij Replace with VM ij CS i CC i The jth newly added sub-constraint CC ij The acquisition steps include: according to subexp ij and VM ij Generate CS i New sub-constraint CC ij .
[0083] P300, based on P, collaboratively calculates exp, including the following loop steps:
[0084] P310, each type of constraint solver in CS selects candidate variables from V and its own VM respectively to obtain candidate variables for each type of constraint solver.
[0085] The step of selecting candidate variables is completed inside each constraint solver. The candidate variables selected by each constraint solver are original variables in the original variable set or intermediate variables in the current intermediate variable set.
[0086] Optionally, each type of constraint solver selects candidate variables according to preset internal rules, wherein the internal rules are rules for selecting variables within each type of constraint solver preset in advance by the user.
[0087] P320, the collaborative scheduler selects L target candidate variables from all candidate variables of CS, and obtains random values of the L target candidate variables respectively, where L is greater than or equal to 1, and L≤N.
[0088] Optionally, a collaborative scheduler is used to collaboratively solve multiple constraint solvers. It is a pre-designed, reusable software structure framework that is responsible for scheduling each constraint solver to collaboratively calculate and solve.
[0089] Optionally, the collaborative scheduler selects target candidate variables according to preset global rules. The global rules are rules preset in advance for reselecting target candidate variables from candidate variables of all constraint solvers. Optionally, the global rules include the frequency of occurrence of candidate variables and the value range of candidate variables. In the prior art, other rules for selecting target candidate variables also fall within the protection scope of the present invention.
[0090] P330, add L target candidate variables and their random values to the list to be propagated bList.
[0091] P340, when the target candidate variable in bList is empty, the collaborative calculation result of exp is obtained and the loop ends.
[0092] It should be noted that when the target candidate variable in bList is empty, it means that all the original variables of V in P310 and all the intermediate variables of all constraint solvers have been selected and propagated, and all variables have obtained corresponding values. At this time, the collaborative calculation result of exp can be obtained.
[0093] P350, when the target candidate variable in bList is not empty, each constraint solver propagates bList within the scope of its respective CC and CF.
[0094] It can be understood that by propagating bList, it can be ensured that within the scope of CC and CF of each constraint solver, when the value of the target candidate variable changes, all other variables and constraints affected by this change can be updated accordingly, so that the entire system can meet all constraints. This collaborative method selects the target candidate variable and its random value through the collaborative scheduler, so that N constraint solvers can perform collaborative calculations, thereby improving the calculation efficiency.
[0095] All the prior art propagation mechanisms for propagating variable values fall within the protection scope of the present invention.
[0096] It is important to understand that when the value of a variable is propagated and updated, the impact of the updated value of the variable on the constraints and other variables related to it is checked. If the updated value does not satisfy the current constraints, the values of other variables related to it are adjusted to re-satisfy the current constraints. This process is performed recursively until a stable state is reached, that is, all constraints are satisfied, or it is determined that there is no solution.
[0097] As a preferred embodiment, the P350 further includes an i-th constraint solver CS i Propagate the tth target candidate variable var t and its rth random value data r Steps:
[0098] P351, when CS i When a conflict occurs during the propagation process, it returns to the co-scheduler, which calls CS i The rollback function executes steps P3511-P3513 to roll back.
[0099] A conflict is when a variable value is changed or assigned a value that violates other existing constraints. There are many types of conflicts. For example, a logical conflict occurs when the value of a variable causes a directly related constraint to no longer hold.
[0100] Among them, each constraint solver has three functions. The first function is to select candidate variables, the second function is the propagation function, and the third function is the fallback function.
[0101] P3511, get var t The current range of t .
[0102] Among them, data r var t The random value of t var t All possible values that can be obtained theoretically. During the propagation process, if var t The value is determined, which actually reduces the range t Reduced to data r When data r When the propagation fails, it means data r The constraints cannot be met and need to be changed from rang t Excluded.
[0103] P3512, data r From rang t Exclude from the equation, and get var t The update range of rang t ´.
[0104] P3513, when rang t If it is not empty, it will go back to S310; otherwise, the return is unsuccessful, the calculation fails, and the loop of S300 is exited.
[0105] It should be noted that if rang t´ is empty, indicating that there is no possible value that can satisfy all relevant constraints, that is, the constraint expression has no solution, so the calculation fails. Determining the value of each variable by this fallback method can reduce the amount of calculation and improve the calculation efficiency.
[0106] Other fallback methods for conflicts in the prior art all fall within the protection scope of the present invention.
[0107] As a preferred embodiment, the P350 further includes an i-th constraint solver CS i The propagation of the tth target candidate variable var t and its rth random value data r Steps:
[0108] P352, when CS i When no conflict occurs during the propagation process, the following steps are included:
[0109] P3521, check V, CS i The current set of intermediate variables VM i , except CS i Whether the current value range of the variable in other intermediate variable sets VMC(i) of all other constraint solvers has changed.
[0110] Among them, var t data r When changes occur, it will cause direct or indirect dependence on var t The range of other variables in changes. That is, when var t Random value data r Once determined, the constraints associated with it will be re-evaluated, which in turn affects the legal value range of other variables that depend on these constraints. r The propagation not only updates var t The actual value of , and more importantly, the value range of the variables in all constraints is adjusted through propagation.
[0111] P3522, if it exists, gets the intersection of the value ranges before and after the change.
[0112] P3523, if the intersection is not empty, then var t andrang t Add to the list to be propagated and return P350. In this way, the values of the variables that satisfy the constraints are synchronized to all constraint solvers.
[0113] Other methods of synchronizing variable values in the prior art all fall within the protection scope of the present invention.
[0114] As a preferred embodiment, P352 also includes:
[0115] P3524, if the intersection is empty, it is determined that a conflict has occurred and the rollback process is performed according to P351.
[0116] As a preferred embodiment, P350 also includes:
[0117] P353, the co-scheduler excludes the target candidate variables whose values have been determined from bList and returns to S310. For example, the following two cases are target candidate variables whose values have been determined: First, when the random value of the current variable is successfully propagated, the value range of the current variable is the random value of the successful propagation. Second, during the propagation process, the value range of a certain variable is reduced to a value. It has been determined that the value of the current variable satisfies all constraints, so no further propagation is required.
[0118] In summary, the present invention provides a collaborative method based on multiple constraint solvers, which selects candidate variables through each constraint solver, and then selects the target candidate variable from all candidate variables again through the collaborative scheduler and obtains the random value of the target candidate variable, adds the target candidate variable and its random value to the propagation list, and each constraint solver propagates bList within the scope of its own newly added sub-constraint set and the remaining constraint set. This collaborative method enables all constraint solvers to calculate collaboratively, improving the efficiency and accuracy of calculating constraint expressions.
[0119] An embodiment of the present invention also provides a non-transitory computer-readable storage medium, which can be set in an electronic device to store at least one instruction or at least one program related to implementing a method in a method embodiment. The at least one instruction or the at least one program is loaded and executed by the processor to implement the method provided in the above embodiment.
[0120] An embodiment of the present invention further provides an electronic device, comprising a processor and the aforementioned non-transitory computer-readable storage medium.
[0121] An embodiment of the present invention further provides a computer program product, which includes program code. When the program product is run on an electronic device, the program code is used to enable the electronic device to execute the steps of the method according to various exemplary embodiments of the present invention described above in this specification.
[0122] Although some specific embodiments of the present invention have been described in detail by way of example, it should be understood by those skilled in the art that the above examples are for illustration only and are not intended to limit the scope of the present invention. It should also be understood by those skilled in the art that various modifications may be made to the embodiments without departing from the scope and spirit of the present invention. The scope of the present invention is defined by the appended claims.
Claims
1. A method for adapting a constraint solver, characterized in that: The method comprises the following steps: S100, obtaining N types of constraint solver sequences CS to be adapted and their adapted operation types; wherein CS={CS1, CS2, …, CS i ,…,CS N }, CS i is the i-th constraint solver in CS, and the value of i ranges from 1 to N; S200, obtaining a constraint expression exp of a constraint solver to be adapted; S300, constructing a tree structure tree of the constraint expression according to exp; S400, traverse the tree to obtain the operation type, and obtain the constraint conditions P={P1,P2,…,P i ,…,P N }, P i To adapt to CS i The constraint condition of P i =(V,VM i ,VMC(i),CC i ,CF), V is the original variable set of all variables in exp, VM i To adapt to CS i The current intermediate variable set generated, VMC(i) is the variable in CS except CS i Other intermediate variable sets of all constraint solvers except CC i For CS i The newly generated sub-constraint set, CF, is the remaining constraint set that cannot be matched by any of the N types of constraint solvers; i The jth current intermediate variable VM ij and its newly added sub-constraint CC ij The generation steps include: S410, obtaining the last updated tree structure tree'; S420, traverse upward from the leaf nodes of tree´, and adapt CS according to the traversal i The operation type obtains the maximum subtree subtree that is suitable for i , and according to subtree i Get CS i The jth subexpression subexp ij ; S430, create CS i The jth current intermediate variable VM ij ; S440, subtree in tree´ i Replace with a bound VM ij Nodes of the tree structure tree″ are updated; S450, according to VM ij and subexp ij Generate CS i New sub-constraint CC ij ; Wherein, the method further comprises: S470, obtaining a remaining constraint set CF, wherein the hth remaining constraint CF ih The steps to obtain include: S471, when traversing upward from the leaf node of tree´, obtain the target operation type to which the traversed node belongs. When the target operation type is incompatible with all N types of constraint solvers, obtain the hth incompatible subtree Usubtree ih ; and according to Usubtree ih Get the hth unsuitable subexpression Usubexp ih ; S472, create the hth intermediate variable VF h ; S473, according to Usubexp ih Generate the hth remaining constraint CF of CF ih ; Among them, S420 also includes: subtree i Steps to obtain: S421, traverse upward from the leaf node along the path to the root node, when the operation type of the traversed operator node is adapted to CS i , continue to traverse upwards; when the operation type of the traversed operator node does not match CS i When , fall back to the last traversal of the adaptation CS i The operator node of , after backing off, continues to traverse on another branch; S422, after traversing all potential paths, the traversal ends and the subtree is obtained i .
2. The method according to claim 1, characterized in that The S450 also includes: VM ij and CC ij Meets: CC ij :=VM ij ==subexp ij ; Among them, ":=" is a definition symbol.
3. The method according to claim 1, characterized in that S400 also includes: when the operation type of the current operator of the traversal is compatible with the L-type constraint solvers, and the last adapted constraint solver is one of the L-type constraint solvers, adapting the current operator to the last adapted constraint solver.
4. The method according to claim 1, characterized in that: The original variable set V of all sub-constraints in P is the same, which is all the variables in exp.
5. The method according to claim 1, characterized in that: The constraint expression in S200 includes operands and operators, and the operands are constants or variables.
6. The method according to claim 5, characterized in that S421 also includes: a method for determining the operation type to which the node belongs is: when traversing to an operator node, determining the operation type according to the operator node.
7. A non-transitory computer-readable storage medium, wherein at least one instruction or at least one program is stored in the storage medium, characterized in that: The at least one instruction or the at least one program is loaded and executed by the processor to implement the method according to any one of claims 1 to 6.
8. An electronic device, characterized in that: The invention comprises a processor and the non-transitory computer-readable storage medium as claimed in claim 7.
