Skip to content

Commit a8b113e

Browse files
minor fixes
1 parent 5d7e961 commit a8b113e

File tree

2 files changed

+0
-66
lines changed

2 files changed

+0
-66
lines changed

algorithm/guided_local_search.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,11 @@ def solve(self):
5252
cost = tools.compute_solution(self.problem, tmp_solution)
5353
self.history.append(cost)
5454
if self.cur_cost > cost:
55-
# print('less')
5655
self.solution = tmp_solution
5756
self.cur_cost = cost
5857
self.last_state = epoch
5958
unimprove_counter = 0
6059
else:
61-
# self.solution = tmp_solution
62-
# self.cur_cost = cost
6360
no_improve_counter += 1
6461
self.update_penalty()
6562
self.refresh_params()
@@ -78,19 +75,13 @@ def update_penalty(self):
7875
self.utility = np.zeros((self.n, self.n), dtype=np.float32)
7976
for i in range(self.n):
8077
for j in range(self.n):
81-
# dist = self.dist[self.solution[i]][self.solution[j]]
8278
dist = self.dist[i][self.solution[i]]
8379
flow = self.flow[i][j]
8480
c = dist * flow
85-
# self.utility[self.solution[i]][self.solution[j]] = \
86-
# c / (1 + self.penalty[self.solution[i]][self.solution[j]])
8781
self.utility[i][self.solution[i]] = \
8882
c / (1 + self.penalty[i][self.solution[i]])
8983
maximized = self.utility.max()
9084
for i in range(self.n):
91-
# for j in range(self.n):
92-
# if self.utility[self.solution[i]][self.solution[j]] == maximized:
93-
# self.penalty[self.solution[i]][self.solution[j]] += 1
9485
if self.utility[i][self.solution[i]] == maximized:
9586
self.penalty[i][self.solution[i]] += 1
9687

@@ -101,13 +92,9 @@ def augmented_cost(problem, solution, params):
10192
mu = params['mu']
10293
n = params['n']
10394
total_penalty = 0
104-
# for i in range(n):
105-
# for j in range(n):
106-
# total_penalty += penalty[solution[i]][solution[j]]
10795
for i in range(n):
10896
total_penalty += penalty[i][solution[i]]
10997
_lambda = cost / n
110-
# print( mu * _lambda )
11198
return cost + mu * _lambda * total_penalty
11299

113100

@@ -139,5 +126,4 @@ def get_history(self):
139126
plt.grid()
140127
plt.legend()
141128
plt.title(self.name)
142-
# plt.show()
143129
return self.history

utils/tools.py

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -30,55 +30,3 @@ def get_problem_dct(path) -> dict:
3030
return dict(n=n,
3131
dists=distances,
3232
flows=flows)
33-
34-
35-
def generate_stat(algorithms,
36-
benchmarks,
37-
alg_params,
38-
n_observations=3,
39-
**params):
40-
41-
for algorithm, params in zip(algorithms, alg_params):
42-
test_knap = dict(benchmarks[1], **params)
43-
assert isinstance(algorithm(test_knap), Algorithm)
44-
45-
info_dct = {
46-
'algorithm': [],
47-
'benchmark': [],
48-
'capacity': [],
49-
'preprocessing': [],
50-
'execution': [],
51-
'observation': [],
52-
'optim_weight': [],
53-
'optim_profit': [],
54-
}
55-
for observation in range(n_observations):
56-
57-
for key in benchmarks:
58-
59-
knapsack = benchmarks[key]
60-
61-
for algorithm, params in zip(algorithms, alg_params):
62-
63-
knapsack = dict(knapsack, **params)
64-
65-
start_time = datetime.now()
66-
alg = algorithm(knapsack)
67-
preprocess = datetime.now() - start_time
68-
69-
start_time = datetime.now()
70-
optimal = alg.solve()
71-
execution = datetime.now() - start_time
72-
73-
w, p = compute_knapsack(knapsack, optimal)
74-
75-
76-
info_dct['algorithm'] += [alg.name]
77-
info_dct['benchmark'] += [key]
78-
info_dct['capacity'] += [knapsack['capacity'][0]]
79-
info_dct['preprocessing'] += [preprocess.total_seconds()]
80-
info_dct['execution'] += [execution.total_seconds()]
81-
info_dct['observation'] += [observation]
82-
info_dct['optim_weight'] += [w]
83-
info_dct['optim_profit'] += [p]
84-
return pd.DataFrame.from_dict(info_dct)

0 commit comments

Comments
 (0)