PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, June 27, 2022

[FIXED] How to use always the same type of edge in a directed weighted graph?

 June 27, 2022     c++, dijkstra, graph, path     No comments   

Issue

I'm doing a project for college and we are simulating a public transport (Only bus) system using directed weighted graphs in c++. Each node represents a stop and each edge represents the line of the bus and the line is a parameter of the edge besides the weight. So between stops we can have multiple buses doing that bit of the trip. I'm using the Dijkstra algorithm to find the shortest path in distance but I would like to add another option which is to choose the path with the least line changes (i.e. even if the path is longer, choose the one that uses always the same bus).

I've thought about implementing it with binary weight but I'm not sure if it would work. Any help is appreciated!


Solution

For each node where there are more than one line, split the node into several connected by edges with weight the cost of changing lines. The run Dijkstra.



Answered By - ravenspoint
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing