Optaplanner VRP将客户从工作解决方案中移除

问题描述 投票:3回答:1

基于来自云平衡问题的这个example,我试图从一个工作解决方案中删除客户,如下所示:

Location toBeRemovedLocation = customerToBeRemoved.getLocation();
Location lookUpWorkingObject = (Location) scoreDirector.lookUpWorkingObject(toBeRemovedLocation);
scoreDirector.beforeProblemFactRemoved(lookUpWorkingObject);
routingSolution.getLocationList().remove(lookUpWorkingObject);
scoreDirector.afterProblemFactRemoved(lookUpWorkingObject);

Customer workingCustomer=(Customer) scoreDirector.lookUpWorkingObject(customerToBeRemoved);

for (Customer customer : routingSolution.getCustomerList()) {
    nextCustomer=customer.getNextCustomer();
    if (nextCustomer==workingCustomer) {
        scoreDirector.beforeVariableChanged(customer, "nextCustomer");
        customer.setNextCustomer(null);
        scoreDirector.afterVariableChanged(customer, "nextCustomer");
    }
}

scoreDirector.beforeEntityRemoved(workingCustomer);
routingSolution.getCustomerList().remove(workingCustomer);
scoreDirector.afterEntityRemoved(workingCustomer);
scoreDirector.triggerVariableListeners();

结果我得到了这个例外:

java.lang.IllegalStateException:实体(Customer - 6361356485874019865)有一个变量(previousStandstill),其值为(Customer - 9027426768799526425),它有一个sourceVariableName变量(nextCustomer),其值(null)不是该实体。验证sourceVariableName变量的输入问题的一致性

在那之后,我试图setPreviousStandstillnull

scoreDirector.beforeVariableChanged(customer, "previousStandstill");
customer.setPreviousStandstill(null);
scoreDirector.afterVariableChanged(customer, "previousStandstill");

但是,我收到了:

java.lang.IllegalStateException:实体(Customer - 6361368382933429785)有一个变量(previousStandstill),其值为(Customer - 9027434800388369945),它有一个sourceVariableName变量(nextCustomer),其值(null)不是该实体。验证sourceVariableName变量的输入问题的一致性。

请帮忙。

java optaplanner
1个回答
0
投票

如果您目前有链[Customer1,Customer2,Customer3],VRP中的客户将被链接/链接

- Customer1: nextCustomer = Customer2
- Customer2: nextCustomer = Customer2, prevStandstill = Customer1
- Customer3: prevStandstill = Customer2

并且您尝试从中删除Customer2,您必须修复上一个和下一个元素:

- Customer1: nextCustomer = Customer3
- Customer2: nextCustomer = null, prevStandstill = null
- Customer3: prevStandStill = Customer1
© www.soinside.com 2019 - 2024. All rights reserved.