Re: [rules-users] How to handle generics in Drools?
2011/10/17 Martin A wml...@gmail.com: Hello, In my rules file I'd like to set something like this: rule mayThrowDice when $user : User($gp : gameplay) $gameplay(this == $gp) then exists ListBoost() { . some business logic } This looks weird: exists is a conditional element which can't be used on the right hand side (after then). end But it looks like there is no generics support Correct. . How can I make sure there is a List of type Boost inserted into the session? You would have to write some code that detects any element in the List that is not instanceof Boost, or some accumulate that produces true if all elements are instanceof Boost. -W Thank you, Martin ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] How to handle generics in Drools?
Java's generics are implemented by erasure, which implies that there no information available at runtime that a instance of a List is of a certain generic type, for example Boost. So I don't think this is possible. Note that some things do work in erasure IIRC, like the generic type of a defined field in a class is available at runtime: public class Foo { private ListBar list; } but that's not useful in this case :) Op 17-10-11 11:30, Martin A schreef: Hello, In my rules file I'd like to set something like this: rule mayThrowDice when $user : User($gp : gameplay) $gameplay(this == $gp) then exists ListBoost() { . some business logic } end But it looks like there is no generics support. How can I make sure there is a List of type Boost inserted into the session? Thank you, Martin ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users -- With kind regards, Geoffrey De Smet ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] How to handle generics in Drools?
Thanks for the prompt response! Best regards, Martin 2011/10/17 Geoffrey De Smet ge0ffrey.s...@gmail.com ** Java's generics are implemented by erasure, which implies that there no information available at runtime that a instance of a List is of a certain generic type, for example Boost. So I don't think this is possible. Note that some things do work in erasure IIRC, like the generic type of a defined field in a class is available at runtime: public class Foo { private ListBar list; } but that's not useful in this case :) Op 17-10-11 11:30, Martin A schreef: Hello, In my rules file I'd like to set something like this: rule mayThrowDice when $user : User($gp : gameplay) $gameplay(this == $gp) then exists ListBoost() { . some business logic } end But it looks like there is no generics support. How can I make sure there is a List of type Boost inserted into the session? Thank you, Martin ___ rules-users mailing listrules-users@lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users -- With kind regards, Geoffrey De Smet ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] [planner] Problem setting configuration file
Hi, 2011/10/14 Geoffrey De Smet ge0ffrey.s...@gmail.com ** I was wondering now if I can achieve the same with the drools rule file. That's a bit harder, but not that hard. Look in the Drools Planner manual for setRuleBase() (as an alternative to using scoreDrl's in your SolverConfig.xml) and look in the Drools Expert manual on how to create a RuleBase. Great, that worked too! Just for future reference, I used the following tutorial to create a rule base: http://hydrogen.informatik.tu-cottbus.de/wiki/index.php/How_to_create_and_execute_a_Drools_rulebase And http://docs.jboss.org/drools/release/5.2.0.Final/drools-planner-docs/html/ch04.html#d0e1566 to set the rule base. Thank you for the help! Op 13-10-11 15:37, Guilherme Kunigami schreef: Geoffrey, Thank you, that worked! I was wondering now if I can achieve the same with the drools rule file. The method below wouldn't work because it's not me who load the file (I think it's at AbstractSolverConfig.buildRuleBase, which seems to use getResourceAsStream too). 2011/10/11 Geoffrey De Smet ge0ffrey.s...@gmail.com Hi Guilharme, There's an overloaded method called configure(InputStream in) and configure(Reader reader) too, use either of those instead: try { InputStream in = new FileInputStream( /path/to/xml/file/SolverConf.xml); configurer.configure(in); } finally { IOUtils.closeSilently(in); } Op 11-10-11 15:01, Guilherme Kunigami schreef: Hi, I'm trying to load a configuration file (namely SolverConf.xml) into XmlSolver with the code below: XmlSolverConfigurer configurer = new XmlSolverConfigurer(); configurer.configure(SOLVER_CONFIG); Solver solver = configurer.buildSolver(); If I bundle SolverConf.xml file with the application .jar file, then using SOLVER_CONFIG as /path/to/xml/file/SolverConf.xml works fine. But I want to use SolverConf.xml outside the .jar, so I can easiliy edit it, but I don't know what path should I pass to it. I know it's a Java related question, but I was wondering if anyone had a similar problem when configuring drools planner. (I've asked on stackoverflow, but none of the answers worked for me: http://stackoverflow.com/questions/7718807/can-getresourceasstream-find-files-outside-the-jar-file ) (Supposing my .jar is in /some/path and the SolverConf.xml will be on /some/path/conf for example) Thanks, ___ rules-users mailing listrules-users@lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users -- With kind regards, Geoffrey De Smet ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing listrules-users@lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users -- With kind regards, Geoffrey De Smet ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] How to handle generics in Drools?
Geoffrey is correct. Java erasure makes it impossible to match objects based on generic types. It is also a best practice anyway to not use general purpose collections as your business entities in your business model. Best to use a properly defined business entity and then the generics issue is not really an issue. Edson 2011/10/17 Geoffrey De Smet ge0ffrey.s...@gmail.com ** Java's generics are implemented by erasure, which implies that there no information available at runtime that a instance of a List is of a certain generic type, for example Boost. So I don't think this is possible. Note that some things do work in erasure IIRC, like the generic type of a defined field in a class is available at runtime: public class Foo { private ListBar list; } but that's not useful in this case :) Op 17-10-11 11:30, Martin A schreef: Hello, In my rules file I'd like to set something like this: rule mayThrowDice when $user : User($gp : gameplay) $gameplay(this == $gp) then exists ListBoost() { . some business logic } end But it looks like there is no generics support. How can I make sure there is a List of type Boost inserted into the session? Thank you, Martin ___ rules-users mailing listrules-users@lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users -- With kind regards, Geoffrey De Smet ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users -- Edson Tirelli JBoss Drools Core Development JBoss by Red Hat @ www.jboss.com ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Drools Guvnor -- Not seeing Model Correctly
Thanks for the advice Mike. I did a quick read of the user manual and was able to setup a rule based on some of the fields I created in the POJO. My next thing to try was to test a rule. So thru Guvnor I setup a Test Scenario. When I click the Run Scenario I get a [package configuration problem]Error importing : Vehicle error. Any ideas? From: rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Michael Anstis Sent: Sunday, October 16, 2011 3:06 AM To: Rules Users List Subject: Re: [rules-users] Drools Guvnor -- Not seeing Model Correctly Hi, You can create two types of Model I'm Guvnor: 1) a declarative model, in which case you can open the model and see the facts and fields; 2) upload a POJO model, in which case the model screen only allows you to download the current version. When authoring rules in Guvnor you select a Fact (class) first and then click on this to select fields. By what you describe I get the feeling you may not have read Guvnor's user-guide. Please do have a look. With kind regards, Mike sent on the move On 16 Oct 2011 03:07, johnz jz...@plymouthrock.commailto:jz...@plymouthrock.com wrote: I'm new to Drools. Want to play with Guvnor to see if it will be applicable for my application. I have Guvnor running thru Eclipse/Jboss. I can get into Guvnor and create categories and packages. I create a real simple domain model (see below). I then upload the jar file to create a model in Guvnor. After uploading i don't see anything appear on the model tab. i was expecting to see the classes and attributes. when i try creating a new rule using the model i only see the class, but don't see any of the attributes. what am i doing wrong? here is the code for the domain model public class Driver { private String name; private int age; private Vehicle car; public Driver() {} public Driver(String name, int age, Vehicle car) { this.namehttp://this.name = name; this.age = age; this.car = car; } public String getName() { return name; } public void setName(String name) { this.namehttp://this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public Vehicle getCar() { return car; } public void setCar(Vehicle car) { this.car = car; } } public class Vehicle { private Long id; private String make; private String model; private String VIN; private String damageType; public Vehicle() { } public Vehicle(Long id, String make, String model, String VIN, String damageType) { this.idhttp://this.id = id; this.make = make; this.model = model; this.VIN = VIN; this.damageType = damageType; } public Long getId() { return id; } public void setId(Long id) { this.idhttp://this.id = id; } public String getMake() { return make; } public void setMake(String make) { this.make = make; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } public String getVIN() { return VIN; } public void setVIN(String vIN) { VIN = vIN; } public String getDamageType() { return damageType; } public void setDamageType(String damageType) { this.damageType = damageType; } } -- View this message in context: http://drools.46999.n3.nabble.com/Drools-Guvnor-Not-seeing-Model-Correctly-tp3425245p3425245.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.orgmailto:rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Does Quartz-calendar work with Drools 5.1.1 ?
Hi all, Does Quartz-Calendar work with Drools 5.1.1 ? See Drools-expert user guide: http://docs.jboss.org/drools/release/5.2.0.Final/drools-expert-docs/html/ch05.html#d0e3921 We have configured Drools server as a web service with xml-files (knowledge-services.xml, camel-server.xml, camel-client.xml, ...) If Drools 5.1.1 is Quartz-capable, next question is: Which is the best way to configure Quartz-scheduler with xml files ? I'm not sure whether we can migrate from Drools 5.1.1 to a newer version. thanks, Esko - Esko Hujanen www.ebsolut.fi -- View this message in context: http://drools.46999.n3.nabble.com/Does-Quartz-calendar-work-with-Drools-5-1-1-tp3428578p3428578.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] [planner] The presumed score is corrupted
2011/10/14 Geoffrey De Smet ge0ffrey.s...@gmail.com ** In your doMove you're doing: crew.addActivity(activity); remainingActivities.remove(activity); If crew and/or remainingActivities are used by your score rules, the working memory should be notified of their changes. That's causing the corruption Hmm, actually the only object that are being used by the score rules is an activity. Here's the corresponding .drl: rule remainingActivitiesCount when $remainingCount : Number() from accumulate( $activity : ActivityBundle(), sum(1) ) then insertLogical(new IntConstraintOccurrence(remainingActivitiesCount, ConstraintType.NEGATIVE_HARD, $remainingCount.intValue(), null)); end Extra advice: I think you're making your moves too complex and your domain model too complex. If you upgrade to 5.3, it will be hard to identify the planning entities. There will be many (and I doubt you need more than 1). Read http://docs.jboss.org/drools/release/5.3.0.CR1/drools-planner-docs/html_single/index.html#d0e1411 and specificly this note in that chapter: *Do not create unnecessary planning entity classes.* This leads to difficult Move implementations and slower score calculation. For example, do not create a planning entity class to hold the total free time of a teacher, which needs to be kept up to date as the Lectureplanning entities change. Instead, calculate the free time in the score constraints and put the result per teacher into a logically inserted score object. If historic data needs to be considered too, then create problem fact to hold the historic data up to, but *not including*, the planning window (so it doesn't change when a planning entity changes) and let the score constraints take it into account. Thanks for the advice. I'll rethink my model and try to use a single planning entity. Op 14-10-11 15:48, Guilherme Kunigami schreef: 2011/10/14 Geoffrey De Smet ge0ffrey.s...@gmail.com Probably you forgot to notify the workingMemory.update in the doMove method: public void doMove(WorkingMemory workingMemory) { FactHandle factHandle = workingMemory.getFactHandle(activity); activity.setAssignee(...); workingMemory.update(factHandle, activity); } Op 14-10-11 09:21, Geoffrey De Smet schreef: A corrupted score normally indicates a problem with the Move implementation (or sometimes the score drl). Basically this happened: for a number of moves, it did the move, calculated the score and undo the move. One of those move was associated with a score -10hard/0soft, that was the best one. Now, it does that move (which is now called the step) and when it calculates the score it's a different score 0hard/0soft. Try TRACE environment and see if it crashes sooner. Copy paste your Move implementation here. Using the TRACE environment gave the same results of DEBUG. Here's my move implementation, as well as the snipet of drools rule file that calculates the score based on remaining activities: http://pastebin.mozilla.org/1355014 In Planner 5.4 there will be 2 out-of-the-box Move implementations to use, so writing Move's become optional. Cool! By the way, I'm using Drools 5.2.0 final. Thanks, Op 13-10-11 16:37, Guilherme Kunigami schreef: Hi, I've implemented a very simple application using drools planner consisting of a bunch of activities. My rule file is very simple too and just counts the number of activities not assigned. When I run Solver.solve(), I get the following error message: Exception in thread AWT-EventQueue-0 java.lang.IllegalStateException: The presumedScore (-10hard/0soft) is corrupted because it is not the realScore (0hard/0soft). Presumed workingMemory: Score rule (remainingActivitiesCount) has count (1) and weight total (11). Real workingMemory: Score rule (remainingActivitiesCount) has count (1) and weight total (0). I've tracked down this message and found this piece of code @DefaultLocalSearchSolver.solveImplementation(): // there is no need to recalculate the score, but we still need to set it localSearchSolverScope.getWorkingSolution().setScore(localSearchStepScope.getScore()); if (assertStepScoreIsUncorrupted) { localSearchSolverScope.assertWorkingScore(localSearchStepScope.getScore()); } It seems that the working score is never updated along the algorithm, but the score in the working memory changes. Thus, when we use the DEBUG environment, assertStepScoreIsUncorrupted is turned on and the assertion fails. Should the score be updated or am I using the library incorrectly? Thanks, ___ rules-users mailing listrules-users@lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users -- With kind regards, Geoffrey De Smet ___
Re: [rules-users] Does Quartz-calendar work with Drools 5.1.1 ?
On 17/10/2011 16:44, eskomk wrote: Hi all, Does Quartz-Calendar work with Drools 5.1.1 ? See Drools-expert user guide: http://docs.jboss.org/drools/release/5.2.0.Final/drools-expert-docs/html/ch05.html#d0e3921 We have configured Drools server as a web service with xml-files (knowledge-services.xml, camel-server.xml, camel-client.xml, ...) If Drools 5.1.1 is Quartz-capable, next question is: Which is the best way to configure Quartz-scheduler with xml files ? I'm not sure whether we can migrate from Drools 5.1.1 to a newer version. Drools provides an adapter for the Quartz interface: QuartzHelper. public static Calendar quartzCalendarAdapter(org.quartz.Calendar calendar) { return new QuartzCalendarAdapter( calendar ); } So you give this helper an instance of the Quartz calendar and it returns a Calendar instance Drools can understand. Mark thanks, Esko - Esko Hujanen www.ebsolut.fi -- View this message in context: http://drools.46999.n3.nabble.com/Does-Quartz-calendar-work-with-Drools-5-1-1-tp3428578p3428578.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Drools Guvnor -- Not seeing Model Correctly
I assume Vehicle is in your POJO model? I also assume your import statements (in your package configuration) also include Vehicle (if it is in a different package to that in which your QA Test is being defined)? 2011/10/17 Zink, John jz...@plymouthrock.com Thanks for the advice Mike. I did a quick read of the user manual and was able to setup a rule based on some of the fields I created in the POJO. ** ** My next thing to try was to test a rule. So thru Guvnor I setup a “Test Scenario”. When I click the “Run Scenario” I get a “[package configuration problem]Error importing : Vehicle error”. ** ** Any ideas? ** ** *From:* rules-users-boun...@lists.jboss.org [mailto: rules-users-boun...@lists.jboss.org] *On Behalf Of *Michael Anstis *Sent:* Sunday, October 16, 2011 3:06 AM *To:* Rules Users List *Subject:* Re: [rules-users] Drools Guvnor -- Not seeing Model Correctly** ** ** ** Hi, You can create two types of Model I'm Guvnor: 1) a declarative model, in which case you can open the model and see the facts and fields; 2) upload a POJO model, in which case the model screen only allows you to download the current version. When authoring rules in Guvnor you select a Fact (class) first and then click on this to select fields. By what you describe I get the feeling you may not have read Guvnor's user-guide. Please do have a look. With kind regards, Mike sent on the move On 16 Oct 2011 03:07, johnz jz...@plymouthrock.com wrote: I'm new to Drools. Want to play with Guvnor to see if it will be applicable for my application. I have Guvnor running thru Eclipse/Jboss. I can get into Guvnor and create categories and packages. I create a real simple domain model (see below). I then upload the jar file to create a model in Guvnor. After uploading i don't see anything appear on the model tab. i was expecting to see the classes and attributes. when i try creating a new rule using the model i only see the class, but don't see any of the attributes. what am i doing wrong? here is the code for the domain model public class Driver { private String name; private int age; private Vehicle car; public Driver() {} public Driver(String name, int age, Vehicle car) { this.name = name; this.age = age; this.car = car; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public Vehicle getCar() { return car; } public void setCar(Vehicle car) { this.car = car; } } public class Vehicle { private Long id; private String make; private String model; private String VIN; private String damageType; public Vehicle() { } public Vehicle(Long id, String make, String model, String VIN, String damageType) { this.id = id; this.make = make; this.model = model; this.VIN = VIN; this.damageType = damageType; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getMake() { return make; } public void setMake(String make) { this.make = make; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } public String getVIN() { return VIN; } public void setVIN(String vIN) { VIN = vIN; } public String getDamageType() { return damageType; } public void setDamageType(String damageType) { this.damageType = damageType; } } -- View this message in context: http://drools.46999.n3.nabble.com/Drools-Guvnor-Not-seeing-Model-Correctly-tp3425245p3425245.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users