@@ -59,36 +59,35 @@ def generate_unique_combinations(built_permutation, remaining_columns, full_perm
59
59
# remove the most recent column and put it back on the remaining column list where we found it (sorted)
60
60
remaining_columns .insert (c , built_permutation .pop (- 1 ))
61
61
62
- import pickle
63
62
import os
64
63
from os import environ , path
65
- master_unique_permutation_list = {}
64
+ unique_permutation_list = {}
66
65
def generate_all_unique_combinations (C , M , must_use_all_groups = False ):
67
66
68
67
cache_dir_path = ASP_CACHE_DIR_DEFAULT
69
68
# The user is allowed to set the cache directory via an environment variable.
70
69
if environ .get (ASP_CACHE_DIR_ENV_VAR ) is not None :
71
70
cache_dir_path = environ .get (ASP_CACHE_DIR_ENV_VAR )
72
- cache_file_path = path .join (cache_dir_path , "master_list.pkl " )
71
+ cache_file_path = path .join (cache_dir_path , f"permutations_ { C } _ { M } .npy " )
73
72
74
- global master_unique_permutation_list
75
- if len ( master_unique_permutation_list ) == 0 and path . exists ( cache_file_path ) :
76
- with open (cache_file_path , "rb" ) as cache :
77
- master_unique_permutation_list = pickle .load (cache )
73
+ global unique_permutation_list
74
+ if ( C , M ) not in unique_permutation_list :
75
+ if path . exists (cache_file_path ) :
76
+ unique_permutation_list [( C , M )] = np .load (cache_file_path , allow_pickle = False )
78
77
79
- if (C ,M ) not in master_unique_permutation_list :
80
- full_permutation_list = []
81
- generate_unique_combinations ([0 ], [c for c in range (1 ,C )], full_permutation_list , M )
82
- master_unique_permutation_list [(C ,M )] = full_permutation_list
83
- if not path .exists (cache_dir_path ):
84
- os .makedirs (cache_dir_path )
85
- with open (cache_file_path , "wb" ) as cache :
86
- pickle .dump (master_unique_permutation_list , cache )
78
+ else :
79
+ full_permutation_list = []
80
+ generate_unique_combinations ([0 ], [c for c in range (1 ,C )], full_permutation_list , M )
81
+ unique_permutation_list [(C ,M )] = full_permutation_list
82
+ if not path .exists (cache_dir_path ):
83
+ os .makedirs (cache_dir_path )
84
+ np .save (cache_file_path , full_permutation_list , allow_pickle = False )
87
85
88
- unique_permutations = master_unique_permutation_list [(C ,M )]
86
+ unique_permutations = unique_permutation_list [(C ,M )]
89
87
90
88
return unique_permutations
91
89
90
+
92
91
# analytical solution
93
92
import math
94
93
def predict_unique_combinations (C , M ):
0 commit comments