Sorting a sparse axis array in JuMP

Hi,

I am using the JuMP model, after the optimization process, I have a sparse axis array, I need to sort this array in the descending direction. How can I sort this? Thanking you in advance for the suggestions.


The image is attached with it.

Hi there! Take a read of Please read: make it easier to help you. In particular, it’s easier to help if you provide a minimal working example and avoid using screenshots.

y = [(k, value(Status[k]) for k in eachindex(Status)]
sort!(y, by = x -> x[2])

But it looks like you might want

y = [k for k in eachindex(Status) if value(Status[k]) > 0.5]

Thank you. It is working, but I also need to know, how can I get the values at only those indices where “i<j”. for example (i,j) = value, only those indices where the value of “i” is less than “j”.

There is nothing special about the keys of your SparseAxisArray – they’re just a Julia tuple. So you can go

y = [(k, value(Status[k]) for k in eachindex(Status) if k[1] < k[2]]