2016-04-21 22 views
0

我正在嘗試設置OptaPlanner基準測試運行。從文件加載問題批註被證明是有問題的,因爲我的很多類都不可序列化。這需要很多工作才能發揮作用。OptaPlanner基準:使用內存中輸入解決方案代替inputSolutionFile

有沒有辦法來運行使用,當我開始我的正常運行策劃者,這已經是我的現有的Java代碼構造,我使用相同的懸案的解決方案的標杆?如果以某種方式起作用,那麼啓動基準將是微不足道的。

我在OptaPlanner benchmarking without XML inputSolutionFile找到部分解決方案。

我是能夠使這項工作,通過編碼SolutionFileIO的實現,並使用一個靜態變量爲,沿已創建的懸案的解決方案通過。

這工作在有限的能力。

有沒有辦法直接在PlannerBenchmarkFactory或PlannerBenchmark設置懸案的解決方案,這樣我就不必使用一個靜態變量?

回答

1

是的,就創建一個文本文件,例如input1.txt裏面是空的,或者只包含一個1條線路標識符。然後實施SolutionFileIO

public class MachineReassignmentFileIO implements SolutionFileIO<MachineReassignment> { 

    public static final String FILE_EXTENSION = "txt"; 

    @Override 
    public String getInputFileExtension() { 
     return FILE_EXTENSION; 
    } 

    @Override 
    public String getOutputFileExtension() { 
     return FILE_EXTENSION; 
    } 

    @Override 
    public MachineReassignment read(File inputSolutionFile) { 
     // Ignore the inputSolutionFile or just read the id 
     return ... // Create your solution manually 
    } 

    @Override 
    public void write(MachineReassignment solution, File outputSolutionFile) { 
     throw new UnsupportedOperationException(); 
    } 

} 

然後只配置

<problemBenchmarks> 
    <solutionFileIOClass>org...MachineReassignmentFileIO</solutionFileIOClass> 
    <inputSolutionFile>data/machinereassignment/import/input1.txt</inputSolutionFile> 
    <problemStatisticType>BEST_SCORE</problemStatisticType> 
</problemBenchmarks> 
+0

這種做法(在我的情況,至少)的問題是,MachineReassignmentFileIO進行實例化默認的無參數的構造函數。以這種方式實例化的類的實例將無法訪問創建解決方案所需的各種構造。 我目前在MachineReassignmentFileIO中使用靜態變量來傳遞我需要的東西,它可以工作,但不是很好。我想我可以使用線程局部變量,但這並不比靜態好多少。 – Mitch

+0

有趣的一點,隨時打開這個jira。我想我們需要支持替代inputFileSolution元素 –

+1

完成,請參閱https://issues.jboss.org/browse/PLANNER-568 – Mitch