简体   繁体   中英

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.

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.

Now these solved X values are the key value to the D dictionary.

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?

You can turn the list into a tuple . Tuples are hashable and as such are valid dictionary keys.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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