Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6684033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:53:30+00:00 2026-05-26T04:53:30+00:00

I want to find a path in a graph that has connects two nodes

  • 0

I want to find a path in a graph that has connects two nodes and does not use the same node twice. The sum of the weights of the edges must be within a certain range.

I need to implement this in pygraph. I’m not sure if there is already an algorithm that I can use for this purpose or not. What’s the best way to achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:53:31+00:00Added an answer on May 26, 2026 at 4:53 am

    EDIT: I misunderstood the question initially. I’ve corrected my answer. This functionality isn’t built into the pygraphlib library, but you can easily implement it. Consider something like this, which basically gets the shortest path, decides if it’s in a predefined range, then removes the edge with the smallest weight, and computes the new shortest path, and repeats.

    from pygraphlib import pygraph, algo
    
    edges = [(1,2),(2,3),(3,4),(4,6),(6,7),(3,5),(4,5),(7,1),(2,5),(5,7)]
    graph = pygraph.from_list(edges)
    
    pathList = []
    shortestPath = algo.shortest_path(graph, startNode, endNode)
    cost = shortestPath[len(shortestPath)-1][1]
    
    while cost <= maxCost:
        if cost >= minCost:
            pathList.append(shortestPath)
    
        minEdgeWt = float('inf')
        for i in range(len(shortestPath)-1):
            if shortestPath[i+1][1] - shortestPath[i][1] < minEdgeWt:
                minEdgeWt = shortestPath[i+1][1] - shortestPath[i][1]
                edgeNodes = (shortestPath[i][0], shortestPath[i+1][0])
    
        #Not sure of the syntax here, edgeNodes is a tuple, and hide_edge requires an edge.
        graph.hide_edge(edgeNodes)
        shortestPath = alog.shortest_path(graph, startNode, endNode)
        cost = shortestPath[len(shortestPath)-1][1]
    
    return pathList
    

    Note that I couldn’t find a copy of pygraphlib, seeing as it is no longer under development, so I couldn’t test the above code. It should work, mod the syntax uncertainty. Also, if possible, I would recommend using networkx[link] for any kind of graph manipulation in python, as it is more complete, under active development, and more completely documented then pygraphlib. Just a suggestion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to find an SQL query to find rows where field1 does not
I am aware that Dijkstra's algorithm can find the minimum distance between two nodes
Basically I want to find a path between two NP tokens in the dependencies
I have a random undirected social graph. I want to find a Hamiltonian path
I want to find the next shortest path between 2 vertices in a graph
I want to find the path between two locations on Google Maps which I
i want to find the path of the file which is not in my
I want to setup a minimal set of cygwin applications (ls, diff, path, find,
I want to find any text in a file that matches a regexp of
I want to find a sql command or something that can do this where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.