Offhand, it seems like the room needs to maintain a 'grid' of x and y tiles and
which tables occupy each tile. That way you can plan while making sure that no two tables
overlap.
Sent from my iPhone
On Jun 22, 2012, at 5:55 PM, Ricardo <sprabakkar(a)gmail.com> wrote:
Hi when i use the following drl file for score calculation ....It assign a
bigger table into the smaller room. help will be appreciated....
console output is as follows..
*Solved Organizer with 2 rooms and 3 tables:
Table 1 -> Room 1
Table 2 -> Room 2
Table 3 -> Room 2*
test data:
Room room1 = new Room(10, 10);
room1.setId((long) 1);
Room room2 = new Room(10, 10);
room2.setId((long) 2);
----
Table table1 = new Table(10, 10);
table1.setId((long) 1);
Table table2 = new Table(9, 9);
table2.setId((long) 2);
Table table3 = new Table(9, 9);
table3.setId((long) 3);
drl file for score calculation...
//created on: Jun 18, 2012
package org.drools.planner.organizer;
dialect "java"
//list any import classes here.
import
org.drools.planner.core.score.buildin.hardandsoft.HardAndSoftScoreHolder;
import org.drools.planner.core.score.constraint.IntConstraintOccurrence;
import org.drools.planner.core.score.constraint.ConstraintType;
import org.drools.planner.organizer.domain.Room;
import org.drools.planner.organizer.domain.Table;
//declare any global variables here
global HardAndSoftScoreHolder scoreHolder;
//
############################################################################
// Hard constraints
//
############################################################################
rule "requiredLengthTotal"
when
$room : Room($length : length)
$requiredSpaceTotal : Number(intValue > $length) from accumulate(
Table(
room == $room,
$tablelength : length),
sum($tablelength)
)
then
insertLogical(new IntConstraintOccurrence("requiredLengthTotal",
ConstraintType.NEGATIVE_HARD,
$requiredSpaceTotal.intValue() - $length,
$room));
end
rule "requiredWidthTotal"
when
$room : Room($width : width)
$requiredSpaceTotal : Number(intValue > $width) from accumulate(
Table(
room == $room,
$tablewidth : width),
sum($tablewidth)
)
then
insertLogical(new IntConstraintOccurrence("requiredWidthTotal",
ConstraintType.NEGATIVE_HARD,
$requiredSpaceTotal.intValue() - $width,
$room));
end
//
############################################################################
// Soft constraints
//
############################################################################
rule "roomLengthCapacity"
when
$room : Room($length : length)
$table : Table(room == $room, length > $length, $tablelength :
length)
then
insertLogical(new IntConstraintOccurrence("roomLengthCapacity",
ConstraintType.NEGATIVE_SOFT,
($tablelength - $length),
$room, $table));
end
rule "roomWidthCapacity"
when
$room : Room($width : width)
$table : Table(room == $room, width > $width, $tablewidth : width)
then
insertLogical(new IntConstraintOccurrence("roomWidthCapacity",
ConstraintType.NEGATIVE_SOFT,
($tablewidth - $width),
$room, $table));
end
//
############################################################################
// Calculate score
//
############################################################################
// Accumulate hard constraints
rule "hardConstraintsBroken"
salience -1 // Do the other rules first (optional, for performance)
when
$hardTotal : Number() from accumulate(
IntConstraintOccurrence(constraintType ==
ConstraintType.NEGATIVE_HARD, $weight : weight),
sum($weight)
)
then
scoreHolder.setHardConstraintsBroken($hardTotal.intValue());
end
// Accumulate soft constraints
rule "softConstraintsBroken"
salience -1 // Do the other rules first (optional, for performance)
when
$softTotal : Number() from accumulate(
IntConstraintOccurrence(constraintType ==
ConstraintType.NEGATIVE_SOFT, $weight : weight),
sum($weight)
)
then
scoreHolder.setSoftConstraintsBroken($softTotal.intValue());
end
-----
with kind regards,
--
View this message in context:
http://drools.46999.n3.nabble.com/planner-score-calculation-error-tp40181...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users