1

currently i am implementing my second project in OptaPlanner. I am retrieving the following error:

    Exception in thread "main" java.lang.IllegalArgumentException:
    A planning entity is an instance of a entitySubclass (class com.company.Assignment)
    that is not configured as a planning entity.
    If that class (Assignment) (or superclass thereof) is not a entityClass 
    ([class com.company.Car]), check your Solution implementation's annotated methods.
    If it is, check your solver configuration.

My SolverConfig.xml is this:

<?xml version="1.0" encoding="UTF-8"?>
<solver>
<solutionClass>com.company.Planning</solutionClass>
<entityClass>com.company.Car</entityClass>
<scoreDirectorFactory>
    <scoreDefinitionType>HARD_SOFT</scoreDefinitionType>
    <easyScoreCalculatorClass>com.company.PlanningEasyScoreCalculator</easyScoreCalculatorClass>
    <initializingScoreTrend>ONLY_DOWN</initializingScoreTrend>
</scoreDirectorFactory>
<constructionHeuristic>
    <constructionHeuristicType>FIRST_FIT</constructionHeuristicType>
</constructionHeuristic>
<localSearch>
    <termination>
        <secondsSpentLimit>10</secondsSpentLimit>
    </termination>
    <changeMoveSelector>
        <entitySelector>
            <entityClass>com.company.Car</entityClass>
        </entitySelector>
        <valueSelector>
            <variableName>assignment</variableName>
        </valueSelector>
    </changeMoveSelector>
    <acceptor>
        <entityTabuSize>7</entityTabuSize>
    </acceptor>
    <forager>
        <acceptedCountLimit>1000</acceptedCountLimit>
    </forager>
</localSearch>
</solver>

The "Car" class is annotated with "@PlanningEntity". The "Planning" class is annotated with "@PlanningSolution". Tha "Assignment" class is my problem fact. The solution's "@PlanningEntityCollectionProperty" is on a getter that runs a list of "Car".

The "Main" class looks like this:

public class Main {
public static final String SOLVER_CONFIG_XML = "com/company/PlanningSolverConfig.xml";
public static ScoreDirector scoreDirector;
public static void main(String[] args) {
    // Read data from XLS file and initialize the problem
    ReadDataFromXls Reader = new ReadDataFromXls();
    Planning planningSituation = new Planning(Reader.ReadAssignments(),Reader.ReadCars());
    // Build the solver
    Solver solver = SolverFactory.createFromXmlResource(SOLVER_CONFIG_XML).buildSolver();
    // Solve the problem and get the best solution
    solver.solve(planningSituation);
    Planning solvedPlanning = (Planning) solver.getBestSolution();
    // Display the result
    System.out.println("TODO");
}
}

Error message with 6.3.0.CR1 is basically the same + an error concerning SLF4J

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.IllegalArgumentException: A planning entity is an instance of an entitySubclass (class com.company.Assignment) that is not configured as a planning entity.
If that class (Assignment) (or superclass thereof) is not a entityClass ([class com.company.Car]), check your Solution implementation's annotated methods.
If it is, check your solver configuration.

EDIT: My first project in OptaPlanner was a "One to Many" problem (a project has a developer, a developer can have multiple projects). This project is a "One to One" problem (a car is needed to drive to an assignment, an assignment is reched by a car).

EDIT: I changed the model of my planning problem. Now the class "Assignment" is my "planning entity" and the class "Car" is the "planning fact". The error message ist still the same, besides the fact that "Car" and "Assignment" switched places :)

P. Krämer
  • 15
  • 5
  • If I recall correctly, that error message has improved to be more understandable in `6.3.0.CR1` which was released a few days ago. Try that version and report the error message here. It must be a misconfiguration on your domain model somehow. – Geoffrey De Smet Aug 12 '15 at 12:05
  • Basically the same error message (inserted it in the post above). – P. Krämer Aug 12 '15 at 12:37

2 Answers2

0

I bet the Solution's @PlanningEntityCollectionProperty is on a getter that runs a Collection of Assignment (which is not an entity in your case) instead of Car (which is an entity).

The class naming is confusing though. I would rename the class Assignment to Task and the class Car to CarAssignment because anything name assignment is usually the planning entity...

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
  • The solution's "@PlanningEntityCollectionProperty" is on a getter that runs a list of "Car". Basically it is the same structure that i used in my first (working) OptaPlanner project in which i optimized the planning of projects to developers. – P. Krämer Aug 12 '15 at 11:08
0

It must be a misconfiguration on your domain model somehow.

You have been totally right! I called this constructor:

    public Planning(List<Car> carList, List<Assignment> assignmentList) {
    this.carList = carList;
    this.assignmentList = assignmentList;
    }

With this arguments:

Planning planningSituation = new Planning(Reader.ReadAssignments(),Reader.ReadCars());

Thanks for helping!

P. Krämer
  • 15
  • 5