第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在規(guī)則中使用 CountableValueRange

在規(guī)則中使用 CountableValueRange

翻翻過去那場雪 2023-09-13 15:40:24
我目前正在為共享一些資源的任務(wù)構(gòu)建一個調(diào)度應(yīng)用程序。每個任務(wù)可能使用一定百分比的資源。我需要在 Drools 規(guī)則中檢查的是并行任務(wù)對每個共享資源的使用率不超過 100%。所以代碼看起來像:@Datapublic class Resource {   @PlanningId   private Integer id;   private String label;}public class ResourceUsage {   @PlanningId   private Integer id;   private Resource resource;   private int usagePercent;}要安排的實體@Data@PlanningEntitypublic class TaskAssignment {   @PlanningId   private Integer id;   @PlanningVariable(valueRangeProviderRefs = { "slotRange" })   private Integer timeSlot;   private int duration;   private ResourceUsage resourceUsage;   public Integer getEndingSlot() {        return timeSlot + duration;   }}最后是解決方案@Data@PlanningSolutionpublic class PlanningSolution {  @PlanningId  private Integer id;  @PlanningEntityCollectionProperty  private List<TaskAssignment> tasks = new ArrayList<>();  @ValueRangeProvider(id = "slotRange")  public CountableValueRange<Integer> getSlotRange() {        return ValueRangeFactory.createIntValueRange(0, 10_000);  }  @ProblemFactCollectionProperty  private Set<Resource> resources = new TreeSet<>();}Setter 和 getter 不存在,因為我使用 Lombok 來避免編寫它們。過去,我使用一個類來表示時隙,編寫一個規(guī)則來迭代時隙集合很容易,我能夠按時隙檢查每個資源的全局使用情況,并在使用率大于 100% 時進(jìn)行懲罰。由于我在內(nèi)存使用方面遇到問題,我決定將 TimeSlot 類轉(zhuǎn)換為 CountableValueRange ,但現(xiàn)在,我不知道如何創(chuàng)建與該范圍的每個值相匹配的規(guī)則。執(zhí)行與之前相同的計算。有什么辦法或者我必須切換回我的 TimeSlot 課程嗎?編輯:包含在一種影子規(guī)劃實體中的影子變量可以解決這個問題嗎?
查看完整描述

1 回答

?
狐的傳說

TA貢獻(xiàn)1804條經(jīng)驗 獲得超3個贊

我終于找到了一種編寫規(guī)則的方法,該規(guī)則允許我避免在時間段上進(jìn)行迭代。這個想法是在作業(yè)開始時計算使用情況


rule "Maximum usage of a resource"

       when

             $r : Resource()

             $p : TaskAssignment($id1 : id, $ts : timeSlot != null,

                                 resourceUsage!.ressource==$r,

                                 $usage : resourceUsage!.usagePercent);

             accumulate(TaskAssignment(timeSlot != null, timeSlot <= $ts, 

                                      endingSlot > $ts, id != $id1, 

                                      resourceUsage!.ressource==$r, 

                                      $rate : resourceUsage!.usagePercent);

                                  $s:sum($rate);

                                  $s + $usage > 100) 

       then

             scoreHolder.addHardConstraintMatch(kcontext, 100-($s + $usage));         

end


查看完整回答
反對 回復(fù) 2023-09-13
  • 1 回答
  • 0 關(guān)注
  • 83 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號