-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathABC.java
More file actions
89 lines (75 loc) · 3.52 KB
/
Copy pathABC.java
File metadata and controls
89 lines (75 loc) · 3.52 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package CVRP;
import java.io.IOException;
import java.util.Random;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Collections;
import java.util.Calendar;
public class ABC
{
private Calendar timeStart;
public void runABC()
{
timeStart=Calendar.getInstance();
Calendar timeNow;
int hour=0,minute=0,second=0;
CVRPData.readFile("fruitybun250.vrp");
System.out.println("Load File");
System.out.println("Initialize");
Bee beeColony =new Bee();
beeColony.initializeBees();
beeColony.foodSourceList.get(0).setFoodSource(Print.readResult("best-solution.txt"));
Print.printList(beeColony.foodSourceList.get(0).foodSource);
System.out.println(beeColony.foodSourceList.get(0).cost);
System.out.println("-----------------------");
System.out.println("Current Lowest Cost: "+ Double.toString(beeColony.lowestCost)+"\t"+"Current Vehicle Num: "+ Integer.toString(beeColony.solutionVehicleNum));
System.out.println("Invalid Results: "+ Integer.toString(beeColony.invalidFoodNum)+"\t"+"Alpha: "+Double.toString(Configuration.ALPHA));
for(long i=0;i<Configuration.EPOCH_LIM;i++)
{
beeColony.employedBees();
beeColony.onlookerBees();
beeColony.scoutBees();
beeColony.searchBestSolution();
timeNow= Calendar.getInstance();
//print computing results every 100 iterations
if(i%3000==1)
{
System.out.println("-----------------------runtime: "+Integer.toString(hour)+" hours: "+Integer.toString(minute)+" minutes: "+Integer.toString(second)+" seconds:"+"----------------------------");
System.out.println("Epoch: "+Long.toString(i)+"\t"+"Current Lowest Cost: "+ Double.toString(beeColony.lowestCost)+"\t"+"Current Vehicle Num: "+ Integer.toString(beeColony.solutionVehicleNum));
System.out.println("Invalid Results: "+ Integer.toString(beeColony.invalidFoodNum)+"\t"+"Alpha: "+Double.toString(Configuration.ALPHA));
System.out.println("Best Solution length: "+ Integer.toString(beeColony.bestSolution.size()));
}
//if the runtime of the program has reached its limit, terminate program
hour=timeNow.get(Calendar.HOUR_OF_DAY)-timeStart.get(Calendar.HOUR_OF_DAY);
minute=timeNow.get(Calendar.MINUTE)-timeStart.get(Calendar.MINUTE);
second=timeNow.get(Calendar.SECOND)-timeStart.get(Calendar.SECOND);
if(second<0)
{
minute--;
second+=60;
}
if(minute<0)
{
hour--;
minute+=60;
}
if(hour*60+minute>=Configuration.RUNTIME_LIM)
{
System.out.println("-----------------------runtime: "+Integer.toString(hour)+" hours: "+Integer.toString(minute)+" minutes: "+Integer.toString(second)+" seconds:"+"----------------------------");
System.out.println("Epoch: "+Long.toString(i)+"\t"+"Current Lowest Cost: "+ Double.toString(beeColony.lowestCost)+"\t"+"Current Vehicle Num: "+ Integer.toString(beeColony.solutionVehicleNum));
System.out.println("Invalid Results: "+ Integer.toString(beeColony.invalidFoodNum)+"\t"+"Alpha: "+Double.toString(Configuration.ALPHA));
System.out.println("Best Solution length: "+ Integer.toString(beeColony.bestSolution.size()));
break;
}
}
Print.printList(beeColony.bestSolution);
String description="Artificial Bee Colony Algorithm with a modified scout bee that searches for result near the best solution instead of random search";
Print.writeResult("test.txt", "cy15267", "26733", "Chuanyu Yang", description, beeColony.lowestCost, beeColony.bestSolution);
}
public static void main(String[] args) throws IOException
{
ABC abc = new ABC();
abc.runABC();
}
}