Optaplanner添加计算机室限制 [英] Optaplanner add computerroom restriction
问题描述
这是我在这里的第一篇文章,我发布为我的学习Java程序员的学校项目团队。所以我们不是好的程序员。
如何添加约束,使Optaplanner将讲座移动到特定的房间类型。
例如,我想将编程课程移动到计算机室,在正常的房间里演讲数学。但是我的约束声明了硬约束,但不移动他们的房间里的讲座。这应该是一个负约束。所以显示这个硬约束的负分数,但它仍然不会被解决/移动。
it's my first post here and I'm posting for my team of learning Java programmer for an school project. So we aren't good programmer. how can I add a constraint to make the Optaplanner move the lectures into a specific room type. For example I want to move the lecture "Programming" into a computerroom and the lecture "Math" in a normal room. But with my constraint it declares the hard constraints but doesn't move the lectures in their room. This should be a negative constraint. So the negative score for this hard constraint is shown, but it still won't be resolved/moved.
以下是约束:
rule "computerroom"
when
$room : Room($computerroom : computerroom)
$course : Course(computerroom == $computerroom)
then
scoreHolder.addHardConstraintMatch(kcontext, -1);
end
我们在Room类中添加了一个新变量, p>
We added a new variable to the class Room, that look like:
package org.optaplanner.examples.curriculumcourse.domain;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import org.optaplanner.examples.common.domain.AbstractPersistable;
@XStreamAlias("Room")
public class Room extends AbstractPersistable {
private String code;
private int capacity;
private boolean computerroom;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public boolean getComputerroom() {
return computerroom;
}
public void setComputerroom(boolean computerroom) {
this.computerroom = computerroom;
}
public int getCapacity() {
return capacity;
}
public void setCapacity(int capacity) {
this.capacity = capacity;
}
public String getLabel() {
return code;
}
@Override
public String toString() {
return code + " {C" + capacity + "}";
}
}
我们?
另一件小事:Optaplanner获得了大量的数据:
我们如何增加解决的最大秒花费?因为我们尝试了超过1152的其他值,但它不工作。
这只是一个小问题,约束更重要,但我们很乐意让程序运行!
Another little thing: the Optaplanner gets a lot of data to work with: How can we increase the maximun seconds spend for resolving? Because we tried other values over 1152 but it does't work. It's only a little question, the constraint is more important, but we would be happy to get the program running!
Greets
SEP2014
Greets SEP2014
推荐答案
该分数规则不检查任何计划变量(=在解决过程中更改的变量)。
That score rule isn't checking anything that is "planning variable" (= a variable that changes during solving). So it's static, it can never have a different score than with what it starts out with.
请考虑这样做:
rule "computerroom"
when
// If there's a room which has no computer
$r : Room(hasComputer == false)
// And we're putting a course which needs a computer in that room
$course : Course(needsComputer == true, room == $r)
then
scoreHolder.addHardConstraintMatch(kcontext, -1);
end
这里重要的是 ...,room == $ r)
。 room
是一个规划变量:在规划期间会发生变化。
The important thing here is Course(..., room == $r)
. That room
is a planning variable: it changes during planning.
注意:
相同的规则,但写得更短,更有效率
Same rule, but written shorter and more efficiently:
rule "computerroom"
when
$course : Course(needsComputer == true, room != null, room.hasComputer == false)
then
scoreHolder.addHardConstraintMatch(kcontext, -1);
end
这篇关于Optaplanner添加计算机室限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!