0

First of all, question is related to timetabling problem. I have requirement that says that after a scheduling step all scheduled lessons have to meet hard constraints, no matter how long algorithm worked. And a question is, how can I achieve this? My solver configuration looks like this

<?xml version="1.0" encoding="UTF-8"?>
<solver>
    <solutionClass>com.krakfin.praca.mgr.cp.algorytm.solver.TimetableSolution</solutionClass>
    <entityClass>com.krakfin.praca.mgr.cp.algorytm.domain.Lesson</entityClass>
    <scoreDirectorFactory>
        <scoreDefinitionType>HARD_MEDIUM_SOFT</scoreDefinitionType>
    <scoreDrl>com/krakfin/praca/mgr/cp/algorytm/solver/algorytmScoreRules.drl</scoreDrl>
    <initializingScoreTrend>ONLY_DOWN</initializingScoreTrend>
</scoreDirectorFactory>
<environmentMode>FAST_ASSERT</environmentMode>
<constructionHeuristic>
    <constructionHeuristicType>FIRST_FIT_DECREASING</constructionHeuristicType>
</constructionHeuristic>
<localSearch>
    <unionMoveSelector>
        <changeMoveSelector>
            <valueSelector>
                <variableName>dzienNrLekcji</variableName>
            </valueSelector>
        </changeMoveSelector>
        <changeMoveSelector>
            <valueSelector>
                <variableName>sala</variableName>
            </valueSelector>
        </changeMoveSelector>
    </unionMoveSelector>
    <termination>
        <!--Default value if not set-->
        <secondsSpentLimit>180</secondsSpentLimit>
        <bestScoreLimit>0hard/0medium/0soft</bestScoreLimit>
    </termination>
    <acceptor>
        <moveTabuSize>7</moveTabuSize>
    </acceptor>
    <forager>
        <acceptedCountLimit>100</acceptedCountLimit>
    </forager>
</localSearch>
</solver>

but for example, if I run algorithm for 1 minute result looks like (-6hard/-24medium/365soft). Is there any way to make solver not schedule as many lessons but meet all hard constraints?

  • Comment out FAST_ASSERT to solve faster in a minute. – Geoffrey De Smet Oct 14 '15 at 11:24
  • An acceptedCountLimit of 100 is low for Tabu Search. Use the benchmarker to try higher values with Tabu Search or try Late Acceptance with a low value (usually 1). It wouldn't be surprised it's solvable to feasibility without overconstrained planning. – Geoffrey De Smet Oct 14 '15 at 11:26
  • Also see termination that checks if it's feasible. Understand the difference between AND and OR termination composition. – Geoffrey De Smet Oct 14 '15 at 11:26

2 Answers2

0

Yes, it's called overconstrained planning. Look for that keyword in the docs. The Hospital Bed Planning example has this feature enabled.

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
0

Ok, documentation says:

1.Add a additional score level (usually a medium level between the hard and soft level) by switching ScoreDefinition.
2.Make the planning variable nullable.
3.Add a score constraint on the new level (so usually a medium constraint) to penalize the number of unassigned entities (or a weighted sum of them).

So I made my planning variables nullable

@PlanningVariable(valueRangeProviderRefs = {"workingDays"}, strengthWeightFactoryClass = DayLessonNumberStrengthWeightFactory.class, nullable = true)
public DzienNrLekcji getDzienNrLekcji() {
    return base.getDzienNrLekcji();
}

@PlanningVariable(valueRangeProviderRefs = {"roomRange"}, strengthWeightFactoryClass = RoomStrengthWeightFactory.class, nullable = true)
public Sala getSala() {
    return base.getSala();
}

at the next step, I added medium constraint fot not assigned lessons

rule "scheduledLesson"
    when
        $lesson : Lesson( scheduled == false )
    then
        scoreHolder.addMediumConstraintMatch(kcontext, -$lesson.getBase().getDuration());
end

and solver configuration stay the same as in first comment. But changes didn't improve situation. Still I have hard contraints broken. What can I do wrong? Btw, thanks for current tips, they are VERY helpful.

Coroneal
  • 21
  • 2