简体   繁体   English

如何使用列表值作为 Z3py 中的字典索引

[英]How to use list value as the dictionary indices in Z3py

I have a python array (Arr) with j number of integer elements, one Z3 list (X) whose values are z3 Int variables and one Z3 dictionary (D) whose values are Z3 Bool variables.我有一个 python 数组(Arr),其中 j 个 integer 元素,一个 Z3 列表(X),其值为 z3 Int 变量和一个 Z3 字典(D),其值为 Z3 Bool 变量。

Eg:例如:


    X = [ [ x_0_0, x_0_1, …, x_0_j],   
          [ x_1_0, x_1_1, …, x_1_j],   
                          …  
          [ x_i_0, x_i_1, …, x_i_j] ]  
    
    X[0] = Arr      /* Arr is python integer array */
    
    
    D = { (x, i, j): D_x_i_j }  for all i and j, and where x is the value present at X[i][j] location.

The remaining values of X[i 1 ][j] are decided by the solver depending on the D value, ie, True/False, where 1<=i 1 <=i. X[i 1 ][j] 的剩余值由求解器根据 D 值决定,即真/假,其中 1<=i 1 <=i。

Now these solved X values are the key value to the D dictionary.现在这些求解的 X 值是 D 字典的键值。

Hence, I want to use these values as the key index of dictionary.因此,我想将这些值用作字典的键索引。

My question is how to use Z3 list values as the key values of Z3 dictionary or as the index of another z3 list?我的问题是如何使用 Z3 列表值作为 Z3 字典的键值或另一个 z3 列表的索引?

You can turn the list into a tuple .您可以将列表转换为tuple Tuples are hashable and as such are valid dictionary keys. Tuples是可散列的,因此是有效的字典键。

d = {(x, i, j): D_x_i_j}
X[0] = Arr                # [x, i, j]
key = tuple(X[0])
print(d[key])             # yields D_x_i_j

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM