在硬约束OptaPlanner算法的影响 [英] OptaPlanner algorithm impact on hard constraints

查看:425
本文介绍了在硬约束OptaPlanner算法的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,问题是有关时间表的问题。我有要求,指出调度步骤后所有预定的课程必须满足硬约束,无论多久算法的工作。而一个问题是,我怎么能做到这一点?我的解算器的配置看起来像这样

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>

但举例来说,如果我运行算法1分钟结果如下(-6hard / -24medium / 365soft)。有没有什么办法让求解器无法安排尽可能多的经验教训,但满足所有严格约束?

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?

推荐答案

好了,文件说:

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();
}

在下一步,我添加的中约束FOT未分配的教训

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.

这篇关于在硬约束OptaPlanner算法的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆