First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
1

How do I find an available bus number?

asked Mar 23 '12

Daniel_Hillier gravatar image

I am looking to add a bus to an existing network. Ignoring any numbering conventions my colleagues may have, how do I find a available bus number to use?

Comments

Both Chip's (the selected answer) and JervisW's answers solve my problem. Thanks guys!

Daniel_Hillier gravatar imageDaniel_Hillier (Apr 8 '12)

5 answers

Sort by » oldest newest most voted
1

answered Mar 23 '12

chip gravatar image

updated Mar 23 '12

JervisW gravatar image

I just wrote this a couple hours ago for a similar problem. So it can probably be cleaned up:

def get_next_free_busnum():
    """
    get the next free bus number
    """
    # find largest bus number

    ierr, all_buses = psspy.abusint(
            sid=-1,    # all buses in the case.
            flag=2,    # in-service and out-of-service buses
            string=["NUMBER"]
            )
    # transpose from 2D array to 1D list.
    all_buses = zip(*all_buses)[0]
    busnum = max(all_buses) + 1

    return busnum

I guess you could do something smart like:

  busnum = min(set(range(15000)) - set(all_buses))
  # where 15000 is highest busnum you want to use

This will return 0, which I'm not sure is a valid number or not.

link

Comments

I like your max + 1 approach.

JervisW gravatar imageJervisW (Mar 23 '12)

you can set the range to begin at 1. range(1, 15000) your zero bus problem should go away.

JervisW gravatar imageJervisW (Mar 23 '12)
0

answered Sep 26 '16

SqFKYo gravatar image

Get the maximum bus number and add one would probably the easiest way: max(psspy.abusint(flag=2, string='NUMBER')[1][0])+1

link
0

answered Sep 21 '16

perolofl gravatar image

The next free bus number can be found in this easy way:

 def nextfreebus(ibus):
    """ Returns the first unused bus number, starting from ibus
    """
    while psspy.busexs(ibus)==0: ibus += 1
    return ibus
link
0

answered Jan 5 '15

If the intent is to just print out the available bus numbers in a text report, then you can use built in psspy.busn.

Use this API to tabulate unused bus numbers within a specified bus number range (activity BUSN).
Batch command syntax:

BAT_BUSN BUSLO BUSHI

Python syntax:
ierr = busn(buslo, bushi)

Fortran syntax:
CALL BUSNAPI(BUSLO, BUSHI, IERR)

where:
Integer BUSLO Is the low limit of bus number range (input; 1 by default).
Integer BUSHI Is the high limit of bus number range (input; 999,997 by default).
Integer IERR Is the error code (output).
IERR = 0 no error occurred.
IERR = 1 invalid starting bus number.
IERR = 2 starting bus number is greater than ending bus number.
IERR = 3 prerequisite requirements for API are not met.
link
0

answered Mar 23 '12

JervisW gravatar image

updated Mar 23 '12

Ok, first you need to know what buses exist in the system already. Then work out a bus that fits into one of the gaps.

ierr, buses = psspy.abusint(-1, flag=2, string="NUMBER")
# convert to a simple set of buses
taken_buses = set(zip(*buses)[0])

# now find the first available gap between 1 and 10,000:
# 10,000 - or any suitably high number.
available_bus = None
for bus in range(1, 10000):
   if bus not in taken_buses:
       available_bus = bus
       break

print "You can use bus=%d if you want." % available_bus
link

Comments

You did say that you don't care about colleagues conventions.. They probably won't like that :)

JervisW gravatar imageJervisW (Mar 23 '12)

Nice, i didn't know about the -1 subsystem trick.

chip gravatar imagechip (Mar 23 '12)

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

Stats

Asked: Mar 23 '12

Seen: 2,508 times

Last updated: Sep 26 '16