2017-12-07 1 views
0

7.4.1.Finalディストリビューションでプロジェクトジョブスケジューリングの例を再利用しようとしています。私はoptaplannerプロジェクトジョブスケジューリングの例 - drlファイルに切り替えるときに正常にコンパイルできない

<scoreDrl>org/optaplanner/examples/projectjobscheduling/solver/projectJobSchedulingScoreRules.drl</scoreDrl>

の代わり<incrementalScoreCalculatorClass>org.optaplanner.examples.projectjobscheduling.solver.score.ProjectJobSchedulingIncrementalScoreCalculator</incrementalScoreCalculatorClass>使用するprojectJobSchedulingSolverConfig.xmlファイルを変更しました。

鮮明にするには、次の

私だけprojectJobSchedulingSolverConfig.xmlファイルのこの部分の変更:

<scoreDirectorFactory> 
    <!--<incrementalScoreCalculatorClass>org.optaplanner.examples.projectjobscheduling.solver.score.ProjectJobSchedulingIncrementalScoreCalculator</incrementalScoreCalculatorClass>--> 
    <scoreDrl>org/optaplanner/examples/projectjobscheduling/solver/projectJobSchedulingScoreRules.drl</scoreDrl> 
</scoreDirectorFactory> 

をしかし、私は、コンパイルエラーが発生しました:

Exception in thread "main" java.lang.IllegalStateException: There are errors in a score DRL: 
Error Messages: 
Message [id=1, kieBase=defaultKieBase, level=ERROR, path=org/optaplanner/examples/projectjobscheduling/solver/projectJobSchedulingScoreRules.drl, line=95, column=0 
    text=Rule Compilation error The operator - is undefined for the argument type(s) Comparable] 
--- 
Warning Messages: 
--- 
Info Messages: 

at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildDroolsScoreDirectorFactory(ScoreDirectorFactoryConfig.java:507) 
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildScoreDirectorFactory(ScoreDirectorFactoryConfig.java:331) 
at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:220) 
at org.optaplanner.core.impl.solver.AbstractSolverFactory.buildSolver(AbstractSolverFactory.java:61) 
at org.optaplanner.examples.common.app.CommonApp.createSolver(CommonApp.java:103) 
at org.optaplanner.examples.common.app.CommonApp.createSolutionBusiness(CommonApp.java:97) 
at org.optaplanner.examples.common.app.CommonApp.init(CommonApp.java:84) 
at org.optaplanner.examples.common.app.CommonApp.init(CommonApp.java:80) 
at org.optaplanner.examples.projectjobscheduling.app.ProjectJobSchedulingApp.main(ProjectJobSchedulingApp.java:34) 

私はprojectJobSchedulingScoreRules.drlファイルを変更しませんでした、ファイルの内容は次のとおりです。

/* 
* Copyright 2010 Red Hat, Inc. and/or its affiliates. 
* 
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
*  http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/ 

package org.optaplanner.examples.projectjobscheduling.solver; 
    dialect "java" 

import org.optaplanner.core.api.score.buildin.bendable.BendableScoreHolder; 

import org.optaplanner.examples.projectjobscheduling.domain.Allocation; 
import org.optaplanner.examples.projectjobscheduling.domain.ExecutionMode; 
import org.optaplanner.examples.projectjobscheduling.domain.Job; 
import org.optaplanner.examples.projectjobscheduling.domain.JobType; 
import org.optaplanner.examples.projectjobscheduling.domain.Project; 
import org.optaplanner.examples.projectjobscheduling.domain.ResourceRequirement; 
import org.optaplanner.examples.projectjobscheduling.domain.resource.Resource; 
import org.optaplanner.examples.projectjobscheduling.solver.score.capacity.NonrenewableResourceCapacityTracker; 
import org.optaplanner.examples.projectjobscheduling.solver.score.capacity.RenewableResourceCapacityTracker; 
import org.optaplanner.examples.projectjobscheduling.solver.score.capacity.ResourceCapacityTracker; 
import org.optaplanner.examples.projectjobscheduling.solver.score.drools.RenewableResourceUsedDay; 

global BendableScoreHolder scoreHolder; 

// ############################################################################ 
// Hard constraints 
// ############################################################################ 

rule "nonrenewableResourceCapacity" 
    when 
     $resource : Resource(renewable == false, $capacity : capacity) 
     accumulate(
      ResourceRequirement(resource == $resource, 
        $executionMode : executionMode, 
        $requirement : requirement) 
      and Allocation(executionMode == $executionMode); 
      $used : sum($requirement); 
      $used > $capacity 
     ) 
    then 
     scoreHolder.addHardConstraintMatch(kcontext, 0, $capacity - $used); 
end 

rule "renewableResourceUsedDay" 
     salience 1 // Do these rules first (optional, for performance) 
    when 
     ResourceRequirement(resourceRenewable == true, $executionMode : executionMode, $resource : resource) 
     Allocation(executionMode == $executionMode, 
       $startDate : startDate, $endDate : endDate) 
    then 
     for (int i = $startDate; i < $endDate; i++) { 
      insertLogical(new RenewableResourceUsedDay($resource, i)); 
     } 
end 

rule "renewableResourceCapacity" 
    when 
     RenewableResourceUsedDay($resource : resource, $capacity : resourceCapacity, $usedDay : usedDay) 
     accumulate(
      ResourceRequirement(resource == $resource, 
        $executionMode : executionMode, 
        $requirement : requirement) 
      and Allocation(executionMode == $executionMode, $usedDay >= startDate, $usedDay < endDate); 
      $used : sum($requirement); 
      $used > $capacity 
     ) 
    then 
     scoreHolder.addHardConstraintMatch(kcontext, 0, $capacity - $used); 
end 

// ############################################################################ 
// Soft constraints 
// ############################################################################ 

rule "totalProjectDelay" 
    when 
     Allocation(jobType == JobType.SINK, endDate != null, $endDate : endDate, 
       $criticalPathEndDate : projectCriticalPathEndDate) 
    then 
     scoreHolder.addSoftConstraintMatch(kcontext, 0, $criticalPathEndDate - $endDate); 
end 


rule "totalMakespan" 
    when 
     accumulate(
      Allocation(jobType == JobType.SINK, $endDate : endDate); 
      $maxProjectEndDate : max($endDate) 
     ) 
    then 
     scoreHolder.addSoftConstraintMatch(kcontext, 1, -$maxProjectEndDate); 
end 

誰も似たような問題が発生しましたか?任意の手掛かりどのようにそれを修正するには?前もって感謝します。

+1

問題を再現するために提供した手順を試しましたが、問題は発生しません。スローされた例外から、あなたはdroolsファイル(projectJobSchedulingScoreRules.drl)95行に問題があると言います。そのdroolsファイル内の何かを変更しますか?ここにあなたのdroolsファイルを投稿すればもっと良いでしょう。私はあなたを助けることができます。 –

+0

@ the.wizardお返事ありがとうございます。私はdroolsファイルを追加して投稿を更新しました。 –

+0

エラーメッセージに 'projectJobSchedulingScoreRules.drl、line = 95'と表示されます –

答えて

3

エラーメッセージは次のとおりです。

The operator - is undefined for the argument type(s) Comparable

は、これは一般的なものではなく、その戻り値の型は、あなたがInteger引数でそれを養う場合でも、常にComparableあるmax() Droolsのアキュムレータ機能の制限の結果です。したがって、$maxProjectEndDate変数のタイプはComparable(数字ではありません)であり、-演算子を使用してその値を否定することはできません。

クイックフィックスとして、あなたはtotalMakespanルールでそれを否定する前Integerにキャストすることができます

scoreHolder.addSoftConstraintMatch(kcontext, 1, -((Integer) $maxProjectEndDate)); 
+0

マスターで修正済み:http://github.com/kiegroup/optaplanner/commit/845ee9525 –

1

を説明yurlocとして、MAX()の結果は、蓄積機能が同等の目的であったdroolsが、それはです - 演算子を使ってなぜ否定できないのか?この回答はyurlocの別の代替手段です。

rule "totalMakespan" 
    when 
     $maxProjectEndDate : Number() from accumulate(
      Allocation(jobType == JobType.SINK, $endDate : endDate); 
      max($endDate) 
     ) 
    then 
     scoreHolder.addSoftConstraintMatch(kcontext, 1, -$maxProjectEndDate.intValue()); 
end 
+0

これも有効なアプローチです。小さな改善の提案:intValue()コールを避けるために、Integerを直接収集することもできます($ i:Integer()からaccumulate(...)など)。 – yurloc

+0

ああ私は..それは良い改善になると思う..ありがとう@yylloc .. –

関連する問題