0

I have a following Facts domain ProposedFare and Fare. The idea here is ProposedFare could be a competitor fare and from that create/clone/update Fare. A rule can further update Fare which was already cloned.

And my drl is as follows:

dialect "mvel"
rule "Set Carrier Code to AA"
salience 100
when
 $prf : ProposedFare()
then
 Fare fare = new Fare();
 fare.setCarrierCode("AA");
 fare.setOrigin($prf.getOrigin());
 fare.setDestination($prf.getDestination());
 fare.setTariffNumber($prf.getTariffNumber());
 fare.setFareClassCode($prf.getFareClassCode());
 fare.setFootnoteCode("3B");
 fare.setFareAmount($prf.getFareAmount());
 fare.setCurrencyCode($prf.getCurrencyCode());
 fare.setRoundTripIndicator($prf.getRoundTripIndicator());
 insert(fare);
end
rule "Increase Fare Amount by double"
salience 99
when
 $fare : Fare(origin=="ABC", destination=="XYZ")
then
 modify($fare){
 setFareAmount($fare.getFareAmount() * 2),
 setFareClassCode("2X")
 }
end
rule "Change Fare ClassCode"
salience 95
when
 $prf : ProposedFare(origin=="ABC", destination=="XYZ")
then
 Fare fare = new Fare();
 fare.setCarrierCode($prf.getCarrierCode());
 fare.setOrigin($prf.getOrigin());
 fare.setDestination($prf.getDestination());
 fare.setTariffNumber($prf.getTariffNumber());
 fare.setFareClassCode("1X");
 fare.setFootnoteCode($prf.getFootnoteCode());
 fare.setFareAmount($prf.getFareAmount());
 fare.setCurrencyCode($prf.getCurrencyCode());
 fare.setRoundTripIndicator($prf.getRoundTripIndicator());
 insert(fare);
end
rule "Change CarrierCode"
salience 90
when
 $fare : Fare(origin=="ABC", destination=="XYZ", fareClassCode=="1X")
then
 modify($fare){
 setCarrierCode("AB")
 }
end

For the new Fare that is inserted by salience 95, I do not want that fact to execute from rule 100, instead it should only execute rules where salience is < 95. (Once new fact is inserted by any rule, only rules that have salience lower than that rule should be executed on that fact). However, when I insert the new Fare at salience 95, it starts getting executed from very first rule.

President Jam
1,3141 gold badge6 silver badges22 bronze badges
asked Sep 4, 2025 at 4:34
2
  • By the time the fare is inserted from the salience 95 rule, the salience 100 rule has already been evaluated and (if a match) executed. But once you insert a new fact using insert (not update) all lower salience rules will be re-evaluated ... that's just how it works. If you're seeing something different, please provide a unit test/reproducer. Commented Sep 11, 2025 at 20:42
  • That said you could easily keep the salience 100 rule from re-firing by updating the when to include a negative check for Fare ... eg not(Fare()). So as long as there's a Fare in working memory, the salience 100 rule won't fire. Commented Sep 11, 2025 at 20:44

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.