使用drools解決小明喝汽水的問題

2022-09-18 21:27:12 字數 1262 閱讀 7811

問題描寫敘述:

1、小明手上有50元錢。

2、1元錢能夠買一瓶飲料;

3、2個空瓶能夠兌換一瓶飲料;

4、問題是:終於小明能夠喝多少瓶飲料 ? 

首先。新建m**en專案。增加drools依賴

org.drools

drools-core

6.2.0.final

org.drools

drools-compiler

6.2.0.final

package com.lala.bean;

public class drinks

public integer getmoney()

public void setmoney(integer money)

public integer gettotal()

public void settotal(integer total)

public integer getbottle()

public void setbottle(integer bottle)

}

drools規則:

package com.drink;

import com.lala.bean.drinks;

rule "money"

salience 2

when

$d:drinks(money > 0);

then

modify($d);

endrule "bottle"

salience 1

when

$d:drinks(bottle >= 2);

then

modify($d);

end

測試:

package com.lala.mydrools;

import org.kie.api.kieservices;

import org.kie.api.runtime.kiecontainer;

import org.kie.api.runtime.kiesession;

import com.lala.bean.drinks;

public class test

public static void main(string args)

}

最後,輸出結果為:

總執行了99條規則

總共能夠喝:99瓶

使用async await更好的解決非同步問題

async函式是generator的乙個語法糖,使用async函式實際上返回的是乙個promise物件。如下 async function fn 或者 const fn async 複製 在宣告函式的時候,前面加上關鍵字async即可。我們可以使用console.log列印出上邊宣告的函式fn,結果...

解決使用 libcurl 遇到的多執行緒崩潰問題

使用 curl 訪問 http 鏈結時,用 easy handle,阻塞方式訪問時發現會每個訪問啟動乙個執行緒去進行dns 想減少這種消耗,故此採用了 sh curl share init curl share setopt sh,curlshopt share,curl lock data dns...

使用DIGITS執行時候遇到的問和解決方案

問題1 valueerror caffe executable not found in path 解決方法 export caffe home home wzh caffe master source etc profile 問題2 file usr local lib python2.7 dis...