Skip to content

Instantly share code, notes, and snippets.

View ge0ffrey's full-sized avatar

Geoffrey De Smet ge0ffrey

View GitHub Profile
import accumulate org.optaplanner.examples.tennis.solver.drools.functions.LoadBalanceAccumulateFunction loadBalance;
rule "fairAssignmentCountPerTeam"
when
accumulate(
$t : Team()
and accumulate(
TeamAssignment(team == $t);
$assignmentCount : count()
);
rule "fairAssignmentCountPerTeam"
when
accumulate(
$t : Team()
and accumulate(
$a : TeamAssignment(team == $t);
$teamTotal : count($a)
);
$total : sum($teamTotal.intValue() * $teamTotal.intValue())
)
Requirements:
1) Parse n properties from a Map
2) Fail fast with good error message if such a property is not the correct type (for example partCount is not an int)
3) Fail fast if an unknown key is in the Map
4) Do not modify the Map because it is reused
Proposal A:
public void applyCustomProperties(Map<String, String> customPropertyMap) {
String partCountString = customPropertyMap.remove("partCount"); // BUG: MODIFIES MAP
rule "Fairness standard deviation"
when
accumulate (
$c : candidate
accumulate (
$f : FederalState ( winningCandidate == $c );
$candidateSum : sum( $f.getElectoralVotes() )
);
$variance : sum($candidateSum * $candidateSum)
)
@ge0ffrey
ge0ffrey / gist:7d14f27c0610035e77d88721ff21c637
Created January 3, 2017 13:44
NoClassDefFoundError RuleEngineOption
When running KieContainerSolverFactoryTest, I get:
java.lang.NoClassDefFoundError: org/kie/internal/builder/conf/RuleEngineOption
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.junit.internal.MethodSorter.getDeclaredMethods(MethodSorter.java:54)
at org.junit.runners.model.TestClass.scanAnnotatedMembers(TestClass.java:65)
15:21:36.775 [main] DEBUG o.d.c.k.b.impl.KieRepositoryImpl - Cannot load a KieRepositoryScanner, using the DummyKieScanner
java.lang.IllegalArgumentException: Unable to instantiate service for Class 'org.kie.api.builder.KieScannerFactoryService'
at org.kie.internal.utils.ServiceRegistryImpl.get(ServiceRegistryImpl.java:169) ~[kie-internal-7.0.0-20160824.165432-310.jar:7.0.0-SNAPSHOT]
at org.drools.compiler.kie.builder.impl.KieRepositoryImpl$KieScannerHolder.getInternalKieScanner(KieRepositoryImpl.java:88) [drools-compiler-7.0.0-20160824.170017-483.jar:7.0.0-SNAPSHOT]
at org.drools.compiler.kie.builder.impl.KieRepositoryImpl$KieScannerHolder.<clinit>(KieRepositoryImpl.java:80) [drools-compiler-7.0.0-20160824.170017-483.jar:7.0.0-SNAPSHOT]
at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.getKieModule(KieRepositoryImpl.java:130) [drools-compiler-7.0.0-20160824.170017-483.jar:7.0.0-SNAPSHOT]
at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.getKieModule(KieRepositoryImpl.java:117) [drools-co
public class TwMain {
// I have 8 cores.
// If I set this to 2, then my CPU is at 25%
// If I set this to 4, then my CPU is at 50%
// If I set this to 6, then my CPU is at 74%
// If I set this to 8, then my CPU is at 98%
// If I set this to 10, then my CPU is at 98%
private static final int ACTIVE_THREAD_LIMIT = 10;
ublic class TwMain {
private final static Semaphore SEMAPHORE = new Semaphore(2, true);
public static void main(String[] args) {
for (int i = 0; i < 6; i++) {
StringBuilder name = new StringBuilder();
for (int j = 0; j < i + 1; j++) {
name.append(i);
}
This rule:
// Identical shiftTypes during a weekend
rule "identicalShiftTypesDuringWeekend"
when
$contractLine : BooleanContractLine(contractLineType == ContractLineType.IDENTICAL_SHIFT_TYPES_DURING_WEEKEND,
enabled == true, $contract : contract)
$employee : Employee(contract == $contract, $weekendLength : weekendLength)
ShiftDate(dayOfWeek == DayOfWeek.SUNDAY, $sundayIndex : dayIndex)