473,763 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Min Time Cost Problem (Dijkstra’s algorithm)

2 New Member
D.K. is traveling from City A to City B. He can stop at some designated spots only.
I am trying to use Dijkstra’s algorithm to determine the “spot-to-spot” path that will get D.K. from City A to the City B in the minimum amount of time.

The input in my program is an integer n and the 2D coordinates of n spots.

Some assumptions have been made about the physical layout of the problem:
1) All the spots are considered to be in a square of side 1600 km. A coordinate system is laid out for this square so that the lower left corner of the square is at the origin.
2) The coordinates of City A are (0, 1600) and the City B is at (1600, 0).
3) There is no “clumping” of spots. This means that for any pair of spots, the difference in their xcoordinates is >= 40 km or the difference in their y-coordinates is >= 40 km.
4) As the input size n increases for other problem instances, the clumping constraint may require that the area of the square must also increase. In other words, I am not allowed to assume that the number of spots is bounded above by some constant.

In addition, D.K. may choose to travel at either speed of the following:
Option 1: D.K. can travel at 10 km/hr but can only travel for 10 hours at this speed when he is still energetic
Option 2: D.K. can travel faster at 20 km/hr but can only last for 5 hours even though he has been out of energy.

That is, D.K. can travel up to 200km between spots: travel at 10km/hr for 10 hours and then travel at 20 km/hr for 5 hours.

(Because of these constraints, it is quite possible to have input data that will cause the algorithm to claim that the trip from City A to the City B cannot be done)

It is obvious that there is a limitation on distance traveled between spots because of the time limitations imposed by the constraints above, so I don’t want to use a complete graph to describe the distances between all the spots. I want a sparse graph represented by an adjacency list instead.

However, this adjacency list is built only after building a data structure that can provide a list of spots that are close by to any given spot. Once this is accomplished, I can add time costs to the graph edges.

So, my question is how I should build the data structure that can satisfy the following query: For a given “query” spot Q, find all nearby spots.

Could someone kindly suggest some pseudo-code that describes how the data structure is built? And I hope the construction of the adjacency list is faster than theta(n^2).

Thanks a looooooooooooot in advence!
Nov 10 '07 #1
3 7845
numberwhun
3,509 Recognized Expert Moderator Specialist
D.K. is traveling from City A to City B. He can stop at some designated spots only.
I am trying to use Dijkstra’s algorithm to determine the “spot-to-spot” path that will get D.K. from City A to the City B in the minimum amount of time.

The input in my program is an integer n and the 2D coordinates of n spots.

Some assumptions have been made about the physical layout of the problem:
1) All the spots are considered to be in a square of side 1600 km. A coordinate system is laid out for this square so that the lower left corner of the square is at the origin.
2) The coordinates of City A are (0, 1600) and the City B is at (1600, 0).
3) There is no “clumping” of spots. This means that for any pair of spots, the difference in their xcoordinates is >= 40 km or the difference in their y-coordinates is >= 40 km.
4) As the input size n increases for other problem instances, the clumping constraint may require that the area of the square must also increase. In other words, I am not allowed to assume that the number of spots is bounded above by some constant.

In addition, D.K. may choose to travel at either speed of the following:
Option 1: D.K. can travel at 10 km/hr but can only travel for 10 hours at this speed when he is still energetic
Option 2: D.K. can travel faster at 20 km/hr but can only last for 5 hours even though he has been out of energy.

That is, D.K. can travel up to 200km between spots: travel at 10km/hr for 10 hours and then travel at 20 km/hr for 5 hours.

(Because of these constraints, it is quite possible to have input data that will cause the algorithm to claim that the trip from City A to the City B cannot be done)

It is obvious that there is a limitation on distance traveled between spots because of the time limitations imposed by the constraints above, so I don’t want to use a complete graph to describe the distances between all the spots. I want a sparse graph represented by an adjacency list instead.

However, this adjacency list is built only after building a data structure that can provide a list of spots that are close by to any given spot. Once this is accomplished, I can add time costs to the graph edges.

So, my question is how I should build the data structure that can satisfy the following query: For a given “query” spot Q, find all nearby spots.

Could someone kindly suggest some pseudo-code that describes how the data structure is built? And I hope the construction of the adjacency list is faster than theta(n^2).

Thanks a looooooooooooot in advence!
Sorry, but nobody here is going to do your homework for you. If you read the forum Posting Guidelines, you will find that it is against the site policy to post homework questions.

Regards,

Moderator
Nov 10 '07 #2
SwissProgrammer
220 New Member
victorporton,

Read my post at https://bytes.com/topic/c/answers/97...ap-help-please and see how I am (currently) attempting to get help with a "useable" shortest path algorithm. A lot of people have run their mouth on other sites about how to create a shortest path algorithm, but not one of those worked for me. So, I came here. See what I did and start there if it helps.

I still have NOT gotten it to work.
Mar 7 '21 #3
SwissProgrammer
220 New Member
Update:

Not there yet.
Mar 26 '21 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4196
by: Ricardo Batista | last post by:
I need that someone help me. I need to program the dijkstra algorithm by object oriented. I'll send my code. #!/usr/bin/env python # -*- encoding: latin -*- NIL =
3
6242
by: A_StClaire_ | last post by:
implemented Dijkstra's algorithm as follows. plz pour on the negative criticism cuz I know I have a ton to learn. oh, before you flame me regarding the language, my class was told to do this in C# but, what can I say, I just like you guys better than the crowd in the C# newsgroup. ;o) using System;
1
2055
by: AvrilComplic8ed | last post by:
Hello there I wonder if you can help me. I am creating a loans system for a make-believe CD rental company, in Microsoft Access. I have 3 tables: CD details, Member Details, and Loan Details. I have created forms for each, so the user of the system can view member details, enter new members, view loan details, enter new loans, etc. A main menu has also been created so the user can easily access the three forms from this page. However,...
5
2206
by: A_StClaire_ | last post by:
thoughts or criticism anyone? using System; namespace Dijkstra { public class Algorithm { private const int nodes = 10;
3
5023
by: Ook | last post by:
This is probably a bit OT, as I'm not looking for a c++ implementaiton of Dijkstra's algorithm, rather I'm just trying to understand it (is there a better place then here to ask this question?). I've reviewed several sites and the faq (no, I'm not asking you to do my homework for me) and the examples don't give me the information I need to continue on. I'm working with a complex tree, and am not sure how to logically apply Dijkstra's...
8
4131
by: abhradwip | last post by:
I want to write a program which will find the shortest path between n no. of cities using dijkstra's algorithm ...... but could not do it..... i have written a program which will give the shortest path between finite no. of cities....... plz help me out....... i would also like to know for the states & city names should i use a database.....if so how???? Im giving the prog which ive written... plz help me with the source code........... ...
1
1941
by: chaos | last post by:
Hi all, anyone know what is Dijkstra algorithm . what is the code for Dijkstra algorithm
1
2352
by: victorporton | last post by:
D.K. is traveling from City A to City B. He can stop at some designated spots only. I am trying to use Dijkstra’s algorithm to determine the “spot-to-spot” path that will get D.K. from City A to the City B in the minimum amount of time. The input in my program is an integer n and the 2D coordinates of n spots. Some assumptions have been made about the physical layout of the problem: 1) All the spots are considered to be in a square of...
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.