[英]Adding new Planning Variable to the Vehicle Routing Problem
I'm trying to add a new variable to the Vehicle Routing Problem to represent a vehicle (bus) picking up people and let them in locations with match some facts (these resources must attend one customer each).我正在尝试向车辆路线问题添加一个新变量,以表示一辆载人的车辆(公共汽车)并让他们在与某些事实相匹配的位置(这些资源必须每个人服务一个客户)。 I have created a new class called Resource and declared a new resource variable inside the Customer class, so when a new move is made, I want the solver to select a new Customer to a Vehicle (route) and a Resource from the list (which eventually will be also in the vehicle, as well).我创建了一个名为 Resource 的新 class 并在客户 class 中声明了一个新的资源变量,所以当进行新的移动时,我希望求解器到 select 一个新客户列表中的资源(最终也将在车辆中)。 In the Customer.java:在 Customer.java 中:
@PlanningVariable(valueRangeProviderRefs = {"resourceRange"})
public Resource getResource() {
return resource;
}
public void setResource(Resource resource) {
this.resource = resource;
}
And in the VehicleRoutingSolution.java:在 VehicleRoutingSolution.java 中:
protected List<Resource> resourceList;
[...] [...]
@ProblemFactCollectionProperty
@ValueRangeProvider(id = "resourceRange")
public List<Resource> getResourceList() {
return resourceList;
}
public void setResourceList(List<Resource> resourceList) {
this.resourceList = resourceList;
}
Finally I have made some changes to the vehicleRoutingSolverConfig.xml:最后我对vehicleRoutingSolverConfig.xml做了一些修改:
<?xml version="1.0" encoding="UTF-8"?>
<solver>
<!--<environmentMode>FAST_ASSERT</environmentMode>-->
<solutionClass>com.ezentis.mplanner.vehiclerouting.domain.VehicleRoutingSolution</solutionClass>
<entityClass>com.ezentis.mplanner.vehiclerouting.domain.Standstill</entityClass>
<entityClass>com.ezentis.mplanner.vehiclerouting.domain.Customer</entityClass>
<entityClass>com.ezentis.mplanner.vehiclerouting.domain.timewindowed.TimeWindowedCustomer</entityClass>
<scoreDirectorFactory>
<!--<easyScoreCalculatorClass>com.ezentis.mplanner.vehiclerouting.solver.score.VehicleRoutingEasyScoreCalculator</easyScoreCalculatorClass>-->
<incrementalScoreCalculatorClass>com.ezentis.mplanner.vehiclerouting.solver.score.VehicleRoutingIncrementalScoreCalculator</incrementalScoreCalculatorClass>
<!-- scoreDrl>com/ezentis/mplanner/vehiclerouting/solver/vehicleRoutingScoreRules.drl</scoreDrl-->
<!--<assertionScoreDirectorFactory>-->
<!--<easyScoreCalculatorClass>com.ezentis.mplanner.vehiclerouting.solver.score.VehicleRoutingEasyScoreCalculator</easyScoreCalculatorClass>-->
<!--</assertionScoreDirectorFactory>-->
<initializingScoreTrend>ONLY_DOWN</initializingScoreTrend>
</scoreDirectorFactory>
<termination>
<minutesSpentLimit>5</minutesSpentLimit>
</termination>
<constructionHeuristic>
<constructionHeuristicType>FIRST_FIT</constructionHeuristicType>
<!-- <queuedEntityPlacer>
<entitySelector id="placerEntitySelector">
<entityClass>com.ezentis.mplanner.vehiclerouting.domain.Customer</entityClass>
<cacheType>PHASE</cacheType>
<selectionOrder>SORTED</selectionOrder>
<sorterManner>DECREASING_DIFFICULTY</sorterManner>
</entitySelector>
<cartesianProductMoveSelector>
<changeMoveSelector>
<entitySelector mimicSelectorRef="placerEntitySelector"/>
<valueSelector variableName="vehicleRange">
<downcastEntityClass>com.ezentis.mplanner.vehiclerouting.domain.Vehicle</downcastEntityClass>
<cacheType>PHASE</cacheType> -->
<!--<selectionOrder>SORTED</selectionOrder>-->
<!--<sorterManner>INCREASING_STRENGTH</sorterManner>-->
<!-- </valueSelector>
</changeMoveSelector>
<changeMoveSelector>
<entitySelector mimicSelectorRef="placerEntitySelector"/>
<valueSelector variableName="resourceRange">
<cacheType>PHASE</cacheType>
<selectionOrder>SORTED</selectionOrder>
<sorterManner>INCREASING_STRENGTH</sorterManner>
</valueSelector>
</changeMoveSelector>
</cartesianProductMoveSelector>
</queuedEntityPlacer> -->
</constructionHeuristic>
<localSearch>
<unionMoveSelector>
<changeMoveSelector>
<entitySelector id="entitySelector1"/>
<valueSelector>
<nearbySelection>
<originEntitySelector mimicSelectorRef="entitySelector1"/>
<nearbyDistanceMeterClass>com.ezentis.mplanner.vehiclerouting.domain.solver.nearby.CustomerNearbyDistanceMeter</nearbyDistanceMeterClass>
<parabolicDistributionSizeMaximum>40</parabolicDistributionSizeMaximum>
</nearbySelection>
</valueSelector>
</changeMoveSelector>
<swapMoveSelector>
<entitySelector id="entitySelector2"/>
<secondaryEntitySelector>
<nearbySelection>
<originEntitySelector mimicSelectorRef="entitySelector2"/>
<nearbyDistanceMeterClass>com.ezentis.mplanner.vehiclerouting.domain.solver.nearby.CustomerNearbyDistanceMeter</nearbyDistanceMeterClass>
<parabolicDistributionSizeMaximum>40</parabolicDistributionSizeMaximum>
</nearbySelection>
</secondaryEntitySelector>
</swapMoveSelector>
<tailChainSwapMoveSelector>
<entitySelector id="entitySelector3"/>
<valueSelector>
<nearbySelection>
<originEntitySelector mimicSelectorRef="entitySelector3"/>
<nearbyDistanceMeterClass>com.ezentis.mplanner.vehiclerouting.domain.solver.nearby.CustomerNearbyDistanceMeter</nearbyDistanceMeterClass>
<parabolicDistributionSizeMaximum>40</parabolicDistributionSizeMaximum>
</nearbySelection>
</valueSelector>
</tailChainSwapMoveSelector>
</unionMoveSelector>
<acceptor>
<lateAcceptanceSize>200</lateAcceptanceSize>
</acceptor>
<forager>
<acceptedCountLimit>1</acceptedCountLimit>
</forager>
</localSearch>
</solver>
But when I upload the problem and start the solver, I get this error:但是当我上传问题并启动求解器时,我收到了这个错误:
java.lang.IllegalStateException: Multiple EntityMimicRecorders (usually EntitySelectors) have the same id (entitySelector1).
I am really stuck with this as I'm not able to include the new Planning Variable.我真的坚持这一点,因为我无法包含新的计划变量。 I have tried a lot of another code configurations, although I think this is the more clear.我已经尝试了很多其他代码配置,尽管我认为这更清楚。 Any help would be really appreciated.任何帮助将非常感激。
I am not sure if this will really work but when you do something like that you won't get the error.我不确定这是否真的有效,但是当你做类似的事情时,你不会得到错误。
<valueSelector variableName="variableName">
I only need the nearbySelection for the chained variable.我只需要链式变量的附近选择。
If you want the nearby selection for both variables you could try to have two <changeMoveSelector>
with each one nearby config.如果您想要两个变量的附近选择,您可以尝试有两个<changeMoveSelector>
与每个附近的配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.