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

时间:2017-12-20 19:39:57

标签: java optaplanner

根据云平衡问题中的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:实体   (客户 - 6361356485874019865)有一个变量(previousStandstill)   有价值的(客户 - 9027426768799526425)有一个   sourceVariableName变量(nextCustomer),其值为(null)   不是那个实体。验证输入问题的一致性   那个sourceVariableName变量

之后,我还尝试setPreviousStandstillnull

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

但是,我收到了:

  

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

请帮助。

1 个答案:

答案 0 :(得分:0)

如果您目前拥有链[Customer1,Customer2,Customer3]

,VRP中的客户将被链接/链接
asan_device_setup

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

async Task Add(Item item) { ... }

async Task YourMethod()
{
    var tasks = new List<Task>();
    foreach (var item in collection)
    {
        tasks.Add(Add(item));
    }

    // do any work you need
    Console.WriteLine("Working...");

    // then ensure the tasks are done
    await Task.WhenAll(tasks);

    // and flush them out
    await Flush();
}