-
Notifications
You must be signed in to change notification settings - Fork 5
/
Interface.inc
172 lines (138 loc) · 5.03 KB
/
Interface.inc
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
{
Copyright (c) Peter Karpov 2010 - 2018.
Usage of the works is permitted provided that this instrument is retained with
the works, so that any entity that uses the works is notified of this instrument.
DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
}
{////////////////////////////////////////////////////////////////////////////////////
>> Version: 1.0
>> Description
Problem definition module interface
>> Author
Peter Karpov
Email : [email protected]
Homepage : inversed.ru
GitHub : inversed-ru
Twitter : @inversed_ru
>> Changelog
1.0 : 2018.09.16 - Interface for algorithms omitted from Ascension 2.0
~ MakeNeighbour is now temperature-aware
0.4 : 2012.04.24 + Problem-specific improvement
0.3 : 2012.02.06 + Guided move
0.2 : 2011.10.14 ~ Moved to generic types
0.1 : 2011.08.29
Notation: + added, - removed, * fixed, ~ changed
}
{-----------------------<< Solution operations >>-----------------------------------}
type
TSolutions = array of TSolution;
// Assign SolFrom to SolTo
procedure AssignSolution(
var SolTo : TSolution;
const SolFrom : TSolution);
// Save Solution to fileSol
procedure SaveSolution(
var fileSol : Text;
const Solution : TSolution);
// Load Solution from fileSol
procedure LoadSolution(
var Solution : TSolution;
var fileSol : Text);
// Problem-specific improvement
procedure SpecialImprove(
var Solution : TSolution);
{-----------------------<< Scores >>------------------------------------------------}
// Return a string representation of Score
function FormatScore(
Score : TScore
) : AnsiString;
{-----------------------<< Heuristic-unspecific >>----------------------------------}
// Create new random Solution
procedure NewSolution(
var Solution : TSolution);
// Return distance between Solution1 and Solution2
function Distance(
const Solution1,
Solution2 : TSolution
) : TSolutionDistance;
{-----------------------<< Move lists >>--------------------------------------------}
type
TMoveList =
record
N : Integer;
Moves : array of TMove;
end;
// Apply a Move to a Solution
procedure PerformMove(
var Solution : TSolution;
const Move : TMove);
overload;
// Apply a Move to a Solution, save the Undo
procedure PerformMove(
var Solution : TSolution;
var Undo : TMoveUndo;
const Move : TMove);
overload;
// Undo the last move applied to a Solution
procedure UndoMove(
var Solution : TSolution;
const Undo : TMoveUndo);
{-----------------------<< Local Search >>------------------------------------------}
// Make a MoveList of a Solution for use in Local Search. Level determines
// neighborhood size, with 1 being the smallest.
procedure MakeLSMoveList(
var MoveList : TMoveList;
const Solution : TSolution;
Level : Integer);
{-----------------------<< Simulated Annealing >>-----------------------------------}
// Apply a random move to the Solution at temperature T, save Undo
procedure MakeNeighbour(
var Solution : TSolution;
var Undo : TSAUndo;
T : Real);
// Undo the last move applied to a Solution
procedure UndoSAMove(
var Solution : TSolution;
const Undo : TSAUndo);
{-----------------------<< Genetic Algorithm >>-------------------------------------}
// Apply mutation operator to a Solution
procedure Mutate(
var Solution : TSolution);
// Obtain the Child via crossover between Parent1 and Parent2. Recalc indicates if
// score recalculation is strictly necessary.
procedure Crossover(
var Child : TSolution;
const Parent1,
Parent2 : TSolution;
Recalc : Boolean);
{-----------------------<< Tabu Search >>-------------------------------------------}
// ListTo := ListFrom
procedure AssignTabuList(
var ListTo : TTabuList;
const ListFrom : TTabuList);
// Initialize the TabuList, must be called before use
procedure InitTabuList(
var TabuList : TTabuList);
// Age the TabuList
procedure AgeTabuList(
var TabuList : TTabuList);
// Add a Move that will be applied to Sol to the TabuList with Tenure
procedure AddToTabuList(
var TabuList : TTabuList;
const Move : TMove;
Tenure : Integer;
const Sol : TSolution);
// Make a MoveList for the tabu search
procedure MakeTSMoveList(
var MoveList : TMoveList;
const Solution : TSolution);
// Return whether a Move is in the Solution's TabuList
function IsMoveTabu(
const Move : TMove;
const Solution : TSolution;
const TabuList : TTabuList
) : Boolean;
// Return a tabu tenure at normalized time t
function TabuTenure(
t : Real // [0 .. 1]
) : Integer;