<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Алгоритм поиска пути. Убрать gui из готового кода.]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=13708&amp;type=atom" />
	<updated>2018-05-14T22:16:29Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=13708</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Алгоритм поиска пути. Убрать gui из готового кода.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=125372#p125372" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>serzh82saratov пишет:</cite><blockquote><div class="codebox"><pre><code>&#039;%AB%&#039;</code></pre></div><p>Надо убрать кавычки.</p></blockquote></div><p>Спасибо огромное!!!</p>]]></content>
			<author>
				<name><![CDATA[Karagiozis]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=38736</uri>
			</author>
			<updated>2018-05-14T22:16:29Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=125372#p125372</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Алгоритм поиска пути. Убрать gui из готового кода.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=125370#p125370" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>&#039;%AB%&#039;</code></pre></div><p>Надо убрать кавычки.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2018-05-14T21:41:16Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=125370#p125370</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Алгоритм поиска пути. Убрать gui из готового кода.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=125359#p125359" />
			<content type="html"><![CDATA[<p>Разобрался.<br />Но возникла непонятная проблема.<br />Если в data вносить дистанцию через переменую, то почему-то путь показывает ACE, хотя ближе ABE.<br /></p><div class="codebox"><pre><code>
global d := {&quot;A&quot;: [0,0], &quot;B&quot;: [1,1], &quot;C&quot;: [-2,2], &quot;E&quot;: [2,3]}
AB := round(points_dist(&quot;A&quot;,&quot;B&quot;), 2)
AC := round(points_dist(&quot;A&quot;,&quot;C&quot;), 2)
BE := round(points_dist(&quot;B&quot;,&quot;E&quot;), 2)
CE := round(points_dist(&quot;C&quot;,&quot;E&quot;), 2)
msgbox, AB: %AB%`nAC: %AC%`nBE: %BE%`nCE: %CE%
data =
(
A	B	&#039;%AB%&#039;
A	C	&#039;%AC%&#039;
B	E	&#039;%BE%&#039;
C	E	&#039;%CE%&#039;
)
nodes:=[], Distance := []
for each, line in StrSplit(data, &quot;`n&quot; , &quot;`r&quot;)
{
    field := StrSplit(line,&quot;`t&quot;), nodes[field.1] := 1, nodes[field.2] := 1
    , Distance[field.1,field.2] := field.3  , Distance[field.2,field.1] := field.3
}
 
for node, v in nodes
    nodeList .= (nodeList?&quot;|&quot;:&quot;&quot;) node (A_Index=1?&quot;|&quot;:&quot;&quot;)

Gosub, Routing
Gosub, result
return

Routing:
arr := []
From := &quot;A&quot;
To := &quot;E&quot;
arr.Push(To)
res := Dijkstra(data, From)
Loop % objCount(nodes)
{
    for xTo , xFrom in res.2
	{
		if (xTo = To)
        {
			arr.insertAt(1, xFrom)
			To := xFrom
            if (xFrom = From)
				return
        }
	}
}
return

result:
for k, v in arr
{
	msgbox % v
}
return

Dijkstra(data, start){
	nodes := [], dist := [], Distance := [], dist := [], prev := [], Q := [], min := &quot;x&quot;
	for each, line in StrSplit(data, &quot;`n&quot; , &quot;`r&quot;)
	{
		field := StrSplit(line,&quot;`t&quot;), nodes[field.1] := 1, nodes[field.2] := 1
		, Distance[field.1,field.2] := field.3, Distance[field.2,field.1] := field.3
	}
	dist[start] := 0, prev[start] := &quot;&quot;
 
	for node in nodes {
		if (node &lt;&gt; start)
			dist[node] := &quot;x&quot;
			, prev[node] := &quot;&quot;
		Q[node] := 1
	}
 
	while % ObjCount(Q) {
		u := MinDist(Q, dist).2
		for node, val in Q
			if (node = u) {
				q.Remove(node)
				break
			}
 
		for v, length in Distance[u] {
			alt := dist[u] + length
			if (alt &lt; dist[v])
				dist[v] := alt	
				, prev[v] := u
		}
	}
	return [dist, prev]
}
;-----------------------------------------------
MinDist(Q, dist){
	for node , val in Q
		if A_Index=1
			min := dist[node], minNode := node
		else
			min := min &lt; dist[node] ? min : dist[node]	, minNode := min &lt; dist[node] ? minNode : node		
	return [min,minNode]
}
ObjCount(Obj){
	for key, val in Obj
		count := A_Index
	return count
}

getDist(pos1,pos2) {
	if(!pos1 || !pos2)
		return 0
    return Sqrt((pos1[1]-pos2[1])*(pos1[1]-pos2[1])+(pos1[2]-pos2[2])*(pos1[2]-pos2[2]))
}

points_dist(p1, p2)
{
	return getDist([d[p1][1],d[p1][2]],[d[p2][1],d[p2][2]])
}

</code></pre></div><p>Если дистанцию записать в ручную так, то нормально выводить результат ABE<br /></p><div class="codebox"><pre><code>
data =
(
A	B	1.41
A	C	2.83
B	E	2.24
C	E	4.12
)
nodes:=[], Distance := []
for each, line in StrSplit(data, &quot;`n&quot; , &quot;`r&quot;)
{
    field := StrSplit(line,&quot;`t&quot;), nodes[field.1] := 1, nodes[field.2] := 1
    , Distance[field.1,field.2] := field.3  , Distance[field.2,field.1] := field.3
}
 
for node, v in nodes
    nodeList .= (nodeList?&quot;|&quot;:&quot;&quot;) node (A_Index=1?&quot;|&quot;:&quot;&quot;)

Gosub, Routing
Gosub, result
return

Routing:
arr := []
From := &quot;A&quot;
To := &quot;E&quot;
arr.Push(To)
res := Dijkstra(data, From)
Loop % objCount(nodes)
{
    for xTo , xFrom in res.2
	{
		if (xTo = To)
        {
			arr.insertAt(1, xFrom)
			To := xFrom
            if (xFrom = From)
				return
        }
	}
}
return

result:
for k, v in arr
{
	msgbox % v
}
return

Dijkstra(data, start){
	nodes := [], dist := [], Distance := [], dist := [], prev := [], Q := [], min := &quot;x&quot;
	for each, line in StrSplit(data, &quot;`n&quot; , &quot;`r&quot;)
	{
		field := StrSplit(line,&quot;`t&quot;), nodes[field.1] := 1, nodes[field.2] := 1
		, Distance[field.1,field.2] := field.3, Distance[field.2,field.1] := field.3
	}
	dist[start] := 0, prev[start] := &quot;&quot;
 
	for node in nodes {
		if (node &lt;&gt; start)
			dist[node] := &quot;x&quot;
			, prev[node] := &quot;&quot;
		Q[node] := 1
	}
 
	while % ObjCount(Q) {
		u := MinDist(Q, dist).2
		for node, val in Q
			if (node = u) {
				q.Remove(node)
				break
			}
 
		for v, length in Distance[u] {
			alt := dist[u] + length
			if (alt &lt; dist[v])
				dist[v] := alt	
				, prev[v] := u
		}
	}
	return [dist, prev]
}
;-----------------------------------------------
MinDist(Q, dist){
	for node , val in Q
		if A_Index=1
			min := dist[node], minNode := node
		else
			min := min &lt; dist[node] ? min : dist[node]	, minNode := min &lt; dist[node] ? minNode : node		
	return [min,minNode]
}
ObjCount(Obj){
	for key, val in Obj
		count := A_Index
	return count
}

getDist(pos1,pos2) {
	if(!pos1 || !pos2)
		return 0
    return Sqrt((pos1[1]-pos2[1])*(pos1[1]-pos2[1])+(pos1[2]-pos2[2])*(pos1[2]-pos2[2]))
}

points_dist(p1, p2)
{
	return getDist([d[p1][1],d[p1][2]],[d[p2][1],d[p2][2]])
}
</code></pre></div><p>Помогите пожалуйста.</p>]]></content>
			<author>
				<name><![CDATA[Karagiozis]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=38736</uri>
			</author>
			<updated>2018-05-14T16:24:36Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=125359#p125359</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Алгоритм поиска пути. Убрать gui из готового кода.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=125342#p125342" />
			<content type="html"><![CDATA[<p>Доброй ночи.<br />Нашел алгоритм поиска пути, но не могу разобраться как убрать этот гуи.<br />Хотел бы без gui и получить результат пути в виде массива []<br /><a href="https://rosettacode.org/wiki/Dijkstra%27s_algorithm#AutoHotkey">https://rosettacode.org/wiki/Dijkstra%2 … AutoHotkey</a><br />P.S. в data надо заносить данные через таб, а не пробел.</p>]]></content>
			<author>
				<name><![CDATA[Karagiozis]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=38736</uri>
			</author>
			<updated>2018-05-14T00:14:24Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=125342#p125342</id>
		</entry>
</feed>
