3 import java
.io
.IOException
;
7 import aco
.graph
.data
.*;
9 import aco
.strategy
.acs
.*;
10 import aco
.strategy
.as
.*;
11 import aco
.strategy
.as
.eas
.*;
12 import aco
.strategy
.as
.asrank
.*;
13 import aco
.strategy
.as
.simpleas
.*;
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
.*;
23 import aco
.environment
.as
.*;
24 import aco
.environment
.acs
.*;
25 import aco
.tsplibreader
.*;
27 public class EnvironmentFactory
{
29 public static Environment
acs(String filename
,
37 ACSMediator acom
= new ACSMediator(new ACSParameter());
38 ACOGraph acog
= new ACOGraph(acom
);
39 acom
.setACOGraph(acog
);
41 /* these are the most important */
42 acom
.setACOStrategy(new ACSStrategy(acom
));
43 acom
.setTauZeroStrategy(new ACSTauZeroStrategy(acom
));
44 acom
.setPheromoneStrategy(new ACSPheromoneStrategy(acom
));
45 acom
.setChoiceInformationStrategy(new ACSChoiceInformationStrategy(acom
));
47 /* these are not very likely to change */
48 acom
.setGraphStrategy(new GraphStrategy(acom
));
49 acom
.setHeuristicInformationStrategy(new HeuristicInformationStrategy(acom
));
51 acom
.setGlobalBestTourMapSize(1);
52 acom
.setMaxNumOfTours(runs
);
56 acom
.setNearestNeighbourListDepth(cl
);
59 TSPLibReader tsplr
= new TSPLibReader(filename
);
60 CoordinateData coordinates
= new CoordinateData(tsplr
);
62 acom
.setDistanceStrategy(DistanceStrategy
.getStrategyFromTSPLibReader(tsplr
, acom
));
63 acog
.initializeFromCoordinates(coordinates
);
65 } catch (IOException e
) {
66 System
.out
.println(e
.toString() + "(" + e
.getClass() + "): " + e
);
70 /* after the graph is initialized we can set the Number of Ants
71 * or leave it to the method parameter */
73 acom
.setNumOfAnts(acom
.getNumOfCities());
75 acom
.setNumOfAnts(numofants
);
77 /* after the graph is initialized we can compute TauZero.. */
78 acom
.computeTauZero();
79 /* ..then we can set the initial pheromone value.. */
80 acom
.setInitialPheromones(acom
.getTauZero());
81 /* ..and finally compute the initial Choice Information */
82 acom
.computeChoiceInformation();
84 System
.out
.println(acom
.getACOParameter());
86 ACSEnvironment env
= new ACSEnvironment(acom
);
87 acom
.setEnvironment(env
);
89 AntView av
= new AntView(acom
);
90 new Thread(av
).start();
93 return (Environment
)env
;
96 public static Environment
as(String filename
,
103 SimpleASMediator acom
= new SimpleASMediator(new SimpleASParameter());
104 ACOGraph acog
= new ACOGraph(acom
);
105 acom
.setACOGraph(acog
);
107 /* these are the most important */
108 acom
.setACOStrategy(new ASStrategy(acom
));
109 acom
.setTauZeroStrategy(new SimpleASTauZeroStrategy(acom
));
110 acom
.setPheromoneStrategy(new SimpleASPheromoneStrategy(acom
));
111 acom
.setChoiceInformationStrategy(new ASChoiceInformationStrategy(acom
));
113 /* these are not very likely to change */
114 acom
.setGraphStrategy(new GraphStrategy(acom
));
115 acom
.setHeuristicInformationStrategy(new HeuristicInformationStrategy(acom
));
117 acom
.setGlobalBestTourMapSize(1);
118 acom
.setMaxNumOfTours(runs
);
119 acom
.setAlpha(alpha
);
124 TSPLibReader tsplr
= new TSPLibReader(filename
);
125 CoordinateData coordinates
= new CoordinateData(tsplr
);
127 acom
.setDistanceStrategy(DistanceStrategy
.getStrategyFromTSPLibReader(tsplr
, acom
));
128 acog
.initializeFromCoordinates(coordinates
);
130 } catch (IOException e
) {
131 System
.out
.println(e
.toString() + "(" + e
.getClass() + "): " + e
);
135 /* after the graph is initialized we can set the Number of Ants
136 * or leave it to the method parameter */
137 if (numofants
== 0) {
138 acom
.setNumOfAnts(acom
.getNumOfCities());
140 acom
.setNumOfAnts(numofants
);
142 /* after the graph is initialized we can compute TauZero.. */
143 acom
.computeTauZero();
144 /* ..then we can set the initial pheromone value.. */
145 acom
.setInitialPheromones(acom
.getTauZero());
146 /* ..and finally compute the initial Choice Information */
147 acom
.computeChoiceInformation();
149 System
.out
.println(acom
.getACOParameter());
151 ASEnvironment env
= new ASEnvironment(acom
);
152 acom
.setEnvironment(env
);
154 AntView av
= new AntView(acom
);
155 new Thread(av
).start();
158 return (Environment
)env
;
161 public static Environment
eas(String filename
,
169 EASMediator acom
= new EASMediator(new EASParameter());
170 ACOGraph acog
= new ACOGraph(acom
);
171 acom
.setACOGraph(acog
);
173 /* these are the most important */
174 acom
.setACOStrategy(new ASStrategy(acom
));
175 acom
.setTauZeroStrategy(new EASTauZeroStrategy(acom
));
176 acom
.setPheromoneStrategy(new EASPheromoneStrategy(acom
));
177 acom
.setChoiceInformationStrategy(new ASChoiceInformationStrategy(acom
));
179 /* these are not very likely to change */
180 acom
.setGraphStrategy(new GraphStrategy(acom
));
181 acom
.setHeuristicInformationStrategy(new HeuristicInformationStrategy(acom
));
183 acom
.setGlobalBestTourMapSize(1);
184 acom
.setMaxNumOfTours(runs
);
185 acom
.setAlpha(alpha
);
190 TSPLibReader tsplr
= new TSPLibReader(filename
);
191 CoordinateData coordinates
= new CoordinateData(tsplr
);
193 acom
.setDistanceStrategy(DistanceStrategy
.getStrategyFromTSPLibReader(tsplr
, acom
));
194 acog
.initializeFromCoordinates(coordinates
);
196 } catch (IOException exception
) {
197 System
.out
.println(exception
.toString() +
198 "(" + exception
.getClass() + "): " + exception
);
203 acom
.setE((double)acom
.getNumOfCities());
208 /* after the graph is initialized we can set the Number of Ants
209 * or leave it to the method parameter */
210 if (numofants
== 0) {
211 acom
.setNumOfAnts(acom
.getNumOfCities());
213 acom
.setNumOfAnts(numofants
);
216 /* after the graph is initialized we can compute TauZero.. */
217 acom
.computeTauZero();
218 /* ..then we can set the initial pheromone value.. */
219 acom
.setInitialPheromones(acom
.getTauZero());
220 /* ..and finally compute the initial Choice Information */
221 acom
.computeChoiceInformation();
223 System
.out
.println(acom
.getACOParameter());
225 ASEnvironment env
= new ASEnvironment(acom
);
226 acom
.setEnvironment(env
);
228 AntView av
= new AntView(acom
);
229 new Thread(av
).start();
232 return (Environment
)env
;
235 public static Environment
asrank(String filename
,
243 ASRankMediator acom
= new ASRankMediator(new ASRankParameter());
244 ACOGraph acog
= new ACOGraph(acom
);
245 acom
.setACOGraph(acog
);
247 /* these are the most important */
248 acom
.setACOStrategy(new ASStrategy(acom
));
250 acom
.setTauZeroStrategy(new ASRankTauZeroStrategy(acom
));
251 acom
.setPheromoneStrategy(new ASRankPheromoneStrategy(acom
));
253 /* these are not very likely to change */
254 acom
.setGraphStrategy(new GraphStrategy(acom
));
255 acom
.setChoiceInformationStrategy(new ASChoiceInformationStrategy(acom
));
256 acom
.setHeuristicInformationStrategy(new HeuristicInformationStrategy(acom
));
258 acom
.setGlobalBestTourMapSize(1);
259 acom
.setMaxNumOfTours(runs
);
260 acom
.setAlpha(alpha
);
265 TSPLibReader tsplr
= new TSPLibReader(filename
);
266 CoordinateData coordinates
= new CoordinateData(tsplr
);
268 acom
.setDistanceStrategy(DistanceStrategy
.getStrategyFromTSPLibReader(tsplr
, acom
));
269 acog
.initializeFromCoordinates(coordinates
);
271 } catch (IOException e
) {
272 System
.out
.println(e
.toString() + "(" + e
.getClass() + "): " + e
);
277 acom
.setW((double)acom
.getNumOfCities());
282 /* after the graph is initialized we can set the Number of Ants
283 * or leave it to the method parameter */
284 if (numofants
== 0) {
285 acom
.setNumOfAnts(acom
.getNumOfCities());
287 acom
.setNumOfAnts(numofants
);
290 /* after the graph is initialized we can compute TauZero.. */
291 acom
.computeTauZero();
292 /* ..then we can set the initial pheromone value.. */
293 acom
.setInitialPheromones(acom
.getTauZero());
294 /* ..and finally compute the initial Choice Information */
295 acom
.computeChoiceInformation();
297 System
.out
.println(acom
.getACOParameter());
299 ASEnvironment env
= new ASEnvironment(acom
);
300 acom
.setEnvironment(env
);
302 AntView av
= new AntView(acom
);
303 new Thread(av
).start();
306 return (Environment
)env
;