How to create & initialize record instances in FICO Xpress Mosel

782 Views Asked by At

I am trying to restructure some code in Mosel and use sets of records to represent the indices of sparse multi-dimensional arrays. I want to be able to populate my sets of records dynamically, so I can't use the initialisation stuff from a file or database.

I have:

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

and then I want to do something like:

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

but in Mosel there is no "new" keyword or operator, and the documentation appears quite weak on this point so I just don't know how to create a new instance of my record and initialise it so I can add it to my dynamic set.

Alternatively, I may be just thinking about this the wrong way - is there a better way to create a sparse index set that retains access to the components of the sparse index.

1

There are 1 best solutions below

0
On

You do not need to define a record for this case. Mosel is great to keep information of sparse arrays. You should do something like:

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

So from now on your sparse matrix will be kept inside my list. Any time you want to iterate through it, you should use a logic like:

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