资源简介
车辆从场站出发对客户进行配送服务最后返回场站,要求所有顾客都被配送,每位顾客一次配送完成,且不能违反车辆容量的限制,目的是所有车辆路线的总距离最小。车辆路线的实际问题包括配送中心配送、公共汽车路线制定、信件和报纸投递、航空和铁路时间表安排、工业废品收集等。
代码片段和文件信息
package cn;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import project.framework.Scenario;
import project.framework.Solution;
public class HCMultiCars {
public static long TIME_TO_TERMINATE;
public static final void main(final String[] args) throws IOException {
Scenario scenario;
Solution solution;
//System.out.println(“hc runs“);
// get time limit and also allocate some time for file writing!
HCMultiCars.TIME_TO_TERMINATE = (Long.parseLong(args[2]) - 1000);
//HCMultiCars.TIME_TO_TERMINATE = System.currentTimeMillis() + 1000*10;
// read the scenario
scenario = new Scenario();
scenario.readFile(new File(args[0]));
// call the method that you are supposed to implement
solution = HCMultiCars.solve(scenario Long.parseLong(args[2]));
// store the solution
if (solution != null) {
solution.writeFile(new File(args[1]));
}
}
public static final Solution solve(final Scenario scenario long runTime) {
final Random r;
Solution best cur;
int[][] bestA curA;
long lastTime curTime maxTime bestF curF;
int carCount = scenario.carCount();
//System.out.println(carCount);
int orderCount = scenario.orderCount();
//System.out.println(orderCount);
r = new Random();
maxTime = 0l;
best = null;
bestA = null;
bestF = Long.MAX_VALUE;
curTime = lastTime = System.currentTimeMillis();
int baseNum = orderCount / carCount;
int[] perCarOrdersCount = new int[carCount];
int[][] perCarOrders = new int[carCount][];
bestA = new int[carCount][];
curA = new int[carCount][];
for(int index = 0; index < carCount; index++){
bestA[index] = null;
curA[index] = null;
perCarOrdersCount[index] = (index == (carCount - 1))?(orderCount - baseNum*(carCount-1)):baseNum;
perCarOrders[index] = new int[perCarOrdersCount[index]];
for(int t = 0; t < perCarOrdersCount[index]; t++){
perCarOrders[index][t] = baseNum*index+ t;
}
}
for (;;) {
if ((curTime + maxTime) >= HCMultiCars.TIME_TO_TERMINATE) {
//best.print(System.out);
return best;
}
for(int index = 0; index < carCount; index++){
if (bestA[index] == null) {
curA[index] = HCMultiCars.randomSolution(
perCarOrdersCount[index] perCarOrders[index]r);
bestA[index] = curA[index].clone();
} else {
curA[index] = HCMultiCars.mutate(bestA[index] r).clone();
}
}
cur = new Solution(curA);
curF = scenario.evaluate(cur);
if ((curF < bestF) || (best == null)) {
bestA = curA.clone();
best = new Solution(bestA);
bestF = curF;
}
curTime = System.currentTimeMillis();
if(curTime - lastTime > runTime) break;
}
System.out.println(“\nover“); //$NON-NLS-1$
return best;//not sure what sh
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 248 2012-12-01 21:14 vrp\.classpath
文件 383 2012-12-01 21:14 vrp\.project
文件 1706 2012-12-01 21:01 vrp\example\benchmarks\scenario_1.txt
文件 1945 2012-12-01 21:01 vrp\example\benchmarks\scenario_2.txt
文件 2644 2012-12-01 21:01 vrp\example\benchmarks\scenario_3.txt
文件 3250 2012-12-01 21:01 vrp\example\benchmarks\scenario_4.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_0.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_1.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_10.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_11.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_12.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_13.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_14.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_15.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_16.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_17.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_18.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_19.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_2.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_3.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_4.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_5.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_6.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_7.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_8.txt
文件 2329 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\run_9.txt
文件 100 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_1\summary.txt
文件 2419 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_2\run_0.txt
文件 2419 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_2\run_1.txt
文件 2419 2012-12-01 21:01 vrp\example\results\HillClimber\scenario_2\run_10.txt
............此处省略435个文件信息
评论
共有 条评论