資源簡介
車輛從場站出發對客戶進行配送服務最后返回場站,要求所有顧客都被配送,每位顧客一次配送完成,且不能違反車輛容量的限制,目的是所有車輛路線的總距離最小。車輛路線的實際問題包括配送中心配送、公共汽車路線制定、信件和報紙投遞、航空和鐵路時間表安排、工業廢品收集等。

代碼片段和文件信息
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????? ?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???? ?? 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????? ??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?
???? 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個文件信息
評論
共有 條評論