翻一番我試圖使用Java,這裏的代碼的一部分從讀取Excel列中的值:轉換IloNumVar variabale在Java中
.....
List<ReportRow> listOfDataFromReport = new ArrayList<ReportRow>();
for(int x = 1; x<=sheet.getPhysicalNumberOfRows(); x++){
ReportRow rr = new ReportRow();
HSSFRow dataRow = sheet.getRow(x);
int idxForColumn1 = map.get("Cost");
int idxForColumn2 = map.get("Level");
HSSFCell cell1 = dataRow.getCell(idxForColumn1);
HSSFCell cell2 = dataRow.getCell(idxForColumn2);
rr.setCost(cell1.getNumericCellValue());
rr.setLevel(cell2.getNumericCellValue());
.....
所以從Excel中讀取數據的代碼工作正常,問題我有是制定者的功能,因爲我沒有同類型的,我使用CPLEX求解另一個類:
private IloNumVar Cost = new IloNumVar;
public IloNumVar getCost() {
return Cost;
}
public void setCost(IloNumVar cost) {
Cost = cost;
}
所以我得到這個錯誤:
The method setCost is not applicable for the arguments (double)
所以我想知道是否有可能隱藏IloNumVar加倍或任何解決方案來使用它們兩個,獲得值爲雙重,但使用它作爲IloNumVar。
EDIT
爲了解釋更多,我使用電功率的值(從Excel)作爲輸入來使用它們來解決成本問題CPLEX解算器。
來讀取Excel中我只能用POI
getNumericCellValue()
方法來獲取值的數據,所以我會有變量double
,但是當我用它們來解決我的模型,因爲我想優化,我必須把它們作爲IloNumVar[]
24小時內能源成本的價值取決於從excel文件中獲取的權力值。
如果您有來自Excel電子表格(或數據庫,文本文件或其他任何地方)的數字值,那麼這些數字就是簡單數字。當你說你想'用他們來解決我的模型',你是什麼意思?如果它們是已知值(即輸入數據),則通常不應將它們建模爲InlNumVars。 – TimChippingtonDerrick