将Excel文件连接到Cplex [英] Connecte Excel file to Cplex

查看:485
本文介绍了将Excel文件连接到Cplex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使用Cplex解决优化问题.

I'm to solve an optimization problem using Cplex.

在file.dat中,我使用SheetConnection my_sheet("ExcelFile.xls")将Excel文件链接到我的cplex程序,然后使用SheetRead()从Excel文件中读取数据.

In my file.dat I use SheetConnection my_sheet("ExcelFile.xls") to link Excel file to my cplex program, and after that I use SheetRead() to read data from Excel file.

但是运行配置后,出现以下错误:

But after I run my configuration I've got the following error:

"sheet data not supported on this platform"
"Processing failed"

我发现Linux不支持在ILOG CPLEX优化工作室上读取excel电子表格

I found that reading excel spreadsheet on ILOG CPLEX optimization studio is not supported on Linux

请问有什么想法吗?

推荐答案

我遇到了同样的问题. 我的解决方案是将我的数据转换为csv并使用IloOplInputFile读取它. 示例:

I had the same problem. My solution was to transform my data into csv and use IloOplInputFile to read it. Example:

假设您具有以下export.cvs文件:

Suppose you have the following export.cvs file:

Nicolas;2; 
Alexander;3;

您可以使用以下代码将其转换为数据.

You can use the following code to convert it into your data.

tuple t
{
   string firstname;
   int number;
}

{t} s={};

execute
{
   var f=new IloOplInputFile("export.csv");
   while (!f.eof){
      var str=f.readline();
      var ar=str.split(";");
      if (ar.length==3) s.add(ar[0],Opl.intValue(ar[1]));
   }
   f.close();
}

execute
{
    writeln(s);
}

将读取csv文件并计算元组set s:

Which will read the csv file and compute the tuple set s:

{<尼古拉斯" 2><亚历山大" 3>}

{<"Nicolas" 2> <"Alexander" 3>}

如您在IBM论坛中的答案中所见.

这篇关于将Excel文件连接到Cplex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆