- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 JSPRIT 来解决路由和旅行者问题。它实际上适用于简单的约束(时间、容量等)。但我试图实现“相关工作”约束。对于像第 7 个工作在列表中的第 1 个之前服务的简单案例,我成功了。
我想对一些服务进行分组优化。例如,我想强制 7 号在 1 号之前服务,21 号在 13 号之前服务。也许还有更多。
当我尝试这样做时,结果顺序仅排在第 1 个之前的第 7 个,但第 21 个不在第 13 个之前,有时甚至不在同一条路线上。
这是一个比:Related jobs in JSprit 更复杂的案例.
谁能举个例子?有人试过吗?
public final static int PERSON_DIMENSION_INDEX = 0;
public final static boolean VEHICLE_RETURNS_AT_DEPOT = false;
public final static Location TEST_VEHICLE_LOCATION = Location.newInstance(48.856614, 2.352222);
public final static int TEST_VEHICLE_LOCATION_INDEX = 0;
public final static int MAX_INCREMENT = 25;
public final static boolean USE_DISTANCE_MATRIX = true;
public final static boolean ADD_TIME_CONSTRAINTS = false;
public final static boolean USE_ONE_BEFORE_ANOTHER_CONSTRAINT = true;
private static final boolean PLOT_RESULT = false;
public static void main(String[] args) {
/*
* Date today : 8 o'clock
*/
// .getDirections(contextTest, "27 rue jacques louvel tessier", "10 rue
// de geispitzen");
Calendar c = new GregorianCalendar();
c.set(Calendar.HOUR_OF_DAY, 8); // anything 0 - 23
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
Date d1 = c.getTime(); // the midnight, that's the first second of the
// day.
System.out.println("Date today 8h clock");
System.out.println(d1.toString());
System.out.println(d1.getTime() / 1000);
final long TODAY_START_TIME = d1.getTime() / 1000;
/*
* Here, get the vehicles types.
*/
List<TypeVehicle> vehicleTypes = getVehiclesTypesFromDatabase();
/*
* Built de jsprit vehicle types.
*/
Map<String, VehicleTypeImpl> jSpritvVehicleTypes = new HashMap<String, VehicleTypeImpl>();
for (TypeVehicle vehicleType : vehicleTypes) {
String vehicleTypeId = String.valueOf(vehicleType.getId());
int vehicleCapacity = vehicleType.getAvailableSeats();
VehicleTypeImpl jSpritvVehicleType = VehicleTypeImpl.Builder.newInstance(vehicleTypeId)
.addCapacityDimension(PERSON_DIMENSION_INDEX, vehicleCapacity).build();
jSpritvVehicleTypes.put(vehicleTypeId, jSpritvVehicleType);
}
/*
* Here, get the vehicles.
*/
List<Vehicle> vehicles = getVehiclesFromDatabase();
/*
* Here, build the vehicles.
*/
Map<String, VehicleImpl> jSpritVehicles = new HashMap<String, VehicleImpl>();
for (Vehicle Vehicle : vehicles) {
String vehicleId = String.valueOf(Vehicle.getId());
List<Habilitation> habilitations = Vehicle.getHabilitations();
String thisVehicleTypeId = String.valueOf(Vehicle.getType());
VehicleTypeImpl vehicleType = jSpritvVehicleTypes.get(thisVehicleTypeId);
Skills skills = null;
for (Habilitation habilitation : habilitations) {
skills = new Skills.Builder().addSkill(habilitation.getLabel()).build();
}
VehicleImpl vehicleImpl = VehicleImpl.Builder.newInstance(vehicleId).setType(vehicleType).addSkills(skills)
.setStartLocation(TEST_VEHICLE_LOCATION).setEarliestStart(TODAY_START_TIME).build();
jSpritVehicles.put(vehicleId, vehicleImpl);
}
/*
* Here, get the spots to serve (pickups and deliveries)
*/
List<Place> places = getSpots(); // This will change a lot.
List<Service> services = new ArrayList<Service>();
int increment = 0;
String[] origins = new String[MAX_INCREMENT];
String[] destinations = new String[MAX_INCREMENT];
origins[0] = TEST_VEHICLE_LOCATION.getCoordinate().getX() + "," + TEST_VEHICLE_LOCATION.getCoordinate().getY();
destinations[0] = TEST_VEHICLE_LOCATION.getCoordinate().getX() + ","
+ TEST_VEHICLE_LOCATION.getCoordinate().getY();
increment++;
for (Place place : places) {
if (increment < MAX_INCREMENT) {
String id = String.valueOf(increment);
int dimensionValue = place.getAccessibility();
double lat = place.getLat();
double lng = place.getLng();
Location location = Location.newInstance(lat, lng);
Service.Builder builder = Service.Builder.newInstance(id)
.addSizeDimension(PERSON_DIMENSION_INDEX, dimensionValue).setLocation(location);
/*
* TIME CONSTRAINTS
*/
if (ADD_TIME_CONSTRAINTS) {
int random = randomNumber(0, 43200); // 12 hours of possible
// work. 8am / 8pm
System.out.println("Time windows : " + new Date((TODAY_START_TIME + random) * 1000).toString()
+ " / " + new Date((TODAY_START_TIME + random + 1800) * 1000).toString());
builder.addTimeWindow(TODAY_START_TIME + random, TODAY_START_TIME + random + 1800);
}
Service service = builder.build();
services.add(service);
origins[increment] = lat + "," + lng;
destinations[increment] = lat + "," + lng;
increment++;
}
}
/*
* Here, get the constraints (ex : one before another)
*/
/*
* Here, get the time limits
*/
VehicleRoutingTransportCostsMatrix costsMatrix;
if (USE_DISTANCE_MATRIX) {
/*
* Distances matrix
*/
VehicleRoutingTransportCostsMatrix.Builder vrtcMatrix = VehicleRoutingTransportCostsMatrix.Builder
.newInstance(true);
GeoApiContext context = null;
costsMatrix = generateCostMatrix(origins, destinations, vrtcMatrix, context);
}
/*
* Init jsprit
*/
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
vrpBuilder.addAllVehicles(jSpritVehicles.values()).addAllJobs(services);
vrpBuilder.setFleetSize(FleetSize.INFINITE);
if (USE_DISTANCE_MATRIX) {
System.out.println("Using DISTANCE MATRIX...");
vrpBuilder = vrpBuilder.setRoutingCost(costsMatrix);
} else {
System.out.println("NOT Using DISTANCE MATRIX...");
}
VehicleRoutingProblem problem = vrpBuilder.build();
/*
* get the algorithm out-of-the-box.
*/
VehicleRoutingAlgorithm algorithm;
if (USE_ONE_BEFORE_ANOTHER_CONSTRAINT) {
/**
* Adding constraints...
*/
String before = "11";
String after = "9";
final StateManager stateManager = new StateManager(problem);
stateManager.addStateUpdater(new JobsInRouteMemorizer(stateManager));
ConstraintManager constraintManager = new ConstraintManager(problem, stateManager);
constraintManager.addConstraint(new OneJobBeforeAnother(stateManager, before, after));
final RewardAndPenaltiesThroughSoftConstraints contrib = new RewardAndPenaltiesThroughSoftConstraints(problem, before, after);
SolutionCostCalculator costCalculator = new SolutionCostCalculator() {
@Override
public double getCosts(VehicleRoutingProblemSolution solution) {
double costs = 0.;
List<VehicleRoute> routes = (List<VehicleRoute>) solution.getRoutes();
for(VehicleRoute route : routes){
costs+=route.getVehicle().getType().getVehicleCostParams().fix;
costs+=stateManager.getRouteState(route, InternalStates.COSTS, Double.class);
costs+=contrib.getCosts(route);
}
return costs;
}
};
VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(problem,
"algorithmConfig.xml");
vraBuilder.addCoreConstraints();
vraBuilder.setStateAndConstraintManager(stateManager, constraintManager);
vraBuilder.setObjectiveFunction(costCalculator);
algorithm = vraBuilder.build();
} else {
algorithm = Jsprit.createAlgorithm(problem);
}
/*
* and search a solution which returns a collection of solutions (here
* only one solution is constructed)
*/
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
/*
* use the static helper-method in the utility class Solutions to get
* the best solution (in terms of least costs)
*/
for (VehicleRoutingProblemSolution vehicleRoutingProblemSolution : solutions) {
System.out.println("Solution #"
+ ((List<VehicleRoutingProblemSolution>) solutions).indexOf(vehicleRoutingProblemSolution));
System.out.println(vehicleRoutingProblemSolution.getCost());
}
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);
SolutionPrinter.print(problem, bestSolution, Print.VERBOSE);
new GraphStreamViewer(problem, bestSolution).labelWith(Label.ID).setRenderDelay(100).display();
if(PLOT_RESULT){
new GraphStreamViewer(problem, bestSolution).labelWith(Label.ID).setRenderDelay(100).display();
}
}
最佳答案
我终于知道了。我只是忘了将生成的成本添加到成本计算器中。见下文:
final List<RewardAndPenaltiesThroughSoftConstraints> contribs = new ArrayList<RewardAndPenaltiesThroughSoftConstraints>();
for (Integer id : forcedOrdersList.keySet()) {
List<String> order= forcedOrdersList.get(id);
String before = order.get(0);
String after = order.get(1);
constraintManager.addConstraint(new OneJobBeforeAnother(stateManager, before, after));
contribs.add(new RewardAndPenaltiesThroughSoftConstraints(problem, before, after));
}
SolutionCostCalculator costCalculator = new SolutionCostCalculator() {
@Override
public double getCosts(VehicleRoutingProblemSolution solution) {
double costs = 0.;
List<VehicleRoute> routes = (List<VehicleRoute>) solution.getRoutes();
for(VehicleRoute route : routes){
costs+=route.getVehicle().getType().getVehicleCostParams().fix;
costs+=stateManager.getRouteState(route, InternalStates.COSTS, Double.class);
for (RewardAndPenaltiesThroughSoftConstraints contrib : contribs) {
costs+=contrib.getCosts(route);
}
}
return costs;
}
};
关于java - Jsprit : Can't add multiple related jobs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36397318/
I have a question about adding files in git. I have found multiple stackoverflow questions about
我是 visual studio 的新手,来自 Delphi。 我有一个充满 .cs 文件的目录树(根是\Common)。 我还有一个充满应用程序的目录树(根目录是\Applications) 最后,
这个问题在这里已经有了答案: Array's lookup time complexity vs. how it is stored (4 个答案) Time complexity for java
谁能告诉我这两者有什么区别: ALTER TABLE x1 ADD INDEX(a); ALTER TABLE x1 ADD INDEX(b); 和 ALTER TABLE x1 ADD INDEX(
为什么有时我们使用 getChildren() add() 而其他时候我们直接使用 add() es: https://docs.oracle.com/javafx/2/get_started/for
如何使用 bootstrap css 在输入下方添加跨度?我需要做这样的事情: 最佳答案 是这样的吗? http://jsfiddle.net/swm53ran/205/ 您可以使用纯 CSS 来实现
问题 np.add(X, 2*Y, out=X) 比 np.add(X, Y, out=X); np.add(X, Y, out=X).使用 np.add(X, Y, out=X); 是一种实际做法吗
当我跑 git add --intent-to-add .所有未跟踪的文件将其状态从“未跟踪的文件”( git status -s 显示 ?? )更改为“未暂存以进行提交的更改”( git statu
我不知道 .add 之间有什么区别和 .sink.add ? 例子: StreamController myStreamController = StreamController(); stream
getContentPane().add() 和 add() 的意思一样吗? public class TestFrame extends JFrame{ public TestFrame()
git add . 和 git add * 会完成完全相同的事情吗? 最佳答案 不,不会。 * 是一个 glob 模式,不会匹配以 开头的文件。 例如,假设这是当前目录,我有 2 个新文件要添加 fo
git的分支与合并的两种方法 git add -A和 git add . git add -u在功能上看似很相近,但还是存在一点差别 git add . :他会
git add [--all | -A] 之间有什么区别?和 git add . ? 最佳答案 此答案仅适用于 Git 版本 1.x。对于 Git 版本 2.x,请参阅其他答案。 总结: git ad
我刚刚安装了最新的 Wix v3.7。我创建了一个 VS 2010“Excel 2010 加载项”项目,并在同一个解决方案中创建了一个 Wix“安装项目”。 问题是,当我尝试从 Wix 项目中引用 A
YUI.add 和 YUI().add 有什么区别? 最佳答案 在第一种情况下,您要注册一个模块可以加载到 YUI 沙箱中,在第二种情况下,您要构建一个沙箱,然后进行注册(这是一种非常不典型的用法)。
测试代码时,任何输入到列表中的值在按下“enter”后都会消失。 我对编程和网络开发非常陌生。请具体一点,以便我理解。 function addItem(){ var item = documen
我正在浏览 python 的 dis 包。我尝试了代码以查看它是如何工作的 >>> def get(): ... x=4 ... y=x+3 ............ this lin
我已经对我的文件夹进行了版本控制 git init git add . git commit -m 'Initial commit' 我应该怎么做 git add 对于我在 .? 中创建的每个新文件
当我执行 $ git add * 时,有时我意识到 git 不会将已删除的文件添加到舞台上,如果删除或添加它,我需要手动指示,但我想不通找出 $ git add --all 有什么区别。因此,如果星号
这个问题在这里已经有了答案: Difference between "git add -A" and "git add ." (12 个答案) 关闭 6 年前。 目前,当我想提交并将内容推送到远程
我是一名优秀的程序员,十分优秀!