3 import java
.io
.IOException
;
6 import aco
.graph
.data
.*;
8 import aco
.strategy
.acs
.*;
9 import aco
.strategy
.as
.*;
10 import aco
.strategy
.as
.eas
.*;
11 import aco
.strategy
.as
.asrank
.*;
12 import aco
.strategy
.as
.simpleas
.*;
13 import aco
.mediator
.*;
14 import aco
.mediator
.acs
.*;
15 import aco
.mediator
.as
.eas
.*;
16 import aco
.mediator
.as
.asrank
.*;
17 import aco
.mediator
.as
.simpleas
.*;
18 import aco
.parameter
.acs
.*;
19 import aco
.parameter
.as
.eas
.*;
20 import aco
.parameter
.as
.asrank
.*;
21 import aco
.parameter
.as
.simpleas
.*;
22 import aco
.environment
.as
.*;
23 import aco
.environment
.acs
.*;
24 import aco
.tsplibreader
.*;
26 public class AntFactory
{
28 public static ACOMediator
acs(String filename
,
36 ACSMediator acom
= new ACSMediator(new ACSParameter());
37 ACOGraph acog
= new ACOGraph(acom
);
38 acom
.setACOGraph(acog
);
40 /* these are the most important */
41 acom
.setACOStrategy(new ACSStrategy(acom
));
42 acom
.setTauZeroStrategy(new ACSTauZeroStrategy(acom
));
43 acom
.setPheromoneStrategy(new ACSPheromoneStrategy(acom
));
44 acom
.setChoiceInformationStrategy(new ACSChoiceInformationStrategy(acom
));
46 /* these are not very likely to change */
47 acom
.setGraphStrategy(new GraphStrategy(acom
));
48 acom
.setHeuristicInformationStrategy(new HeuristicInformationStrategy(acom
));
50 acom
.setGlobalBestTourMapSize(1);
51 acom
.setMaxNumOfTours(runs
);
55 acom
.setNearestNeighbourListDepth(cl
);
58 TSPLibReader tsplr
= new TSPLibReader(filename
);
59 CoordinateData coordinates
= new CoordinateData(tsplr
);
61 acom
.setDistanceStrategy(DistanceStrategy
.getStrategyFromTSPLibReader(tsplr
, acom
));
62 acog
.initializeFromCoordinates(coordinates
);
64 } catch (IOException e
) {
65 System
.out
.println(e
.toString() + "(" + e
.getClass() + "): " + e
);
69 /* after the graph is initialized we can set the Number of Ants
70 * or leave it to the method parameter */
72 acom
.setNumOfAnts(acom
.getNumOfCities());
74 acom
.setNumOfAnts(numofants
);
76 /* after the graph is initialized we can compute TauZero.. */
77 acom
.computeTauZero();
78 /* ..then we can set the initial pheromone value.. */
79 acom
.setInitialPheromones(acom
.getTauZero());
80 /* ..and finally compute the initial Choice Information */
81 acom
.computeChoiceInformation();
83 ACSEnvironment env
= new ACSEnvironment(acom
);
84 acom
.setEnvironment(env
);
86 return (ACOMediator
)acom
;
89 public static ACOMediator
as(String filename
,
96 SimpleASMediator acom
= new SimpleASMediator(new SimpleASParameter());
97 ACOGraph acog
= new ACOGraph(acom
);
98 acom
.setACOGraph(acog
);
100 /* these are the most important */
101 acom
.setACOStrategy(new ASStrategy(acom
));
102 acom
.setTauZeroStrategy(new SimpleASTauZeroStrategy(acom
));
103 acom
.setPheromoneStrategy(new SimpleASPheromoneStrategy(acom
));
104 acom
.setChoiceInformationStrategy(new ASChoiceInformationStrategy(acom
));
106 /* these are not very likely to change */
107 acom
.setGraphStrategy(new GraphStrategy(acom
));
108 acom
.setHeuristicInformationStrategy(new HeuristicInformationStrategy(acom
));
110 acom
.setGlobalBestTourMapSize(1);
111 acom
.setMaxNumOfTours(runs
);
112 acom
.setAlpha(alpha
);
117 TSPLibReader tsplr
= new TSPLibReader(filename
);
118 CoordinateData coordinates
= new CoordinateData(tsplr
);
120 acom
.setDistanceStrategy(DistanceStrategy
.getStrategyFromTSPLibReader(tsplr
, acom
));
121 acog
.initializeFromCoordinates(coordinates
);
123 } catch (IOException e
) {
124 System
.out
.println(e
.toString() + "(" + e
.getClass() + "): " + e
);
128 /* after the graph is initialized we can set the Number of Ants
129 * or leave it to the method parameter */
130 if (numofants
== 0) {
131 acom
.setNumOfAnts(acom
.getNumOfCities());
133 acom
.setNumOfAnts(numofants
);
135 /* after the graph is initialized we can compute TauZero.. */
136 acom
.computeTauZero();
137 /* ..then we can set the initial pheromone value.. */
138 acom
.setInitialPheromones(acom
.getTauZero());
139 /* ..and finally compute the initial Choice Information */
140 acom
.computeChoiceInformation();
142 ASEnvironment env
= new ASEnvironment(acom
);
143 acom
.setEnvironment(env
);
145 return (ACOMediator
)acom
;
148 public static ACOMediator
eas(String filename
,
156 EASMediator acom
= new EASMediator(new EASParameter());
157 ACOGraph acog
= new ACOGraph(acom
);
158 acom
.setACOGraph(acog
);
160 /* these are the most important */
161 acom
.setACOStrategy(new ASStrategy(acom
));
162 acom
.setTauZeroStrategy(new EASTauZeroStrategy(acom
));
163 acom
.setPheromoneStrategy(new EASPheromoneStrategy(acom
));
164 acom
.setChoiceInformationStrategy(new ASChoiceInformationStrategy(acom
));
166 /* these are not very likely to change */
167 acom
.setGraphStrategy(new GraphStrategy(acom
));
168 acom
.setHeuristicInformationStrategy(new HeuristicInformationStrategy(acom
));
170 acom
.setGlobalBestTourMapSize(1);
171 acom
.setMaxNumOfTours(runs
);
172 acom
.setAlpha(alpha
);
177 TSPLibReader tsplr
= new TSPLibReader(filename
);
178 CoordinateData coordinates
= new CoordinateData(tsplr
);
180 acom
.setDistanceStrategy(DistanceStrategy
.getStrategyFromTSPLibReader(tsplr
, acom
));
181 acog
.initializeFromCoordinates(coordinates
);
183 } catch (IOException exception
) {
184 System
.out
.println(exception
.toString() +
185 "(" + exception
.getClass() + "): " + exception
);
190 acom
.setE((double)acom
.getNumOfCities());
195 /* after the graph is initialized we can set the Number of Ants
196 * or leave it to the method parameter */
197 if (numofants
== 0) {
198 acom
.setNumOfAnts(acom
.getNumOfCities());
200 acom
.setNumOfAnts(numofants
);
203 /* after the graph is initialized we can compute TauZero.. */
204 acom
.computeTauZero();
205 /* ..then we can set the initial pheromone value.. */
206 acom
.setInitialPheromones(acom
.getTauZero());
207 /* ..and finally compute the initial Choice Information */
208 acom
.computeChoiceInformation();
210 ASEnvironment env
= new ASEnvironment(acom
);
211 acom
.setEnvironment(env
);
213 return (ACOMediator
)acom
;
216 public static ACOMediator
asrank(String filename
,
224 ASRankMediator acom
= new ASRankMediator(new ASRankParameter());
225 ACOGraph acog
= new ACOGraph(acom
);
226 acom
.setACOGraph(acog
);
228 /* these are the most important */
229 acom
.setACOStrategy(new ASStrategy(acom
));
231 acom
.setTauZeroStrategy(new ASRankTauZeroStrategy(acom
));
232 acom
.setPheromoneStrategy(new ASRankPheromoneStrategy(acom
));
234 /* these are not very likely to change */
235 acom
.setGraphStrategy(new GraphStrategy(acom
));
236 acom
.setChoiceInformationStrategy(new ASChoiceInformationStrategy(acom
));
237 acom
.setHeuristicInformationStrategy(new HeuristicInformationStrategy(acom
));
239 acom
.setGlobalBestTourMapSize(1);
240 acom
.setMaxNumOfTours(runs
);
241 acom
.setAlpha(alpha
);
246 TSPLibReader tsplr
= new TSPLibReader(filename
);
247 CoordinateData coordinates
= new CoordinateData(tsplr
);
249 acom
.setDistanceStrategy(DistanceStrategy
.getStrategyFromTSPLibReader(tsplr
, acom
));
250 acog
.initializeFromCoordinates(coordinates
);
252 } catch (IOException e
) {
253 System
.out
.println(e
.toString() + "(" + e
.getClass() + "): " + e
);
258 acom
.setW((double)acom
.getNumOfCities());
263 /* after the graph is initialized we can set the Number of Ants
264 * or leave it to the method parameter */
265 if (numofants
== 0) {
266 acom
.setNumOfAnts(acom
.getNumOfCities());
268 acom
.setNumOfAnts(numofants
);
271 /* after the graph is initialized we can compute TauZero.. */
272 acom
.computeTauZero();
273 /* ..then we can set the initial pheromone value.. */
274 acom
.setInitialPheromones(acom
.getTauZero());
275 /* ..and finally compute the initial Choice Information */
276 acom
.computeChoiceInformation();
278 ASEnvironment env
= new ASEnvironment(acom
);
279 acom
.setEnvironment(env
);
281 return (ACOMediator
)acom
;