-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainExample.py
More file actions
65 lines (53 loc) · 1.8 KB
/
Copy pathMainExample.py
File metadata and controls
65 lines (53 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import numpy as np
import PyCode as src
if __name__ == '__main__':
# Example Instance
num_boxes = 8
max_weight = 24
egg_box = src.EggBox(2,2,2,max_weight)
support_threshold = 0.75
boxes = np.array([
src.SmallBox(1,1,1),
src.SmallBox(1,1,1),
src.SmallBox(1,1,1),
src.SmallBox(1,1,1),
src.SmallBox(1,1,1),
src.SmallBox(1,1,1),
src.SmallBox(1,1,1),
src.SmallBox(1,1,1),
])
weight_boxes = np.array([3,3,3,3,3,3,3,3])
# Definition of Objective Function with DE Optimizer
penalties_weights = np.array([1,1,1])
obj_boxes = src.InitObjectiveBoxes(
egg_box,
boxes,
SupportThreshold = support_threshold,
PenaltiesWeights = penalties_weights,
InitOptimizer = src.DifferentialEvolutionOptimizer,
OptimizerParameters = dict(
Iterations = 10,
PopulationSize = 20,
ScalingFactor = 0.3,
CrossoverRate = 0.6,
),
)
# Definition of Functions for Tabu Search
rand_solution = src.InitRandomBoxesSolution(weight_boxes,max_weight)
generate_neighborhood = src.InitGenerateNeighborhoodBoxes(weight_boxes,max_weight)
# Definitions of TB Optimizer
tabu_search = src.TabuSearchOptimizer(
obj_boxes,
rand_solution,
generate_neighborhood,
src.TabuRepresentationBoxes,
)
# Calling of TB Optimizer to Find Best Positions
max_iterations = 6
tabu_time = 3
best_boxes , snapshots_boxes = tabu_search(max_iterations,tabu_time)
# Results Presentation
best_positions = snapshots_boxes[-1].Positions
print(f'Selected Boxes: {best_boxes[:num_boxes]}')
print(f'Rotations Boxes: {best_boxes[num_boxes:]}')
print(f'Positions of Each Box:\n{best_positions}')