【问题标题】:"Sheet data not supported on this platform" error (ILOG cplex studio on Linux)“此平台不支持工作表数据”错误(Linux 上的 ILOG cplex studio)
【发布时间】:2022-08-23 17:43:49
【问题描述】:

有谁知道如何将 csv 或 xlsx 文件中的矩阵导入 CPlex 工作室中的 CPlex 项目的数据文件中?

我在 Linux 上使用 CPlex studio,我正在尝试解决一个线性程序。我有一个 Ax<=b 形式的不等式约束。我有 A 和 b 作为 .csv 或 xlsx 文件。我需要将 A 和 b 加载到我的 CPlex 工作室项目的 .dat 文件中。在在线tutorial 之后,我正在使用SheetConnection Data_A(\"A.xlsx\"); 命令。但程序无法编译,我收到以下错误,“此平台不支持工作表数据”。我改用 .csv 文件,但我得到了同样的错误。

除了SheetConnection 命令,有谁知道如何将矩阵形式的数据导入CPlex 项目?

亲切的问候,我期待着您的回音。

艾哈迈德

    标签: cplex ibm-ilog-opl


    【解决方案1】:

    您可以使用CSVRead

    nbKids=300;
    
    // New feature in CPLEX 20.10
    
    CSVConnection csvinput("zoobusesinput.csv?firstIsHeader=true", "");
    buses from CSVRead(csvinput, "");
    
    CSVConnection csvoutput("zoobusesoutput.csv?outputOnly=true&append=false&outputSeparator=;", "");
    result to CSVPublish(csvoutput, "");
    

    或者如果您使用 to

    o old CPLEX version you can [call some python to do the job][2]
    
    // Read from an Excel spreadsheet without SheetRead
    // which means you can use this on non Windows platform
    
    execute
        {
    
        function read_excel(filename,sheetname,skiprows,nrows,cols,datfilename,resname)
        {
            var quote="\"";
            
            var python=new IloOplOutputFile("c:\\temp\\readexcel.py");
            
            python.writeln("import pandas as pd");
            python.writeln("import xlrd");
            python.writeln("df=pd.read_excel('"+filename+"'"+",sheet_name = '"+sheetname+"'"+
            ",skiprows = "+skiprows+  ",nrows= "+nrows+ ","
            +"header=None,usecols = '"+cols+"')");
            python.writeln("print(df)");
            
            
            
            python.writeln("res = open(",quote,datfilename,quote,",",quote,"w",quote,")");
            python.writeln("res.write(",quote,resname,"=[",quote,")");
            python.writeln("res.write(",quote,"\\","n",quote,")");
            python.writeln("for i, row in enumerate(df.values):");
           
            python.writeln("   res.write(",quote,"[",quote,")");
            
            python.writeln("   for j in row:");
           
            python.writeln("      if (j==j):");
            python.writeln("         res.write(str(j))");
            python.writeln("         res.write(\",\")");
           
            python.writeln("   res.write(\"],\")    ");
            python.writeln("   res.write(",quote,"\\","n",quote,")");
            python.writeln("res.write(\"];\")");
            python.writeln("res.close()");
            python.close();
           
            python.close();
            
            IloOplExec("C:\\Python36\\python.exe c:\\temp\\readexcel.py",true);
            
        }
        read_excel("c:\\\\temp\\\\read2Darray.xls","Sheet1",0,2,"B:D","c:\\\\temp\\\\resexcel","res");
    }    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-30
      • 2022-01-28
      • 2021-01-05
      • 1970-01-01
      • 2015-04-18
      • 1970-01-01
      • 2021-04-29
      相关资源
      最近更新 更多