0

Using Optaplanner, is it possible to define a class to be a planning entity and planning variable at the same time ?

Example :

  @PlanningEntity(difficultyComparatorClass = NodeDifficultyComparator.class)
    public class Node extends ProcessChain {
       // Planning variables: changes during planning, between score calculations.
        private List<Node>  parents;
        private List<Node>  childs;


        @PlanningVariable(valueRangeProviderRefs = {"nodeRange"})
        public List<Node> getParents() {
            return parents;
        }

        @PlanningVariable(valueRangeProviderRefs = {"nodeRange"})
        public List<Node> getChilds() {
            return childs;
        }

        public void setParents(List<Node> parents) {
            this.parents = parents;
        }

        public void setChilds(List<Node> childs) {
            this.childs = childs;
        }
    }
Jack Kass
  • 55
  • 9

1 Answers1

2

The TSP and Vehicle Routing example already have planning values that are planning entities too, although they both use a chained=true variable. Because chained=true, it implies that no 2 planning entities have the same planning variable (and all are directly or indirectly connected to an anchor). See docs section "chained planning variables".

I suspect in your case, that you don't want chains, but instead a tree, a directed graph or an undirected graph. An undirected graph (= a graph which allows cycles) is problematic for Construction Heuristics, because out-of-the-box they can't construct a graph with a cycle. As for a tree and a directed graph: it should work in theory, but you might need custom moves (see docs) to have the moves be efficient. In the future, we'd like to support a tree structure similarly to how we support chains (for job shop scheduling).

In any case: you can't have a @PlanningVariable on a List of planning entities currently. You 'll need to turn many2many relationships into many2one and one2many relationships.

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
  • I'm not sure i can use many2one relationship in my case though. I'm using a kind of directed tree diagram (each node can have multiple parents and children). Each node represent a certain task. The whole graph represent dependencies between tasks. i've got to schedule the tasks considering multiple constraints (minimize the total time of the process, never use more resources than available at any time...). To do this, the planner must modify the parents of each node (many2many) until he find the best solution. Do you think, there's a workaround for my problem? – Jack Kass May 23 '14 at 09:21
  • OptaPlanner currently doesn't fully support the model you're proposing (with the List's). But it sounds to me like you're dealing with a project job scheduling case, and we have a full implemented example of that. See [video](https://www.youtube.com/watch?v=_2zweB9JD7c). – Geoffrey De Smet May 23 '14 at 09:41