This forum is in archive mode. You will not be able to post new content.

Author Topic: urgent....  (Read 1919 times)

0 Members and 1 Guest are viewing this topic.

Offline cyberdemon

  • /dev/null
  • *
  • Posts: 9
  • Cookies: -2
    • View Profile
urgent....
« on: October 20, 2012, 10:46:33 AM »
dear all,
          pls give the c code for problem below


 Testing the traversal through different screens
 Mr. Ajay is a test expert and he has an innovative approach to testing. His current assignment is to test a particular application which traverses through multiple screens.
 One screen can be traversed in multiple ways. The server response time to traverse between screens is different.
 The circles in the diagram represent the screens and if the screens are connected by edges, it means that the screen can be traversed from the connecting screen. The numbers associated with the edges represent the minimum response time in microseconds between the screens.
 He has to navigate from one screen to a destination screen and return to origin screen, visiting each screen exactly once.. What is the fastest way to perform this traversal.
 If he has to navigate from 1 to 7, the navigation path he takes is 1-4-6-7-5-2-1
 
 But, Mr. Ajay finds it difficult to find the fastest route himself so he seeks help.
 PS: always calculate the path from the first node to the last node and back
 Input
 The first line of test case will contain two integers: N(N<= 100) and R representing respectively the number of screens and the connection between screens. Then R lines will follow each containing three integers: C1, C2 and P.  C1 and C2 are the screen numbers and P (P>1) is the limit on the minimum server response time to navigate to the screen. Screen numbers are positive integers ranging from 1 to N.
 
 Output
 For each test case in the input first output the scenario number. Then output the fastest way to traverse the screen exactly once and return to the origin screen.
 
 Sample Input
 7 10
 1 2 30
 1 3 20
 1 4 10
 2 4 25
 2 5 60
 3 6 70
 4 7 35
 4 6 20
 5 7 10
 6 7 15
 Sample Output
 145

Offline kateus

  • Peasant
  • *
  • Posts: 89
  • Cookies: 11
  • scientia potentia est
    • View Profile
Re: urgent....
« Reply #1 on: October 20, 2012, 02:12:23 PM »
If I were you, I would use  Dijkstra's Shortest path algorithm (https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm) to find the shortest path from start to destination then just multiply it by two for the way back.

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: urgent....
« Reply #2 on: October 20, 2012, 02:50:43 PM »
Quote
dear all,
          pls give the c code for problem below

No one will spoonfeed you. Show at least that you try to do it yourself or you won't have any luck here.
I give you a hint, though. This is the travelling salesman problem. Google it. You will find a lot examples and explanations.

If I were you, I would use  Dijkstra's Shortest path algorithm (https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm) to find the shortest path from start to destination then just multiply it by two for the way back.

That doesn't take into account that every node has to be visited exactly once.
« Last Edit: October 20, 2012, 02:58:29 PM by Deque »

Offline kateus

  • Peasant
  • *
  • Posts: 89
  • Cookies: 11
  • scientia potentia est
    • View Profile
Re: urgent....
« Reply #3 on: October 20, 2012, 03:08:06 PM »
No one will spoonfeed you. Show at least that you try to do it yourself or you won't have any luck here.
I give you a hint, though. This is the travelling salesman problem. Google it. You will find a lot examples and explanations.

That doesn't take into account that every node has to be visited exactly once.

Must have missed that part. But yeah, traveling salesman is the way to go in this case.

Offline Xires

  • Noob Eater
  • Administrator
  • Knight
  • *
  • Posts: 379
  • Cookies: 149
    • View Profile
    • Feed The Trolls - Xires
Re: urgent....
« Reply #4 on: October 23, 2012, 03:05:54 PM »
Dijkstra provides shortest path but not necessarily fastest because it doesn't correctly judge the path cost which is what A* is all about.  However, as pointed out, neither will necessarily give you the 'visited exactly once' requirement that you're looking for.  On the other hand, the basic structure should start the same way.  A simple graph using nodes/vertexes & edges is your basic data structure.  Traversal needs to be measured and a heuristic calculated.  You will want to begin much the way that other path-finding algorithms do and probably with a BFS(breadth first search) approach.  Measure your edge costs and try to determine what the cheapest one is.  Mark nodes as visited as you traverse.  If the path is invalid -- meaning that you get locked into a position where you cannot move on to an unvisited node without visiting an already visited node but there are still unvisited nodes in the graph -- then you will need to record the path for comparison and probably try to reverse the traversal to a point where a different path can be chosen.  This task can be a serious PITA but it's not overly difficult, just time consuming and requires adequate forethought.  I strongly suggest that you whiteboard it first.
-Xires

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.