Ask Your Question
1

Retrieving bus numbers in order of connection

asked 2013-03-12 13:12:16 -0600

WIKI gravatar image

I want to retrieve bus numbers of a system in the order of connection with respect to slack bus rather than ascending format as given by psspy.nxtbus. Any ideas?

edit retag flag offensive close merge delete

Comments

Interesting question. Maybe start by developing a function to determine the number of busses/branches along the shortest route between any two busses. Apply this function to every bus in the case relative to a single bus (slack) and sort the results.

AdamF gravatar imageAdamF ( 2013-03-15 08:30:10 -0600 )edit

Hi, how many branches away from the slack bus would you cover - would you rank the entire case?

JervisW gravatar imageJervisW ( 2013-03-15 19:54:58 -0600 )edit

Actually,i need a list of all paths between slack bus and another specified bus??

WIKI gravatar imageWIKI ( 2013-04-08 11:11:12 -0600 )edit

Is the specified bus connected to the slack bus directly with one or more branches? (no dummy buses or other buses in between?)

JervisW gravatar imageJervisW ( 2013-04-08 22:09:48 -0600 )edit

There are other buses in between slack and specified bus

WIKI gravatar imageWIKI ( 2013-04-09 12:48:58 -0600 )edit

If we are able to capture the bus # information from every "Grow" action in 1level, the order problem seems to be solvable.

SC gravatar imageSC ( 2014-02-03 15:05:12 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-12-07 11:11:09 -0600

GaryB gravatar image

updated 2020-12-07 11:12:05 -0600

Just an idea, the attached code can be run in PSSE to get the shortest path between two buses. If you use your slack bus as one, and the queried bus as the other, the length of the result will be your path length. It is feasible to step through your buses and save the path lengths for each and sort. It is computationally expensive however.

# Delivers shortest path (miles) between two buses
# The two buses must be the same voltage level (the script cannot see past transformers)

# Can't default to swing bus for everything if it's a different voltage level than bus1.


from collections import defaultdict

class Graph():
    def __init__(self):
        """
        self.edges is a dict of all possible next nodes e.g. {'X': ['A', 'B', 'C', 'E'], ...}
        self.weights has all the weights between two nodes, with the two nodes as a tuple as the key
        e.g. {('X', 'A'): 7, ('X', 'B'): 2, ...}
        """
        self.edges = defaultdict(list)
        self.weights = {}
    def add_edge(self, from_node, to_node, weight):
        # Note: assumes edges are bi-directional
        self.edges[from_node].append(to_node)
        self.edges[to_node].append(from_node)
        self.weights[(from_node, to_node)] = weight
        self.weights[(to_node, from_node)] = weight

def dijsktra(graph, initial, end):
    # shortest paths is a dict of nodes whose value is a tuple of (previous node, weight)
    shortest_paths = {initial: (None, 0)}
    current_node = initial
    visited = set()
    while current_node != end:
        visited.add(current_node)
        jbus = 1
        ierr = psspy.inibrn(current_node,2)
        # nxtbrn provides neighboring buses until all have been provided. Then it returns jbus = 0
        while jbus > 0:
            ierr, jbus, kbus, ickt = psspy.nxtbrn3(current_node)
            if jbus > 0:
                # Get the length of the line between these two buses (in miles)
                ierr, weight = psspy.brndat(current_node,jbus,ickt,'LENGTH') # gives the literal shortest path
                weight = 1.0 #override weight to minimize the number of bus hops (longer line miles)
                if weight is None:
                    weight=0.0
                edge = (current_node,jbus,weight)
                # Add this edge to the graph if it's not there already
                if edge not in graph.edges:
                    graph.add_edge(*edge)
        # Destinations: all the buses we can go to from the bus we're currently at
        destinations = graph.edges[current_node]
        # weight_to_current_node: how far we've travelled so far to get to this node
        weight_to_current_node = shortest_paths[current_node][1]

        for next_node in destinations:
            weight = graph.weights[(current_node, next_node)] + weight_to_current_node
            if next_node not in shortest_paths:
                shortest_paths[next_node] = (current_node, weight)
            else:
                current_shortest_weight = shortest_paths[next_node][1]
                if current_shortest_weight > weight:
                    shortest_paths[next_node] = (current_node, weight)
        # Don't visit the same node twice. This would lead to an infinite loop
        next_destinations = {node: shortest_paths[node] for node in shortest_paths if node not in visited}

        if not next_destinations:
            return "Route Not Possible"
        # next node is the destination with the lowest weight
        current_node = min(next_destinations, key = lambda k: next_destinations[k][1])

    # Work back through destinations in shortest path
    path = []
    while current_node is not None:
        path.append(current_node)
        next_node = shortest_paths[current_node][0]
        current_node = next_node
    # Reverse path
    path = path[::-1]
    return path

if __name__ == '__main__':                                    ## Main program!!!
    # cases = glob.glob("*.sav")
    # case = cases[0]
    # ierr = psspy.case(case ...
(more)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

Stats

Asked: 2013-03-12 13:12:16 -0600

Seen: 877 times

Last updated: Dec 07 '20