【问题标题】:Export sets with more than one value per cell from Excel to CPLEX将每个单元格具有多个值的集合从 Excel 导出到 CPLEX
【发布时间】:2021-06-16 08:43:24
【问题描述】:

在将一组从 excel 电子表格导入到 CPLEX 时,我需要您的帮助。 套装看起来像这样: enter image description here

如您所见,j = 2 和 j = 11 有两个值。

目标是将其作为 {int} 导入到 CPLEX,使其具有以下结构: enter image description here

如果有人能帮我解决这个问题,我将非常感激。

真诚的

【问题讨论】:

    标签: excel cplex


    【解决方案1】:

    你可以信赖javascript within OPL

    https://github.com/AlexFleischerParis/oplexcel/blob/main/readsetincells.mod

    {int} x=...;
    {int} y=...;
    
    {string} figures={"0","1","2","3","4","5","6","7","8","9"};
    
    string cells[x][y]=...;
    
    
    {int} values[x][y];
    
    execute // parsing
    {
      for(var i in x) for(var j in y)
      {
        
        var s=cells[i][j];
        var buffer="";
        
        for(var k=0;k<s.length;k++) 
        {
         
          if (figures.contains(s.charAt(k))) buffer=buffer+s.charAt(k);
          else
          {
            if (buffer!="")
            {
              var value=Opl.intValue(buffer);
              values[i][j].add(value);
              buffer="";
            }
          }
        }
      
      }
      
    }
    
    execute display
    {
      for(var i in x) for(var j in y) if (Opl.card(values[i][j])!=0) writeln(i,",",j," => ",values[i][j]);
    }
    
    /*
    which gives
    2,12 =>  {4 5}
    10,40 =>  {6}
    */
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-23
      • 1970-01-01
      • 1970-01-01
      • 2022-12-24
      • 1970-01-01
      • 1970-01-01
      • 2014-09-30
      • 1970-01-01
      相关资源
      最近更新 更多