I have to plan a list of orders into machines and I modeled the entities using TaskAssigning as sample.
This is my code:
@PlanningEntity
public class Machine {
private List<Order> m_plannedOrders;
...
@PlanningListVariable
public List<Order> getPlannedOrders() {
return m_plannedOrders;
}
public void setPlannedOrders(List<Order> orders) {
m_plannedOrders = orders;
}
...
}
@PlanningEntity
public class Order {
private Machine m_machine;
...
@InverseRelationShadowVariable(sourceVariableName = "plannedOrders")
public Machine getMachine() {
return m_machine;
}
public void setMachine(Machine machine) {
m_machine = machine;
}
}
@PlanningSolution
public class MachineOrdersPlanning {
...
@PlanningEntityCollectionProperty
public List<Machine> getMachines() {
return m_machines;
}
@ValueRangeProvider
@ProblemFactCollectionProperty
public List<Order> getOrders() {
return m_orders;
}
@PlanningScore
public HardSoftScore getScore() {
return m_score;
}
}
The problem is in the inverse relation shadow variable. After each solving the PlanningListVariable in full of data, but the inverse is always null and I don't know why.
I debugged the TaskAssigning sample and here both PlanninListVar and Inverse contain data.
Any help is appreciated.
The Order
might not be registered as a planning entity.
If you're using the Spring or Quarkus extension, that should happen automatically. Otherwise check your SolverConfig.
The easiest way to verify which planning entities are registered is by turning on TRACE
logging in OptaPlanner/Timefold (and solve for 1 second). On the solving started event it will log all planning entities it detected.