How to find indices of variables created through Fusion

19 views
Skip to first unread message

Alexander Schlüter

unread,
Oct 7, 2020, 9:52:53 AM10/7/20
to mosek
Hi all,

I am creating a Model using the Fusion API which has multiple variables. Afterwards, I am writing the Task to disk using Model.writeTask(). Unfortunately, when I later load the Task, I can no longer tell which indices of the solution correspond to which variable of the original Model.

Is there some way to get the start and end indices of the variables created by a Fusion Model?

Thank you for your help
Alex

Michal Adamaszek

unread,
Oct 7, 2020, 9:55:55 AM10/7/20
to mosek
Hi,

For easier identification you can give the variables names. If you call a variable "x" in Fusion then it will generate variables called "x[0,0],x[0,1]" etc. in the task depending on the shape of x.

Michal

Alexander Schlüter

unread,
Oct 7, 2020, 10:40:15 AM10/7/20
to mosek
Hi Michael,

I have given names to my variables in Fusion. What would be the easiest way to get a numpy vector with the solution values for the variable called "x" from a Task object? The best I can come up with is

_, start = task.getvarnameindex("x[0,0]")
_, end = task.getvarnameindex("x[99,99]")
x_sol = np.empty(end - start + 1)
task.getxxslice(mosek.soltype.itr, start, end + 1, opt_res)

Best
Alex

Michal Adamaszek

unread,
Oct 7, 2020, 11:37:18 AM10/7/20
to mosek
There is nothing better than what you did.

BTW I don't know what you are using it for but if you just want to get a glance of the values with a "naked eye" then you can convert the file to something more readable like *.opf

Michal

Reply all
Reply to author
Forward
0 new messages