Convert external to internal indexing in PowerModels.jl

Some Matpower test systems have their own indexing feature (e.g., nesta_case73_ieee_rts) in which bus indexing is not compatible with actual bus number. Matpower has provided the ext2int script which converts the test case indexing to be compatible with actual bus numbers. I am wondering if there is such thing in PowerModels?

I have to do some internal calculations with the output of run_opf(“nesta_case73_ieee_rts”, QCWRTriPowerModel, IpoptSolver()) but I encounter indexing error just because of the mentioned issue. I will appreciate any help.

The short answer is, there is no ext2int function in PowerModels.

The long answer is: A key advantage of Julia over Matlab is its support for dictionaries, which provide more flexible indexing than arrays or sparse arrays. In PowerModels each component is identified by a unique integer identifier and these need not be contiguous. As long as you do your computations using these unique ids, everything should work. This is the recommended way to work with PowerModels data.

That said, if you would like to re-map the PowerModels ids into the range 1-to-n you could build the map like this,

ext2int = Dict(bus["index"] => i for (i,(k,bus)) in enumerate(sort(data["bus"], by=x->parse(Int, x))))
int2ext = Dict(i => bus["index"] for (i,(k,bus)) in enumerate(sort(data["bus"], by=x->parse(Int, x))))

However, I would not recommend this approach as it is prone to indexing bugs later on in the analysis.