Per 2016, RMID pindah ke RMID Discord (Invite link dihapus untuk mencegah spambot -Theo @ 2019). Posting sudah tidak bisa dilakukan lagi.
Mohon maaf atas ketidaknyamanannya dan mohon kerjasamanya.
|
|
| [GML] Dijkstra's Algorithm (Beta) | |
| 2010-10-24, 23:40 | [GML] Dijkstra's Algorithm (Beta) |
---|
bungatepijalan Moe Princess
Posts : 1487 Thanked : 30 Engine : Multi-Engine User Skill : Intermediate Type : Developer
Awards:
| - Overview:
Algoritma Dijkstra adalah algoritma yang mencari suatu "jalan" terpendek menuju "titik" tujuan dari "titik" asal.
Script: hapus - Code:
-
// hapus(ii) //where ii is index of vertex to be removed from unvisited vertex array q. ii=argument0 for(iii=1;iii<=nq;iii+=1) if(q[iii]==ii) iv=iii; if(iv<=nq){ if(iv<nq){ for(iii=iv;iii<=nq-1;iii+=1){ q[iii]=q[iii+1] } } nq-=1 } Script: ketemu - Code:
-
// ketemu(ii) //where ii is index of vertex to be searched in vertex array q. ii=argument0 ff=false for(iii=1;iii<=nq;iii+=1){ if(q[iii]==ii) ff=true } return ff Script: dijkstra - Code:
-
// dijkstra(s) //where s is index of source vertex. // //Required data //vertices_dist[i]: Path distance from i to source s //vertices_prev[i]: Previous path vertex from vertex i //vertices_neighbors[i]: Number of neighbors of vertex i //vertices_neighbor[i,j]: j-th neighbor vertex index of vertex i //vertices_distb[i,j]: Distance between vertex i and j-th neighbor vertex of vertex i s=argument0 for(i=1;i<=n;i+=1){ vertices_dist[i]=99999 vertices_prev[i]=0 q[i]=i nq=n } vertices_dist[s]=0; while(nq>0){ d=vertices_dist[q[1]] u=q[1] if(nq>1){ for(ii=2;ii<=nq;i+=1){ if(vertices_dist[q[ii]]<d){ d=vertices_dist[q[ii]]; u=q[ii]; } } }
if(vertices_dist[u]==99999) break; hapus(u); if(vertices_neighbors[u]>0){ for(i=1;i<=vertices_neighbors[u];i+=1){ v=vertices_neighbor[u,i] if(ketemu(v)){ alt=vertices_dist[u]+vertices_distb[u,i] if(alt<vertices_dist[v]){ vertices_dist[v]=alt; vertices_prev[v]=u; } } } } } Fungsi: mencari "jalan" terpendek menuju "titik" tujuan dari "titik" asal
Cara pemasangan: - Buat tiga script baru, kasi nama hapus, ketemu, dan dijkstra - Copas masing-masing bagian code di atas ke masing2 script tersebut - Implementasikan script-script tersebut ke action Execute a piece of code. Namun array-array (vertices_*) harus diinisialisasi datanya terlebih dahulu.
Created by: Bunga Tepi Jalan
Credits - http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
NB: Lihat konsep dan prinsip Algoritma Dijkstra di: http://ancuracademy.forumotion.net/programming-f13/programming-dijkstra-s-algorithm-t11.htm Script Algoritma Dijkstra versi bahasa Pascal: http://prodig.forumotion.net/pascal-f54/pascal-dijkstra-s-algorithm-t271.htm |
| | | 2011-01-05, 12:42 | Re: [GML] Dijkstra's Algorithm (Beta) |
---|
Pi-Man Novice
Posts : 115 Thanked : 0 Engine : Other Skill : Intermediate Type : Developer
| Dikasih info juga, scriptnya untuk versi pro, atau bisa juga untuk lite Pi-man |
| | | 2011-01-06, 00:53 | Re: [GML] Dijkstra's Algorithm (Beta) |
---|
KID_VX Senior
Posts : 959 Thanked : 24 Engine : Multi-Engine User Skill : Very Beginner Type : Developer
| woh baru tau, jadi versi lite scriptnya di limit gitu ? daku kira plugin dan add on nya saja maklum bukan pengguna GM |
| | | 2011-01-19, 09:39 | Re: [GML] Dijkstra's Algorithm (Beta) |
---|
bungatepijalan Moe Princess
Posts : 1487 Thanked : 30 Engine : Multi-Engine User Skill : Intermediate Type : Developer
Awards:
| Maap telat bgt ngepostnya Nah, ini scriptnya yang udah stable
- Script: hapus:
- Code:
-
ii=argument0 for(iii=1;iii<=nq;iii+=1){ if(q[iii]==ii) iv=iii; } if(iv<=nq){ if(iv<nq){ for(iii=iv;iii<=nq-1;iii+=1){ q[iii]=q[iii+1]; } } nq=nq-1; }
- Script: ketemu:
- Code:
-
ii=argument0 ff=false; for(iii=1;iii<=nq;iii+=1){ if(q[iii]==ii) ff=true; } return ff;
- Script: dijkstra:
- Code:
-
// dijkstra //where s is index of source vertex. // //Required data //M[i,j]: Distance from vertex i to vertex j
for(i=1;i<=n;i+=1){ vertices_dist[i]=99999 vertices_prev[i]=0 q[i]=i nq=n } vertices_dist[s]=0; while(nq>0){ d=vertices_dist[q[1]] u=q[1] if(nq>1){ for(ii=2;ii<=nq;ii+=1){ if(vertices_dist[q[ii]]<d){ d=vertices_dist[q[ii]]; u=q[ii]; } } }
if(vertices_dist[u]==99999) break; hapus(u); for(i=1;i<=n;i+=1){ if(M[u,i]<99999 && M[u,i]>0){ if(ketemu(i)){ alt=vertices_dist[u]+M[u,i] if(alt<vertices_dist[i]){ vertices_dist[i]=alt; vertices_prev[i]=u; } } } } } Dan juga algoritma Dijkstra dalam script LPM (Listra Pathfinder Module) - Code:
-
/* Dijkstra's Algorithm
@> Function * To find a shortest path from starting vertex (s) to target vertex (t) and return path distance from s to t.
@> Required Data * n: number of grid vertices * s: index of source vertex * t: index of target vertex * global.nb[u,i]: i-th neighbor of grid vertex u, whose distance from u is 1 (as vertex index) * global.tc[u,i]: terrain cost from u to global.nb[u,i] (equal to 1 normally) * global.neighbors: maximum number of each vertices (usually 4 for 4-directional movement or 8 for 8-directional movement)
@> Required Scripts * remove(x): Removes x from array q (as priority queue) * add(x): Inserts x into array q (as priority queue) * u_nearest(): Returns index u of array q, where vertices_dist[u] is smallest
@> Usage Guide * For graph initialization, build a passage graph with script buildGraph(). * Then use this script on a game character. Set its variables s as index of the target's position vertex and t as index of the character's position vertex. * After that, you can trace the character's path by using vertices_prev[t]. * You can also use vertices_dist[t] or value returned by this script to show the character's distance to the target.
@> Credits * Bunga Tepi Jalan (bungatepijalan.wordpress.com) * Wikipedia
@> Notes * If you want to learn more about Dijkstra's algorithm, see the article at: http://en.wikipedia.org/wiki/Dijkstra's_algorithm * The path constructed by this algorithm is always the shortest. * This script is made based on pseudocode at that article, with improvement on efficiency. */
// Initializations nq=0 // Create open list q (as priority queue) add(s) // Add s into open list q for(i=1;i<=n;i+=1){ vertices_dist[i]=9999 // Unknown distance function from source to v vertices_prev[i]=0 // Previous node in optimal path from source } vertices_dist[s]=0 // Distance from source to source while(nq>0){ // The main loop //Finds vertex u with least value of path distance u_nearest() dist_u=vertices_dist[u] if(u==t){ //If u is the target, search completed and returns its distance. //You can add statements here, usually to read/construct path return dist_u } remove(u) for(i=1;i<=global.neighbors;i+=1){ v=global.nb[u,i] // where v has not yet been removed from Q. if(v!=0){ alt=dist_u+global.tc[u,i] if(alt<vertices_dist[v]){ // Relax (u,v) add(v) vertices_dist[v]=alt vertices_prev[v]=u buildpanah(v) } } } } //Statements below this will be executed if all remaining vertices //are inaccessible from source. This means that target vertex is isolated //from source vertex. Also means that vertices_dist[t]==9999. //You can add them here, usually to alert that no path is found. Don't forget to credit me if you want to use this
@Pi-Man Dari isi scriptnya, ya jelaslah bisa utk versi apapun |
| | | | Re: [GML] Dijkstra's Algorithm (Beta) |
---|
Sponsored content
| | | | | [GML] Dijkstra's Algorithm (Beta) | |
|
Similar topics | |
|
Similar topics | |
| |
Halaman 1 dari 1 | |
| Permissions in this forum: | Anda tidak dapat menjawab topik
| |
| |
Latest 10 Topics | [Web Novel] Gloria Infidelis 2016-11-17, 21:27 by LightNightKnight
[Announcement] Forum baru untuk RMID 2016-08-25, 16:39 by TheoAllen
Where I'm Wrong ? 2016-07-24, 16:10 by ReydVires
flakeheartnet's Resources part III 2016-07-08, 14:30 by flakeheartnet
Keira's Art Warehouse 2016-06-28, 19:27 by KeiraBlaze
Theo Core Time System + Bingung 2016-06-27, 16:24 by Lockin
Error Script, Maybe ? 2016-06-27, 16:20 by Lockin
Nusaimoe @ RMID Lounge 2016-06-21, 05:02 by Jihad Bagas
Call Random Battle 2016-06-15, 17:04 by Lockin
Flakeheartnet Resources Part II [come back gift] 2016-06-07, 15:51 by flakeheartnet
|
Statistics
|
Members: [ 4947 ]
Topics: [ 8258 ]
Posts: [ 112606 ]
Newest member: [ https://rmid.forumotion.net/u4968 ]
|
|
|
|
|
|