- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我是 Jsprit 的新手。我试图在我的发货 list 中使用多种尺寸的尺寸。例如,我在 createJob() 中使用 WHEELCHAIRSPACE_INDEX 添加了一些货件的尺寸大小,而一些货件使用了 PASSENGERSEATS_INDEX。但是输出似乎是错误的。
public class Test {
static int WHEELCHAIRSPACE_INDEX = 0;
static int PASSENGERSEATS_INDEX = 1;
private VehicleType vehicleType_wheelchair;
private VehicleType vehicleType_solelypassenger;
private VehicleImpl vehicle1,vehicle1_2,vehicle2,vehicle2_2;
private VehicleRoutingProblem.Builder vrpBuilder;
private HardRouteConstraint wheelchair_bus_passenger_pickup_constraint;
private VehicleRoutingAlgorithm algorithm;
private VehicleRoutingProblem problem;
private VehicleRoutingTransportCosts costMatrix;
private static final String FILENAME = "C:\\Users\\admin\\Desktop\\test.txt";
public static void main(String[] args) {
// TODO Auto-generated method stub
Examples.createOutputFolder();
Test test = new Test();
test.createVehicleType();
test.createVehicle();
test.createJob();
test.createConstraint();
test.createProblem();
test.searchSolution();
}
private void searchSolution() {
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);
SolutionPrinter.print(problem, bestSolution, SolutionPrinter.Print.VERBOSE);
Plotter problemPlotter = new Plotter(problem);
problemPlotter.plotShipments(true);
problemPlotter.setLabel(Plotter.Label.SIZE);
problemPlotter.plot("output/transportOfDisabledPeopleExample_problem.png", "disabled people tp");
Plotter solutionPlotter = new Plotter(problem, Solutions.bestOf(solutions));
solutionPlotter.plotShipments(true);
solutionPlotter.setLabel(Plotter.Label.SIZE);
solutionPlotter.plot("output/transportOfDisabledPeopleExample_solution.png", "disabled people tp");
}
private void createProblem() {
StateManager stateManager = new StateManager(problem);
ConstraintManager constraintManager = new ConstraintManager(problem, stateManager);
constraintManager.addConstraint(wheelchair_bus_passenger_pickup_constraint);
algorithm = Jsprit.Builder.newInstance(problem).setStateAndConstraintManager(stateManager,constraintManager).buildAlgorithm();
algorithm.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100));
}
private void createConstraint() {
wheelchair_bus_passenger_pickup_constraint = new HardRouteConstraint() {
@Override
public boolean fulfilled(JobInsertionContext insertionContext) {
return true;
}
};
}
private void createJob() {
com.graphhopper.jsprit.core.problem.job.Shipment.Builder builder1 = Shipment.Builder.newInstance("1");
builder1.addSizeDimension(WHEELCHAIRSPACE_INDEX, 1);
builder1.setPickupLocation(Location.newInstance("1a"));
builder1.setDeliveryLocation(Location.newInstance("1b"));
builder1.setDeliveryServiceTime(0);
Shipment shipment1 = builder1.build();
com.graphhopper.jsprit.core.problem.job.Shipment.Builder builder2 = Shipment.Builder.newInstance("2");
builder2.addSizeDimension(PASSENGERSEATS_INDEX, 1);
builder2.setPickupLocation(Location.newInstance("2a"));
builder2.setDeliveryLocation(Location.newInstance("2b"));
builder2.setDeliveryServiceTime(0);
Shipment shipment2 = builder2.build();
com.graphhopper.jsprit.core.problem.job.Shipment.Builder builder3 = Shipment.Builder.newInstance("3");
builder3.addSizeDimension(WHEELCHAIRSPACE_INDEX, 1);
builder3.setPickupLocation(Location.newInstance("3a"));
builder3.setDeliveryLocation(Location.newInstance("3b"));
builder3.setDeliveryServiceTime(0);
Shipment shipment3 = builder3.build();
com.graphhopper.jsprit.core.problem.job.Shipment.Builder builder4 = Shipment.Builder.newInstance("4");
builder4.addSizeDimension(PASSENGERSEATS_INDEX, 1);
builder4.setPickupLocation(Location.newInstance("4a"));
builder4.setDeliveryLocation(Location.newInstance("4b"));
builder4.setDeliveryServiceTime(0);
Shipment shipment4 = builder4.build();
com.graphhopper.jsprit.core.problem.job.Shipment.Builder builder5 = Shipment.Builder.newInstance("5");
builder5.addSizeDimension(WHEELCHAIRSPACE_INDEX, 1);
builder5.setPickupLocation(Location.newInstance("5a"));
builder5.setDeliveryLocation(Location.newInstance("5b"));
builder5.setDeliveryServiceTime(0);
Shipment shipment5 = builder5.build();
setTransportCost();
vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
vrpBuilder.addVehicle(vehicle1);
vrpBuilder.addVehicle(vehicle2);
vrpBuilder.addVehicle(vehicle1_2);
vrpBuilder.addVehicle(vehicle2_2);
vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4);
vrpBuilder.addJob(shipment5);
vrpBuilder.setFleetSize(FleetSize.FINITE);
vrpBuilder.setRoutingCost(costMatrix);
problem = vrpBuilder.build();
}
private void setTransportCost() {
// TODO Auto-generated method stub
VehicleRoutingTransportCostsMatrix.Builder costMatrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true);
costMatrixBuilder.addTransportTime("0", "0", 0.0);
costMatrixBuilder.addTransportTime("0", "1a", 2.0);
costMatrixBuilder.addTransportTime("0", "1b", 3.3);
costMatrixBuilder.addTransportTime("0", "2a", 2.0);
costMatrixBuilder.addTransportTime("0", "2b", 4.3);
costMatrixBuilder.addTransportTime("0", "3a", 3.5);
costMatrixBuilder.addTransportTime("0", "3b", 3.0);
costMatrixBuilder.addTransportTime("0", "4a", 1.5);
costMatrixBuilder.addTransportTime("0", "4b", 2.7);
costMatrixBuilder.addTransportTime("0", "5a", 1.2);
costMatrixBuilder.addTransportTime("0", "5b", 3.5);
costMatrixBuilder.addTransportTime("1a", "0", 2.0);
costMatrixBuilder.addTransportTime("1a", "1a", 0.0);
costMatrixBuilder.addTransportTime("1a", "1b", 2.5);
costMatrixBuilder.addTransportTime("1a", "2a", 2.3);
costMatrixBuilder.addTransportTime("1a", "2b", 4.4);
costMatrixBuilder.addTransportTime("1a", "3a", 4.0);
costMatrixBuilder.addTransportTime("1a", "3b", 4.0);
costMatrixBuilder.addTransportTime("1a", "4a", 2.3);
costMatrixBuilder.addTransportTime("1a", "4b", 4.5);
costMatrixBuilder.addTransportTime("1a", "5a", 3.2);
costMatrixBuilder.addTransportTime("1a", "5b", 1.5);
costMatrixBuilder.addTransportTime("1b", "0", 3.3);
costMatrixBuilder.addTransportTime("1b", "1a", 2.5);
costMatrixBuilder.addTransportTime("1b", "1b", 0.0);
costMatrixBuilder.addTransportTime("1b", "2a", 1.7);
costMatrixBuilder.addTransportTime("1b", "2b", 2.2);
costMatrixBuilder.addTransportTime("1b", "3a", 2.5);
costMatrixBuilder.addTransportTime("1b", "3b", 3.4);
costMatrixBuilder.addTransportTime("1b", "4a", 4.5);
costMatrixBuilder.addTransportTime("1b", "4b", 5.0);
costMatrixBuilder.addTransportTime("1b", "5a", 4.5);
costMatrixBuilder.addTransportTime("1b", "5b", 2.2);
costMatrixBuilder.addTransportTime("2a", "0", 2.0);
costMatrixBuilder.addTransportTime("2a", "1a", 2.3);
costMatrixBuilder.addTransportTime("2a", "1b", 1.7);
costMatrixBuilder.addTransportTime("2a", "2a", 0.0);
costMatrixBuilder.addTransportTime("2a", "2b", 2.3);
costMatrixBuilder.addTransportTime("2a", "3a", 1.7);
costMatrixBuilder.addTransportTime("2a", "3b", 1.8);
costMatrixBuilder.addTransportTime("2a", "4a", 3.3);
costMatrixBuilder.addTransportTime("2a", "4b", 3.2);
costMatrixBuilder.addTransportTime("2a", "5a", 3.0);
costMatrixBuilder.addTransportTime("2a", "5b", 2.9);
costMatrixBuilder.addTransportTime("2b", "0", 4.3);
costMatrixBuilder.addTransportTime("2b", "1a", 4.4);
costMatrixBuilder.addTransportTime("2b", "1b", 2.2);
costMatrixBuilder.addTransportTime("2b", "2a", 2.3);
costMatrixBuilder.addTransportTime("2b", "2b", 0.0);
costMatrixBuilder.addTransportTime("2b", "3a", 1.2);
costMatrixBuilder.addTransportTime("2b", "3b", 2.8);
costMatrixBuilder.addTransportTime("2b", "4a", 5.7);
costMatrixBuilder.addTransportTime("2b", "4b", 4.5);
costMatrixBuilder.addTransportTime("2b", "5a", 5.2);
costMatrixBuilder.addTransportTime("2b", "5b", 4.3);
costMatrixBuilder.addTransportTime("3a", "0", 3.5);
costMatrixBuilder.addTransportTime("3a", "1a", 4.0);
costMatrixBuilder.addTransportTime("3a", "1b", 2.5);
costMatrixBuilder.addTransportTime("3a", "2a", 1.7);
costMatrixBuilder.addTransportTime("3a", "2b", 1.2);
costMatrixBuilder.addTransportTime("3a", "3a", 0.0);
costMatrixBuilder.addTransportTime("3a", "3b", 1.5);
costMatrixBuilder.addTransportTime("3a", "4a", 5.0);
costMatrixBuilder.addTransportTime("3a", "4b", 3.3);
costMatrixBuilder.addTransportTime("3a", "5a", 4.2);
costMatrixBuilder.addTransportTime("3a", "5b", 4.3);
costMatrixBuilder.addTransportTime("3b", "0", 3.0);
costMatrixBuilder.addTransportTime("3b", "1a", 4.0);
costMatrixBuilder.addTransportTime("3b", "1b", 3.4);
costMatrixBuilder.addTransportTime("3b", "2a", 1.8);
costMatrixBuilder.addTransportTime("3b", "2b", 2.8);
costMatrixBuilder.addTransportTime("3b", "3a", 1.5);
costMatrixBuilder.addTransportTime("3b", "3b", 0.0);
costMatrixBuilder.addTransportTime("3b", "4a", 4.3);
costMatrixBuilder.addTransportTime("3b", "4b", 1.8);
costMatrixBuilder.addTransportTime("3b", "5a", 2.8);
costMatrixBuilder.addTransportTime("3b", "5b", 5.0);
costMatrixBuilder.addTransportTime("4a", "0", 1.5);
costMatrixBuilder.addTransportTime("4a", "1a", 2.3);
costMatrixBuilder.addTransportTime("4a", "1b", 4.5);
costMatrixBuilder.addTransportTime("4a", "2a", 3.3);
costMatrixBuilder.addTransportTime("4a", "2b", 5.7);
costMatrixBuilder.addTransportTime("4a", "3a", 5.0);
costMatrixBuilder.addTransportTime("4a", "3b", 4.3);
costMatrixBuilder.addTransportTime("4a", "4a", 0.0);
costMatrixBuilder.addTransportTime("4a", "4b", 3.6);
costMatrixBuilder.addTransportTime("4a", "5a", 1.7);
costMatrixBuilder.addTransportTime("4a", "5b", 3.8);
costMatrixBuilder.addTransportTime("4b", "0", 2.7);
costMatrixBuilder.addTransportTime("4b", "1a", 4.5);
costMatrixBuilder.addTransportTime("4b", "1b", 5.0);
costMatrixBuilder.addTransportTime("4b", "2a", 3.2);
costMatrixBuilder.addTransportTime("4b", "2b", 4.5);
costMatrixBuilder.addTransportTime("4b", "3a", 3.3);
costMatrixBuilder.addTransportTime("4b", "3b", 1.8);
costMatrixBuilder.addTransportTime("4b", "4a", 3.6);
costMatrixBuilder.addTransportTime("4b", "4b", 0.0);
costMatrixBuilder.addTransportTime("4b", "5a", 1.9);
costMatrixBuilder.addTransportTime("4b", "5b", 5.7);
costMatrixBuilder.addTransportTime("5a", "0", 1.2);
costMatrixBuilder.addTransportTime("5a", "1a", 3.2);
costMatrixBuilder.addTransportTime("5a", "1b", 4.5);
costMatrixBuilder.addTransportTime("5a", "2a", 3.0);
costMatrixBuilder.addTransportTime("5a", "2b", 5.2);
costMatrixBuilder.addTransportTime("5a", "3a", 4.2);
costMatrixBuilder.addTransportTime("5a", "3b", 2.8);
costMatrixBuilder.addTransportTime("5a", "4a", 1.7);
costMatrixBuilder.addTransportTime("5a", "4b", 1.9);
costMatrixBuilder.addTransportTime("5a", "5a", 0.0);
costMatrixBuilder.addTransportTime("5a", "5b", 4.7);
costMatrixBuilder.addTransportTime("5b", "0", 3.5);
costMatrixBuilder.addTransportTime("5b", "1a", 1.5);
costMatrixBuilder.addTransportTime("5b", "1b", 2.2);
costMatrixBuilder.addTransportTime("5b", "2a", 2.9);
costMatrixBuilder.addTransportTime("5b", "2b", 4.3);
costMatrixBuilder.addTransportTime("5b", "3a", 4.3);
costMatrixBuilder.addTransportTime("5b", "3b", 5.0);
costMatrixBuilder.addTransportTime("5b", "4a", 3.8);
costMatrixBuilder.addTransportTime("5b", "4b", 5.7);
costMatrixBuilder.addTransportTime("5b", "5a", 4.7);
costMatrixBuilder.addTransportTime("5b", "5b", 0.0);
costMatrix = costMatrixBuilder.build();
}
private void createVehicle() {
Builder vehicleBuilder1 = VehicleImpl.Builder.newInstance("wheelchair_bus");
vehicleBuilder1.setStartLocation(Location.newInstance("0")).setEndLocation(Location.newInstance("0"));
vehicleBuilder1.setType(vehicleType_wheelchair);
vehicleBuilder1.setEarliestStart(0);
vehicleBuilder1.setLatestArrival(10);
vehicle1 = vehicleBuilder1.build();
Builder vehicleBuilder1_2 = VehicleImpl.Builder.newInstance("wheelchair_bus_2");
vehicleBuilder1_2.setStartLocation(Location.newInstance("0")).setEndLocation(Location.newInstance("0"));
vehicleBuilder1_2.setType(vehicleType_wheelchair);
vehicleBuilder1_2.setEarliestStart(0);
vehicleBuilder1_2.setLatestArrival(10);
vehicle1_2 = vehicleBuilder1_2.build();
Builder vehicleBuilder2 = VehicleImpl.Builder.newInstance("passenger_bus");
vehicleBuilder2.setStartLocation(Location.newInstance("0")).setEndLocation(Location.newInstance("0"));
vehicleBuilder2.setType(vehicleType_solelypassenger);
vehicleBuilder2.setEarliestStart(0);
vehicleBuilder2.setLatestArrival(10);
vehicle2 = vehicleBuilder2.build();
Builder vehicleBuilder2_2 = VehicleImpl.Builder.newInstance("passenger_bus_2");
vehicleBuilder2_2.setStartLocation(Location.newInstance("0")).setEndLocation(Location.newInstance("0"));
vehicleBuilder2_2.setType(vehicleType_solelypassenger);
vehicleBuilder2_2.setEarliestStart(0);
vehicleBuilder2_2.setLatestArrival(10);
vehicle2_2 = vehicleBuilder2_2.build();
}
private void createVehicleType() {
VehicleTypeImpl.Builder wheelChairTypeBuilder = VehicleTypeImpl.Builder.newInstance("wheelChairBusType");
wheelChairTypeBuilder.addCapacityDimension(WHEELCHAIRSPACE_INDEX, 2);
wheelChairTypeBuilder.addCapacityDimension(PASSENGERSEATS_INDEX, 4);
//wheelChairTypeBuilder.setCostPerDistance(1);
wheelChairTypeBuilder.setCostPerTransportTime(2);
vehicleType_wheelchair = wheelChairTypeBuilder.build();
VehicleTypeImpl.Builder soleyPassengerTypeBuilder = VehicleTypeImpl.Builder.newInstance("passengerBusType");
soleyPassengerTypeBuilder.addCapacityDimension(PASSENGERSEATS_INDEX, 6);
//soleyPassengerTypeBuilder.setCostPerDistance(1);
soleyPassengerTypeBuilder.setCostPerTransportTime(2);
vehicleType_solelypassenger = soleyPassengerTypeBuilder.build();
}
private static Location loc(Coordinate coordinate) {
return Location.Builder.newInstance().setCoordinate(coordinate).build();
}
装运 1 和装运 5 未分配到作业列表。但是,如果我将所有维度的大小更改为 PASSENGERSEATS_INDEX,则所有作业都会正确分配。这是否意味着该算法不支持多个维度?
当我在 Debug模式下进入代码时,我发现有一个分配 4 个作业的解决方案。然而,它被认为是 Jsprit 中不被接受的解决方案。从逻辑上看,这个解决方案应该是正确的解决方案,因为它最大限度地减少了未分配的工作(与原始解决方案相比,只分配 3 个工作)。
最佳答案
当您构建成本矩阵时,您只指定了旅行时间,而不是距离。
默认情况下,未分配任务的成本取决于取货地点和送货地点之间的(最大)距离。由于未设置距离,因此未分配的工作不会受到惩罚。
一个简单的解决方案是在构建成本矩阵时添加一些合理的距离度量:
private void setTransportCost() {
VehicleRoutingTransportCostsMatrix.Builder costMatrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true);
String[] locationIds = new String[] {"0", "1a", "1b", "2a", "2b", "3a", "3b", "4a", "4b", "5a", "5b"};
for (String l1: locationIds) {
for (String l2: locationIds) {
if (!l1.equals(l2)) {
costMatrixBuilder.addTransportDistance(l1, l2, 5);
}
}
}
// ... on with original implementation ...
关于algorithm - Jsprit 的解决方案如果 cargo 有多个尺寸的尺寸是不正确的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54015998/
我正在查看 DOOM 源代码,我找到了 this行。 void * Z_Malloc (int size, int tag, void *user)
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 9 年前。 Improve t
我正从 Python 和 Numpy 转向 C++ 和 Eigen。 在 Python 中,我可以使用 .shape 属性获取 Numpy 数组/矩阵的形状(维度),如下所示: import nump
固定嵌入式YouTube视频的宽度并自己照顾自己的高度是否安全? 我有一个应用程序,用户可以将通知发布到公告板上。这些通知主要是文本(带有有限的html标签)和嵌入式图像。我现在要添加对嵌入式YouT
可以轻松创建一个 THREE.BoxGeometry,在创建宽度、高度和深度的三个独立参数时,您必须在其中传递参数。 我想创建任何和所有不带参数的THREE[types](),并在之后设置值。 有没有
我在 HTML 页面上有一个 Canvas : 属性width和height将 Canvas 拉伸(stretch)到某个字段,但不调整其大小。所以 var canvasElement = docu
我在我的 css 中使用 @media all 和 (max-width: 600px) {} 作为响应式菜单,问题是它没有正确显示。 我想让橙色填充绿色空间……当然,还要将绿色空间变成透明的。基本上
(我知道我问了很多关于这个的问题!) 基本上,我正在尝试将一些代码从 Matlab 转换为 C++,我遇到了这个: n = sum(size(blocks)) - len; 现在我计算了 vector
您好,我有一个用于创建产品的表单。用户应该能够选择类别(例如 T 恤),然后 T 恤的所有尺码(例如 S、M、L)都会下拉。用户可以输入每种尺寸的数量。 Javascript 对此不起作用。用户可以选
我正在尝试在页脚中定位和调整我的社交图标链接的大小,但是,这些命令似乎都没有效果,尤其是当我尝试调整它们的大小时。我试过将宽度和高度标记为“!重要”,但这也没有效果。 这是代码的 JSFiddle:h
我目前正在创建一个 HTML5 canvas基于绘图程序。用户可以绘制一张图像或几张图像“页面”,并将其保存到云端以供日后快速检索。这是用于交互式白板的;老师不能总是确定他们计划类(class)使用的
为网站存储图像的最佳方式是什么? 我不应该超过什么尺寸? 现在,我将所有界面文件保存在 png(主要是 Sprite )中,并将常用图像保存在 jpg 中。一些图像大约为 100-150Kb。 保存图
在 fancybox 主页 ( http://fancybox.net/home ) 中,有一个打开尺寸为屏幕 75% 的 iFrame 的示例。 我无法按照网站上的说明通过修改 .js 文件的宽度和
我想做一个仅适用于 iPhone 4 的应用程序,该应用程序使用 iAd AdBannerView。当我添加它时,它的固定大小为 320x50。在更高分辨率下这如何工作? 有人可以解释一下 iPhon
我们有一个 NSString,我们使用 - (NSSize)sizeWithAttributes:(NSDictionary *)attributes 来测量边界框。一切都好。 现在我们使用标准 NS
我想知道 Canvas 的宽度和高度,但我只知道它的 HDC。 我尝试过这段代码: procedure TForm92.Button1Click(Sender: TObject); var hBi
问题是如何使用数学从 START SVG 维度(不带旋转)和 END SVG 维度(带旋转)获取 >开始 SVG 信息。基本上,要从 START SVG 到 END SVG,我需要执行 -115.60
我的问题是,我有一个包含50万行的Oracle表。我设置了sqoop以将其作为 Parquet 文件导入到HDFS。我将--num-partition参数设置为32,得到了32个 Parquet 文件
是否可以更改 WordPress 中当前主题的 YouTube(或其他视频)的默认嵌入尺寸?我搜索了一个插件和一些代码,但似乎找不到。 我的意思是当您将 YouTube 网址粘贴到帖子或页面中时使用的
我有一个组,其中包含一个矩形和顶部的图像。我希望矩形可以调整大小,并且图像应该具有固定大小,除非矩形小于图像的情况。然后图像应该随着矩形缩小。 图像还应该始终居中并有一些填充。 除了图像的缩小尺寸部分
我是一名优秀的程序员,十分优秀!