【问题标题】:How to create & initialize record instances in FICO Xpress Mosel如何在 FICO Xpress Mosel 中创建和初始化记录实例
【发布时间】:2013-08-21 09:48:13
【问题描述】:

我正在尝试重构 Mosel 中的一些代码并使用记录集来表示稀疏多维数组的索引。我希望能够动态填充我的记录集,因此我不能使用文件或数据库中的初始化内容。

我有:

declarations
    myTuple = record
        index1 : string
        index2 : string
    end-record
    sparseIndex : set of myTuple
end-declarations

然后我想做类似的事情:

forall (a in largeListOfStrings)
    forall (b in anotherListOfStrings)
        if (someCondition(a,b)) then
            sparseIndex += { new myTuple(a, b) }

但是在 Mosel 中没有“new”关键字或运算符,并且文档在这一点上显得很弱,所以我只是不知道如何创建我的记录的新实例并初始化它,以便我可以将它添加到我的动态集。

或者,我可能只是在想这个错误的方式 - 有没有更好的方法来创建一个稀疏索引集,保留对稀疏索引组件的访问。

【问题讨论】:

    标签: mathematical-optimization linear-programming mosel


    【解决方案1】:

    您不需要为此案例定义记录。 Mosel 非常适合保存稀疏数组的信息。你应该这样做:

    declarations
        largeListOfStrings, anotherListOfStrings: set of string
        mylist: dynamic array(largeListOfStrings, anotherListOfStrings) of integer 
    end-declarations
    
    forall(a in largeListOfStrings, b in anotherListOfStrings | someCondition(a,b) = true) do
        mylist(a, b) := 1
    end-do
    

    因此,从现在开始,您的稀疏矩阵将保留在我的列表中。任何时候你想遍历它,你都应该使用如下逻辑:

    forall(a in largeListOfStrings, b in anotherListOfStrings | exists(mylist(a,b))) do
        ! Here you will iterate
    end-do
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多