Jump to content

Ideas to find a route - (Moved)


Recommended Posts

I am trying to solve a "routing" problem.

  • There is a given amount of gates (valves)
  • Each gate either be open or closed
  • Each gate is connected to one, two. three or four other gates

With two given gates I would like to know which gates in-between must be opened to have a connection. Not really sure how to approach this - could someone push me in the right direction?

 

I am aware that I could solve this task manually using a truth table, but that would neither be fun nor flexible SmileSmile

Edited by HurleyShanabarger
Link to comment
Share on other sites

  • Developers

Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Ok, if I understand correctly your drawings, the problem was to open gate 1 to gate 8.  So there is 3 possible solutions, right ?

Since there is a bridge between 1 and 2, it means that 6 is linked to 4 gates (1,2,5,7), while you said max links is 3...

Link to comment
Share on other sites

Here a suggestion how to represent the drawings numerically :

1(2,6)
2(1,3,6,8)
3(2,4,7)
4(3,5)
5(4,6)
6(5,7)
7(3,6)
8(2)

So everyone who wishes to play with your riddle can start with the same representation...

Edited by Nine
typo / corrected paths
Link to comment
Share on other sites

1 hour ago, HurleyShanabarger said:

The input data I have is a drawing, I tried to abstract it.
I don't request someone to solve this for me, but any help is very much appreciated

is it lemons ? is it car doors ? is it valves in a nuclear station ? is it a hardware or software thing ?
Being vague does not aid helping you. Just state what in real life is you need to get done.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

There you go.  That was fun :).

#include <Array.au3>

Local $sGates = _
  "1(2,6)" & _
  "2(1,3,6,8)" & _
  "3(2,4,7)" & _
  "4(3,5)" & _
  "5(4,6)" & _
  "6(5,7)" & _
  "7(3,6)" & _
  "8(2)"

Local $aTemp = StringSplit($sGates, ")"), $aArr
Local $aGate[$aTemp[0]][2] = [[$aTemp[0] - 1, 0]]
For $i = 1 to $aTemp[0] - 1
  $aArr = StringSplit($aTemp[$i], "(,", $STR_NOCOUNT)
  $aGate[$i][0] = $aArr[0]
  _ArrayDelete($aArr, 0)
  $aGate[$i][1] = $aArr
Next

OpenGate(1, "1", 8)

Func OpenGate($iStart, $sPath, $iEnd)
  For $i = 0 to UBound($aGate[$iStart][1]) - 1
    If ($aGate[$iStart][1])[$i] = $iEnd Then Return ConsoleWrite($sPath & "|" & $iEnd & @CRLF)
    If StringInStr($sPath, String(($aGate[$iStart][1])[$i])) Then ContinueLoop
    OpenGate(($aGate[$iStart][1])[$i], $sPath & "|" & ($aGate[$iStart][1])[$i], $iEnd)
  Next
EndFunc

I needed to change the links a bit, since 6 cannot send to 1 and 2.  It can receive from 1 and 2, but not send.  Untested with other path than from 1 to 8.  I'll let you play with my riddle now ;)

Link to comment
Share on other sites

..some of my knowing comes from aviation. Make sure that if an error can create a safety problem, to take measures to attend to that too. Automated systems should include what to default to, or do, in case of failures. So the system may need more than just, send a signal, with the expectancy that what is intended will occur, as it may not behave as expected, outside the lab. with possible real world "oops" . My 2 cents. 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Your problem can be solved by well-known results established by the Graph Theory. Depending on characteristics of your devices/problem, generic solutions and algorithms are likely to apply.

For instance, is the flow of hydraulics between valves oriented in all/some/none of the valves?

Can cycles occur in the graph?

Do you want to get the shortest path between two valves, any path, all possible pathes?

Read on about DAGs, Trees, Forests, simple graphs and you'll learn howto tackle this kind of problem

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Thank you all for thje input and your work.

 

12 hours ago, Nine said:

There you go.  That was fun :).

I needed to change the links a bit, since 6 cannot send to 1 and 2.  It can receive from 1 and 2, but not send.  Untested with other path than from 1 to 8.  I'll let you play with my riddle now ;)

Glad that you enjoyed it, and this one approach that also crossed my mind. I will try to understand and adapt this for my porpose.

 

11 hours ago, argumentum said:

..some of my knowing comes from aviation. Make sure that if an error can create a safety problem, to take measures to attend to that too. Automated systems should include what to default to, or do, in case of failures. So the system may need more than just, send a signal, with the expectancy that what is intended will occur, as it may not behave as expected, outside the lab. with possible real world "oops" . My 2 cents. 

Thanks you for pointing this out. Due to covid and part shortage we are currently not able to the new scenarios on real hardware, which would be the pre-validation. Settings/control of valves ist done by and external control. Within a simulation we want to see in which scenarios sensors connected to the system would measure flow/pressure/temperature depending on the valve position. My goal is to determine this exactly by using some scripting apporach. But I will keep the real world "oopsies" in mind and will use any solution only as guide and have it reviewed/triple checked.

 

8 hours ago, jchd said:

Your problem can be solved by well-known results established by the Graph Theory. Depending on characteristics of your devices/problem, generic solutions and algorithms are likely to apply.

For instance, is the flow of hydraulics between valves oriented in all/some/none of the valves?

Can cycles occur in the graph?

Do you want to get the shortest path between two valves, any path, all possible pathes?

Read on about DAGs, Trees, Forests, simple graphs and you'll learn howto tackle this kind of problem

That looks interesting. Not really the kind of theory I like, but sometimes what someones likes and what is required to get the job done are completley different things. Thank you very much.

 

I also gave my simplification some thoughts and realized after the feedback from @argumentum and @jchd, that there is more to it than my simplification provides. Once I figured on how to show this I will share it with you!

Link to comment
Share on other sites

This is just a variant of TSP, see the simulated annealing thread for example code.

Edited by RTFC
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...