I am working on a project that uses OptaPlanner earlier they have implemented using drools using drl file I Now I need to update the OptaPlanner to latest 9.44.0 version where drools are depreciated
I’m rewriting some constraints from drools syntax to the new Constraint Streams API I have changed some but I could not able to figure out a way for some rules like
rule :
rule “unavailabilityTimePenalty”
when
UnavailablePeriodPenalty(locationId == null, teamId == null, $startTime : startTimeInMin, $endTime : endTimeInMin)
Game(gamePeriod != null, ((startTimeInMin > $startTime && endTimeInMin < $endTime) || (startTimeInMin < $startTime && endTimeInMin > $endTime) || (startTimeInMin < $startTime && endTimeInMin > $startTime) || (startTimeInMin < $endTime && endTimeInMin > $endTime) || (startTimeInMin == $startTime && endTimeInMin == $endTime) || (startTimeInMin == $startTime && endTimeInMin < $endTime) || (startTimeInMin == $startTime && endTimeInMin > $endTime) || (startTimeInMin > $startTime && endTimeInMin == $endTime) || (startTimeInMin < $startTime && endTimeInMin == $endTime)))
then
scoreHolder.addHardConstraintMatch(kcontext, -1);
end
2)
rule “eachTeamCanPlayNoOfTimesPerTime”
when
Game($leftId : id, gamePeriod != null, $matchDate : matchDate, $startTime : startTime, $teamPlayGamesPerTime : teamPlayGamesPerTime, $homeTeam : homeTeam, $awayTeam : awayTeam)
$teamCanPlayPerTime : Number(intValue > $teamPlayGamesPerTime) from accumulate(
Game(id < $leftId, gamePeriod != null, matchDate == $matchDate, startTime == $startTime, $teamTimeCount : gameStaticCount, (homeTeam == $homeTeam || awayTeam == $homeTeam || homeTeam == $awayTeam || awayTeam == $awayTeam)),
sum($teamTimeCount)
)
then
scoreHolder.addHardConstraintMatch(kcontext, -$teamCanPlayPerTime.intValue());
end
3)
rule “eachTeamCanPlayNoOfTimesPerWeek”
when
Game($leftId : id, gamePeriod != null, $matchDate : matchDate, isPoolOrLeague == 0, teamPlayGamesPerWeek > 1, $teamPlayGamesPerWeek : teamPlayGamesPerWeek, $homeTeam : homeTeam, $awayTeam : awayTeam)
$weekDays : WeeksList($weekStartDate : weekStartDate, $weekEndDate : weekEndDate, $matchDate >= weekStartDate && $matchDate <= weekEndDate)
$teamCanPlayPerWeek : Number(intValue > $teamPlayGamesPerWeek) from accumulate(
Game(id < $leftId, gamePeriod != null, (matchDate >= $weekStartDate && matchDate <= $weekEndDate), $teamWeekCount : gameStaticCount, (homeTeam == $homeTeam || awayTeam == $homeTeam || homeTeam == $awayTeam || awayTeam == $awayTeam)),
sum($teamWeekCount)
)
then
scoreHolder.addHardConstraintMatch(kcontext, -$teamCanPlayPerWeek.intValue());
end
I have tried using constraints stream but I could not able to get a solution
Sairam Reddy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.