1
0
Fork 0

Added some comments

master
Luca Moretti 4 years ago
parent 0f44006371
commit 49172e568b
  1. 12
      main_package/classes/optimizers/tabu_search.py
  2. 8
      main_package/tests/optimizers/test_tabu_search.py

@ -64,11 +64,14 @@ class TabuSearch(Optimizer):
"""
print(f"tabu search is processing the structure of {self.node_id}")
#'Create the graph for the single node'
graph = ng.NetworkGraph(self.structure_estimator.sample_path.structure)
'Create the graph for the single node'
graph = ng.NetworkGraph(self.structure_estimator.sample_path.structure)
'get all the possible parents'
other_nodes = set([node for node in self.structure_estimator.sample_path.structure.nodes_labels if node != self.node_id])
'calculate the score for the node without parents'
actual_best_score = self.structure_estimator.get_score_from_graph(graph,self.node_id)
@ -79,6 +82,7 @@ class TabuSearch(Optimizer):
if self.tabu_rules_duration is None:
self.tabu_tabu_rules_durationength = len(other_nodes)
'inizialize the data structures'
tabu_set = set()
tabu_queue = queue.Queue()
@ -144,7 +148,7 @@ class TabuSearch(Optimizer):
graph.add_edges([current_edge])
'update patience count'
patince_count += 1
tabu_count += 1
if tabu_queue.qsize() >= self.tabu_length:
current_removed = tabu_queue.get()
@ -153,7 +157,9 @@ class TabuSearch(Optimizer):
tabu_queue.put(current_new_parent)
tabu_set.add(current_new_parent)
tabu_count += 1
'Every tabu_rules_duration step remove an item from the tabu list '
if tabu_count % self.tabu_rules_duration == 0:
if tabu_queue.qsize() > 0:
current_removed = tabu_queue.get()

@ -23,7 +23,7 @@ class TestTabuSearch(unittest.TestCase):
@classmethod
def setUpClass(cls):
#cls.read_files = glob.glob(os.path.join('../../data', "*.json"))
cls.importer = ji.JsonImporter("../../data/networks_and_trajectories_ternary_data_04_10.json", 'samples', 'dyn.str', 'variables', 'Time', 'Name')
cls.importer = ji.JsonImporter("../../data/networks_and_trajectories_binary_data_20.json", 'samples', 'dyn.str', 'variables', 'Time', 'Name')
cls.s1 = sp.SamplePath(cls.importer)
cls.s1.build_trajectories()
cls.s1.build_structure()
@ -37,10 +37,10 @@ class TestTabuSearch(unittest.TestCase):
se1 = se.StructureScoreBasedEstimator(self.s1)
edges = se1.estimate_structure(
max_parents = None,
iterations_number = 40,
iterations_number = 30,
patience = None,
tabu_length = 15,
tabu_rules_duration = 15,
tabu_length = 17,
tabu_rules_duration = 20,
optimizer = 'tabu'
)